You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/10/04 22:49:20 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/request Jdk12Interceptor.java

costin      00/10/04 13:49:19

  Modified:    src/share/org/apache/tomcat/context Tag: tomcat_32
                        LoaderInterceptor.java
               src/share/org/apache/tomcat/core Tag: tomcat_32
                        ContextManager.java
               src/share/org/apache/tomcat/request Tag: tomcat_32
                        Jdk12Interceptor.java
  Log:
  Patch from Sebastien Alborini <se...@m4x.org>.
  
  It has 3 components:
  
  - added a field and get/setParentClassLoader() in ContextManager.
  That can't have any side effects.
  
  - In LoaderInterceptor, check if parentClassLoader is set, and if
  it is use it instead of getClass().getLoader(). In normal use ( if
  cm.parentClassLoader is not set ) it doesn't change anything in the
  current functionality.
  
  - In Jdk12Interceptor, nothing change unless "useThreadLoader" is
  set ( probably a better name would be useful ). If this property
  is set, Jdk12Interceptor will set the ContextManager parent loader
  to be the context class loader. This doesn't change anything in
  normal operation. The default is false, to match current functionality.
  
  Please review and if you feel that have any side effects I can roll
  back.
  
  Submitted by: Sebastien Alborini <se...@m4x.org>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.3   +6 -1      jakarta-tomcat/src/share/org/apache/tomcat/context/Attic/LoaderInterceptor.java
  
  Index: LoaderInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/Attic/LoaderInterceptor.java,v
  retrieving revision 1.2.2.2
  retrieving revision 1.2.2.3
  diff -u -r1.2.2.2 -r1.2.2.3
  --- LoaderInterceptor.java	2000/09/07 02:51:21	1.2.2.2
  +++ LoaderInterceptor.java	2000/10/04 20:49:14	1.2.2.3
  @@ -91,7 +91,12 @@
       {
           ContextManager cm = context.getContextManager();
   	AdaptiveServletLoader loader=new AdaptiveServletLoader();
  -	loader.setParentLoader(this.getClass().getClassLoader());
  +	ClassLoader cl= cm.getParentClassLoader();
  +	if( cl==null ) 
  +	    loader.setParentLoader(this.getClass().getClassLoader());
  +	else
  +	    loader.setParentLoader( cl );
  +	
   	context.setServletLoader( loader );
   
           String base = context.getDocBase();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.100.2.11 +18 -1     jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
  retrieving revision 1.100.2.10
  retrieving revision 1.100.2.11
  diff -u -r1.100.2.10 -r1.100.2.11
  --- ContextManager.java	2000/09/28 02:07:05	1.100.2.10
  +++ ContextManager.java	2000/10/04 20:49:16	1.100.2.11
  @@ -177,6 +177,10 @@
        */
       public static final String DEFAULT_WORK_DIR="work";
   
  +    // when tomcat is embeded in a product, this will be
  +    // used as parent for all context class loaders.
  +    private ClassLoader parentLoader;
  +    
       /**
        * Construct a new ContextManager instance with default values.
        */
  @@ -343,8 +347,21 @@
        */
       public void setShowDebugInfo(boolean showDebugInfo) {
   	this.showDebugInfo = showDebugInfo;
  +    }
  +
  +    /** When tomcat is embeded in other applications you
  +	can set this property to the application classloader.
  +
  +	This will be used as the parent loader for all
  +	context class loaders.
  +    */
  +    public void setParentClassLoader( ClassLoader cl ) {
  +	parentLoader=cl;
  +    }
  +
  +    public ClassLoader getParentClassLoader() {
  +	return parentLoader;
       }
  -	
   
       // -------------------- Support functions --------------------
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.8.2.1   +16 -0     jakarta-tomcat/src/share/org/apache/tomcat/request/Jdk12Interceptor.java
  
  Index: Jdk12Interceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/Jdk12Interceptor.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- Jdk12Interceptor.java	2000/06/23 02:16:21	1.8
  +++ Jdk12Interceptor.java	2000/10/04 20:49:18	1.8.2.1
  @@ -72,6 +72,7 @@
   public final class Jdk12Interceptor extends  BaseInterceptor {
       private ContextManager cm;
       private int debug=0;
  +    private boolean useThreadLoader=false;
   
       public Jdk12Interceptor() {
       }
  @@ -84,6 +85,21 @@
   	debug=i;
       }
   
  +    public void setUseThreadLoader( boolean t ) {
  +	useThreadLoader=t;
  +    }
  +    
  +    public void engineInit( ContextManager cm ) {
  +	if( useThreadLoader ) {
  +	    ClassLoader cl= cm.getParentClassLoader();
  +	    if( cl==null ) {
  +		cl=Thread.currentThread().getContextClassLoader();
  +		if( cl!=null )
  +		    cm.setParentClassLoader( cl );
  +	    }
  +	}
  +    }
  +    
       public void preServletInit( Context ctx, ServletWrapper sw )
   	throws TomcatException
       {