jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java
changeset 12458 d601e4bba306
parent 12457 c348e06f0e82
child 16953 a44e04deb948
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java	Tue Apr 17 11:17:59 2012 -0700
@@ -49,6 +49,7 @@
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.URIResolver;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
@@ -64,11 +65,14 @@
 import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler;
 import com.sun.org.apache.xml.internal.utils.StopParseException;
 
+import com.sun.org.apache.xalan.internal.XalanConstants;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
 import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
+import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
 
 
 import org.xml.sax.InputSource;
@@ -212,11 +216,28 @@
      * <p>State of secure mode.</p>
      */
     private boolean _isSecureMode = false;
+
+    /**
+     * Indicates whether implementation parts should use
+     *   service loader (or similar).
+     * Note the default value (false) is the safe option..
+     */
+    private boolean _useServicesMechanism;
+
     /**
      * javax.xml.transform.sax.TransformerFactory implementation.
      */
     public TransformerFactoryImpl() {
-        m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass();
+        this(true);
+    }
+
+    public static TransformerFactory newTransformerFactoryNoServiceLoader() {
+        return new TransformerFactoryImpl(false);
+    }
+
+    private TransformerFactoryImpl(boolean useServicesMechanism) {
+        this.m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(useServicesMechanism);
+        this._useServicesMechanism = useServicesMechanism;
         if (System.getSecurityManager() != null) {
             _isSecureMode = true;
             _isNotSecureProcessing = false;
@@ -274,6 +295,12 @@
         else if (name.equals(AUTO_TRANSLET)) {
             return new Boolean(_autoTranslet);
         }
+        else if (name.equals(ENABLE_INLINING)) {
+            if (_enableInlining)
+              return Boolean.TRUE;
+            else
+              return Boolean.FALSE;
+        }
 
         // Throw an exception for all other attributes
         ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name);
@@ -420,6 +447,11 @@
             // all done processing feature
             return;
         }
+        else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) {
+            //in secure mode, let _useServicesMechanism be determined by the constructor
+            if (!_isSecureMode)
+                _useServicesMechanism = value;
+        }
         else {
             // unknown feature
             ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name);
@@ -448,7 +480,8 @@
             StreamSource.FEATURE,
             StreamResult.FEATURE,
             SAXTransformerFactory.FEATURE,
-            SAXTransformerFactory.FEATURE_XMLFILTER
+            SAXTransformerFactory.FEATURE_XMLFILTER,
+            XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM
         };
 
         // feature name cannot be null
@@ -471,6 +504,12 @@
         // Feature not supported
         return false;
     }
+    /**
+     * Return the state of the services mechanism feature.
+     */
+    public boolean useServicesMechnism() {
+        return _useServicesMechanism;
+    }
 
     /**
      * javax.xml.transform.sax.TransformerFactory implementation.
@@ -543,7 +582,7 @@
                 isource = SAXSource.sourceToInputSource(source);
                 baseId = isource.getSystemId();
 
-                SAXParserFactory factory = SAXParserFactory.newInstance();
+                SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism);
                 factory.setNamespaceAware(true);
 
                 if (!_isNotSecureProcessing) {
@@ -702,8 +741,7 @@
                 transletName = _packageName + "." + transletName;
 
             try {
-                final Class clazz = ObjectFactory.findProviderClass(
-                    transletName, ObjectFactory.findClassLoader(), true);
+                final Class clazz = ObjectFactory.findProviderClass(transletName, true);
                 resetTransientAttributes();
 
                 return new TemplatesImpl(new Class[]{clazz}, transletName, null, _indentNumber, this);
@@ -753,9 +791,13 @@
         }
 
         // Create and initialize a stylesheet compiler
-        final XSLTC xsltc = new XSLTC();
+        final XSLTC xsltc = new XSLTC(_useServicesMechanism);
         if (_debug) xsltc.setDebug(true);
-        if (_enableInlining) xsltc.setTemplateInlining(true);
+        if (_enableInlining)
+                xsltc.setTemplateInlining(true);
+        else
+                xsltc.setTemplateInlining(false);
+
         if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true);
         xsltc.init();