src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java

Print this page

        

@@ -21,10 +21,21 @@
  * $Id: TransformerFactoryImpl.java,v 1.8 2007/04/09 21:30:41 joehw Exp $
  */
 
 package com.sun.org.apache.xalan.internal.xsltc.trax;
 
+import com.sun.org.apache.xalan.internal.XalanConstants;
+import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
+import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
+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.xml.internal.utils.StopParseException;
+import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
 import java.io.IOException;

@@ -35,15 +46,13 @@
 import java.util.Hashtable;
 import java.util.Properties;
 import java.util.Vector;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
-
 import javax.xml.XMLConstants;
-import javax.xml.parsers.SAXParserFactory;
 import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
 
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.Source;
 import javax.xml.transform.Templates;
 import javax.xml.transform.Transformer;

@@ -56,27 +65,13 @@
 import javax.xml.transform.sax.SAXResult;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.sax.TemplatesHandler;
 import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stax.*;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
-import javax.xml.transform.stax.*;
-
-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 com.sun.org.apache.xalan.internal.utils.SecuritySupport;
-
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLFilter;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 

@@ -199,18 +194,10 @@
      * Number of indent spaces when indentation is turned on.
      */
     private int _indentNumber = -1;
 
     /**
-     * The provider of the XSLTC DTM Manager service.  This is fixed for any
-     * instance of this class.  In order to change service providers, a new
-     * XSLTC <code>TransformerFactory</code> must be instantiated.
-     * @see XSLTCDTMManager#getDTMManagerClass()
-     */
-    private Class m_DTMManagerClass;
-
-    /**
      * <p>State of secure processing feature.</p>
      */
     private boolean _isNotSecureProcessing = true;
     /**
      * <p>State of secure mode.</p>

@@ -244,11 +231,10 @@
     public static TransformerFactory newTransformerFactoryNoServiceLoader() {
         return new TransformerFactoryImpl(false);
     }
 
     private TransformerFactoryImpl(boolean useServicesMechanism) {
-        this.m_DTMManagerClass = XSLTCDTMManager.getDTMManagerClass(useServicesMechanism);
         this._useServicesMechanism = useServicesMechanism;
 
         String defaultAccess = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
         if (System.getSecurityManager() != null) {
             _isSecureMode = true;

@@ -268,10 +254,11 @@
      * transformation itself.
      *
      * @param listener The error listener to use with the TransformerFactory
      * @throws IllegalArgumentException
      */
