morten 01/11/08 06:11:15
Modified: java/src/org/apache/xalan/xsltc DOMCache.java
java/src/org/apache/xalan/xsltc/cmdline Transform.java
java/src/org/apache/xalan/xsltc/compiler FunctionCall.java
java/src/org/apache/xalan/xsltc/dom
NodeSortRecordFactory.java
java/src/org/apache/xalan/xsltc/trax
TransformerFactoryImpl.java
Added: java/src/org/apache/xalan/xsltc/runtime TransletLoader.java
Log:
Added a new TransletLoader class to the runtime package. This class will
be used only when the default Class.forName() call fails. The forName()
call will fail if XSLTC is packed in a JAR and installed under
$JAVA_HOME/jre/lib/ext. This is because the extensions class
loader is used instead of the bootstrap class loader, and that the
extensions class loader does not load classes for the default class path.
But, if the extensions class loader is being used, then we know two things:
(1) XSLTC is running on Java 1.2 or later (when extensions were introduced)
(2) XSLTC has access to the ClassLoader.getSystemClassLoader() method
This class takes advantage of this and uses a privileged call to this
method to get a reference to the bootstrap class loader. It then uses this
class loader to load the desired class.
PR: none
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.2 +2 -2 xml-xalan/java/src/org/apache/xalan/xsltc/DOMCache.java
Index: DOMCache.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/DOMCache.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DOMCache.java 2001/04/17 18:51:13 1.1
+++ DOMCache.java 2001/11/08 14:11:14 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DOMCache.java,v 1.1 2001/04/17 18:51:13 sboag Exp $
+ * @(#)$Id: DOMCache.java,v 1.2 2001/11/08 14:11:14 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -71,7 +71,7 @@
* This method is responsible for:
*
* (1) building the DOMImpl tree
- *
+ *
* Parser _parser = new Parser();
* DOMImpl _dom = new DOMImpl();
* _parser.setDocumentHandler(_dom.getBuilder());
1.13 +17 -2
xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Transform.java
Index: Transform.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/cmdline/Transform.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Transform.java 2001/10/30 14:57:53 1.12
+++ Transform.java 2001/11/08 14:11:14 1.13
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Transform.java,v 1.12 2001/10/30 14:57:53 morten Exp $
+ * @(#)$Id: Transform.java,v 1.13 2001/11/08 14:11:14 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -128,9 +128,24 @@
_jarFileSrc = jarFile;
}
+ private Class loadTranslet(String name) throws ClassNotFoundException {
+ // First try to load the class using the default class loader
+ try {
+ return Class.forName(name);
+ }
+ catch (ClassNotFoundException e) {
+ // ignore
+ }
+
+ // Then try to load the class using the bootstrap class loader
+ TransletLoader loader = new TransletLoader();
+ return loader.loadTranslet(name);
+ }
+
private void doTransform() {
try {
- final Class clazz = Class.forName(_className);
+
+ final Class clazz = loadTranslet(_className);
final Translet translet = (Translet)clazz.newInstance();
// Create a SAX parser and get the XMLReader object it uses
1.11 +8 -3
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java
Index: FunctionCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionCall.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FunctionCall.java 2001/10/30 08:42:55 1.10
+++ FunctionCall.java 2001/11/08 14:11:15 1.11
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: FunctionCall.java,v 1.10 2001/10/30 08:42:55 morten Exp $
+ * @(#)$Id: FunctionCall.java,v 1.11 2001/11/08 14:11:15 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,10 +68,13 @@
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
+
import java.lang.reflect.*;
+
import org.apache.xalan.xsltc.compiler.util.Type;
import de.fub.bytecode.generic.*;
import org.apache.xalan.xsltc.compiler.util.*;
+import org.apache.xalan.xsltc.runtime.TransletLoader;
class FunctionCall extends Expression {
@@ -100,7 +103,7 @@
// Legal conversions between Java and internal types.
private static final Hashtable _java2Internal = new Hashtable();
-
+
/**
* Defines 2 conversion tables:
* 1. From internal types to Java types and
@@ -486,7 +489,9 @@
namespace.startsWith(JAVA_EXT_XALAN)) {
final int nArgs = _arguments.size();
try {
- final Class clazz = Class.forName(_className);
+ TransletLoader loader = new TransletLoader();
+ final Class clazz = loader.loadClass(_className);
+
if (clazz == null) {
final ErrorMsg msg =
new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
1.7 +19 -2
xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java
Index: NodeSortRecordFactory.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NodeSortRecordFactory.java 2001/11/05 13:51:58 1.6
+++ NodeSortRecordFactory.java 2001/11/08 14:11:15 1.7
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: NodeSortRecordFactory.java,v 1.6 2001/11/05 13:51:58 morten Exp $
+ * @(#)$Id: NodeSortRecordFactory.java,v 1.7 2001/11/08 14:11:15 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -68,6 +68,7 @@
import org.apache.xalan.xsltc.Translet;
import org.apache.xalan.xsltc.TransletException;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
+import org.apache.xalan.xsltc.runtime.TransletLoader;
public class NodeSortRecordFactory {
@@ -81,6 +82,20 @@
private int _type[];
private final AbstractTranslet _translet;
+ private Class loadTranslet(String name) throws ClassNotFoundException {
+ // First try to load the class using the default class loader
+ try {
+ return Class.forName(name);
+ }
+ catch (ClassNotFoundException e) {
+ // ignore
+ }
+
+ // Then try to load the class using the bootstrap class loader
+ TransletLoader loader = new TransletLoader();
+ return loader.loadTranslet(name);
+ }
+
/**
* Creates a NodeSortRecord producing object. The DOM specifies which
tree
* to get the nodes to sort from, the class name specifies what auxillary
@@ -94,8 +109,10 @@
try {
_dom = dom;
_className = className;
+ // This should return a Class definition if using TrAX
_class = translet.getAuxiliaryClass(className);
- if (_class == null) _class = Class.forName(className);
+ // This code is only run when the native API is used
+ if (_class == null) _class = loadTranslet(className);
_translet = (AbstractTranslet)translet;
int levels = order.length;
1.1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/TransletLoader.java
Index: TransletLoader.java
===================================================================
/*
* @(#)$Id: TransletLoader.java,v 1.1 2001/11/08 14:11:15 morten Exp $
*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Sun
* Microsystems., http://www.sun.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* @author Morten Jorgensen
*
*/
package org.apache.xalan.xsltc.runtime;
import java.lang.Class;
import java.lang.ClassLoader;
/**
* This class is intended used when the default Class.forName() method fails.
* This method will fail if XSLTC is installed in a jar-file under the
* $JAVA_HOME/jre/lib/ext directory. This is because the extensions class
* loader is used instead of the bootstrap class loader, and that the
* extensions class loader does not load classes for the default class path.
* But, if the extensions class loader is being used, then we know two things:
* (1) XSLTC is running on Java 1.2 or later (when extensions were
introduced)
* (2) XSLTC has access to the ClassLoader.getSystemClassLoader() method
* This class takes advantage of this and uses a privileged call to this
* method to get a reference to the bootstrap class loader. It then uses this
* class loader to load the desired class.
*
* Note that this class should only be _instanciated_ if Class.forName()
fails.
* And, YES, I do mean _instanciated_, and not called. By instanciating this
* class on Java 1.1 you'll get a NoSuchMethodException.
*/
final public class TransletLoader {
ClassLoader _loader = null; // Reference to class loader
/**
* Create a translet loader.
* Get a handle to the system class loader
*/
public TransletLoader() {
// Get the default class loader
ClassLoader loader = this.getClass().getClassLoader();
// If this is the extensions class loader we need to get the
// default system class loader instead. This is permitted if
// this class was loaded by the extensions class loader.
String loaderName = loader.getClass().getName();
if (loaderName.equals("sun.misc.Launcher$ExtClassLoader"))
loader = ClassLoader.getSystemClassLoader();
_loader = loader;
}
/**
* Loads a Class definition, but does not run static initializers
*/
public Class loadClass(String name) throws ClassNotFoundException {
return(Class.forName(name, false, _loader));
}
/**
* Loads a Class definition and runs static initializers.
*/
public Class loadTranslet(String name) throws ClassNotFoundException {
return(Class.forName(name, true, _loader));
}
}
1.29 +3 -4
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- TransformerFactoryImpl.java 2001/10/31 07:29:39 1.28
+++ TransformerFactoryImpl.java 2001/11/08 14:11:15 1.29
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransformerFactoryImpl.java,v 1.28 2001/10/31 07:29:39 morten
Exp $
+ * @(#)$Id: TransformerFactoryImpl.java,v 1.29 2001/11/08 14:11:15 morten
Exp $
*
* The Apache Software License, Version 1.1
*
@@ -96,9 +96,6 @@
public class TransformerFactoryImpl
extends SAXTransformerFactory implements SourceLoader, ErrorListener {
- // This constant should be removed once all abstract methods are impl'ed.
- private static final String NYI = "Not yet implemented";
-
// This error listener is used only for this factory and is not passed to
// the Templates or Transformer objects that we create!!!
private ErrorListener _errorListener = this;
@@ -512,6 +509,8 @@
passErrorsToListener(xsltc.getErrors());
else
xsltc.printErrors();
+ System.err.println("java.class.path is
"+System.getProperty("java.class.path"));
+ System.err.println("class loader
"+this.getClass().getClassLoader());
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR);
throw new TransformerConfigurationException(err.toString());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]