tmiller 01/12/11 08:25:56
Modified: java/src/org/apache/xalan/xsltc/trax
SmartTransformerFactoryImpl.java
Log:
added factory creation methods and checks
Revision Changes Path
1.2 +88 -46
xml-xalan/java/src/org/apache/xalan/xsltc/trax/SmartTransformerFactoryImpl.java
Index: SmartTransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/SmartTransformerFactoryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SmartTransformerFactoryImpl.java 2001/12/11 15:16:21 1.1
+++ SmartTransformerFactoryImpl.java 2001/12/11 16:25:56 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: SmartTransformerFactoryImpl.java,v 1.1 2001/12/11 15:16:21
tmiller Exp $
+ * @(#)$Id: SmartTransformerFactoryImpl.java,v 1.2 2001/12/11 16:25:56
tmiller Exp $
*
* The Apache Software License, Version 1.1
*
@@ -77,7 +77,6 @@
* creation of Transformer objects.
*/
public class SmartTransformerFactoryImpl extends SAXTransformerFactory
- implements SourceLoader, ErrorListener
{
private TransformerFactory _xsltcFactory = null;
@@ -91,16 +90,14 @@
* org.apache.xalan.processor.TransformerFactory
* to return Transformer objects.
*/
- public SmartTransformerFactoryImpl() {
+ public SmartTransformerFactoryImpl() { }
+
+ private void createXSLTCTransformerFactory() {
// set up error messages from each factory...
final String xsltcMessage =
"org.apache.xalan.xsltc.trax.SmartTransformerFactoryImpl "+
"could not create an "+
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl.";
- final String xalanMessage =
- "org.apache.xalan.xsltc.trax.SmartTransformerFactoryImpl "+
- "could not create an "+
- "org.apache.xalan.processor.TransformerFactoryImpl.";
// try to create instance of XSLTC factory...
try {
@@ -118,8 +115,14 @@
catch (IllegalAccessException e) {
System.err.println(xsltcMessage);
}
-
+ _currFactory = _xsltcFactory;
+ }
+ public void createXalanTransformerFactory() {
+ final String xalanMessage =
+ "org.apache.xalan.xsltc.trax.SmartTransformerFactoryImpl "+
+ "could not create an "+
+ "org.apache.xalan.processor.TransformerFactoryImpl.";
// try to create instance of Xalan factory...
try {
Class xalanFactClass = Class.forName(
@@ -136,45 +139,79 @@
catch (IllegalAccessException e) {
System.err.println(xalanMessage);
}
+ _currFactory = _xalanFactory;
}
public void setErrorListener(ErrorListener listener)
- throws IllegalArgumentException {
+ throws IllegalArgumentException
+ {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
+ if (_xalanFactory == null) {
+ createXalanTransformerFactory();
+ }
_xsltcFactory.setErrorListener(listener);
_xalanFactory.setErrorListener(listener);
}
public ErrorListener getErrorListener() {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
return _xsltcFactory.getErrorListener();
}
public Object getAttribute(String name)
throws IllegalArgumentException {
+ // GTM: look at name, if one of ours, get attr from xsltc fact
+ // else default to xalan
return _currFactory.getAttribute(name);
}
public void setAttribute(String name, Object value)
throws IllegalArgumentException {
+ // GTM: look at name arg, if it is an xsltc attr (debug,defaulttransfor)
+ // then create an xsltc factory and set attr
+ // else default to xalan factory and set attr
_xsltcFactory.setAttribute(name, value);
_xalanFactory.setAttribute(name, value);
}
public boolean getFeature(String name) {
+ // GTM: may have to treat like set/get attribute...
+ if (_currFactory == null) {
+ createXSLTCTransformerFactory();
+ }
return _currFactory.getFeature(name);
}
public URIResolver getURIResolver() {
+ // GTM: may have to treat like set/get attribute...
+ if (_currFactory == null) {
+ createXSLTCTransformerFactory();
+ }
return _currFactory.getURIResolver();
}
public void setURIResolver(URIResolver resolver) {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
+ if (_xalanFactory == null) {
+ createXalanTransformerFactory();
+ }
_xsltcFactory.setURIResolver(resolver);
_xalanFactory.setURIResolver(resolver);
}
public Source getAssociatedStylesheet(Source source, String media,
String title, String charset)
- throws TransformerConfigurationException {
+ throws TransformerConfigurationException
+ {
+ if (_currFactory == null) {
+ createXSLTCTransformerFactory();
+ }
return _currFactory.getAssociatedStylesheet(source, media,
title, charset);
}
@@ -185,7 +222,11 @@
* @return A Transformer object.
*/
public Transformer newTransformer()
- throws TransformerConfigurationException {
+ throws TransformerConfigurationException
+ {
+ if (_xalanFactory == null) {
+ createXalanTransformerFactory();
+ }
_currFactory = _xalanFactory;
return _currFactory.newTransformer();
}
@@ -197,7 +238,11 @@
* @return A Transformer object.
*/
public Transformer newTransformer(Source source) throws
- TransformerConfigurationException {
+ TransformerConfigurationException
+ {
+ if (_xalanFactory == null) {
+ createXalanTransformerFactory();
+ }
_currFactory = _xalanFactory;
return _currFactory.newTransformer(source);
}
@@ -209,7 +254,11 @@
* @return A Templates object.
*/
public Templates newTemplates(Source source)
- throws TransformerConfigurationException {
+ throws TransformerConfigurationException
+ {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
_currFactory = _xsltcFactory;
return _currFactory.newTemplates(source);
}
@@ -220,7 +269,11 @@
* org.apache.xalan.xsltc.trax.TransformerFactory.
*/
public TemplatesHandler newTemplatesHandler()
- throws TransformerConfigurationException {
+ throws TransformerConfigurationException
+ {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
return ((SAXTransformerFactory)_xsltcFactory).newTemplatesHandler();
}
@@ -230,7 +283,11 @@
* Uses org.apache.xalan.processor.TransformerFactory.
*/
public TransformerHandler newTransformerHandler()
- throws TransformerConfigurationException {
+ throws TransformerConfigurationException
+ {
+ if (_xalanFactory == null) {
+ createXalanTransformerFactory();
+ }
return ((SAXTransformerFactory)_xalanFactory).newTransformerHandler();
}
@@ -240,7 +297,11 @@
* Uses org.apache.xalan.processor.TransformerFactory.
*/
public TransformerHandler newTransformerHandler(Source src)
- throws TransformerConfigurationException {
+ throws TransformerConfigurationException
+ {
+ if (_xalanFactory == null) {
+ createXalanTransformerFactory();
+ }
return
((SAXTransformerFactory)_xalanFactory).newTransformerHandler(src);
}
@@ -252,7 +313,11 @@
* Uses org.apache.xalan.xsltc.trax.TransformerFactory.
*/
public TransformerHandler newTransformerHandler(Templates templates)
- throws TransformerConfigurationException {
+ throws TransformerConfigurationException
+ {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
return
((SAXTransformerFactory)_xsltcFactory).newTransformerHandler(templates);
}
@@ -265,6 +330,9 @@
*/
public XMLFilter newXMLFilter(Source src)
throws TransformerConfigurationException {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
Templates templates = _xsltcFactory.newTemplates(src);
if (templates == null ) return null;
return newXMLFilter(templates);
@@ -281,6 +349,9 @@
return new org.apache.xalan.xsltc.trax.TrAXFilter(templates);
}
catch(TransformerConfigurationException e1) {
+ if (_xsltcFactory == null) {
+ createXSLTCTransformerFactory();
+ }
ErrorListener errorListener = _xsltcFactory.getErrorListener();
if(errorListener != null) {
try {
@@ -293,35 +364,6 @@
}
throw e1;
}
- }
-
- /**
- * This method implements XSLTC's SourceLoader interface. It is used to
- * glue a TrAX URIResolver to the XSLTC compiler's Input and Import
classes.
- *
- * @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
- */
- public InputSource loadSource(String href, String context, XSLTC xsltc) {
- return
((org.apache.xalan.xsltc.trax.TransformerFactoryImpl)_xsltcFactory).loadSource(href,
- context, xsltc);
- }
-
- public void error(TransformerException e)
- throws TransformerException {
- // TBD:::to be done...
- }
-
- public void fatalError(TransformerException e)
- throws TransformerException {
- // TBD:::to be done...
- }
-
- public void warning(TransformerException e)
- throws TransformerException {
- // TBD:::to be done...
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]