The getDOM method might be entered more than once during a transformation, so
the DTMManager that is created the first time in must be saved so that
subsequent DTM's can be created with respect to it, and then discarded at the
end of the transformation.

This change restores logic that I had foolishly eliminated with my previous
change to this file.


git-svn-id: https://svn.apache.org/repos/asf/xalan/java/trunk@337798 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/apache/xalan/xsltc/trax/TransformerImpl.java b/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
index 9b821ed..633749e 100644
--- a/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
+++ b/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
@@ -193,6 +193,12 @@
     private TransformerFactoryImpl _tfactory = null;
 
     /**
+     * A reference to the XSLTCDTMManager which is used to build the DOM/DTM
+     * for this transformer.
+     */
+    private XSLTCDTMManager _dtmManager = null;
+
+    /**
      * A reference to an object that creates and caches XMLReader objects.
      */
     private XMLReaderManager _readerManager = XMLReaderManager.getInstance();
@@ -463,10 +469,12 @@
                  boolean hasIdCall = (_translet != null) ? _translet.hasIdCall()
                                                          : false;
 
-                 XSLTCDTMManager dtmManager =
+                 if (_dtmManager == null) {
+                     _dtmManager =
                          (XSLTCDTMManager)_tfactory.getDTMManagerClass()
                                                    .newInstance();
-                 dom = (DOM)dtmManager.getDTM(source, false, wsfilter, true,
+                 }
+                 dom = (DOM)_dtmManager.getDTM(source, false, wsfilter, true,
                                               false, false, 0, hasIdCall);
             } else if (_dom != null) {
                  dom = _dom;
@@ -492,6 +500,14 @@
         }
     }
  
+    /**
+     * Returns the {@link org.apache.xalan.xsltc.trax.TransformerFactoryImpl}
+     * object that create this <code>Transformer</code>.
+     */
+    protected TransformerFactoryImpl getTransformerFactory() {
+        return _tfactory;
+    }
+
     private void transformIdentity(Source source, SerializationHandler handler)
 	throws Exception 
     {
@@ -595,7 +611,7 @@
              * situations, since there is no clear spec. how to create 
              * an empty tree when both SAXSource() and StreamSource() are used.
              */
-             if ((source instanceof StreamSource && source.getSystemId()==null 
+            if ((source instanceof StreamSource && source.getSystemId()==null 
                 && ((StreamSource)source).getInputStream()==null &&
                 ((StreamSource)source).getReader()==null)||
                 (source instanceof SAXSource &&
@@ -614,26 +630,24 @@
                         if (systemID != null) {
                           source.setSystemId(systemID);
                         }
-             }           
+            }           
 	    if (_isIdentity) {
 		transformIdentity(source, handler);
-	    }
-	    else {
+	    } else {
 		_translet.transform(getDOM(source), handler);
 	    }
-	}
-	catch (TransletException e) {
+	} catch (TransletException e) {
 	    if (_errorListener != null)	postErrorToListener(e.getMessage());
 	    throw new TransformerException(e);
-	}
-	catch (RuntimeException e) {
+	} catch (RuntimeException e) {
 	    if (_errorListener != null)	postErrorToListener(e.getMessage());
 	    throw new TransformerException(e);
-	}
-	catch (Exception e) {
+	} catch (Exception e) {
 	    if (_errorListener != null)	postErrorToListener(e.getMessage());
 	    throw new TransformerException(e);
-	}
+	} finally {
+            _dtmManager = null;
+        }
     }
 
     /**