FileDocCategorySizeDatePackage
SmartTransformerFactoryImpl.javaAPI DocJava SE 5 API14669Fri Aug 26 14:55:40 BST 2005com.sun.org.apache.xalan.internal.xsltc.trax

SmartTransformerFactoryImpl

public class SmartTransformerFactoryImpl extends SAXTransformerFactory
Implementation of a transformer factory that uses an XSLTC transformer factory for the creation of Templates objects and uses the Xalan processor transformer factory for the creation of Transformer objects.

Fields Summary
private SAXTransformerFactory
_xsltcFactory
private SAXTransformerFactory
_xalanFactory
private SAXTransformerFactory
_currFactory
private ErrorListener
_errorlistener
private URIResolver
_uriresolver
Constructors Summary
public SmartTransformerFactoryImpl()
implementation of the SmartTransformerFactory. This factory uses com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory to return Templates objects; and uses com.sun.org.apache.xalan.internal.processor.TransformerFactory to return Transformer objects.


                               
       
Methods Summary
private voidcreateXSLTCTransformerFactory()

	_xsltcFactory = new TransformerFactoryImpl();
	_currFactory = _xsltcFactory;
    
private voidcreateXalanTransformerFactory()

 	final String xalanMessage =
	    "com.sun.org.apache.xalan.internal.xsltc.trax.SmartTransformerFactoryImpl "+
	    "could not create an "+
	    "com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl.";
	// try to create instance of Xalan factory...	
	try {
            Class xalanFactClass = ObjectFactory.findProviderClass(
                "com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl",
                ObjectFactory.findClassLoader(), true);
	    _xalanFactory = (SAXTransformerFactory)
		xalanFactClass.newInstance();
	} 
	catch (ClassNotFoundException e) {
	    System.err.println(xalanMessage);
        }
 	catch (InstantiationException e) {
	    System.err.println(xalanMessage);
	}
 	catch (IllegalAccessException e) {
	    System.err.println(xalanMessage);
	}
	_currFactory = _xalanFactory;
    
public javax.xml.transform.SourcegetAssociatedStylesheet(javax.xml.transform.Source source, java.lang.String media, java.lang.String title, java.lang.String charset)

	if (_currFactory == null) {
            createXSLTCTransformerFactory();
        }
	return _currFactory.getAssociatedStylesheet(source, media,
		title, charset);
    
public java.lang.ObjectgetAttribute(java.lang.String name)

	// GTM: NB: 'debug' should change to something more unique... 
	if ((name.equals("translet-name")) || (name.equals("debug"))) { 
	    if (_xsltcFactory == null) {
                createXSLTCTransformerFactory();
            }
            return _xsltcFactory.getAttribute(name); 
        }
        else {
	    if (_xalanFactory == null) {
	        createXalanTransformerFactory();
	    } 
	    return _xalanFactory.getAttribute(name);
        }
    
public javax.xml.transform.ErrorListenergetErrorListener()

 
	return _errorlistener;
    
public booleangetFeature(java.lang.String name)
javax.xml.transform.sax.TransformerFactory implementation. Look up the value of a feature (to see if it is supported). This method must be updated as the various methods and features of this class are implemented.

param
name The feature name
return
'true' if feature is supported, 'false' if not

 
	// All supported features should be listed here
        String[] features = {
            DOMSource.FEATURE,
            DOMResult.FEATURE,
            SAXSource.FEATURE,
            SAXResult.FEATURE,
            StreamSource.FEATURE,
            StreamResult.FEATURE
        };

        // Inefficient, but it really does not matter in a function like this
        for (int i=0; i<features.length; i++) {
            if (name.equals(features[i])) return true;
	}

        // Feature not supported
        return false;
    
public javax.xml.transform.URIResolvergetURIResolver()

	return _uriresolver; 
    
public javax.xml.transform.TemplatesnewTemplates(javax.xml.transform.Source source)
Create a Templates object that from the input stylesheet Uses the com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.

param
source the stylesheet.
return
A Templates object.

        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xsltcFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xsltcFactory.setURIResolver(_uriresolver);
	}
 	_currFactory = _xsltcFactory;	 
	return _currFactory.newTemplates(source); 
    
