costin 00/10/09 20:38:40
Modified: java/src/org/apache/xalan/extensions ExtensionHandler.java
ExtensionHandlerGeneral.java
java/src/org/apache/xalan/templates ElemExtensionDecl.java
Log:
Like in xalan1, use dynamic class loading to load the BSF extension
handler. This allow xalan2 builds without BSF in classpath, while
allowing to use BSF when available.
Right now Xalan2 builds with no external dependency ( only standard
interfaces and it's own code ).
Revision Changes Path
1.2 +65 -2
xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandler.java
Index: ExtensionHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExtensionHandler.java 2000/10/08 03:34:30 1.1
+++ ExtensionHandler.java 2000/10/10 03:38:39 1.2
@@ -67,6 +67,7 @@
import org.w3c.dom.Node;
import org.apache.xalan.templates.Stylesheet;
import org.apache.xalan.utils.QName;
+import org.apache.xalan.utils.StringVector;
// Temp??
import org.apache.xalan.transformer.TransformerImpl;
@@ -87,7 +88,57 @@
protected String m_namespaceUri; // uri of the extension namespace
protected String m_scriptLang; // scripting language of implementation
+ public static final String BSF_HANDLER=
+ "org.apache.xalan.extensions.ExtensionHandlerGeneral";
+ /** Use dynamic loading to load the BSF ( or other ) extension handler.
+ */
+ public static ExtensionHandler createGeneralHandler(String namespaceUri,
+ StringVector elemNames,
+ StringVector funcNames,
+ String scriptLang,
+ String scriptSrcURL,
+ String scriptSrc)
+ throws SAXException
+ {
+ try {
+ Class ehClass=Class.forName( BSF_HANDLER );
+ ExtensionHandler eh= (ExtensionHandler)ehClass.newInstance();
+ eh.init( namespaceUri, elemNames, funcNames, scriptLang,
+ scriptSrcURL, scriptSrc );
+ return eh;
+ } catch ( Exception ex ) {
+ return null;
+ }
+ }
+
+ /** Initalize an extension handler with all the information needed.
+ * @param namespaceUri the extension namespace URI that I'm implementing
+ * @param funcNames string containing list of functions of extension NS
+ * @param lang language of code implementing the extension
+ * @param srcURL value of src attribute (if any) - treated as a URL
+ * or a classname depending on the value of lang. If
+ * srcURL is not null, then scriptSrc is ignored.
+ * @param scriptSrc the actual script code (if any)
+ */
+ protected void init( String namespaceUri,
+ StringVector elemNames,
+ StringVector funcNames,
+ String scriptLang,
+ String scriptSrcURL,
+ String scriptSrc)
+ throws SAXException
+ {
+
+ }
+
+ /**
+ * Construct a new extension handler. It must be initialized
+ * with init()
+ */
+ protected ExtensionHandler() {
+ }
+
/**
* Construct a new extension namespace handler given all the information
* needed.
@@ -97,12 +148,24 @@
*/
protected ExtensionHandler (String namespaceUri,
- String scriptLang)
+ String scriptLang)
{
+ this.init( namespaceUri, scriptLang);
+ }
+
+ /**
+ * Initialize a new extension namespace handler given all the information
+ * needed.
+ *
+ * @param namespaceUri the extension namespace URI that I'm implementing
+ * @param scriptLang language of code implementing the extension
+ */
+ protected void init(String namespaceUri,
+ String scriptLang)
+ {
m_namespaceUri = namespaceUri;
m_scriptLang = scriptLang;
}
-
/**
* Tests whether a certain function name is known within this namespace.
1.2 +18 -1
xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandlerGeneral.java
Index: ExtensionHandlerGeneral.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandlerGeneral.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExtensionHandlerGeneral.java 2000/10/08 03:34:30 1.1
+++ ExtensionHandlerGeneral.java 2000/10/10 03:38:39 1.2
@@ -100,6 +100,10 @@
private BSFManager m_mgr = new BSFManager(); // mgr used to run scripts
private BSFEngine m_engine = null; // engine used
+ public ExtensionHandlerGeneral()
+ {
+ super();
+ }
/**
* Construct a new extension namespace handler given all the information
@@ -120,8 +124,21 @@
String scriptSrcURL,
String scriptSrc)
throws SAXException
+ {
+ super();
+ init( namespaceUri, elemNames, funcNames, scriptLang,
+ scriptSrcURL, scriptSrc);
+ }
+
+ public void init(String namespaceUri,
+ StringVector elemNames,
+ StringVector funcNames,
+ String scriptLang,
+ String scriptSrcURL,
+ String scriptSrc)
+ throws SAXException
{
- super(namespaceUri, scriptLang);
+ super.init(namespaceUri, scriptLang);
if (elemNames != null)
{
1.6 +7 -7
xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionDecl.java
Index: ElemExtensionDecl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionDecl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ElemExtensionDecl.java 2000/10/08 08:25:43 1.5
+++ ElemExtensionDecl.java 2000/10/10 03:38:40 1.6
@@ -6,7 +6,6 @@
import org.apache.xalan.utils.StringToStringTable;
import org.apache.xalan.utils.StringVector;
import org.apache.xalan.extensions.ExtensionHandler;
-import org.apache.xalan.extensions.ExtensionHandlerGeneral;
import org.apache.xalan.extensions.ExtensionsTable;
import org.apache.xalan.transformer.TransformerImpl;
import org.xml.sax.SAXException;
@@ -157,12 +156,13 @@
}
else // not java
{
- nsh = new ExtensionHandlerGeneral(declNamespace,
- this.m_elements,
- this.m_functions,
- lang,
- srcURL,
- scriptSrc);
+ nsh = ExtensionHandler.createGeneralHandler(
+ declNamespace,
+ this.m_elements,
+ this.m_functions,
+ lang,
+ srcURL,
+ scriptSrc);
// System.out.println("Adding NS Handler: declNamespace = "+
// declNamespace+", lang = "+lang+", srcURL = "+
// srcURL+", scriptSrc="+scriptSrc);