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/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean BeandefTag.java
Date Thu, 09 Sep 2004 15:09:02 GMT
dion        2004/09/09 08:09:02

  Modified:    jelly/jelly-tags/sql/src/java/org/apache/commons/jelly/tags/sql
                        DataSourceWrapper.java
               jelly/jelly-tags/betwixt/src/java/org/apache/commons/jelly/tags/betwixt
                        ParseTag.java
               jelly/jelly-tags/define/src/java/org/apache/commons/jelly/tags/define
                        BeanTag.java ClassLoaderTag.java
               jelly/jelly-tags/junit/src/java/org/apache/commons/jelly/tags/junit
                        AssertThrowsTag.java
               jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean
                        BeandefTag.java
  Log:
  JELLY-134 - Handle VMs that return null for getClass().getClassLoader()
  
  Revision  Changes    Path
  1.5       +2 -1      jakarta-commons/jelly/jelly-tags/sql/src/java/org/apache/commons/jelly/tags/sql/DataSourceWrapper.java
  
  Index: DataSourceWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/sql/src/java/org/apache/commons/jelly/tags/sql/DataSourceWrapper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DataSourceWrapper.java	9 Sep 2004 12:16:03 -0000	1.4
  +++ DataSourceWrapper.java	9 Sep 2004 15:09:01 -0000	1.5
  @@ -24,6 +24,7 @@
   import javax.sql.DataSource;
   
   import org.apache.commons.jelly.tags.Resources;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -51,7 +52,7 @@
           }
   
           this.driverClassName = driverClassName;
  -        getClass().getClassLoader().loadClass(driverClassName).newInstance();
  +        ClassLoaderUtils.getClassLoader(getClass()).loadClass(driverClassName).newInstance();
       }
   
       public void setJdbcURL(String jdbcURL) {
  
  
  
  1.8       +2 -9      jakarta-commons/jelly/jelly-tags/betwixt/src/java/org/apache/commons/jelly/tags/betwixt/ParseTag.java
  
  Index: ParseTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/betwixt/src/java/org/apache/commons/jelly/tags/betwixt/ParseTag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ParseTag.java	9 Sep 2004 12:07:06 -0000	1.7
  +++ ParseTag.java	9 Sep 2004 15:09:01 -0000	1.8
  @@ -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.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -201,14 +202,6 @@
        * @return the ClassLoader to be used to load bean classes.
        */
       protected ClassLoader getClassLoader() {
  -        if ( classLoader != null ) {
  -            return classLoader;
  -        }
  -        if ( useContextClassLoader ) {
  -            return Thread.currentThread().getContextClassLoader();
  -        }
  -        else {
  -            return getClass().getClassLoader();
  -        }
  +        return ClassLoaderUtils.getClassLoader(classLoader, useContextClassLoader, getClass());
       }
   }
  
  
  
  1.6       +12 -28    jakarta-commons/jelly/jelly-tags/define/src/java/org/apache/commons/jelly/tags/define/BeanTag.java
  
  Index: BeanTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/define/src/java/org/apache/commons/jelly/tags/define/BeanTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BeanTag.java	8 Sep 2004 04:48:32 -0000	1.5
  +++ BeanTag.java	9 Sep 2004 15:09:02 -0000	1.6
  @@ -27,6 +27,7 @@
   import org.apache.commons.jelly.impl.Attribute;
   import org.apache.commons.jelly.impl.DynamicBeanTag;
   import org.apache.commons.jelly.impl.TagFactory;
  +import org.apache.commons.jelly.util.ClassLoaderUtils;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -88,25 +89,15 @@
           Class theClass = null;
           try {
               ClassLoader classLoader = getClassLoader();
  -            theClass = classLoader.loadClass(className);
  +            theClass = ClassLoaderUtils.loadClass(className, getClassLoader(), getContext().getUseContextClassLoader(),
getClass());
           }
           catch (ClassNotFoundException e) {
  -            try {
  -                theClass = getClass().getClassLoader().loadClass(className);
  -            }
  -            catch (ClassNotFoundException e2) {
  -                try {
  -                    theClass = Class.forName(className);
  -                }
  -                catch (ClassNotFoundException e3) {
  -                    log.error( "Could not load class: " + className + " exception: " +
e, e );
  -                    throw new JellyTagException(
  -                        "Could not find class: "
  -                            + className
  -                            + " using ClassLoader: "
  -                            + classLoader);
  -                }
  -            }
  +            log.error( "Could not load class: " + className + " exception: " + e, e );
  +            throw new JellyTagException(
  +                "Could not find class: "
  +                    + className
  +                    + " using ClassLoader: "
  +                    + classLoader);
           }
   
           final Class beanClass = theClass;
  @@ -153,18 +144,11 @@
       }
   
       /**
  -     * @return the ClassLoader to use to load classes
  -     *  or will use the thread context loader if none is specified.
  +     * @return the ClassLoader to use to load classes specified by this object, 
  +     *  the thread context loader if the context flag is set, or the class used to load
this class.
        */
       public ClassLoader getClassLoader() {
  -        if ( classLoader == null ) {
  -            ClassLoader answer = Thread.currentThread().getContextClassLoader();
  -            if ( answer == null ) {
  -                answer = getClass().getClassLoader();
  -            }
  -            return answer;
  -        }
  -        return classLoader;
  +        return ClassLoaderUtils.getClassLoader(classLoader, getContext().getUseContextClassLoader(),
getClass());
       }
   
       /**
  
  
  
  1.6       +3 -2      jakarta-commons/jelly/jelly-tags/define/src/java/org/apache/commons/jelly/tags/define/ClassLoaderTag.java
  
  Index: ClassLoaderTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/define/src/java/org/apache/commons/jelly/tags/define/ClassLoaderTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ClassLoaderTag.java	9 Sep 2004 12:07:23 -0000	1.5
  +++ ClassLoaderTag.java	9 Sep 2004 15:09:02 -0000	1.6
  @@ -23,6 +23,7 @@
   import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.MissingAttributeException;
   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;
   
  @@ -89,7 +90,7 @@
   
           ClassLoader parent = Thread.currentThread().getContextClassLoader();
           if (parent == null) {
  -            parent = getClass().getClassLoader();
  +            parent = ClassLoaderUtils.getClassLoader(getClass());
           }
   
           URLClassLoader newClassLoader = null;
  
  
  
  1.6       +2 -4      jakarta-commons/jelly/jelly-tags/junit/src/java/org/apache/commons/jelly/tags/junit/AssertThrowsTag.java
  
  Index: AssertThrowsTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/junit/src/java/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:50:39 -0000	1.5
  +++ AssertThrowsTag.java	9 Sep 2004 15:09:02 -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;
   
  @@ -112,10 +113,7 @@
       }
   
       public ClassLoader getClassLoader() {
  -        if (classLoader == null) {
  -            return getClass().getClassLoader();
  -        }
  -        return classLoader;
  +        return ClassLoaderUtils.getClassLoader(classLoader, getContext().getUseContextClassLoader(),
getClass());
       }
   
       // Implementation methods
  
  
  
  1.8       +10 -29    jakarta-commons/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeandefTag.java
  
  Index: BeandefTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bean/src/java/org/apache/commons/jelly/tags/bean/BeandefTag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BeandefTag.java	8 Sep 2004 04:40:22 -0000	1.7
  +++ BeandefTag.java	9 Sep 2004 15:09:02 -0000	1.8
  @@ -25,6 +25,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.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -79,26 +80,13 @@
   
           Class theClass = null;
           try {
  -            ClassLoader classLoader = getClassLoader();
  -            theClass = classLoader.loadClass(className);
  -        }
  -        catch (ClassNotFoundException e) {
  -            try {
  -                theClass = getClass().getClassLoader().loadClass(className);
  -            }
  -            catch (ClassNotFoundException e2) {
  -                try {
  -                    theClass = Class.forName(className);
  -                }
  -                catch (ClassNotFoundException e3) {
  -                    log.error( "Could not load class: " + className + " exception: " +
e, e );
  -                    throw new JellyTagException(
  -                        "Could not find class: "
  -                            + className
  -                            + " using ClassLoader: "
  -                            + classLoader);
  -                }
  -            }
  +            theClass = ClassLoaderUtils.loadClass(className, classLoader, getContext().getUseContextClassLoader(),
getClass());
  +        } catch (ClassNotFoundException e) {
  +            log.error( "Could not load class: " + className + " exception: " + e, e );
  +            throw new JellyTagException("Could not find class: "
  +                    + className
  +                    + " using ClassLoader: "
  +                    + classLoader);
           }
   
           Method invokeMethod = getInvokeMethod(theClass);
  @@ -139,14 +127,7 @@
        *  or will use the thread context loader if none is specified.
        */
       public ClassLoader getClassLoader() {
  -        if ( classLoader == null ) {
  -            ClassLoader answer = Thread.currentThread().getContextClassLoader();
  -            if ( answer == null ) {
  -                answer = getClass().getClassLoader();
  -            }
  -            return answer;
  -        }
  -        return classLoader;
  +        return ClassLoaderUtils.getClassLoader(classLoader, true, 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