public javax.xml.transform.sax.TemplatesHandlernewTemplatesHandler()
Get a TemplatesHandler object that can process SAX ContentHandler events into a Templates object. Uses the com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.

        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xsltcFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xsltcFactory.setURIResolver(_uriresolver);
	}
	return _xsltcFactory.newTemplatesHandler();
    
public javax.xml.transform.TransformernewTransformer()
Create a Transformer object that copies the input document to the result. Uses the com.sun.org.apache.xalan.internal.processor.TransformerFactory.

return
A Transformer object.

	if (_xalanFactory == null) {
            createXalanTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xalanFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xalanFactory.setURIResolver(_uriresolver);
	}
 	_currFactory = _xalanFactory;	 
	return _currFactory.newTransformer(); 
    
public javax.xml.transform.TransformernewTransformer(javax.xml.transform.Source source)
Create a Transformer object that from the input stylesheet Uses the com.sun.org.apache.xalan.internal.processor.TransformerFactory.

param
source the stylesheet.
return
A Transformer object.

        if (_xalanFactory == null) {
            createXalanTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xalanFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xalanFactory.setURIResolver(_uriresolver);
	}
 	_currFactory = _xalanFactory;	 
	return _currFactory.newTransformer(source); 
    
public javax.xml.transform.sax.TransformerHandlernewTransformerHandler()
Get a TransformerHandler object that can process SAX ContentHandler events based on a copy transformer. Uses com.sun.org.apache.xalan.internal.processor.TransformerFactory.

        if (_xalanFactory == null) {
            createXalanTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xalanFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xalanFactory.setURIResolver(_uriresolver);
	}
	return _xalanFactory.newTransformerHandler(); 
    
public javax.xml.transform.sax.TransformerHandlernewTransformerHandler(javax.xml.transform.Source src)
Get a TransformerHandler object that can process SAX ContentHandler events based on a transformer specified by the stylesheet Source. Uses com.sun.org.apache.xalan.internal.processor.TransformerFactory.

        if (_xalanFactory == null) {
            createXalanTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xalanFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xalanFactory.setURIResolver(_uriresolver);
	}
	return _xalanFactory.newTransformerHandler(src); 
    
public javax.xml.transform.sax.TransformerHandlernewTransformerHandler(javax.xml.transform.Templates templates)
Get a TransformerHandler object that can process SAX ContentHandler events based on a transformer specified by the stylesheet Source. Uses com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.

        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xsltcFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xsltcFactory.setURIResolver(_uriresolver);
	}
        return _xsltcFactory.newTransformerHandler(templates);
    
public org.xml.sax.XMLFilternewXMLFilter(javax.xml.transform.Source src)
Create an XMLFilter that uses the given source as the transformation instructions. Uses com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.

        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
	if (_errorlistener != null) {
	    _xsltcFactory.setErrorListener(_errorlistener);	    
	}
	if (_uriresolver != null) {
	    _xsltcFactory.setURIResolver(_uriresolver);
	}
	Templates templates = _xsltcFactory.newTemplates(src);
	if (templates == null ) return null;
	return newXMLFilter(templates); 
    
public org.xml.sax.XMLFilternewXMLFilter(javax.xml.transform.Templates templates)

	try {
            return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
        }
        catch(TransformerConfigurationException e1) {
            if (_xsltcFactory == null) {
                createXSLTCTransformerFactory();
            }
	    ErrorListener errorListener = _xsltcFactory.getErrorListener();
            if(errorListener != null) {
                try {
                    errorListener.fatalError(e1);
                    return null;
                }
                catch( TransformerException e2) {
                    new TransformerConfigurationException(e2);
                }
            }
            throw e1;
        }
    
public voidsetAttribute(java.lang.String name, java.lang.Object value)

 
	// GTM: NB: 'debug' should change to something more unique... 
	if ((name.equals("translet-name")) || (name.equals("debug"))) { 
	    if (_xsltcFactory == null) {
                createXSLTCTransformerFactory();
            }
            _xsltcFactory.setAttribute(name, value); 
        }
        else {
	    if (_xalanFactory == null) {
	        createXalanTransformerFactory();
	    } 
	    _xalanFactory.setAttribute(name, value);
        }
    
public voidsetErrorListener(javax.xml.transform.ErrorListener listener)

	_errorlistener = listener;
    
public voidsetURIResolver(javax.xml.transform.URIResolver resolver)

	_uriresolver = resolver;