commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl DefaultTagLibraryResolver.java
Date Thu, 09 Sep 2004 15:10:05 GMT
dion        2004/09/09 08:10:05

  Modified:    jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt
                        ImageTag.java
               jelly/src/java/org/apache/commons/jelly Jelly.java
                        JellyContext.java
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/tags/core
                        GetStaticTag.java BaseClassLoaderTag.java
                        InvokeStaticTag.java UseBeanTag.java
               jelly/src/java/org/apache/commons/jelly/util
                        CommandLineParser.java
               jelly/src/test/org/apache/commons/jelly/test/impl
                        DummyTag.java
               jelly/src/test/org/apache/commons/jelly/tags/junit
                        AssertThrowsTag.java
               jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate
                        VerifierTag.java
               jelly/src/java/org/apache/commons/jelly/impl
                        DefaultTagLibraryResolver.java
  Log:
  JELLY-134 - Handle VMs that return null for getClass().getClassLoader()
  
  Revision  Changes    Path
  1.7       +3 -2      jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/ImageTag.java
  
  Index: ImageTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/ImageTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ImageTag.java	8 Sep 2004 04:51:31 -0000	1.6
  +++ ImageTag.java	9 Sep 2004 15:10:03 -0000	1.7
  @@ -19,6 +19,7 @@
   import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.eclipse.swt.graphics.Image;
   import org.eclipse.swt.widgets.Button;
   import org.eclipse.swt.widgets.Decorations;
  @@ -147,8 +148,8 @@
        * Creates an Image, loaded from a specified resource.
        */
       private Image loadResourceImage(Display display) {
  -        InputStream stream =
  -            getClass().getClassLoader().getResourceAsStream(getResource());
  +        ClassLoader loader = ClassLoaderUtils.getClassLoader(null, getContext().getUseContextClassLoader(),
getClass());
  +        InputStream stream = loader.getResourceAsStream(getResource());
           return new Image(display, stream);
       }
   
  
  
  
  1.34      +4 -3      jakarta-commons/jelly/src/java/org/apache/commons/jelly/Jelly.java
  
  Index: Jelly.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/Jelly.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Jelly.java	9 Sep 2004 12:25:39 -0000	1.33
  +++ Jelly.java	9 Sep 2004 15:10:03 -0000	1.34
  @@ -26,6 +26,7 @@
   import java.util.Properties;
   
   import org.apache.commons.jelly.parser.XMLParser;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.apache.commons.jelly.util.CommandLineParser;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -217,7 +218,7 @@
        */
       protected URL resolveURL(String name) throws MalformedURLException {
           
  -        URL resourceUrl = this.getClass().getClassLoader().getResource(name);
  +        URL resourceUrl = ClassLoaderUtils.getClassLoader(getClass()).getResource(name);
           if (resourceUrl == null)
           {
               File file = new File(name);
  @@ -245,7 +246,7 @@
           loadProperties(f);
           
           
  -        is = getClass().getClassLoader().getResourceAsStream("jelly.properties");
  +        is = ClassLoaderUtils.getClassLoader(getClass()).getResourceAsStream("jelly.properties");
           if (is != null) {
               try {
                   loadProperties(is);
  
  
  
  1.61      +2 -10     jakarta-commons/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- JellyContext.java	9 Sep 2004 12:25:39 -0000	1.60
  +++ JellyContext.java	9 Sep 2004 15:10:03 -0000	1.61
  @@ -25,6 +25,7 @@
   import java.util.Map;
   
   import org.apache.commons.jelly.parser.XMLParser;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -869,16 +870,7 @@
        * </ul>
        */
       public ClassLoader getClassLoader() {
  -        if (this.classLoader != null) {
  -            return (this.classLoader);
  -        }
  -        if (this.useContextClassLoader) {
  -            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
  -            if (contextClassLoader != null) {
  -                return (contextClassLoader);
  -            }
  -        }
  -        return (this.getClass().getClassLoader());
  +        return ClassLoaderUtils.getClassLoader(classLoader, useContextClassLoader, getClass());
       }
   
       /**
  
  
  
  1.57      +3 -11     jakarta-commons/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
  
  Index: XMLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- XMLParser.java	9 Sep 2004 11:10:27 -0000	1.56
  +++ XMLParser.java	9 Sep 2004 15:10:04 -0000	1.57
  @@ -45,6 +45,7 @@
   import org.apache.commons.jelly.impl.TagFactory;
   import org.apache.commons.jelly.impl.TagScript;
   import org.apache.commons.jelly.impl.TextScript;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.apache.commons.jelly.expression.CompositeExpression;
   import org.apache.commons.jelly.expression.ConstantExpression;
   import org.apache.commons.jelly.expression.Expression;
  @@ -364,16 +365,7 @@
        * </ul>
        */
       public ClassLoader getClassLoader() {
  -        if (this.classLoader != null) {
  -            return (this.classLoader);
  -        }
  -        if (this.useContextClassLoader) {
  -            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  -            if (classLoader != null) {
  -                return (classLoader);
  -            }
  -        }
  -        return (this.getClass().getClassLoader());
  +        return ClassLoaderUtils.getClassLoader(classLoader, useContextClassLoader, getClass());
       }
   
       /**
  
  
  
  1.3       +3 -2      jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/GetStaticTag.java
  
  Index: GetStaticTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/GetStaticTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GetStaticTag.java	9 Sep 2004 12:27:53 -0000	1.2
  +++ GetStaticTag.java	9 Sep 2004 15:10:04 -0000	1.3
  @@ -20,6 +20,7 @@
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   
   
   /**
  @@ -102,7 +103,7 @@
               throw new MissingAttributeException(message);
   
           try {
  -            Class type     = getClass().getClassLoader().loadClass(className);
  +            Class type     = ClassLoaderUtils.getClassLoader(getClass()).loadClass(className);
               Object result  = type.getField(field).get(null);
               JellyContext context = getContext();
   
  
  
  
  1.5       +3 -11     jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/BaseClassLoaderTag.java
  
  Index: BaseClassLoaderTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/BaseClassLoaderTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaseClassLoaderTag.java	9 Sep 2004 12:27:54 -0000	1.4
  +++ BaseClassLoaderTag.java	9 Sep 2004 15:10:04 -0000	1.5
  @@ -16,6 +16,7 @@
   package org.apache.commons.jelly.tags.core;
   
   import org.apache.commons.jelly.TagSupport;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   
   /** Abstract base tag providing {@link ClassLoader} support.
     *
  @@ -49,16 +50,7 @@
        * </ul>
        */
       public ClassLoader getClassLoader() {
  -        if (this.classLoader != null) {
  -            return (this.classLoader);
  -        }
  -        if (this.useContextClassLoader) {
  -            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  -            if (classLoader != null) {
  -                return (classLoader);
  -            }
  -        }
  -        return (this.getClass().getClassLoader());
  +        return ClassLoaderUtils.getClassLoader(classLoader, useContextClassLoader, getClass());
       }
   
       /**
  
  
  
  1.9       +3 -11     jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/InvokeStaticTag.java
  
  Index: InvokeStaticTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/InvokeStaticTag.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- InvokeStaticTag.java	8 Sep 2004 04:35:22 -0000	1.8
  +++ InvokeStaticTag.java	9 Sep 2004 15:10:04 -0000	1.9
  @@ -24,6 +24,7 @@
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   
   /**
     * A Tag which can invoke a static method on a class, without an
  @@ -163,16 +164,7 @@
        * current threads context class loader
        */
       protected Class loadClass() throws ClassNotFoundException {
  -        ClassLoader loader = getClass().getClassLoader();
  -        if (loader != null) {
  -            try {
  -                return loader.loadClass( className );
  -            }
  -            catch (ClassNotFoundException e) {
  -                // ignore this exception as we'll try another loader
  -            }
  -        }
  -        return getClass().getClassLoader().loadClass( className );
  +        return ClassLoaderUtils.loadClass(className, getClass());
       }
   
       /**
  
  
  
  1.19      +2 -9      jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java
  
  Index: UseBeanTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/UseBeanTag.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- UseBeanTag.java	9 Sep 2004 12:27:53 -0000	1.18
  +++ UseBeanTag.java	9 Sep 2004 15:10:04 -0000	1.19
  @@ -29,6 +29,7 @@
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.impl.BeanSource;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   
   /**
    * A tag which instantiates an instance of the given class
  @@ -154,15 +155,7 @@
        * otherise use the class loader which loaded this class.
        */
       protected Class loadClass(String className) throws ClassNotFoundException {
  -        try {
  -          ClassLoader loader = Thread.currentThread().getContextClassLoader();
  -          if (loader == null) {
  -              loader = getClass().getClassLoader();
  -          }
  -          return loader.loadClass(className);
  -        } catch (ClassNotFoundException e) {
  -            return getClass().getClassLoader().loadClass(className);
  -        }
  +        return ClassLoaderUtils.loadClass(className, getClass());
       }
   
       /**
  
  
  
  1.7       +2 -2      jakarta-commons/jelly/src/java/org/apache/commons/jelly/util/CommandLineParser.java
  
  Index: CommandLineParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/util/CommandLineParser.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CommandLineParser.java	9 Sep 2004 12:29:35 -0000	1.6
  +++ CommandLineParser.java	9 Sep 2004 15:10:05 -0000	1.7
  @@ -80,7 +80,7 @@
           //
           // Use classloader to find file
           //
  -        URL url = this.getClass().getClassLoader().getResource(scriptFile);
  +        URL url = ClassLoaderUtils.getClassLoader(getClass()).getResource(scriptFile);
           // check if the script file exists
           if (url == null && !(new File(scriptFile)).exists()) {
               throw new JellyException("Script file " + scriptFile + " not found");
  
  
  
  1.7       +2 -2      jakarta-commons/jelly/src/test/org/apache/commons/jelly/test/impl/DummyTag.java
  
  Index: DummyTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/test/impl/DummyTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DummyTag.java	9 Sep 2004 12:31:57 -0000	1.6
  +++ DummyTag.java	9 Sep 2004 15:10:05 -0000	1.7
  @@ -18,6 +18,7 @@
   import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -42,8 +43,7 @@
               log.debug("********Executing DummyTag Body*********");
           if (m_classToBeLoaded != null) {
               try {
  -                Class clazz =
  -                    getClass().getClassLoader().loadClass(m_classToBeLoaded);
  +                Class clazz = ClassLoaderUtils.loadClass(m_classToBeLoaded, getClass());
                   if (log.isDebugEnabled())
                       log.debug("Class[" + m_classToBeLoaded + "] FOUND");
               }
  
  
  
  1.6       +2 -4      jakarta-commons/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertThrowsTag.java
  
  Index: AssertThrowsTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertThrowsTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AssertThrowsTag.java	8 Sep 2004 04:36:52 -0000	1.5
  +++ AssertThrowsTag.java	9 Sep 2004 15:10:05 -0000	1.6
  @@ -18,6 +18,7 @@
   import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -105,10 +106,7 @@
       }
   
       public ClassLoader getClassLoader() {
  -        if (classLoader == null) {
  -            return getClass().getClassLoader();
  -        }
  -        return classLoader;
  +        return ClassLoaderUtils.getClassLoader(classLoader, getClass());
       }
   
       // Implementation methods
  
  
  
  1.10      +3 -5      jakarta-commons/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/VerifierTag.java
  
  Index: VerifierTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/VerifierTag.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- VerifierTag.java	8 Sep 2004 04:52:07 -0000	1.9
  +++ VerifierTag.java	9 Sep 2004 15:10:05 -0000	1.10
  @@ -26,6 +26,7 @@
   import org.apache.commons.jelly.MissingAttributeException;
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.iso_relax.verifier.Schema;
   import org.iso_relax.verifier.Verifier;
   import org.iso_relax.verifier.VerifierConfigurationException;
  @@ -166,10 +167,7 @@
       public VerifierFactory getFactory() throws JellyTagException {
           if ( factory == null ) {
               try {
  -                ClassLoader loader = Thread.currentThread().getContextClassLoader();
  -                if (loader == null) {
  -                    loader = getClass().getClassLoader();
  -                }
  +                ClassLoader loader = ClassLoaderUtils.getClassLoader(null, true, getClass());
                   factory = (VerifierFactory)loader.loadClass(
                       "com.sun.msv.verifier.jarv.TheFactoryImpl").newInstance();
               } catch (ClassNotFoundException e) {
  
  
  
  1.9       +2 -10     jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/DefaultTagLibraryResolver.java
  
  Index: DefaultTagLibraryResolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/DefaultTagLibraryResolver.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultTagLibraryResolver.java	9 Sep 2004 12:26:22 -0000	1.8
  +++ DefaultTagLibraryResolver.java	9 Sep 2004 15:10:05 -0000	1.9
  @@ -20,6 +20,7 @@
   import org.apache.commons.discovery.resource.ClassLoaders;
   import org.apache.commons.discovery.resource.classes.DiscoverClasses;
   import org.apache.commons.jelly.TagLibrary;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -125,16 +126,7 @@
        * </ul>
        */
       public ClassLoader getClassLoader() {
  -        if (this.classLoader != null) {
  -            return (this.classLoader);
  -        }
  -        if (this.useContextClassLoader) {
  -            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  -            if (classLoader != null) {
  -                return (classLoader);
  -            }
  -        }
  -        return (this.getClass().getClassLoader());
  +        return ClassLoaderUtils.getClassLoader(classLoader, useContextClassLoader, getClass());
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message