garyp       01/05/21 11:12:44

  Modified:    java/src/org/apache/xalan/templates OutputProperties.java
  Log:
  Correct implementation of ContextClassLoader to support case where properties 
file is to be loaded by a different ClassLoader than the OutputProperties 
class.  Thanks to Davanum Srinivas <[EMAIL PROTECTED]> for this code and for 
reporting this bug.
  loadPropertiesFile should eventually be moved into a thread-specific class.
  
  Revision  Changes    Path
  1.16      +26 -4     
xml-xalan/java/src/org/apache/xalan/templates/OutputProperties.java
  
  Index: OutputProperties.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/OutputProperties.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- OutputProperties.java     2001/05/21 16:16:15     1.15
  +++ OutputProperties.java     2001/05/21 18:12:39     1.16
  @@ -181,12 +181,30 @@
     static private Properties loadPropertiesFile(String resourceName, 
Properties defaults)
       throws IOException
     {
  +
  +    // This static method should eventually be moved to a thread-specific 
class
  +    // so that we can cache the ContextClassLoader and bottleneck all 
properties file
  +    // loading throughout Xalan.
  +
       Properties props = new Properties(defaults);
   
       InputStream is = null;
       BufferedInputStream bis = null;
  +
       try {
  -      is = 
ExtensionHandler.getClassForName("org.apache.xalan.templates.OutputProperties").getResourceAsStream(resourceName);
  +      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("org/apache/xalan/templates/" + 
resourceName);
  +        }
  +      }
  +      catch (Exception e) {}
  +
  +      if ( is == null ) {
  +        is = OutputProperties.class.getResourceAsStream(resourceName);
  +      }
  +      
         bis = new BufferedInputStream(is);
         props.load(bis);
       } 
  @@ -207,9 +225,6 @@
           throw new WrappedRuntimeException("Could not load '"+resourceName+"' 
(check CLASSPATH, applet security), now using just the defaults ", se);
         }
       } 
  -    catch (ClassNotFoundException cnfe) {
  -      throw new WrappedRuntimeException("Internal error.  Could not load 
org.apache.xalan.templates.OutputProperties!", cnfe);
  -    }
       finally {
         if ( bis != null ) {
           bis.close();
  @@ -1037,4 +1052,11 @@
   
     /** Synchronization object for lazy initialization of the above tables. */
     private static Integer m_synch_object = new Integer(1);
  +
  +  /** a zero length Class array used in loadPropertiesFile() */
  +  private static final Class[] NO_CLASSES = new Class[0];
  +
  +  /** a zero length Object array used in loadPropertiesFile() */
  +  private static final Object[] NO_OBJS = new Object[0];
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to