avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/repository/main/src/java/org/apache/avalon/repository/main AbstractBuilder.java DefaultBuilder.java DefaultInitialContext.java
Date Mon, 08 Dec 2003 08:29:18 GMT
mcconnell    2003/12/08 00:29:18

  Modified:    repository/main/src/java/org/apache/avalon/repository/main
                        AbstractBuilder.java DefaultBuilder.java
                        DefaultInitialContext.java
  Log:
  Restructure the handling of the classloader established by the builder so that we can pass
the classloader to the factory via its constructor.
  
  Revision  Changes    Path
  1.3       +15 -8     avalon/repository/main/src/java/org/apache/avalon/repository/main/AbstractBuilder.java
  
  Index: AbstractBuilder.java
  ===================================================================
  RCS file: /home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/AbstractBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractBuilder.java	6 Dec 2003 23:51:08 -0000	1.2
  +++ AbstractBuilder.java	8 Dec 2003 08:29:18 -0000	1.3
  @@ -118,23 +118,30 @@
       * <li>[FactoryClass]( )</li>
       * </ul>
       * 
  -    * @param clazz the factory class
  +    * @param classloader the classloader
  +    * @param factory the the factory classname
       * @param context the inital repository context
  -    * @param args command line arguments
       * @return the instantiated factory
       * @exception RepositoryException if a factory creation error occurs
       */
       protected Factory createDelegate( 
  -      Class clazz, InitialContext context, String[] args ) 
  +      ClassLoader classloader, String factory, InitialContext context ) 
         throws RepositoryException
       {
  +
  +        if( null == classloader ) throw new NullPointerException( "classloader" );
  +        if( null == factory ) throw new NullPointerException( "factory" );
  +        if( null == context ) throw new NullPointerException( "context" );
  +
  +        Class clazz = loadFactoryClass( classloader, factory );
  +
           try
           {
               Constructor constructor = 
                 clazz.getConstructor( 
  -                new Class[]{ InitialContext.class, String[].class } );
  +                new Class[]{ InitialContext.class, ClassLoader.class } );
               return createFactory( 
  -              constructor, new Object[]{ context, args } );
  +              constructor, new Object[]{ context, classloader } );
           }
           catch( NoSuchMethodException e )
           {
  @@ -152,9 +159,9 @@
                   {
                       Constructor constructor = 
                         clazz.getConstructor( 
  -                        new Class[]{ String[].class } );
  +                        new Class[]{ ClassLoader.class } );
                       return createFactory( 
  -                      constructor, new Object[]{ args } );
  +                      constructor, new Object[]{ classloader } );
                   }
                   catch( NoSuchMethodException eee )
                   {
  
  
  
  1.5       +21 -7     avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultBuilder.java
  
  Index: DefaultBuilder.java
  ===================================================================
  RCS file: /home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultBuilder.java	7 Dec 2003 03:15:16 -0000	1.4
  +++ DefaultBuilder.java	8 Dec 2003 08:29:18 -0000	1.5
  @@ -126,7 +126,10 @@
       public DefaultBuilder( InitialContext context, Artifact artifact )
           throws Exception
       {
  -        this( context, artifact, new String[0] );
  +        this( 
  +          context, 
  +          Thread.currentThread().getContextClassLoader(),
  +          artifact );
       }
   
      /**
  @@ -138,11 +141,16 @@
       * @exception Exception if a app factory creation error occurs
       */
       public DefaultBuilder( 
  -      InitialContext context, Artifact artifact, String[] args )
  +      InitialContext context, ClassLoader classloader, Artifact artifact )
         throws Exception
       {
  +        if( null == context ) throw new NullPointerException( "context" );
  +        if( null == artifact ) throw new NullPointerException( "artifact" );
  +
           m_context = context;
   
  +        ClassLoader parent = getClassLoader( classloader );
  +
           try
           {
               Factory factory = m_context.getInitialFactory();
  @@ -167,13 +175,12 @@
               throw new IllegalArgumentException( error );
           }
   
  -        ClassLoader parent = Thread.currentThread().getContextClassLoader();
           m_classloader = m_repository.getClassLoader( parent, artifact );
  -        Class clazz = super.loadFactoryClass( m_classloader, classname );
  +        Class clazz = loadFactoryClass( m_classloader, classname );
   
           try
           {
  -            m_delegate = createDelegate( clazz, m_context, args );
  +            m_delegate = createDelegate( m_classloader, classname, m_context );
           }
           catch( Throwable e )
           {
  @@ -189,6 +196,13 @@
           }
       }
   
  +    private ClassLoader getClassLoader( ClassLoader classloader )
  +    {
  +        if( null != classloader ) return classloader;
  +        return DefaultBuilder.class.getClassLoader();
  +    }
  +
  +
      /**
       * Return the factory established by the loader.
       * @return the delegate factory
  @@ -235,7 +249,7 @@
           {
               InitialContext context = new DefaultInitialContext( cache, hosts );
               System.out.println( "Building: " + artifact );
  -            Builder builder = new DefaultBuilder( context, artifact, args );
  +            Builder builder = new DefaultBuilder( context, artifact );
               Object object = builder.getFactory().create();
               System.out.println( "OBJECT: " + object );
           }
  
  
  
  1.7       +21 -9     avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContext.java
  
  Index: DefaultInitialContext.java
  ===================================================================
  RCS file: /home/cvs/avalon/repository/main/src/java/org/apache/avalon/repository/main/DefaultInitialContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultInitialContext.java	7 Dec 2003 04:08:19 -0000	1.6
  +++ DefaultInitialContext.java	8 Dec 2003 08:29:18 -0000	1.7
  @@ -214,7 +214,23 @@
         Artifact artifact, File cache, String[] hosts ) 
         throws RepositoryException
       {
  +        this( 
  +          DefaultInitialContext.class.getClassLoader(), 
  +          artifact, cache, hosts );
  +    }
   
  +    /**
  +     * Creates an initial repository context.
  +     *
  +     * @param artifact an artifact referencing the default implementation
  +     * @param cache the cache directory
  +     * @param hosts a set of initial remote repository addresses 
  +     * @throws RepositoryException if an error occurs during establishment
  +     */
  +    public DefaultInitialContext( 
  +      ClassLoader parent, Artifact artifact, File cache, String[] hosts ) 
  +      throws RepositoryException
  +    {
           Properties avalonHome = getLocalProperties( USER_HOME, AVALON );
           Properties avalonWork = getLocalProperties( USER_DIR, AVALON );
           
  @@ -269,12 +285,8 @@
           // create the classloader
           //
           
  -        ClassLoader classloader = 
  -          new URLClassLoader( 
  -            urls, 
  -            Thread.currentThread().getContextClassLoader() );
  -
  -        Class clazz = super.loadFactoryClass( classloader, factory );
  +        ClassLoader classloader = new URLClassLoader( urls, parent );
  +        Class clazz = loadFactoryClass( classloader, factory );
   
           //
           // load the actual repository implementation 
  @@ -282,7 +294,7 @@
   
           try
           {
  -            m_delegate = createDelegate( clazz, this, new String[0] );
  +            m_delegate = createDelegate( classloader, factory, this );
           }
           catch( Throwable e )
           {
  @@ -298,7 +310,7 @@
               throw new RepositoryException( buffer.toString(), e );
           }
       }
  -
  +  
       // ------------------------------------------------------------------------
       // InitialContext
       // ------------------------------------------------------------------------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message