You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Gary L Peskin <ga...@firstech.com> on 2001/05/16 03:20:55 UTC
Re: cvs commit: xml-xalan/java/src/javax/xml/transform
TransformerFactory.java
Costin --
I noticed you've added a getClassForName() in a few places. Can I clean
this up and move it into org.xml.utils or maybe into the xml-commons
repository? I'd like to have only one getClassForName() across all of
the Xalan classes.
Gary
costin@apache.org wrote:
>
> costin 01/05/15 14:18:36
>
> Modified: java/src/javax/xml/parsers DocumentBuilderFactory.java
> SAXParserFactory.java
> java/src/javax/xml/transform TransformerFactory.java
> Log:
> Use the context class loader if available.
>
> The implementation is based on ExtensionHandler, and it's needed in order
> to work in certain environments ( like tomcat ).
>
> Revision Changes Path
> 1.5 +36 -1 xml-xalan/java/src/javax/xml/parsers/DocumentBuilderFactory.java
>
> Index: DocumentBuilderFactory.java
> ===================================================================
> RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/DocumentBuilderFactory.java,v
> retrieving revision 1.4
> retrieving revision 1.5
> diff -u -r1.4 -r1.5
> --- DocumentBuilderFactory.java 2001/01/29 21:43:33 1.4
> +++ DocumentBuilderFactory.java 2001/05/15 21:18:14 1.5
> @@ -143,7 +143,7 @@
>
> DocumentBuilderFactory factoryImpl;
> try {
> - Class clazz = Class.forName(factoryImplName);
> + Class clazz = getClassForName(factoryImplName);
> factoryImpl = (DocumentBuilderFactory)clazz.newInstance();
> } catch (ClassNotFoundException cnfe) {
> throw new FactoryConfigurationError(cnfe);
> @@ -154,6 +154,41 @@
> }
> return factoryImpl;
> }
> +
> + /** a zero length Object array used in getClassForName() */
> + private static final Object NO_OBJS[] = new Object[0];
> + /** the Method object for getContextClassLoader */
> + private static java.lang.reflect.Method getCCL;
> +
> + static {
> + try {
> + getCCL = Thread.class.getMethod("getContextClassLoader",
> + new Class[0]);
> + } catch (Exception e) {
> + getCCL = null;
> + }
> + }
> +
> + private static Class getClassForName(String className )
> + throws ClassNotFoundException
> + {
> + if (getCCL != null) {
> + try {
> + ClassLoader contextClassLoader =
> + (ClassLoader) getCCL.invoke(Thread.currentThread(),
> + NO_OBJS);
> + return contextClassLoader.loadClass(className);
> + } catch (ClassNotFoundException cnfe) {
> + // nothing, try again with Class.forName
> + } catch (Exception e) {
> + getCCL = null; // don't try again
> + // fallback
> + }
> + }
> +
> + return Class.forName(className);
> + }
> +
>
> /**
> * Creates a new instance of a DocumentBuilder using the
>
>
>
> 1.6 +36 -1 xml-xalan/java/src/javax/xml/parsers/SAXParserFactory.java
>
> Index: SAXParserFactory.java
> ===================================================================
> RCS file: /home/cvs/xml-xalan/java/src/javax/xml/parsers/SAXParserFactory.java,v
> retrieving revision 1.5
> retrieving revision 1.6
> diff -u -r1.5 -r1.6
> --- SAXParserFactory.java 2001/01/29 21:43:34 1.5
> +++ SAXParserFactory.java 2001/05/15 21:18:18 1.6
> @@ -144,7 +144,7 @@
>
> SAXParserFactory factoryImpl = null;
> try {
> - Class clazz = Class.forName(factoryImplName);
> + Class clazz = getClassForName(factoryImplName);
> factoryImpl = (SAXParserFactory)clazz.newInstance();
> } catch (ClassNotFoundException cnfe) {
> throw new FactoryConfigurationError(cnfe);
> @@ -155,7 +155,42 @@
> }
> return factoryImpl;
> }
> +
> + /** a zero length Object array used in getClassForName() */
> + private static final Object NO_OBJS[] = new Object[0];
> + /** the Method object for getContextClassLoader */
> + private static java.lang.reflect.Method getCCL;
>
> + static {
> + try {
> + getCCL = Thread.class.getMethod("getContextClassLoader",
> + new Class[0]);
> + } catch (Exception e) {
> + getCCL = null;
> + }
> + }
> +
> + private static Class getClassForName(String className )
> + throws ClassNotFoundException
> + {
> + if (getCCL != null) {
> + try {
> + ClassLoader contextClassLoader =
> + (ClassLoader) getCCL.invoke(Thread.currentThread(),
> + NO_OBJS);
> + return contextClassLoader.loadClass(className);
> + } catch (ClassNotFoundException cnfe) {
> + // nothing, try again with Class.forName
> + } catch (Exception e) {
> + getCCL = null; // don't try again
> + // fallback
> + }
> + }
> +
> + return Class.forName(className);
> + }
> +
> +
> /**
> * Creates a new instance of a SAXParser using the currently
> * configured factory parameters.
>
>
>
> 1.15 +38 -2 xml-xalan/java/src/javax/xml/transform/TransformerFactory.java
>
> Index: TransformerFactory.java
> ===================================================================
> RCS file: /home/cvs/xml-xalan/java/src/javax/xml/transform/TransformerFactory.java,v
> retrieving revision 1.14
> retrieving revision 1.15
> diff -u -r1.14 -r1.15
> --- TransformerFactory.java 2001/01/29 22:03:46 1.14
> +++ TransformerFactory.java 2001/05/15 21:18:32 1.15
> @@ -55,7 +55,7 @@
> * <http://www.apache.org/>.
> */
> /**
> - * $Id: TransformerFactory.java,v 1.14 2001/01/29 22:03:46 costin Exp $
> + * $Id: TransformerFactory.java,v 1.15 2001/05/15 21:18:32 costin Exp $
> */
> package javax.xml.transform;
>
> @@ -143,7 +143,7 @@
> TransformerFactory factoryImpl;
>
> try {
> - Class clazz = Class.forName(classname);
> + Class clazz = getClassForName(classname);
>
> factoryImpl = (TransformerFactory) clazz.newInstance();
> } catch (ClassNotFoundException cnfe) {
> @@ -157,6 +157,42 @@
> return factoryImpl;
> }
>
> +
> +
> + /** a zero length Object array used in getClassForName() */
> + private static final Object NO_OBJS[] = new Object[0];
> + /** the Method object for getContextClassLoader */
> + private static java.lang.reflect.Method getCCL;
> +
> + static {
> + try {
> + getCCL = Thread.class.getMethod("getContextClassLoader",
> + new Class[0]);
> + } catch (Exception e) {
> + getCCL = null;
> + }
> + }
> +
> + private static Class getClassForName(String className )
> + throws ClassNotFoundException
> + {
> + if (getCCL != null) {
> + try {
> + ClassLoader contextClassLoader =
> + (ClassLoader) getCCL.invoke(Thread.currentThread(),
> + NO_OBJS);
> + return contextClassLoader.loadClass(className);
> + } catch (ClassNotFoundException cnfe) {
> + // nothing, try again with Class.forName
> + } catch (Exception e) {
> + getCCL = null; // don't try again
> + // fallback
> + }
> + }
> +
> + return Class.forName(className);
> + }
> +
> /**
> * Process the Source into a Transformer object. Care must
> * be given not to use this object in multiple threads running concurrently.