You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by il...@apache.org on 2003/08/14 18:27:44 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util ObjectType.java
ilene 2003/08/14 09:27:44
Modified: java/src/org/apache/xalan/xsltc/cmdline Transform.java
java/src/org/apache/xpath/functions FuncSystemProperty.java
java/src/org/apache/xml/serializer SerializerFactory.java
Encodings.java OutputPropertiesFactory.java
CharInfo.java
java/src/org/apache/xalan/processor
TransformerFactoryImpl.java
java/src/org/apache/xalan/xsltc/compiler Parser.java
FunctionAvailableCall.java FunctionCall.java
java/src/org/apache/xalan/xsltc/dom NodeSortRecord.java
NodeSortRecordFactory.java
java/src/org/apache/xalan/extensions ExtensionHandler.java
ExtensionHandlerGeneral.java
java/src/org/apache/xalan/xsltc/trax TemplatesImpl.java
TransformerFactoryImpl.java
SmartTransformerFactoryImpl.java
java/src/org/apache/xalan/transformer TransformerImpl.java
java/src/org/apache/xalan/lib/sql DefaultConnectionPool.java
java/src/org/apache/xml/dtm/ref
IncrementalSAXSource_Xerces.java
CoroutineParser.java
java/src/org/apache/xml/dtm DTMManager.java
java/src/org/apache/xalan/xslt Process.java
EnvironmentCheck.java
java/src/org/apache/xml/utils ObjectPool.java
java/src/org/apache/xpath/compiler FuncLoader.java
java/src/org/apache/xalan/lib Extensions.java
java/src/org/apache/xalan/xsltc/compiler/util
ObjectType.java
Removed: java/src/org/apache/xml/dtm SecuritySupport.java
SecuritySupport12.java FactoryFinder.java
java/src/org/apache/xalan/xsltc/runtime TransletLoader.java
Log:
Applying Igor Malinin's (igor@widespace.ee) patch for more convenient (centralized)
classloading. See bugzilla #16675.
Revision Changes Path
1.27 +4 -18 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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- Transform.java 1 Apr 2003 20:29:11 -0000 1.26
+++ Transform.java 14 Aug 2003 16:27:42 -0000 1.27
@@ -80,8 +80,8 @@
import org.apache.xalan.xsltc.dom.XSLTCDTMManager;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
import org.apache.xalan.xsltc.runtime.Constants;
+import org.apache.xml.utils.ObjectFactory;
import org.apache.xalan.xsltc.runtime.Parameter;
-import org.apache.xalan.xsltc.runtime.TransletLoader;
import org.apache.xalan.xsltc.runtime.output.TransletOutputHandlerFactory;
import org.apache.xml.serializer.SerializationHandler;
@@ -130,24 +130,10 @@
_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 = loadTranslet(_className);
+ final Class clazz = ObjectFactory.findProviderClass(
+ _className, ObjectFactory.findClassLoader(), true);
final AbstractTranslet translet = (AbstractTranslet)clazz.newInstance();
// Create a SAX parser and get the XMLReader object it uses
1.14 +10 -32 xml-xalan/java/src/org/apache/xpath/functions/FuncSystemProperty.java
Index: FuncSystemProperty.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncSystemProperty.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- FuncSystemProperty.java 30 Jan 2003 18:46:26 -0000 1.13
+++ FuncSystemProperty.java 14 Aug 2003 16:27:42 -0000 1.14
@@ -72,19 +72,12 @@
*/
public class FuncSystemProperty extends FunctionOneArg
{
-
- /**
- * The path/filename of the property file: XSLTInfo.properties
- * Maintenance note: see also org.apache.xalan.processor.TransformerFactoryImpl.XSLT_PROPERTIES
+ /**
+ * The path/filename of the property file: XSLTInfo.properties
+ * Maintenance note: see also
+ * org.apache.xalan.processor.TransformerFactoryImpl.XSLT_PROPERTIES
*/
static String XSLT_PROPERTIES = "org/apache/xalan/res/XSLTInfo.properties";
-
- /** a zero length Class array used in loadPropertyFile() */
- private static final Class[] NO_CLASSES = new Class[0];
-
- /** a zero length Object array used in loadPropertyFile() */
- private static final Object[] NO_OBJS = new Object[0];
-
/**
* Execute the function. The function must return
@@ -101,9 +94,9 @@
int indexOfNSSep = fullName.indexOf(':');
String result;
String propName = "";
-
- /* List of properties where the name of the property argument is
- * to be looked for. */
+
+ // List of properties where the name of the
+ // property argument is to be looked for.
Properties xsltInfo = new Properties();
loadPropertyFile(XSLT_PROPERTIES, xsltInfo);
@@ -204,26 +197,11 @@
*/
public void loadPropertyFile(String file, Properties target)
{
-
- InputStream is = null;
-
try
{
- try {
- java.lang.reflect.Method getCCL = Thread.class.getMethod("getContextClassLoader", NO_CLASSES);
- if (getCCL != null) {
- ClassLoader contextClassLoader = (ClassLoader) getCCL.invoke(Thread.currentThread(), NO_OBJS);
- is = contextClassLoader.getResourceAsStream(file); // file should be already fully specified
- }
- }
- catch (Exception e) {}
-
- if (is == null) {
- // NOTE! For the below getResourceAsStream in Sun JDK 1.1.8M
- // we apparently must add the leading slash character - I
- // don't know why, but if it's not there, we throw an NPE from the below loading
- is = FuncSystemProperty.class.getResourceAsStream("/" + file); // file should be already fully specified
- }
+ // Reflect TransformerFactoryImpl behavior
+ // i.e. do not use context ClassLoader
+ InputStream is = FuncSystemProperty.class.getResourceAsStream("/" + file);
// get a buffered version
BufferedInputStream bis = new BufferedInputStream(is);
1.3 +15 -21 xml-xalan/java/src/org/apache/xml/serializer/SerializerFactory.java
Index: SerializerFactory.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/SerializerFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SerializerFactory.java 15 May 2003 20:13:17 -0000 1.2
+++ SerializerFactory.java 14 Aug 2003 16:27:42 -0000 1.3
@@ -63,6 +63,7 @@
import org.apache.xml.res.XMLErrorResources;
import org.apache.xml.res.XMLMessages;
+import org.apache.xml.utils.ObjectFactory;
import org.xml.sax.ContentHandler;
/**
@@ -96,38 +97,33 @@
* @throws WrappedRuntimeException (apparently -sc) if an
* exception is thrown while trying to find serializer
*/
- public static Serializer getSerializer(Properties format)
- {
-
+ public static Serializer getSerializer(Properties format)
+ {
Serializer ser = null;
try
{
- Class cls;
String method = format.getProperty(OutputKeys.METHOD);
if (method == null)
throw new IllegalArgumentException(
"The output format has a null method name");
-
-
- String className;
-
- className =
+ String className =
format.getProperty(OutputPropertiesFactory.S_KEY_CONTENT_HANDLER);
- if (null == className)
- {
- throw new IllegalArgumentException(
- "The output format must have a '"
- + OutputPropertiesFactory.S_KEY_CONTENT_HANDLER + "' property!");
- }
+ if (className == null)
+ {
+ throw new IllegalArgumentException(
+ "The output format must have a '"
+ + OutputPropertiesFactory.S_KEY_CONTENT_HANDLER + "' property!");
+ }
- cls = Utils.ClassForName(className);
+ ClassLoader loader = ObjectFactory.findClassLoader();
- // _serializers.put(method, cls);
+ Class cls = ObjectFactory.findProviderClass(className, loader, true);
+ // _serializers.put(method, cls);
Object obj = cls.newInstance();
@@ -153,15 +149,13 @@
* SAX ContentHandler events to the users handler.
*/
className = SerializerConstants.DEFAULT_SAX_SERIALIZER;
- cls = Utils.ClassForName(className);
+ cls = ObjectFactory.findProviderClass(className, loader, true);
SerializationHandler sh =
(SerializationHandler) cls.newInstance();
sh.setContentHandler( (ContentHandler) obj);
sh.setOutputFormat(format);
ser = sh;
-
-
}
else
{
@@ -181,5 +175,5 @@
}
return ser;
- }
+ }
}
1.3 +29 -50 xml-xalan/java/src/org/apache/xml/serializer/Encodings.java
Index: Encodings.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/Encodings.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Encodings.java 15 May 2003 20:13:17 -0000 1.2
+++ Encodings.java 14 Aug 2003 16:27:42 -0000 1.3
@@ -61,6 +61,7 @@
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -76,6 +77,7 @@
* @version $Revision$ $Date$
* @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
*/
+
public class Encodings extends Object
{
@@ -87,19 +89,33 @@
/**
* Standard filename for properties file with encodings data.
*/
- static final String ENCODINGS_FILE =
- "org/apache/xml/serializer/Encodings.properties";
+ static final String ENCODINGS_FILE = "Encodings.properties";
/**
* Standard filename for properties file with encodings data.
*/
static final String ENCODINGS_PROP = "org.apache.xalan.serialize.encodings";
- /** a zero length Class array used in loadPropertyFile() */
- private static final Class[] NO_CLASSES = new Class[0];
+ /** SUN JVM internal ByteToChar converter method */
+ private static final Method
+ SUN_CHAR2BYTE_CONVERTER_METHOD = findCharToByteConverterMethod();
- /** a zero length Object array used in loadPropertyFile() */
- private static final Object[] NO_OBJS = new Object[0];
+ private static Method findCharToByteConverterMethod() {
+ try
+ {
+ Class charToByteConverterClass =
+ Class.forName("sun.io.CharToByteConverter");
+ Class argTypes[] = {String.class};
+ return charToByteConverterClass.getMethod("getConverter", argTypes);
+ }
+ catch (Exception e)
+ {
+ System.err.println(
+ "Warning: Could not get charToByteConverterClass!");
+ }
+
+ return null;
+ }
/**
* Returns a writer for the specified encoding based on
@@ -155,25 +171,10 @@
*/
public static Object getCharToByteConverter(String encoding)
{
-
- Class charToByteConverterClass = null;
- java.lang.reflect.Method getConverterMethod = null;
-
- try
- {
- charToByteConverterClass =
- Utils.ClassForName("sun.io.CharToByteConverter");
- Class argTypes[] = new Class[1];
- argTypes[0] = String.class;
- getConverterMethod =
- charToByteConverterClass.getMethod("getConverter", argTypes);
- }
- catch (Exception e)
- {
- System.err.println(
- "Warning: Could not get charToByteConverterClass!");
+ if (SUN_CHAR2BYTE_CONVERTER_METHOD == null) {
return null;
}
+
Object args[] = new Object[1];
for (int i = 0; i < _encodings.length; ++i)
{
@@ -182,8 +183,9 @@
try
{
args[0] = _encodings[i].javaName;
- Object converter = getConverterMethod.invoke(null, args);
- if (null != converter)
+ Object converter =
+ SUN_CHAR2BYTE_CONVERTER_METHOD.invoke(null, args);
+ if (null != converter)
return converter;
}
catch (Exception iae)
@@ -360,31 +362,8 @@
url = new URL(urlString);
if (url == null)
{
- ClassLoader cl = null;
- try
- {
- java.lang.reflect.Method getCCL =
- Thread.class.getMethod(
- "getContextClassLoader",
- NO_CLASSES);
- if (getCCL != null)
- {
- cl =
- (ClassLoader) getCCL.invoke(
- Thread.currentThread(),
- NO_OBJS);
- }
- }
- catch (Exception e)
- {
- }
- if (cl != null)
- {
- url = cl.getResource(ENCODINGS_FILE);
- }
+ url = Encodings.class.getResource(ENCODINGS_FILE);
}
- if (url == null)
- url = ClassLoader.getSystemResource(ENCODINGS_FILE);
Properties props = new Properties();
if (url != null)
1.3 +36 -117 xml-xalan/java/src/org/apache/xml/serializer/OutputPropertiesFactory.java
Index: OutputPropertiesFactory.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/OutputPropertiesFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- OutputPropertiesFactory.java 15 May 2003 20:13:17 -0000 1.2
+++ OutputPropertiesFactory.java 14 Aug 2003 16:27:42 -0000 1.3
@@ -59,6 +59,8 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
@@ -134,12 +136,8 @@
private static final String S_XALAN_PREFIX = "org.apache.xslt.";
private static final int S_XALAN_PREFIX_LEN = S_XALAN_PREFIX.length();
- /** a zero length Class array used in loadPropertiesFile() */
- private static final Class[] NO_CLASSES = new Class[0];
/** Synchronization object for lazy initialization of the above tables. */
private static Integer m_synch_object = new Integer(1);
- /** a zero length Object array used in loadPropertiesFile() */
- private static final Object[] NO_OBJS = new Object[0];
/** the directory in which the various method property files are located */
private static final String PROP_DIR = "org/apache/xml/serializer/";
@@ -168,6 +166,30 @@
/** The properties when method="" for the "unknown" wrapper */
private static Properties m_unknown_properties = null;
+ private static final Class
+ ACCESS_CONTROLLER_CLASS = findAccessControllerClass();
+
+ private static Class findAccessControllerClass() {
+ try
+ {
+ // This Class was introduced in JDK 1.2. With the re-architecture of
+ // security mechanism ( starting in JDK 1.2 ), we have option of
+ // giving privileges to certain part of code using doPrivileged block.
+ // In JDK1.1.X applications won't be having security manager and if
+ // there is security manager ( in applets ), code need to be signed
+ // and trusted for having access to resources.
+
+ return Class.forName("java.security.AccessController");
+ }
+ catch (Exception e)
+ {
+ //User may be using older JDK ( JDK <1.2 ). Allow him/her to use it.
+ // But don't try to use doPrivileged
+ }
+
+ return null;
+ }
+
/**
* Creates an empty OutputProperties with the defaults specified by
* a property file. The method argument is used to construct a string of
@@ -239,11 +261,11 @@
m_unknown_properties =
loadPropertiesFile(fileName, m_xml_properties);
}
+
defaultProperties = m_unknown_properties;
}
else
{
-
// TODO: Calculate res file from name.
defaultProperties = m_xml_properties;
}
@@ -286,128 +308,25 @@
InputStream is = null;
BufferedInputStream bis = null;
- Class accessControllerClass = null;
try
{
- try
+ if (ACCESS_CONTROLLER_CLASS != null)
{
- try
- {
-
- // This Class was introduced in JDK 1.2. With the re-architecture of
- // security mechanism ( starting in JDK 1.2 ), we have option of
- // giving privileges to certain part of code using doPrivileged block.
- // In JDK1.1.X applications won't be having security manager and if
- // there is security manager ( in applets ), code need to be signed
- // and trusted for having access to resources.
-
- accessControllerClass =
- Utils.ClassForName("java.security.AccessController");
-
- // If we are here means user is using JDK >= 1.2.
- // Using doPrivileged to be able to read property file without opening
- // up secured container permissions like J2EE container
-
- is =
- (
- InputStream) java
- .security
- .AccessController
- .doPrivileged(
- new java
- .security
- .PrivilegedAction()
- {
-
+ is = (InputStream) AccessController
+ .doPrivileged(new PrivilegedAction() {
public Object run()
{
- try
- {
- java.lang.reflect.Method getCCL =
- Thread.class.getMethod(
- "getContextClassLoader",
- NO_CLASSES);
- if (getCCL != null)
- {
- ClassLoader contextClassLoader =
- (ClassLoader) getCCL.invoke(
- Thread.currentThread(),
- NO_OBJS);
- return (
- contextClassLoader.getResourceAsStream(
- PROP_DIR + resourceName));
- }
- }
- catch (Exception e)
- {
- }
-
- return null;
-
+ return OutputPropertiesFactory.class
+ .getResourceAsStream(resourceName);
}
});
- }
- catch (ClassNotFoundException e)
- {
- //User may be using older JDK ( JDK <1.2 ). Allow him/her to use it.
- // But don't try to use doPrivileged
- try
- {
- java.lang.reflect.Method getCCL =
- Thread.class.getMethod(
- "getContextClassLoader",
- NO_CLASSES);
- if (getCCL != null)
- {
- ClassLoader contextClassLoader =
- (ClassLoader) getCCL.invoke(
- Thread.currentThread(),
- NO_OBJS);
- is =
- contextClassLoader.getResourceAsStream(
- PROP_DIR + resourceName);
- }
- }
- catch (Exception exception)
- {
- }
- }
}
- catch (Exception e)
- {
- }
-
- if (is == null)
+ else
{
- if (accessControllerClass != null)
- {
- is =
- (
- InputStream) java
- .security
- .AccessController
- .doPrivileged(
- new java
- .security
- .PrivilegedAction()
- {
- public Object run()
- {
- return OutputPropertiesFactory
- .class
- .getResourceAsStream(
- resourceName);
- }
- });
- }
- else
- {
- // User may be using older JDK ( JDK < 1.2 )
- is =
- OutputPropertiesFactory.class.getResourceAsStream(
- resourceName);
- }
+ // User may be using older JDK ( JDK < 1.2 )
+ is = OutputPropertiesFactory.class
+ .getResourceAsStream(resourceName);
}
bis = new BufferedInputStream(is);
1.6 +93 -143 xml-xalan/java/src/org/apache/xml/serializer/CharInfo.java
Index: CharInfo.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/serializer/CharInfo.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CharInfo.java 23 Jun 2003 20:49:50 -0000 1.5
+++ CharInfo.java 14 Aug 2003 16:27:42 -0000 1.6
@@ -59,18 +59,22 @@
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
import java.net.URL;
-import java.util.BitSet;
-import java.util.Enumeration;
import java.util.Hashtable;
-import java.util.Locale;
-import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
+import java.util.Enumeration;
+import java.util.ResourceBundle;
+
+import javax.xml.transform.TransformerException;
import org.apache.xml.res.XMLErrorResources;
import org.apache.xml.res.XMLMessages;
import org.apache.xml.utils.CharKey;
+import org.apache.xml.utils.ObjectFactory;
import org.apache.xml.utils.SystemIDResolver;
+import org.apache.xml.utils.WrappedRuntimeException;
+
/**
* This class provides services that tell if a character should have
* special treatement, such as entity reference substitution or normalization
@@ -81,8 +85,6 @@
*/
public class CharInfo
{
-
-
/** Lookup table for characters to entity references. */
private Hashtable m_charToEntityRef = new Hashtable();
@@ -177,15 +179,12 @@
*/
private CharInfo(String entitiesResource)
{
- PropertyResourceBundle entities;
- InputStream is = null;
- BufferedReader reader = null;
- int index;
- String name;
- String value;
- int code;
- String line;
-
+ this(entitiesResource, false);
+ }
+
+ private CharInfo(String entitiesResource, boolean internal)
+ {
+ ResourceBundle entities = null;
boolean noExtraEntities = true;
// Make various attempts to interpret the parameter as a properties
@@ -195,13 +194,21 @@
// 2) try using the class loader to find the specified file a resource
// file
// 3) try treating the resource a URI
- entities = loadEntitiesResource(entitiesResource);
- if (null != entities) {
+
+ if (internal) {
+ try {
+ // Load entity property files by using PropertyResourceBundle,
+ // cause of security issure for applets
+ entities = PropertyResourceBundle.getBundle(entitiesResource);
+ } catch (Exception e) {}
+ }
+
+ if (entities != null) {
Enumeration enum = entities.getKeys();
while (enum.hasMoreElements()){
- name = (String) enum.nextElement();
- value = entities.getString(name);
- code = Integer.parseInt(value);
+ String name = (String) enum.nextElement();
+ String value = entities.getString(name);
+ int code = Integer.parseInt(value);
defineEntity(name, (char) code);
if (extraEntity(code))
noExtraEntities = false;
@@ -209,32 +216,27 @@
set(S_LINEFEED);
set(S_CARRIAGERETURN);
} else {
+ InputStream is = null;
+
// Load user specified resource file by using URL loading, it
- // requires a valid URI as parameter;
+ // requires a valid URI as parameter
try {
- try {
- // Maintenance note: we should evaluate replacing getting
- // the ClassLoader with
- // javax.xml.transform.FactoryFinder.findClassLoader()
- // or similar code
- ClassLoader cl = CharInfo.class.getClassLoader();
-
+ if (internal) {
+ is = CharInfo.class.getResourceAsStream(entitiesResource);
+ } else {
+ ClassLoader cl = ObjectFactory.findClassLoader();
if (cl == null) {
- is = ClassLoader.getSystemResourceAsStream(
- entitiesResource);
+ is = ClassLoader.getSystemResourceAsStream(entitiesResource);
} else {
is = cl.getResourceAsStream(entitiesResource);
}
- } catch (Exception e) { }
-
- if (is == null) {
- is = CharInfo.class.getResourceAsStream(entitiesResource);
- }
-
- if (is == null) {
- URL url = new URL(entitiesResource);
- is = url.openStream();
+ if (is == null) {
+ try {
+ URL url = new URL(entitiesResource);
+ is = url.openStream();
+ } catch (Exception e) {}
+ }
}
if (is == null) {
@@ -262,14 +264,15 @@
// versions of Xalan), this should work well enough to keep us
// on the air until we're ready to officially decommit from
// VJ++.
+
+ BufferedReader reader;
try {
- reader = new BufferedReader(new InputStreamReader(is,
- "UTF-8"));
- } catch (java.io.UnsupportedEncodingException e) {
+ reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
reader = new BufferedReader(new InputStreamReader(is));
}
- line = reader.readLine();
+ String line = reader.readLine();
while (line != null) {
if (line.length() == 0 || line.charAt(0) == '#') {
@@ -278,22 +281,22 @@
continue;
}
- index = line.indexOf(' ');
+ int index = line.indexOf(' ');
if (index > 1) {
- name = line.substring(0, index);
+ String name = line.substring(0, index);
++index;
if (index < line.length()) {
- value = line.substring(index);
+ String value = line.substring(index);
index = value.indexOf(' ');
if (index > 0) {
value = value.substring(0, index);
}
- code = Integer.parseInt(value);
+ int code = Integer.parseInt(value);
defineEntity(name, (char) code);
if (extraEntity(code))
@@ -307,24 +310,25 @@
is.close();
set(S_LINEFEED);
set(S_CARRIAGERETURN);
- } catch (Exception except) {
+ } catch (Exception e) {
throw new RuntimeException(
XMLMessages.createXMLMessage(
XMLErrorResources.ER_RESOURCE_COULD_NOT_LOAD,
new Object[] { entitiesResource,
- except.toString(),
+ e.toString(),
entitiesResource,
- except.toString()}));
+ e.toString()}));
} finally {
if (is != null) {
try {
is.close();
- } catch (Exception except) { }
+ } catch (Exception except) {}
}
}
}
+
onlyQuotAmpLtGt = noExtraEntities;
-
+
// initialize the array with a cache of the BitSet values
for (int i=0; i<ASCII_MAX; i++)
quickASCII[i] = get(i);
@@ -333,16 +337,15 @@
// for use by ToStream.character(char[], int , int)
for (int ch = 0; ch <ASCII_MAX; ch++)
if((((0x20 <= ch || (0x0A == ch || 0x0D == ch || 0x09 == ch)))
- && (!get(ch)))
- || ('"' == ch))
- {
- isCleanASCII[ch] = true;
- }
- else
- isCleanASCII[ch] = false;
+ && (!get(ch))) || ('"' == ch))
+ {
+ isCleanASCII[ch] = true;
+ }
+ else {
+ isCleanASCII[ch] = false;
+ }
}
-
/**
* Defines a new character reference. The reference's name and value are
* supplied. Nothing happens if the character reference is already defined.
@@ -425,7 +428,7 @@
// return isCleanASCII;
// }
-
+
/**
* Factory that reads in a resource file that describes the mapping of
* characters to entity references.
@@ -444,85 +447,43 @@
*/
public static CharInfo getCharInfo(String entitiesFileName)
{
- CharInfo retobj = null;
-
- Hashtable getCharInfo_cache = HashtableHolder.m_getCharInfo_cache;
-
- retobj = (CharInfo) getCharInfo_cache.get(entitiesFileName);
-
- if (retobj == null)
- {
- // try to load it.
- try
- {
- retobj = new CharInfo(entitiesFileName);
- getCharInfo_cache.put(entitiesFileName, retobj);
- }
- catch (Exception e)
- {
- retobj = null;
- }
+ CharInfo charInfo = (CharInfo) m_getCharInfoCache.get(entitiesFileName);
+ if (charInfo != null) {
+ return charInfo;
}
- if (null == retobj)
- {
- String absoluteEntitiesFileName;
- if (entitiesFileName.indexOf(':') < 0)
- {
+ // try to load it internally - cache
+ try {
+ charInfo = new CharInfo(entitiesFileName, true);
+ m_getCharInfoCache.put(entitiesFileName, charInfo);
+ return charInfo;
+ } catch (Exception e) {}
+
+ // try to load it externally - do not cache
+ try {
+ return new CharInfo(entitiesFileName);
+ } catch (Exception e) {}
+
+ String absoluteEntitiesFileName;
+
+ if (entitiesFileName.indexOf(':') < 0) {
+ absoluteEntitiesFileName =
+ SystemIDResolver.getAbsoluteURIFromRelative(entitiesFileName);
+ } else {
+ try {
absoluteEntitiesFileName =
- SystemIDResolver.getAbsoluteURIFromRelative(
- entitiesFileName);
+ SystemIDResolver.getAbsoluteURI(entitiesFileName, null);
+ } catch (TransformerException te) {
+ throw new WrappedRuntimeException(te);
}
- else
- {
- try
- {
- absoluteEntitiesFileName =
- SystemIDResolver.getAbsoluteURI(entitiesFileName, null);
- }
- catch (javax.xml.transform.TransformerException te)
- {
- throw new org.apache.xml.utils.WrappedRuntimeException(te);
- }
- }
- retobj = new CharInfo(absoluteEntitiesFileName);
- getCharInfo_cache.put(entitiesFileName, retobj);
}
- return retobj;
- }
-
-//Load entity property files by using PropertyResourceBundle, cause of security issure for applets
- private PropertyResourceBundle loadEntitiesResource(String baseName)
- throws MissingResourceException
- {
- try
- {
- Locale locale = Locale.getDefault();
- java.lang.ClassLoader loader = this.getClass().getClassLoader();
- return (PropertyResourceBundle)PropertyResourceBundle.getBundle(baseName);
- }
- catch (MissingResourceException e)
- {
- return null;
- }
- }
-
- /**
- * This class is not loaded until first referenced (see Java Language
- * Specification by Gosling/Joy/Steele, section 12.4.1)
- *
- * The static members are created when this class is first referenced, as a
- * lazy initialization not needing checking against null or any
- * synchronization later on.
- *
- */
- private static class HashtableHolder
- {
- /** Table of user-specified char infos. */
- private static Hashtable m_getCharInfo_cache = new Hashtable();
+ return new CharInfo(absoluteEntitiesFileName, false);
}
+ /** Table of user-specified char infos. */
+ private static Hashtable m_getCharInfoCache = new Hashtable();
+
/**
* Returns the array element holding the bit value for the
* given integer
@@ -593,17 +554,6 @@
(1 << (i & LOW_ORDER_BITMASK))
) != 0; // 0L for 64 bit words
return in_the_set;
- }
-
- /**
- * This is private to force the use of the factory method:
- * getCharInfo(String) instead.
- */
- private CharInfo()
- {
- // this constructor should never be called, the next line
- // is only here to make the compiler happy.
- onlyQuotAmpLtGt = true;
}
// record if there are any entities other than
1.53 +9 -27 xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- TransformerFactoryImpl.java 24 Apr 2003 15:48:18 -0000 1.52
+++ TransformerFactoryImpl.java 14 Aug 2003 16:27:43 -0000 1.53
@@ -109,10 +109,10 @@
* The path/filename of the property file: XSLTInfo.properties
* Maintenance note: see also org.apache.xpath.functions.FuncSystemProperty.XSLT_PROPERTIES
*/
- public static String XSLT_PROPERTIES =
+ public static final String XSLT_PROPERTIES =
"org/apache/xalan/res/XSLTInfo.properties";
- /**
+ /**
* Constructor TransformerFactoryImpl
*
*/
@@ -120,12 +120,6 @@
{
}
- /** a zero length Class array used in loadPropertyFileToSystem() */
- private static final Class[] NO_CLASSES = new Class[0];
-
- /** a zero length Object array used in loadPropertyFileToSystem() */
- private static final Object[] NO_OBJS = new Object[0];
-
/** Static string to be used for incremental feature */
public static final String FEATURE_INCREMENTAL = "http://xml.apache.org/xalan/features/incremental";
@@ -137,9 +131,11 @@
/**
* Retrieve a propery bundle from XSLT_PROPERTIES and load it
- * int the System properties.
+ * into the System properties.
+ * Maintenance Note: Consider this to be removed. Setting system properties
+ * from a library might have undesirable side effects and should be avoided.
*/
- static
+ static
{
try
{
@@ -149,21 +145,7 @@
{
Properties props = new Properties();
- try {
- java.lang.reflect.Method getCCL = Thread.class.getMethod("getContextClassLoader", NO_CLASSES);
- if (getCCL != null) {
- ClassLoader contextClassLoader = (ClassLoader) getCCL.invoke(Thread.currentThread(), NO_OBJS);
- is = contextClassLoader.getResourceAsStream(XSLT_PROPERTIES); // file should be already fully specified
- }
- }
- catch (Exception e) {}
-
- if (is == null) {
- // NOTE! For the below getResourceAsStream in Sun JDK 1.1.8M
- // we apparently must add the leading slash character - I
- // don't know why, but if it's not there, we throw an NPE from the below loading
- is = TransformerFactoryImpl.class.getResourceAsStream("/" + XSLT_PROPERTIES); // file should be already fully specified
- }
+ is = TransformerFactoryImpl.class.getResourceAsStream("/" + XSLT_PROPERTIES);
// get a buffered version
BufferedInputStream bis = new BufferedInputStream(is);
@@ -195,9 +177,9 @@
// In this case the caller is required to have
// the needed attributes already defined.
}
- }
+ }
-public javax.xml.transform.Templates processFromNode(Node node)
+ public javax.xml.transform.Templates processFromNode(Node node)
throws TransformerConfigurationException
{
1.59 +4 -2 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- Parser.java 31 Mar 2003 13:13:08 -0000 1.58
+++ Parser.java 14 Aug 2003 16:27:43 -0000 1.59
@@ -87,6 +87,7 @@
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
import org.apache.xalan.xsltc.runtime.AttributeList;
+import org.apache.xml.utils.ObjectFactory;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -943,7 +944,8 @@
if (className != null) {
try {
- final Class clazz = Class.forName(className);
+ final Class clazz = ObjectFactory.findProviderClass(
+ className, ObjectFactory.findClassLoader(), true);
node = (SyntaxTreeNode)clazz.newInstance();
node.setQName(qname);
node.setParser(this);
1.17 +11 -13 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java
Index: FunctionAvailableCall.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FunctionAvailableCall.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- FunctionAvailableCall.java 30 Jan 2003 18:46:00 -0000 1.16
+++ FunctionAvailableCall.java 14 Aug 2003 16:27:43 -0000 1.17
@@ -75,7 +75,7 @@
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
import org.apache.xalan.xsltc.compiler.util.Util;
-import org.apache.xalan.xsltc.runtime.TransletLoader;
+import org.apache.xml.utils.ObjectFactory;
final class FunctionAvailableCall extends FunctionCall {
@@ -169,24 +169,22 @@
methodName = replaceDash(methodName);
try {
- TransletLoader loader = new TransletLoader();
- final Class clazz = loader.loadClass(className);
+ final Class clazz = ObjectFactory.findProviderClass(
+ className, ObjectFactory.findClassLoader(), true);
if (clazz == null) {
return false;
}
- else {
- final Method[] methods = clazz.getMethods();
- for (int i = 0; i < methods.length; i++) {
- final int mods = methods[i].getModifiers();
+ final Method[] methods = clazz.getMethods();
- if (Modifier.isPublic(mods)
- && Modifier.isStatic(mods)
+ for (int i = 0; i < methods.length; i++) {
+ final int mods = methods[i].getModifiers();
+
+ if (Modifier.isPublic(mods) && Modifier.isStatic(mods)
&& methods[i].getName().equals(methodName))
- {
- return true;
- }
+ {
+ return true;
}
}
}
1.31 +28 -31 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.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- FunctionCall.java 12 Aug 2003 20:19:40 -0000 1.30
+++ FunctionCall.java 14 Aug 2003 16:27:43 -0000 1.31
@@ -95,7 +95,7 @@
import org.apache.xalan.xsltc.compiler.util.ReferenceType;
import org.apache.xalan.xsltc.compiler.util.Type;
import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
-import org.apache.xalan.xsltc.runtime.TransletLoader;
+import org.apache.xml.utils.ObjectFactory;
class FunctionCall extends Expression {
@@ -203,59 +203,56 @@
* These two tables are used when calling external (Java) functions.
*/
static {
-
try {
- final Class objectClass = Class.forName("java.lang.Object");
- final Class stringClass = Class.forName("java.lang.String");
final Class nodeClass = Class.forName("org.w3c.dom.Node");
final Class nodeListClass = Class.forName("org.w3c.dom.NodeList");
// Possible conversions between internal and Java types
- _internal2Java.put(Type.Boolean, new JavaType(objectClass,2));
- _internal2Java.put(Type.Boolean, new JavaType(java.lang.Boolean.class,1));
+ _internal2Java.put(Type.Boolean, new JavaType(Object.class,2));
+ _internal2Java.put(Type.Boolean, new JavaType(Boolean.class,1));
_internal2Java.put(Type.Boolean, new JavaType(Boolean.TYPE,0));
- _internal2Java.put(Type.Int, new JavaType(objectClass, 8));
+ _internal2Java.put(Type.Int, new JavaType(Object.class, 8));
_internal2Java.put(Type.Int, new JavaType(Character.TYPE, 7));
_internal2Java.put(Type.Int, new JavaType(Byte.TYPE, 6));
_internal2Java.put(Type.Int, new JavaType(Short.TYPE, 5));
_internal2Java.put(Type.Int, new JavaType(Integer.TYPE, 0));
- _internal2Java.put(Type.Int, new JavaType(java.lang.Integer.class, 1));
+ _internal2Java.put(Type.Int, new JavaType(Integer.class, 1));
_internal2Java.put(Type.Int, new JavaType(Long.TYPE, 2));
_internal2Java.put(Type.Int, new JavaType(Float.TYPE, 3));
_internal2Java.put(Type.Int, new JavaType(Double.TYPE, 4));
- _internal2Java.put(Type.Real, new JavaType(objectClass, 8));
+ _internal2Java.put(Type.Real, new JavaType(Object.class, 8));
_internal2Java.put(Type.Real, new JavaType(Character.TYPE, 7));
_internal2Java.put(Type.Real, new JavaType(Byte.TYPE, 6));
_internal2Java.put(Type.Real, new JavaType(Short.TYPE, 5));
_internal2Java.put(Type.Real, new JavaType(Integer.TYPE, 4));
_internal2Java.put(Type.Real, new JavaType(Long.TYPE, 3));
_internal2Java.put(Type.Real, new JavaType(Float.TYPE, 2));
- _internal2Java.put(Type.Real, new JavaType(java.lang.Double.class, 1));
+ _internal2Java.put(Type.Real, new JavaType(Double.class, 1));
_internal2Java.put(Type.Real, new JavaType(Double.TYPE, 0));
- _internal2Java.put(Type.String, new JavaType(objectClass, 1));
- _internal2Java.put(Type.String, new JavaType(stringClass, 0));
+ _internal2Java.put(Type.String, new JavaType(Object.class, 1));
+ _internal2Java.put(Type.String, new JavaType(String.class, 0));
_internal2Java.put(Type.Node, new JavaType(nodeClass, 0));
_internal2Java.put(Type.Node, new JavaType(nodeListClass, 1));
- _internal2Java.put(Type.Node, new JavaType(objectClass, 2));
- _internal2Java.put(Type.Node, new JavaType(stringClass, 3));
+ _internal2Java.put(Type.Node, new JavaType(Object.class, 2));
+ _internal2Java.put(Type.Node, new JavaType(String.class, 3));
_internal2Java.put(Type.NodeSet, new JavaType(Integer.TYPE, 10));
- _internal2Java.put(Type.NodeSet, new JavaType(stringClass, 3));
- _internal2Java.put(Type.NodeSet, new JavaType(objectClass, 2));
+ _internal2Java.put(Type.NodeSet, new JavaType(String.class, 3));
+ _internal2Java.put(Type.NodeSet, new JavaType(Object.class, 2));
_internal2Java.put(Type.NodeSet, new JavaType(nodeClass, 1));
_internal2Java.put(Type.NodeSet, new JavaType(nodeListClass,0));
_internal2Java.put(Type.ResultTree, new JavaType(nodeClass, 1));
_internal2Java.put(Type.ResultTree, new JavaType(nodeListClass, 0));
- _internal2Java.put(Type.ResultTree, new JavaType(objectClass, 2));
- _internal2Java.put(Type.ResultTree, new JavaType(stringClass, 3));
+ _internal2Java.put(Type.ResultTree, new JavaType(Object.class, 2));
+ _internal2Java.put(Type.ResultTree, new JavaType(String.class, 3));
_internal2Java.put(Type.ResultTree, new JavaType(Double.TYPE, 4));
- _internal2Java.put(Type.Reference, new JavaType(objectClass,0));
+ _internal2Java.put(Type.Reference, new JavaType(Object.class,0));
// Possible conversions between Java and internal types
_java2Internal.put(Boolean.TYPE, Type.Boolean);
@@ -268,9 +265,9 @@
_java2Internal.put(Float.TYPE, Type.Real);
_java2Internal.put(Double.TYPE, Type.Real);
- _java2Internal.put(stringClass, Type.String);
+ _java2Internal.put(String.class, Type.String);
- _java2Internal.put(objectClass, Type.Reference);
+ _java2Internal.put(Object.class, Type.Reference);
// Conversions from org.w3c.dom.Node/NodeList to internal NodeSet
_java2Internal.put(nodeListClass, Type.NodeSet);
@@ -386,9 +383,9 @@
}
else {
if (_className != null && _className.length() > 0) {
- try {
- TransletLoader loader = new TransletLoader();
- _clazz = loader.loadClass(_className);
+ try {
+ _clazz = ObjectFactory.findProviderClass(
+ _className, ObjectFactory.findClassLoader(), true);
_namespace_format = NAMESPACE_FORMAT_CLASS;
}
catch (ClassNotFoundException e) {
@@ -889,9 +886,9 @@
final int nArgs = _arguments.size();
try {
if (_clazz == null) {
- TransletLoader loader = new TransletLoader();
- _clazz = loader.loadClass(_className);
-
+ _clazz = ObjectFactory.findProviderClass(
+ _className, ObjectFactory.findClassLoader(), true);
+
if (_clazz == null) {
final ErrorMsg msg =
new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
@@ -936,9 +933,9 @@
final int nArgs = _arguments.size();
try {
if (_clazz == null) {
- TransletLoader loader = new TransletLoader();
- _clazz = loader.loadClass(_className);
-
+ _clazz = ObjectFactory.findProviderClass(
+ _className, ObjectFactory.findClassLoader(), true);
+
if (_clazz == null) {
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
getParser().reportError(Constants.ERROR, msg);
1.13 +5 -3 xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java
Index: NodeSortRecord.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- NodeSortRecord.java 1 Apr 2003 21:39:17 -0000 1.12
+++ NodeSortRecord.java 14 Aug 2003 16:27:43 -0000 1.13
@@ -73,6 +73,7 @@
import org.apache.xalan.xsltc.DOM;
import org.apache.xalan.xsltc.TransletException;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
+import org.apache.xml.utils.ObjectFactory;
/**
* Base class for sort records containing application specific sort keys
@@ -113,7 +114,7 @@
private Object[] _values; // Contains either CollationKey or Double
/**
- * This constructor is run by a call to Class.forName() in the
+ * This constructor is run by a call to ClassLoader in the
* makeNodeSortRecord method in the NodeSortRecordFactory class. Since we
* cannot pass any parameters to the constructor in that case we just set
* the default values here and wait for new values through initialize().
@@ -155,7 +156,8 @@
if (colFactClassname != null) {
try {
- Object candObj = nsrFactory.loadTranslet(colFactClassname);
+ Object candObj = ObjectFactory.findProviderClass(
+ colFactClassname, ObjectFactory.findClassLoader(), true);
_collatorFactory = (CollatorFactory)candObj;
}
catch (ClassNotFoundException e) {
1.10 +6 -16 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- NodeSortRecordFactory.java 1 Apr 2003 21:39:17 -0000 1.9
+++ NodeSortRecordFactory.java 14 Aug 2003 16:27:43 -0000 1.10
@@ -68,7 +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;
+import org.apache.xml.utils.ObjectFactory;
public class NodeSortRecordFactory {
@@ -82,19 +82,6 @@
private int _type[];
private final AbstractTranslet _translet;
- public 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
- return new TransletLoader().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
@@ -111,7 +98,10 @@
// This should return a Class definition if using TrAX
_class = translet.getAuxiliaryClass(className);
// This code is only run when the native API is used
- if (_class == null) _class = loadTranslet(className);
+ if (_class == null) {
+ _class = ObjectFactory.findProviderClass(
+ className, ObjectFactory.findClassLoader(), true);
+ }
_translet = (AbstractTranslet)translet;
int levels = order.length;
1.18 +10 -51 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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ExtensionHandler.java 30 Jan 2003 18:45:41 -0000 1.17
+++ ExtensionHandler.java 14 Aug 2003 16:27:43 -0000 1.18
@@ -57,7 +57,6 @@
package org.apache.xalan.extensions;
import java.io.IOException;
-import java.lang.reflect.Method;
import java.util.Vector;
import javax.xml.transform.TransformerException;
@@ -66,6 +65,7 @@
import org.apache.xalan.templates.Stylesheet;
import org.apache.xalan.transformer.TransformerImpl;
import org.apache.xpath.functions.FuncExtFunction;
+import org.apache.xml.utils.ObjectFactory;
/**
* <meta name="usage" content="internal"/>
@@ -79,70 +79,29 @@
public abstract class ExtensionHandler
{
- /** uri of the extension namespace */
+ /** uri of the extension namespace */
protected String m_namespaceUri;
- /** scripting language of implementation */
+ /** scripting language of implementation */
protected String m_scriptLang;
- /** a zero length Object array used in getClassForName() */
- private static final Object NO_OBJS[] = new Object[0];
-
- /** the Method object for getContextClassLoader */
- private static Method getCCL;
-
- static
- {
- try
- {
- getCCL = Thread.class.getMethod("getContextClassLoader", new Class[0]);
- }
- catch (Exception e)
- {
- getCCL = null;
- }
- }
-
/**
- * Replacement for Class.forName. This method loads a class using the context class loader
- * if we're running under Java2 or higher. If we're running under Java1, this
- * method just uses Class.forName to load the class.
+ * This method loads a class using the context class loader if we're
+ * running under Java2 or higher.
*
* @param className Name of the class to load
*/
- public static Class getClassForName(String className)
+ static Class getClassForName(String className)
throws ClassNotFoundException
{
- Class result = null;
-
// Hack for backwards compatibility with XalanJ1 stylesheets
- if(className.equals("org.apache.xalan.xslt.extensions.Redirect"))
+ if(className.equals("org.apache.xalan.xslt.extensions.Redirect")) {
className = "org.apache.xalan.lib.Redirect";
-
- if (getCCL != null)
- {
- try {
- ClassLoader contextClassLoader =
- (ClassLoader) getCCL.invoke(Thread.currentThread(), NO_OBJS);
- result = contextClassLoader.loadClass(className);
- }
- catch (ClassNotFoundException cnfe)
- {
- result = Class.forName(className);
- }
- catch (Exception e)
- {
- getCCL = null;
- result = Class.forName(className);
- }
}
- else
- result = Class.forName(className);
-
- return result;
- }
-
+ return ObjectFactory.findProviderClass(
+ className, ObjectFactory.findClassLoader(), true);
+ }
/**
* Construct a new extension namespace handler given all the information
1.19 +40 -60 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ExtensionHandlerGeneral.java 30 Jan 2003 18:45:41 -0000 1.18
+++ ExtensionHandlerGeneral.java 14 Aug 2003 16:27:43 -0000 1.19
@@ -73,6 +73,7 @@
import org.apache.xalan.transformer.TransformerImpl;
import org.apache.xml.dtm.DTMIterator;
import org.apache.xml.dtm.ref.DTMNodeList;
+import org.apache.xml.utils.ObjectFactory;
import org.apache.xml.utils.StringVector;
import org.apache.xml.utils.SystemIDResolver;
import org.apache.xpath.XPathProcessorException;
@@ -104,67 +105,23 @@
// BSF objects used to invoke BSF by reflection. Do not import the BSF classes
// since we don't want a compile dependency on BSF.
- /** Instance of Manager class */
- private Object m_mgr; //
+ /** BSF manager used to run scripts */
+ private Object m_engine;
- /** BSF manager used to run scripts */
- private Object m_engine;
+ /** Engine call to invoke scripts */
+ private Method m_engineCall;
// static fields
- /** BSFManager package name */
+ /** BSFManager package name */
private static final String BSF_MANAGER = "com.ibm.bsf.BSFManager";
- /** Manager class */
- private static Class managerClass;
-
- /** Manager load scripting engine */
- private static Method mgrLoadScriptingEngine;
-
- /** BSFEngine package name */
+ /** BSFEngine package name */
private static final String BSF_ENGINE = "com.ibm.bsf.BSFEngine";
- /** Engine call to "compile" scripts */
- private static Method engineExec;
-
- /** Engine call to invoke scripts */
- private static Method engineCall;
-
- /** Negative one integer */
+ /** Negative one integer */
private static final Integer NEG1INT = new Integer(-1);
- static
- {
- try
- {
- //managerClass = Class.forName(BSF_MANAGER);
- managerClass = ExtensionHandler.getClassForName(BSF_MANAGER);
- mgrLoadScriptingEngine = managerClass.getMethod("loadScriptingEngine",
- new Class[]{ String.class });
-
- //Class engineClass = Class.forName(BSF_ENGINE);
- Class engineClass = ExtensionHandler.getClassForName(BSF_ENGINE);
-
- engineExec = engineClass.getMethod("exec", new Class[]{ String.class,
- Integer.TYPE,
- Integer.TYPE,
- Object.class });
- engineCall = engineClass.getMethod("call", new Class[]{ Object.class,
- String.class,
- Class.forName(
- "[Ljava.lang.Object;") });
- }
- catch (Exception e)
- {
- managerClass = null;
- mgrLoadScriptingEngine = null;
- engineExec = null;
- engineCall = null;
-
- e.printStackTrace();
- }
- }
-
/**
* Construct a new extension namespace handler given all the information
* needed.
@@ -268,19 +225,37 @@
}
}
-
- if (null == managerClass)
+
+ Object manager = null;
+ try
+ {
+ manager = ObjectFactory.newInstance(
+ BSF_MANAGER, ObjectFactory.findClassLoader(), true);
+ }
+ catch (ObjectFactory.ConfigurationError e)
+ {
+ e.printStackTrace();
+ }
+
+ if (manager == null)
+ {
throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_INIT_BSFMGR, null)); //"Could not initialize BSF manager");
+ }
try
{
- m_mgr = managerClass.newInstance();
- m_engine = mgrLoadScriptingEngine.invoke(m_mgr,
- new Object[]{ scriptLang });
+ Method loadScriptingEngine = manager.getClass()
+ .getMethod("loadScriptingEngine", new Class[]{ String.class });
+
+ m_engine = loadScriptingEngine.invoke(manager,
+ new Object[]{ scriptLang });
+
+ Method engineExec = m_engine.getClass().getMethod("exec",
+ new Class[]{ String.class, Integer.TYPE, Integer.TYPE, Object.class });
// "Compile" the program
- engineExec.invoke(m_engine, new Object[]{ "XalanScript", NEG1INT,
- NEG1INT, m_scriptSrc });
+ engineExec.invoke(m_engine,
+ new Object[]{ "XalanScript", NEG1INT, NEG1INT, m_scriptSrc });
}
catch (Exception e)
{
@@ -347,8 +322,13 @@
}
}
- return engineCall.invoke(m_engine, new Object[]{ null, funcName,
- argArray });
+ if (m_engineCall != null) {
+ m_engineCall = m_engine.getClass().getMethod("call",
+ new Class[]{ Object.class, String.class, Object[].class });
+ }
+
+ return m_engineCall.invoke(m_engine,
+ new Object[]{ null, funcName, argArray });
}
catch (Exception e)
{
1.29 +13 -23 xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java
Index: TemplatesImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- TemplatesImpl.java 25 Jun 2003 19:55:46 -0000 1.28
+++ TemplatesImpl.java 14 Aug 2003 16:27:43 -0000 1.29
@@ -68,8 +68,6 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.Properties;
import javax.xml.transform.Templates;
@@ -82,6 +80,7 @@
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
import org.apache.xalan.xsltc.runtime.AbstractTranslet;
import org.apache.xalan.xsltc.runtime.Hashtable;
+import org.apache.xml.utils.ObjectFactory;
public final class TemplatesImpl implements Templates, Serializable {
@@ -150,18 +149,21 @@
*/
private transient TransformerFactoryImpl _tfactory = null;
- private class TransletClassLoader extends ClassLoader {
-
- protected TransletClassLoader(ClassLoader parent){
+ static final class TransletClassLoader extends ClassLoader {
+ TransletClassLoader(ClassLoader parent) {
super(parent);
}
- public Class defineClass(byte[] b) {
- return super.defineClass(null, b, 0, b.length);
+
+ /**
+ * Access to final protected superclass member from outer class.
+ */
+ Class defineClass(byte[] b) {
+ return defineClass(null, b, 0, b.length);
}
}
- /**
+ /**
* Create an XSLTC template object from the bytecodes.
* The bytecodes for the translet and auxiliary classes, plus the name of
* the main translet class, must be supplied.
@@ -284,20 +286,8 @@
throw new TransformerConfigurationException(err.toString());
}
- TransletClassLoader loader =
- (TransletClassLoader) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run() {
- /*
- * Get the loader from the current thread instead of
- * the class. This is important for translets that load
- * external Java classes and run in multi-threaded envs.
- */
- return new TransletClassLoader(
- Thread.currentThread().getContextClassLoader());
- }
- }
- );
+ TransletClassLoader loader =
+ new TransletClassLoader(ObjectFactory.findClassLoader());
try {
final int classCount = _bytecodes.length;
1.64 +4 -22 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.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- TransformerFactoryImpl.java 19 Jun 2003 19:14:21 -0000 1.63
+++ TransformerFactoryImpl.java 14 Aug 2003 16:27:43 -0000 1.64
@@ -97,11 +97,10 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import org.apache.xalan.xsltc.Translet;
import org.apache.xalan.xsltc.compiler.SourceLoader;
import org.apache.xalan.xsltc.compiler.XSLTC;
import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
-import org.apache.xalan.xsltc.runtime.TransletLoader;
+import org.apache.xml.utils.ObjectFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLFilter;
@@ -565,24 +564,6 @@
}
/**
- * Load the translet class using the context class loader of the current
- * thread or the default class loader.
- */
- private Class loadTranslet(String name)
- throws ClassNotFoundException
- {
- // First try to load the class using the context class loader of the current thread
- try {
- TransletLoader loader = new TransletLoader();
- return loader.loadTranslet(name);
- }
- catch (ClassNotFoundException e) {
- // Then try to load the class using the default class loader.
- return Class.forName(name);
- }
- }
-
- /**
* javax.xml.transform.sax.TransformerFactory implementation.
* Process the Source into a Templates object, which is a a compiled
* representation of the source.
@@ -604,7 +585,8 @@
transletName = _packageName + "." + transletName;
try {
- final Class clazz = loadTranslet(transletName);
+ final Class clazz = ObjectFactory.findProviderClass(
+ transletName, ObjectFactory.findClassLoader(), true);
resetTransientAttributes();
return new TemplatesImpl(new Class[]{clazz}, transletName, null, _indentNumber, this);
1.9 +13 -35 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SmartTransformerFactoryImpl.java 31 Mar 2003 17:39:04 -0000 1.8
+++ SmartTransformerFactoryImpl.java 14 Aug 2003 16:27:43 -0000 1.9
@@ -69,7 +69,6 @@
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
@@ -81,6 +80,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.apache.xml.utils.ObjectFactory;
import org.xml.sax.XMLFilter;
/**
@@ -92,9 +92,9 @@
public class SmartTransformerFactoryImpl extends SAXTransformerFactory
{
- private TransformerFactory _xsltcFactory = null;
- private TransformerFactory _xalanFactory = null;
- private TransformerFactory _currFactory = null;
+ private SAXTransformerFactory _xsltcFactory = null;
+ private SAXTransformerFactory _xalanFactory = null;
+ private SAXTransformerFactory _currFactory = null;
private ErrorListener _errorlistener = null;
private URIResolver _uriresolver = null;
@@ -108,28 +108,7 @@
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.";
-
- // try to create instance of XSLTC factory...
- try {
- Class xsltcFactClass = Class.forName(
- "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
- _xsltcFactory = (org.apache.xalan.xsltc.trax.TransformerFactoryImpl)
- xsltcFactClass.newInstance();
- }
- catch (ClassNotFoundException e) {
- System.err.println(xsltcMessage);
- }
- catch (InstantiationException e) {
- System.err.println(xsltcMessage);
- }
- catch (IllegalAccessException e) {
- System.err.println(xsltcMessage);
- }
+ _xsltcFactory = new TransformerFactoryImpl();
_currFactory = _xsltcFactory;
}
@@ -140,8 +119,9 @@
"org.apache.xalan.processor.TransformerFactoryImpl.";
// try to create instance of Xalan factory...
try {
- Class xalanFactClass = Class.forName(
- "org.apache.xalan.processor.TransformerFactoryImpl");
+ Class xalanFactClass = ObjectFactory.findProviderClass(
+ "org.apache.xalan.processor.TransformerFactoryImpl",
+ ObjectFactory.findClassLoader(), true);
_xalanFactory = (SAXTransformerFactory)
xalanFactClass.newInstance();
}
@@ -332,7 +312,7 @@
if (_uriresolver != null) {
_xsltcFactory.setURIResolver(_uriresolver);
}
- return ((SAXTransformerFactory)_xsltcFactory).newTemplatesHandler();
+ return _xsltcFactory.newTemplatesHandler();
}
/**
@@ -352,7 +332,7 @@
if (_uriresolver != null) {
_xalanFactory.setURIResolver(_uriresolver);
}
- return ((SAXTransformerFactory)_xalanFactory).newTransformerHandler();
+ return _xalanFactory.newTransformerHandler();
}
/**
@@ -372,8 +352,7 @@
if (_uriresolver != null) {
_xalanFactory.setURIResolver(_uriresolver);
}
- return
- ((SAXTransformerFactory)_xalanFactory).newTransformerHandler(src);
+ return _xalanFactory.newTransformerHandler(src);
}
@@ -394,8 +373,7 @@
if (_uriresolver != null) {
_xsltcFactory.setURIResolver(_uriresolver);
}
- return
- ((SAXTransformerFactory)_xsltcFactory).newTransformerHandler(templates);
+ return _xsltcFactory.newTransformerHandler(templates);
}
1.147 +6 -8 xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -r1.146 -r1.147
--- TransformerImpl.java 27 May 2003 15:47:43 -0000 1.146
+++ TransformerImpl.java 14 Aug 2003 16:27:44 -0000 1.147
@@ -58,7 +58,6 @@
import java.io.IOException;
import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Stack;
@@ -98,6 +97,7 @@
import org.apache.xalan.templates.StylesheetComposed;
import org.apache.xalan.templates.StylesheetRoot;
import org.apache.xalan.templates.XUnresolvedVariable;
+import org.apache.xalan.trace.GenerateEvent;
import org.apache.xalan.trace.TraceManager;
import org.apache.xml.dtm.DTM;
import org.apache.xml.dtm.DTMIterator;
@@ -111,7 +111,6 @@
import org.apache.xml.serializer.SerializationHandler;
import org.apache.xml.utils.BoolStack;
import org.apache.xml.utils.DOMBuilder;
-import org.apache.xml.utils.DOMHelper;
import org.apache.xml.utils.NodeVector;
import org.apache.xml.utils.ObjectPool;
import org.apache.xml.utils.ObjectStack;
@@ -132,7 +131,6 @@
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
-import org.apache.xalan.trace.GenerateEvent;
/**
* <meta name="usage" content="advanced"/>
* This class implements the
@@ -200,7 +198,7 @@
* Please note that each of these also holds onto a Text Serializer.
*/
private ObjectPool m_textResultHandlerObjectPool =
- new ObjectPool("org.apache.xml.serializer.ToTextStream");
+ new ObjectPool(ToTextStream.class);
/**
* Related to m_textResultHandlerObjectPool, this is a pool of
@@ -208,7 +206,7 @@
* (I'm not sure if this is really needed any more. -sb)
*/
private ObjectPool m_stringWriterObjectPool =
- new ObjectPool("java.io.StringWriter");
+ new ObjectPool(StringWriter.class);
/**
* A static text format object, which can be used over and
@@ -819,7 +817,7 @@
if (null == value)
{
- if (!props.isLegalPropertyKey(qnameString))
+ if (!OutputProperties.isLegalPropertyKey(qnameString))
throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_OUTPUT_PROPERTY_NOT_RECOGNIZED, new Object[]{qnameString})); //"output property not recognized: "
//+ qnameString);
}
@@ -852,7 +850,7 @@
if (null == value)
{
- if (!props.isLegalPropertyKey(qnameString))
+ if (!OutputProperties.isLegalPropertyKey(qnameString))
throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_OUTPUT_PROPERTY_NOT_RECOGNIZED, new Object[]{qnameString})); //"output property not recognized: "
// + qnameString);
}
@@ -886,7 +884,7 @@
(OutputProperties) getStylesheet().getOutputComposed().clone();
}
- if (!m_outputFormat.isLegalPropertyKey(name))
+ if (!OutputProperties.isLegalPropertyKey(name))
throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_OUTPUT_PROPERTY_NOT_RECOGNIZED, new Object[]{name})); //"output property not recognized: "
//+ name);
1.17 +5 -21 xml-xalan/java/src/org/apache/xalan/lib/sql/DefaultConnectionPool.java
Index: DefaultConnectionPool.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/DefaultConnectionPool.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DefaultConnectionPool.java 30 Jan 2003 18:45:44 -0000 1.16
+++ DefaultConnectionPool.java 14 Aug 2003 16:27:44 -0000 1.17
@@ -56,7 +56,6 @@
*/
package org.apache.xalan.lib.sql;
-import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
@@ -68,6 +67,7 @@
import org.apache.xalan.res.XSLMessages;
import org.apache.xalan.res.XSLTErrorResources;
+import org.apache.xml.utils.ObjectFactory;
/**
* For internal connectiones, i.e. Connection information supplies in the
@@ -478,33 +478,17 @@
try
{
- // We need to implement the context classloader
- Class cls = null;
- try
- {
- Method m = Thread.class.getMethod("getContextClassLoader", null);
- ClassLoader classLoader = (ClassLoader) m.invoke(Thread.currentThread(), null);
- cls = classLoader.loadClass(m_driver);
- }
- catch (Exception e)
- {
- cls = Class.forName(m_driver);
- }
-
- if (cls == null)
- cls = Class.forName(m_driver);
-
// We have also had problems with drivers unloading
// load an instance that will get freed with the class.
- m_Driver = (Driver) cls.newInstance();
+ m_Driver = (Driver) ObjectFactory.newInstance(
+ m_driver, ObjectFactory.findClassLoader(), true);
- // Register the Driver that was loaded with the Contect Classloader
+ // Register the Driver that was loaded with the Context Classloader
// but we will ask for connections directly from the Driver
// instance
DriverManager.registerDriver(m_Driver);
-
}
- catch(ClassNotFoundException e)
+ catch(ObjectFactory.ConfigurationError e)
{
throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_DRIVER_NAME, null));
// "Invalid Driver Name Specified!");
1.13 +10 -4 xml-xalan/java/src/org/apache/xml/dtm/ref/IncrementalSAXSource_Xerces.java
Index: IncrementalSAXSource_Xerces.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/IncrementalSAXSource_Xerces.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- IncrementalSAXSource_Xerces.java 1 Apr 2003 19:14:05 -0000 1.12
+++ IncrementalSAXSource_Xerces.java 14 Aug 2003 16:27:44 -0000 1.13
@@ -64,6 +64,7 @@
import org.apache.xerces.parsers.SAXParser;
import org.apache.xml.res.XMLErrorResources;
import org.apache.xml.res.XMLMessages;
+import org.apache.xml.utils.ObjectFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -131,17 +132,20 @@
// Reflection is used to allow us to continue to compile against
// Xerces1. If/when we can abandon the older versions of the parser,
// this will simplify significantly.
- Class me=this.getClass();
// If we can't get the magic constructor, no need to look further.
- Class xniConfigClass=Class.forName("org.apache.xerces.xni.parser.XMLParserConfiguration");
+ Class xniConfigClass=ObjectFactory.findProviderClass(
+ "org.apache.xerces.xni.parser.XMLParserConfiguration",
+ ObjectFactory.findClassLoader(), true);
Class[] args1={xniConfigClass};
Constructor ctor=SAXParser.class.getConstructor(args1);
// Build the parser configuration object. StandardParserConfiguration
// happens to implement XMLPullParserConfiguration, which is the API
// we're going to want to use.
- Class xniStdConfigClass=Class.forName("org.apache.xerces.parsers.StandardParserConfiguration");
+ Class xniStdConfigClass=ObjectFactory.findProviderClass(
+ "org.apache.xerces.parsers.StandardParserConfiguration",
+ ObjectFactory.findClassLoader(), true);
fPullParserConfig=xniStdConfigClass.newInstance();
Object[] args2={fPullParserConfig};
fIncrementalParser = (SAXParser)ctor.newInstance(args2);
@@ -149,7 +153,9 @@
// Preload all the needed the configuration methods... I want to know they're
// all here before we commit to trying to use them, just in case the
// API changes again.
- Class fXniInputSourceClass=Class.forName("org.apache.xerces.xni.parser.XMLInputSource");
+ Class fXniInputSourceClass=ObjectFactory.findProviderClass(
+ "org.apache.xerces.xni.parser.XMLInputSource",
+ ObjectFactory.findClassLoader(), true);
Class[] args3={fXniInputSourceClass};
fConfigSetInput=xniStdConfigClass.getMethod("setInputSource",args3);
1.7 +5 -6 xml-xalan/java/src/org/apache/xml/dtm/ref/CoroutineParser.java
Index: CoroutineParser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/CoroutineParser.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CoroutineParser.java 30 Jan 2003 18:46:16 -0000 1.6
+++ CoroutineParser.java 14 Aug 2003 16:27:44 -0000 1.7
@@ -166,12 +166,11 @@
* */
public void doTerminate(int appCoroutine);
-
- /**
- * Initialize the coroutine parser. Same parameters could be passed
- * in a non-default constructor, or by using using Class.forName and
- * newInstance and then calling init()
- */
+ /**
+ * Initialize the coroutine parser. Same parameters could be passed
+ * in a non-default constructor, or by using using context ClassLoader
+ * and newInstance and then calling init()
+ */
public void init( CoroutineManager co, int appCoroutineID, XMLReader parser );
} // class CoroutineParser
1.16 +19 -14 xml-xalan/java/src/org/apache/xml/dtm/DTMManager.java
Index: DTMManager.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/DTMManager.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DTMManager.java 1 Apr 2003 19:00:51 -0000 1.15
+++ DTMManager.java 14 Aug 2003 16:27:44 -0000 1.16
@@ -58,6 +58,7 @@
import org.apache.xml.res.XMLErrorResources;
import org.apache.xml.res.XMLMessages;
+import org.apache.xml.utils.ObjectFactory;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xml.utils.XMLStringFactory;
@@ -90,7 +91,7 @@
/** The default class name to use as the manager. */
private static String defaultClassName =
- "org.apache.xml.dtm.ref.DTMManagerDefault";
+ "org.apache.xml.dtm.ref.DTMManagerDefault";
/**
* Factory for creating XMLString objects.
@@ -138,7 +139,7 @@
* </li>
* <li>
* Use the JAVA_HOME(the parent directory where jdk is
- * installed)/lib/jaxp.properties for a property file that contains the
+ * installed)/lib/xalan.properties for a property file that contains the
* name of the implementation class keyed on the same value as the
* system property defined above.
* </li>
@@ -146,7 +147,7 @@
* Use the Services API (as detailed in the JAR specification), if
* available, to determine the classname. The Services API will look
* for a classname in the file
- * <code>META-INF/services/javax.xml.parsers.DTMManager</code>
+ * <code>META-INF/services/org.apache.xml.dtm.DTMManager</code>
* in jars available to the runtime.
* </li>
* <li>
@@ -167,20 +168,24 @@
public static DTMManager newInstance(XMLStringFactory xsf)
throws DTMConfigurationException
{
-
- DTMManager factoryImpl = null;
- try {
- factoryImpl = (DTMManager) FactoryFinder.find(defaultPropName,
- /* The fallback implementation class name */
- defaultClassName);
- } catch (FactoryFinder.ConfigurationError e) {
- throw new DTMConfigurationException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_DEFAULT_IMPL, null)); //"No default implementation found");
- }
-
+ DTMManager factoryImpl = null;
+ try
+ {
+ factoryImpl = (DTMManager) ObjectFactory
+ .createObject(defaultPropName, defaultClassName);
+ }
+ catch (ObjectFactory.ConfigurationError e)
+ {
+ throw new DTMConfigurationException(XMLMessages.createXMLMessage(
+ XMLErrorResources.ER_NO_DEFAULT_IMPL, null), e.getException());
+ //"No default implementation found");
+ }
if (factoryImpl == null)
{
- throw new DTMConfigurationException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_DEFAULT_IMPL, null)); //"No default implementation found");
+ throw new DTMConfigurationException(XMLMessages.createXMLMessage(
+ XMLErrorResources.ER_NO_DEFAULT_IMPL, null));
+ //"No default implementation found");
}
factoryImpl.setXMLStringFactory(xsf);
1.58 +10 -9 xml-xalan/java/src/org/apache/xalan/xslt/Process.java
Index: Process.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xslt/Process.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- Process.java 3 Jun 2003 19:52:37 -0000 1.57
+++ Process.java 14 Aug 2003 16:27:44 -0000 1.58
@@ -90,6 +90,7 @@
import org.apache.xalan.trace.TraceManager;
import org.apache.xalan.transformer.XalanProperties;
import org.apache.xml.utils.DefaultErrorHandler;
+import org.apache.xml.utils.ObjectFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -462,12 +463,12 @@
{
try
{
- uriResolver =
- (URIResolver) Class.forName(argv[++i],true,ClassLoader.getSystemClassLoader()).newInstance();
+ uriResolver = (URIResolver) ObjectFactory.newInstance(
+ argv[++i], ObjectFactory.findClassLoader(), true);
tfactory.setURIResolver(uriResolver);
}
- catch (Exception cnfe)
+ catch (ObjectFactory.ConfigurationError cnfe)
{
System.err.println(
XSLMessages.createMessage(
@@ -491,10 +492,10 @@
{
try
{
- entityResolver =
- (EntityResolver) Class.forName(argv[++i],true,ClassLoader.getSystemClassLoader()).newInstance();
+ entityResolver = (EntityResolver) ObjectFactory.newInstance(
+ argv[++i], ObjectFactory.findClassLoader(), true);
}
- catch (Exception cnfe)
+ catch (ObjectFactory.ConfigurationError cnfe)
{
System.err.println(
XSLMessages.createMessage(
@@ -518,10 +519,10 @@
{
try
{
- contentHandler =
- (ContentHandler) Class.forName(argv[++i],true,ClassLoader.getSystemClassLoader()).newInstance();
+ contentHandler = (ContentHandler) ObjectFactory.newInstance(
+ argv[++i], ObjectFactory.findClassLoader(), true);
}
- catch (Exception cnfe)
+ catch (ObjectFactory.ConfigurationError cnfe)
{
System.err.println(
XSLMessages.createMessage(
1.21 +47 -75 xml-xalan/java/src/org/apache/xalan/xslt/EnvironmentCheck.java
Index: EnvironmentCheck.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xslt/EnvironmentCheck.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- EnvironmentCheck.java 26 May 2003 19:48:29 -0000 1.20
+++ EnvironmentCheck.java 14 Aug 2003 16:27:44 -0000 1.21
@@ -66,6 +66,8 @@
import java.util.StringTokenizer;
import java.util.Vector;
+import org.apache.xml.utils.ObjectFactory;
+
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -108,9 +110,7 @@
*
* <p>Also see http://xml.apache.org/xalan-j/faq.html</p>
*
- * <p>Note: This class is pretty simplistic: it does a fairly simple
- * unordered search of the classpath; it only uses Class.forName()
- * to load things, not actually querying the classloader; so the
+ * <p>Note: This class is pretty simplistic:
* results are not necessarily definitive nor will it find all
* problems related to environment setup. Also, you should avoid
* calling this in deployed production code, both because it is
@@ -835,7 +835,8 @@
final String JAXP1_CLASS = "javax.xml.parsers.DocumentBuilder";
final String JAXP11_METHOD = "getDOMImplementation";
- clazz = classForName(JAXP1_CLASS);
+ clazz = ObjectFactory.findProviderClass(
+ JAXP1_CLASS, ObjectFactory.findClassLoader(), true);
Method method = clazz.getMethod(JAXP11_METHOD, noArgs);
@@ -880,7 +881,9 @@
{
final String XALAN1_VERSION_CLASS =
"org.apache.xalan.xslt.XSLProcessorVersion";
- Class clazz = classForName(XALAN1_VERSION_CLASS);
+
+ Class clazz = ObjectFactory.findProviderClass(
+ XALAN1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
// Found Xalan-J 1.x, grab it's version fields
StringBuffer buf = new StringBuffer();
@@ -911,7 +914,9 @@
// is being replaced by class below
final String XALAN2_VERSION_CLASS =
"org.apache.xalan.processor.XSLProcessorVersion";
- Class clazz = classForName(XALAN2_VERSION_CLASS);
+
+ Class clazz = ObjectFactory.findProviderClass(
+ XALAN2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
// Found Xalan-J 2.x, grab it's version fields
StringBuffer buf = new StringBuffer();
@@ -932,7 +937,9 @@
final String XALAN2_2_VERSION_METHOD = "getVersion";
final Class noArgs[] = new Class[0];
- Class clazz = classForName(XALAN2_2_VERSION_CLASS);
+ Class clazz = ObjectFactory.findProviderClass(
+ XALAN2_2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+
Method method = clazz.getMethod(XALAN2_2_VERSION_METHOD, noArgs);
Object returnValue = method.invoke(null, new Object[0]);
@@ -962,7 +969,9 @@
try
{
final String XERCES1_VERSION_CLASS = "org.apache.xerces.framework.Version";
- Class clazz = classForName(XERCES1_VERSION_CLASS);
+
+ Class clazz = ObjectFactory.findProviderClass(
+ XERCES1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
// Found Xerces-J 1.x, grab it's version fields
Field f = clazz.getField("fVersion");
@@ -979,7 +988,9 @@
try
{
final String XERCES2_VERSION_CLASS = "org.apache.xerces.impl.Version";
- Class clazz = classForName(XERCES2_VERSION_CLASS);
+
+ Class clazz = ObjectFactory.findProviderClass(
+ XERCES2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
// Found Xerces-J 2.x, grab it's version fields
Field f = clazz.getField("fVersion");
@@ -995,7 +1006,9 @@
try
{
final String CRIMSON_CLASS = "org.apache.crimson.parser.Parser2";
- Class clazz = classForName(CRIMSON_CLASS);
+
+ Class clazz = ObjectFactory.findProviderClass(
+ CRIMSON_CLASS, ObjectFactory.findClassLoader(), true);
//@todo determine specific crimson version
h.put(VERSION + "crimson", CLASS_PRESENT);
@@ -1023,7 +1036,9 @@
final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs
final Class noArgs[] = new Class[0];
- Class clazz = classForName(ANT_VERSION_CLASS);
+ Class clazz = ObjectFactory.findProviderClass(
+ ANT_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+
Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);
Object returnValue = method.invoke(null, new Object[0]);
@@ -1061,7 +1076,9 @@
try
{
- Class clazz = classForName(DOM_LEVEL2_CLASS);
+ Class clazz = ObjectFactory.findProviderClass(
+ DOM_LEVEL2_CLASS, ObjectFactory.findClassLoader(), true);
+
Method method = clazz.getMethod(DOM_LEVEL2_METHOD, twoStringArgs);
// If we succeeded, we have loaded interfaces from a
@@ -1070,10 +1087,11 @@
try
{
-
// Check for the working draft version, which is
// commonly found, but won't work anymore
- clazz = classForName(DOM_LEVEL2WD_CLASS);
+ clazz = ObjectFactory.findProviderClass(
+ DOM_LEVEL2WD_CLASS, ObjectFactory.findClassLoader(), true);
+
method = clazz.getMethod(DOM_LEVEL2WD_METHOD, twoStringArgs);
h.put(ERROR + VERSION + "DOM.draftlevel", "2.0wd");
@@ -1083,9 +1101,10 @@
{
try
{
-
// Check for the final draft version as well
- clazz = classForName(DOM_LEVEL2FD_CLASS);
+ clazz = ObjectFactory.findProviderClass(
+ DOM_LEVEL2FD_CLASS, ObjectFactory.findClassLoader(), true);
+
method = clazz.getMethod(DOM_LEVEL2FD_METHOD, twoStringArgs);
h.put(VERSION + "DOM.draftlevel", "2.0fd");
@@ -1138,7 +1157,9 @@
{
// This method was only added in the final SAX 2.0 release;
// see changes.html "Changes from SAX 2.0beta2 to SAX 2.0prerelease"
- Class clazz = classForName(SAX_VERSION2BETA_CLASSNF);
+ Class clazz = ObjectFactory.findProviderClass(
+ SAX_VERSION2BETA_CLASSNF, ObjectFactory.findClassLoader(), true);
+
Method method = clazz.getMethod(SAX_VERSION2BETA_METHODNF, attributesArg);
// If we succeeded, we have loaded interfaces from a
@@ -1154,7 +1175,9 @@
try
{
- Class clazz = classForName(SAX_VERSION2_CLASS);
+ Class clazz = ObjectFactory.findProviderClass(
+ SAX_VERSION2_CLASS, ObjectFactory.findClassLoader(), true);
+
Method method = clazz.getMethod(SAX_VERSION2_METHOD, oneStringArg);
// If we succeeded, we have loaded interfaces from a
@@ -1171,7 +1194,9 @@
try
{
- Class clazz = classForName(SAX_VERSION1_CLASS);
+ Class clazz = ObjectFactory.findProviderClass(
+ SAX_VERSION1_CLASS, ObjectFactory.findClassLoader(), true);
+
Method method = clazz.getMethod(SAX_VERSION1_METHOD, oneStringArg);
// If we succeeded, we have loaded interfaces from a
@@ -1188,59 +1213,6 @@
}
}
- }
- }
-
- /**
- * Worker method to load a class.
- * Factor out loading classes for future use and JDK differences.
- * Copied from javax.xml.*.FactoryFinder
- * @param className name of class to load from
- * an appropriate classLoader
- * @return the class asked for
- */
- protected static Class classForName(String className)
- throws ClassNotFoundException
- {
- ClassLoader classLoader = findClassLoader();
- if (classLoader == null)
- {
- return Class.forName(className);
- }
- else
- {
- return classLoader.loadClass(className);
- }
- }
-
- /**
- * Worker method to figure out which ClassLoader to use.
- * For JDK 1.2 and later use the context ClassLoader.
- * Copied from javax.xml.*.FactoryFinder
- * @return the appropriate ClassLoader
- */
- protected static ClassLoader findClassLoader()
- throws ClassNotFoundException
- {
- ClassLoader classLoader = null;
- Method m = null;
-
- try
- {
- m = Thread.class.getMethod("getContextClassLoader", null);
- }
- catch (NoSuchMethodException e)
- {
- // Assume that we are running JDK 1.1, use the current ClassLoader
- return EnvironmentCheck.class.getClassLoader();
- }
- try
- {
- return (ClassLoader) m.invoke(Thread.currentThread(), null);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e.toString());
}
}
1.9 +2 -1 xml-xalan/java/src/org/apache/xml/utils/ObjectPool.java
Index: ObjectPool.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/ObjectPool.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ObjectPool.java 30 Jan 2003 18:46:19 -0000 1.8
+++ ObjectPool.java 14 Aug 2003 16:27:44 -0000 1.9
@@ -97,7 +97,8 @@
{
try
{
- objectType = Class.forName(className);
+ objectType = ObjectFactory.findProviderClass(
+ className, ObjectFactory.findClassLoader(), true);
}
catch(ClassNotFoundException cnfe)
{
1.7 +11 -29 xml-xalan/java/src/org/apache/xpath/compiler/FuncLoader.java
Index: FuncLoader.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/FuncLoader.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FuncLoader.java 30 Jan 2003 18:46:25 -0000 1.6
+++ FuncLoader.java 14 Aug 2003 16:27:44 -0000 1.7
@@ -56,6 +56,9 @@
*/
package org.apache.xpath.compiler;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xml.utils.ObjectFactory;
import org.apache.xpath.functions.Function;
/**
@@ -113,42 +116,21 @@
* @throws javax.xml.transform.TransformerException if ClassNotFoundException,
* IllegalAccessException, or InstantiationException is thrown.
*/
- public Function getFunction() throws javax.xml.transform.TransformerException
+ public Function getFunction() throws TransformerException
{
-
try
{
- Class function;
-
- // first get package name if necessary
- if (m_funcName.indexOf(".") < 0)
- {
-
- // String thisName = this.getClass().getName();
- // int lastdot = thisName.lastIndexOf(".");
- // String classname = thisName.substring(0,lastdot+1) + m_funcName;
- String classname = "org.apache.xpath.functions." + m_funcName;
-
- function = Class.forName(classname);
+ String className = m_funcName;
+ if (className.indexOf(".") < 0) {
+ className = "org.apache.xpath.functions." + className;
}
- else
- function = Class.forName(m_funcName);
-
- Function func = (Function) function.newInstance();
- return func;
- }
- catch (ClassNotFoundException e)
- {
- throw new javax.xml.transform.TransformerException(e);
- }
- catch (IllegalAccessException e)
- {
- throw new javax.xml.transform.TransformerException(e);
+ return (Function) ObjectFactory.newInstance(
+ className, ObjectFactory.findClassLoader(), true);
}
- catch (InstantiationException e)
+ catch (ObjectFactory.ConfigurationError e)
{
- throw new javax.xml.transform.TransformerException(e);
+ throw new TransformerException(e.getException());
}
}
}
1.26 +4 -4 xml-xalan/java/src/org/apache/xalan/lib/Extensions.java
Index: Extensions.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/Extensions.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Extensions.java 30 Apr 2003 02:43:42 -0000 1.25
+++ Extensions.java 14 Aug 2003 16:27:44 -0000 1.26
@@ -69,6 +69,7 @@
import org.apache.xpath.objects.XBoolean;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
+import org.apache.xml.utils.ObjectFactory;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
@@ -401,12 +402,11 @@
try
{
// Use reflection to try to find xml-commons utility 'Which'
- // Classloader note: if anyone really cares, we could try to
- // use the context classloader instead
- Class clazz = Class.forName(WHICH_CLASSNAME);
+ Class clazz = ObjectFactory.findProviderClass(
+ WHICH_CLASSNAME, ObjectFactory.findClassLoader(), true);
if (null == clazz)
return null;
-
+
// Fully qualify names since this is the only method they're used in
java.lang.reflect.Method method = clazz.getMethod(WHICH_METHODNAME, WHICH_METHOD_ARGS);
Hashtable report = new Hashtable();
1.6 +5 -5 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ObjectType.java
Index: ObjectType.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/util/ObjectType.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ObjectType.java 1 Apr 2003 21:12:39 -0000 1.5
+++ ObjectType.java 14 Aug 2003 16:27:44 -0000 1.6
@@ -74,7 +74,7 @@
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.PUSH;
import org.apache.xalan.xsltc.compiler.Constants;
-import org.apache.xalan.xsltc.runtime.TransletLoader;
+import org.apache.xml.utils.ObjectFactory;
public final class ObjectType extends Type {
@@ -93,10 +93,10 @@
*/
public ObjectType(String javaClassName) {
_javaClassName = javaClassName;
-
+
try {
- TransletLoader loader = new TransletLoader();
- _clazz = loader.loadClass(javaClassName);
+ _clazz = ObjectFactory.findProviderClass(
+ javaClassName, ObjectFactory.findClassLoader(), true);
}
catch (ClassNotFoundException e) {
_clazz = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org