mcconnell    2003/02/16 02:59:04

  Modified:    assembly/src/java/org/apache/avalon/assembly/engine
                        EngineClassLoader.java
  Log:
  Simplification of the process for creating a child engine.
  
  Revision  Changes    Path
  1.34      +102 -4    
avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java
  
  Index: EngineClassLoader.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- EngineClassLoader.java    8 Feb 2003 08:52:11 -0000       1.33
  +++ EngineClassLoader.java    16 Feb 2003 10:59:04 -0000      1.34
  @@ -55,6 +55,7 @@
   import java.lang.reflect.Constructor;
   import java.net.URL;
   import java.net.URLClassLoader;
  +import java.net.MalformedURLException;
   import java.net.JarURLConnection;
   import java.net.URLStreamHandlerFactory;
   import java.util.Map;
  @@ -145,6 +146,11 @@
      /**
       * Constructor supplied urls.
       */
  +    private URL m_base;
  +
  +   /**
  +    * Constructor supplied urls.
  +    */
       private URL[] m_urls = new URL[0];
   
      /**
  @@ -330,6 +336,11 @@
               m_map = (Map) context.get( "urn:assembly:system-map" );
           }
   
  +        if( context.hasEntry( "urn:assembly:engine.base"  ) )
  +        {
  +            m_base = (URL) context.get( "urn:assembly:engine.base" );
  +        }
  +
           if( context.hasEntry( "urn:assembly:engine.extensions" ) )
           {
               m_descriptor = (LibraryDescriptor)context.get( 
"urn:assembly:engine.extensions" );
  @@ -641,6 +652,58 @@
           }
       }
   
  +   /**
  +    * Creation of a subsidiary engine.
  +    * @param base the URL from which classpath declarations 
  +    *    shall be resolved
  +    * @param extensions the declaration of supplimentary extension directories
  +    * @param classpath a classpath descriptor
  +    * @return the new engine
  +    */
  +    public EngineClassLoader newInstance( 
  +      URL base, LibraryDescriptor extensions, ClasspathDescriptor classpath )
  +      throws EngineException
  +    {
  +        return newInstance( base, extensions, classpath, new URL[0] );
  +    }
  +
  +   /**
  +    * Creation of a subsidiary engine.
  +    * @param base the URL from which classpath declarations 
  +    *    shall be resolved
  +    * @param extensions the declaration of supplimentary extension directories
  +    * @param classpath a classpath descriptor
  +    * @param urls a set of URLs to be added to the engine
  +    * @return the new engine
  +    */
  +    public EngineClassLoader newInstance( 
  +      URL base, LibraryDescriptor extensions, ClasspathDescriptor classpath, URL[] 
urls )
  +      throws EngineException
  +    {
  +        try
  +        {
  +            EngineClassLoader engine = new EngineClassLoader( urls, this );
  +            engine.enableLogging( getLogger() );
  +            DefaultLocator context = new DefaultLocator();
  +            context.put( "urn:assembly:home", m_home );
  +            context.put( "urn:assembly:engine.base", base );
  +            context.put( "urn:assembly:engine.bootstrap", "false" );
  +            context.put( "urn:assembly:engine.extensions", extensions );
  +            context.put( "urn:assembly:engine.classpath", classpath );
  +            context.put( "urn:assembly:logging.manager", m_logging );
  +            context.put( "urn:assembly:threads.manager", m_pool );
  +            context.makeReadOnly();
  +            engine.contextualize( context );
  +            engine.initialize();
  +            return engine;
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "Engine creation failure.";
  +             throw new EngineException( error, e );
  +        }
  +    }
  +
       //==============================================================
       // URLClassLoader
       //==============================================================
  @@ -665,21 +728,52 @@
        * @param base the base directory from which relative classpath entries
        * will be resolved.
        */
  -    public void addClasspath( ClasspathDescriptor classpath )
  +    public void addClasspath( ClasspathDescriptor classpath ) throws 
MalformedURLException
       {
           if( classpath == null )
           {
               throw new NullPointerException( "classpath" );
           }
  +
           if( getLogger() == null )
           {
               throw new IllegalStateException( "logging" );
           }
  +
           if( getLogger().isDebugEnabled() )
           {
              getLogger().debug( REZ.getString( "add.classpath" ) );
           }
   
  +        if( m_base != null )
  +        {
  +            URL[] urls = ClasspathDescriptor.expand( m_base, classpath );
  +            for( int j = 0; j < urls.length; j++ )
  +            {
  +                URL inc = urls[ j ];
  +                try
  +                {
  +                    addURL( inc );
  +                }
  +                catch( Throwable e )
  +                {
  +                    throw new EngineRuntimeException( 
  +                      REZ.getString( "classpath.include.error", inc ) , e );
  +                }
  +            }
  +            return;
  +        }
  +        else
  +        {
  +           getLogger().warn( "#### Expanding a classpath without a base!" );
  +        }
  +
  +        //
  +        // #########################################################
  +        // we should be able to drop the rest once we update the m_base to be a 
required
  +        // context value - or we construct a rationale default
  +        // ##########################################################
  +
           List list = new ArrayList();
           FilesetDescriptor[] dirs = classpath.getFilesetDescriptors();
           if( getLogger().isDebugEnabled() )
  @@ -731,6 +825,11 @@
           }
       }
   
  +   /**
  +    * Check the jar file manifest from the supplied URL for extension depedencies
  +    * and for all extensions add each extension to the classloader.
  +    * @param url a jar file URL
  +    */
       private void addExtensions( URL url )
       {
           if( isDirectory( url ) )
  @@ -759,8 +858,7 @@
           }
           catch( Throwable e )
           {
  -            final String error = REZ.getString("add.extension.error", url );
  -            throw new EngineRuntimeException( error, e );
  +            // error will be captured when we invoke addURL
           }
       }
   
  
  
  

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

Reply via email to