avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel DefaultKernel.java
Date Wed, 11 Dec 2002 01:27:05 GMT
mcconnell    2002/12/10 17:27:05

  Modified:    merlin/src/java/org/apache/avalon/merlin/kernel
                        DefaultKernel.java
  Log:
  Added ability to get a block configuration for the jar file.
  
  Revision  Changes    Path
  1.5       +52 -8     avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultKernel.java	9 Dec 2002 12:16:25 -0000	1.4
  +++ DefaultKernel.java	11 Dec 2002 01:27:05 -0000	1.5
  @@ -55,9 +55,11 @@
   import java.io.FileInputStream;
   import java.io.InputStream;
   import java.net.URL;
  +import java.util.Enumeration;
   import java.util.jar.JarFile;
   import java.util.jar.Attributes;
   import java.util.jar.Manifest;
  +import java.util.zip.ZipEntry;
   import java.net.JarURLConnection;
   
   import org.apache.avalon.framework.CascadingException;
  @@ -69,6 +71,7 @@
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  +import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.context.Contextualizable;
  @@ -114,6 +117,8 @@
       // static
       //==============================================================
   
  +    private static final String BLOCK_XML_ENTRY = "BLOCK-INF/block.xml";
  +
       /**
        * The logging manager that we use to construct logging catagories
        * and logging channels.
  @@ -280,7 +285,7 @@
   
           if( getLogger().isDebugEnabled() )
           {
  -            getLogger().debug( "commencing container assembly" );
  +            getLogger().debug( "block assembly" );
           }
   
           ClasspathDescriptor blocks = 
  @@ -304,7 +309,8 @@
   
       private Block installBlock( URL url ) throws Exception
       {
  -         Manifest manifest = getManifest( url );
  +         JarFile jar = getJarFile( url );
  +         Manifest manifest = jar.getManifest();
            if( !isBlock( manifest ) )
            {
                final String warning = 
  @@ -312,6 +318,8 @@
                throw new IllegalArgumentException( warning );
            }
   
  +         Configuration blockConfig = getBlockConfiguration( jar );
  +
            String name = DefaultBlock.getName( manifest );
            if( name == null )
            {
  @@ -319,7 +327,7 @@
                throw new IllegalArgumentException( error );
            }
   
  -         getLogger().debug( "installing block: " + name );
  +         getLogger().debug( "[" + name + "]");
            DefaultBlock block = new DefaultBlock();
            block.enableLogging( getLogger().getChildLogger( name ) );
            DefaultContext context = new DefaultContext();
  @@ -498,18 +506,17 @@
           return ( manifest.getAttributes( Block.AVALON_BLOCK_KEY ) != null );
       }
   
  -    private Manifest getManifest( URL url )
  +    private JarFile getJarFile( URL url )
       {
           try
           {
               JarURLConnection connection = (JarURLConnection) url.openConnection();
  -            JarFile jar = connection.getJarFile();
  -            return jar.getManifest();
  +            return connection.getJarFile();
           }
           catch( IOException ioe )
           {
               final String error = 
  -              "Unexpected IO Exception while reading manifest on url: " + url;
  +              "Unexpected IO Exception while jar file from url: " + url;
               throw new RuntimeException( error );
           }
       }
  @@ -524,4 +531,41 @@
           return "DefaultKernel"
             + ":" + System.identityHashCode( this );
       }
  +
  +    private Configuration getBlockConfiguration( JarFile jar ) throws Exception
  +    {
  +        if( jar == null )
  +        {
  +            throw new NullPointerException( "jar" );
  +        }
  +
  +        ZipEntry entry = jar.getEntry( BLOCK_XML_ENTRY );
  +        if( entry == null )
  +        {
  +            if( getLogger().isDebugEnabled() )
  +            {
  +                final String msg = "No block configuration - applying defaults.";
  +                getLogger().debug( msg );
  +            }
  +            return new DefaultConfiguration( "default", null );
  +        }
  +
  +        try
  +        {
  +            DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +            InputStream is = jar.getInputStream( entry );
  +            if( is == null )
  +            {
  +                throw new RuntimeException(
  +                    "Could not load the configuration resource \"" + jar.getName() + "\""
);
  +            }
  +            return builder.build( is );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "Unable to create configuration from jar file: " + jar.getName();
  +            throw new KernelException( error, e );
  +        }
  +    }
  +
   }
  
  
  

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


Mime
View raw message