+    @Override
     public void setErrorListener(ErrorListener listener)
         throws IllegalArgumentException
     {
         if (listener == null) {
             ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,

@@ -285,10 +272,11 @@
      * javax.xml.transform.sax.TransformerFactory implementation.
      * Get the error event handler for the TransformerFactory.
      *
      * @return The error listener used with the TransformerFactory
      */
+    @Override
     public ErrorListener getErrorListener() {
         return _errorListener;
     }
 
     /**

@@ -297,10 +285,11 @@
      *
      * @param name The attribute name
      * @return An object representing the attribute value
      * @throws IllegalArgumentException
      */
+    @Override
     public Object getAttribute(String name)
         throws IllegalArgumentException
     {
         // Return value for attribute 'translet-name'
         if (name.equals(TRANSLET_NAME)) {

@@ -336,10 +325,11 @@
      *
      * @param name The attribute name
      * @param value An object representing the attribute value
      * @throws IllegalArgumentException
      */
+    @Override
     public void setAttribute(String name, Object value)
         throws IllegalArgumentException
     {
         // Set the default translet name (ie. class name), which will be used
         // for translets that cannot be given a name from their system-id.

@@ -458,10 +448,11 @@
      *
      * @throws TransformerConfigurationException if this <code>TransformerFactory</code>
      *   or the <code>Transformer</code>s or <code>Template</code>s it creates cannot support this feature.
      * @throws NullPointerException If the <code>name</code> parameter is null.
      */
+    @Override
     public void setFeature(String name, boolean value)
         throws TransformerConfigurationException {
 
         // feature name cannot be null
         if (name == null) {

@@ -502,10 +493,11 @@
      * class are implemented.
      *
      * @param name The feature name
      * @return 'true' if feature is supported, 'false' if not
      */
+    @Override
     public boolean getFeature(String name) {
         // All supported features should be listed here
         String[] features = {
             DOMSource.FEATURE,
             DOMResult.FEATURE,

@@ -553,10 +545,11 @@
      * resolve URIs used in document(), xsl:import, or xsl:include.
      *
      * @return The URLResolver used for this TransformerFactory and all
      * Templates and Transformer objects created using this factory
      */
+    @Override
     public URIResolver getURIResolver() {
         return _uriResolver;
     }
 
     /**

@@ -567,10 +560,11 @@
      * created with this factory.
      *
      * @param resolver The URLResolver used for this TransformerFactory and all
      * Templates and Transformer objects created using this factory
      */
+    @Override
     public void setURIResolver(URIResolver resolver) {
         _uriResolver = resolver;
     }
 
     /**

@@ -586,17 +580,18 @@
      * @param title The value of the title attribute to match. May be null.
      * @param charset The value of the charset attribute to match. May be null.
      * @return A Source object suitable for passing to the TransformerFactory.
      * @throws TransformerConfigurationException
      */
+    @Override
     public Source  getAssociatedStylesheet(Source source, String media,
                                           String title, String charset)
         throws TransformerConfigurationException {
 
         String baseId;
-        XMLReader reader = null;
-        InputSource isource = null;
+        XMLReader reader;
+        InputSource isource;
 
 
         /**
          * Fix for bugzilla bug 24187
          */

@@ -674,10 +669,11 @@
      * Create a Transformer object that copies the input document to the result.
      *
      * @return A Transformer object that simply copies the source to the result.
      * @throws TransformerConfigurationException
      */
+    @Override
     public Transformer newTransformer()
         throws TransformerConfigurationException
     {
         TransformerImpl result = new TransformerImpl(new Properties(),
             _indentNumber, this);

@@ -699,10 +695,11 @@
      * and every transformation.
      *
      * @return A Templates object that can be used to create Transformers.
      * @throws TransformerConfigurationException
      */
+    @Override
     public Transformer newTransformer(Source source) throws
         TransformerConfigurationException
     {
         final Templates templates = newTemplates(source);
         final Transformer transformer = templates.newTransformer();

@@ -762,10 +759,11 @@
      *
      * @param source The input stylesheet - DOMSource not supported!!!
      * @return A Templates object that can be used to create Transformers.
      * @throws TransformerConfigurationException
      */
+    @Override
     public Templates newTemplates(Source source)
         throws TransformerConfigurationException
     {
         // If the _useClasspath attribute is true, try to load the translet from
         // the CLASSPATH and create a template object using the loaded

@@ -795,11 +793,11 @@
         }
 
         // If _autoTranslet is true, we will try to load the bytecodes
         // from the translet classes without compiling the stylesheet.
         if (_autoTranslet)  {
-            byte[][] bytecodes = null;
+            byte[][] bytecodes;
             String transletClassName = getTransletBaseName(source);
 
             if (_packageName != null)
                 transletClassName = _packageName + "." + transletClassName;
 

@@ -917,11 +915,11 @@
         }
 
         // Check that the transformation went well before returning
     if (bytecodes == null) {
         Vector errs = xsltc.getErrors();
-        ErrorMsg err = null;
+        ErrorMsg err;
         if (errs != null) {
             err = (ErrorMsg)errs.elementAt(errs.size()-1);
         } else {
             err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
         }

@@ -962,10 +960,11 @@
      * events into a Templates object.
      *
      * @return A TemplatesHandler object that can handle SAX events
      * @throws TransformerConfigurationException
      */
+    @Override
     public TemplatesHandler newTemplatesHandler()
         throws TransformerConfigurationException
     {
         final TemplatesHandlerImpl handler =
             new TemplatesHandlerImpl(_indentNumber, this);

@@ -981,10 +980,11 @@
      * events into a Result. This method will return a pure copy transformer.
      *
      * @return A TransformerHandler object that can handle SAX events
      * @throws TransformerConfigurationException
      */
+    @Override
     public TransformerHandler newTransformerHandler()
         throws TransformerConfigurationException
     {
         final Transformer transformer = newTransformer();
         if (_uriResolver != null) {

@@ -1001,10 +1001,11 @@
      *
      * @param src The source of the transformation instructions.
      * @return A TransformerHandler object that can handle SAX events
      * @throws TransformerConfigurationException
      */
+    @Override
     public TransformerHandler newTransformerHandler(Source src)
         throws TransformerConfigurationException
     {
         final Transformer transformer = newTransformer(src);
         if (_uriResolver != null) {

@@ -1021,10 +1022,11 @@
      *
      * @param templates Represents a pre-processed stylesheet
      * @return A TransformerHandler object that can handle SAX events
      * @throws TransformerConfigurationException
      */
+    @Override
     public TransformerHandler newTransformerHandler(Templates templates)
         throws TransformerConfigurationException
     {
         final Transformer transformer = templates.newTransformer();
         final TransformerImpl internal = (TransformerImpl)transformer;

@@ -1038,10 +1040,11 @@
      *
      * @param src The source of the transformation instructions.
      * @return An XMLFilter object, or null if this feature is not supported.
      * @throws TransformerConfigurationException
      */
+    @Override
     public XMLFilter newXMLFilter(Source src)
         throws TransformerConfigurationException
     {
         Templates templates = newTemplates(src);
         if (templates == null) return null;

@@ -1055,10 +1058,11 @@
      *
      * @param templates The source of the transformation instructions.
      * @return An XMLFilter object, or null if this feature is not supported.
      * @throws TransformerConfigurationException
      */
+    @Override
     public XMLFilter newXMLFilter(Templates templates)
         throws TransformerConfigurationException
     {
         try {
             return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);

@@ -1086,10 +1090,11 @@
      * @param e The warning information encapsulated in a transformer
      * exception.
      * @throws TransformerException if the application chooses to discontinue
      * the transformation (always does in our case).
      */
+    @Override
     public void error(TransformerException e)
         throws TransformerException
     {
         Throwable wrapped = e.getException();
         if (wrapped != null) {

@@ -1114,10 +1119,11 @@
      * @param e warning information encapsulated in a transformer
      * exception.
      * @throws TransformerException if the application chooses to discontinue
      * the transformation (always does in our case).
      */
+    @Override
     public void fatalError(TransformerException e)
         throws TransformerException
     {
         Throwable wrapped = e.getException();
         if (wrapped != null) {

@@ -1142,10 +1148,11 @@
      * @param e The warning information encapsulated in a transformer
      * exception.
      * @throws TransformerException if the application chooses to discontinue
      * the transformation (never does in our case).
      */
+    @Override
     public void warning(TransformerException e)
         throws TransformerException
     {
         Throwable wrapped = e.getException();
         if (wrapped != null) {

@@ -1165,10 +1172,11 @@
      * @param href The URI of the document to load
      * @param context The URI of the currently loaded document
      * @param xsltc The compiler that resuests the document
      * @return An InputSource with the loaded document
      */
+    @Override
     public InputSource loadSource(String href, String context, XSLTC xsltc) {
         try {
             if (_uriResolver != null) {
                 final Source source = _uriResolver.resolve(href, context);
                 if (source != null) {

@@ -1251,11 +1259,11 @@
 
         // Load the translet into a bytecode array.
         Vector bytecodes = new Vector();
         int fileLength = (int)transletFile.length();
         if (fileLength > 0) {
-            FileInputStream input = null;
+            FileInputStream input;
             try {
                 input = new FileInputStream(transletFile);
             }
             catch (FileNotFoundException e) {
                 return null;

@@ -1283,10 +1291,11 @@
         File transletParentFile = new File(transletParentDir);
 
         // Find all the auxiliary files which have a name pattern of "transletClass$nnn.class".
         final String transletAuxPrefix = transletName + "$";
         File[] auxfiles = transletParentFile.listFiles(new FilenameFilter() {
+                @Override
                 public boolean accept(File dir, String name)
                 {
                     return (name.endsWith(".class") && name.startsWith(transletAuxPrefix));
                 }
               });

@@ -1346,11 +1355,11 @@
         File xslFile = null;
         if (xslFileName != null)
             xslFile = new File(xslFileName);
 
         // Construct the path for the jar file
-        String jarPath = null;
+        String jarPath;
         if (_destinationDirectory != null)
             jarPath = _destinationDirectory + "/" + _jarFileName;
         else {
             if (xslFile != null && xslFile.getParent() != null)
                 jarPath = xslFile.getParent() + "/" + _jarFileName;

@@ -1371,11 +1380,11 @@
             if (transletTimestamp < xslTimestamp)
                 return null;
         }
 
         // Create a ZipFile object for the jar file
-        ZipFile jarFile = null;
+        ZipFile jarFile;
         try {
             jarFile = new ZipFile(file);
         }
         catch (IOException e) {
             return null;

@@ -1489,11 +1498,11 @@
         if (systemId != null) {
             File file = new File(systemId);
             if (file.exists())
                 return systemId;
             else {
-                URL url = null;
+                URL url;
                 try {
                     url = new URL(systemId);
                 }
                 catch (MalformedURLException e) {
                     return null;

@@ -1508,11 +1517,11 @@
         else
             return null;
     }
 
     /**
-     * Returns the Class object the provides the XSLTC DTM Manager service.
+     * Returns a new instance of the XSLTC DTM Manager service.
      */
-    protected Class getDTMManagerClass() {
-        return m_DTMManagerClass;
+    protected final XSLTCDTMManager createNewDTMManagerInstance() {
+        return XSLTCDTMManager.createNewDTMManagerInstance();
     }
 }