mcconnell 02/05/02 21:59:48
Modified: all/src/scratchpad/org/apache/avalon/excalibur/service
ServiceRegistry.java
Log:
no message
Revision Changes Path
1.7 +87 -63
jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/service/ServiceRegistry.java
Index: ServiceRegistry.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/all/src/scratchpad/org/apache/avalon/excalibur/service/ServiceRegistry.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ServiceRegistry.java 24 Mar 2002 09:56:41 -0000 1.6
+++ ServiceRegistry.java 3 May 2002 04:59:48 -0000 1.7
@@ -8,41 +8,50 @@
package org.apache.avalon.excalibur.service;
import java.io.File;
+import java.io.InputStream;
import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.Vector;
import java.util.Iterator;
import java.util.Map;
-import java.util.Vector;
-import java.util.jar.Attributes;
+import java.util.Hashtable;
+import java.util.Enumeration;
import java.util.jar.JarFile;
-import org.apache.avalon.framework.CascadingException;
+import java.util.jar.Attributes;
+import java.util.jar.Attributes.Name;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.CascadingException;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
/**
- * Implementation class that provides support for the registration of
+ * Implementation class that provides support for the registration of
* meta information about available service implementations.
*/
class ServiceRegistry extends AbstractLogEnabled implements Configurable
{
- private Configuration m_config;
+ private Configuration m_config;
private Vector m_repository = new Vector();
private UnitInfo[] m_block_info_set;
private Hashtable m_table;
private Hashtable m_lookup;
private boolean m_verbose = false;
+ private File m_root;
- /**
- * Creation of a new <code>ServiceRegistry</code>
- * @param verbose if TRUE, enable DEBUG message priority logging
- */
- public ServiceRegistry( boolean verbose )
+ /**
+ * Creation of a new <code>ServiceRegistry</code>
+ * @param verbose if TRUE, enable DEBUG message priority logging
+ */
+ public ServiceRegistry( File root, boolean verbose )
{
m_verbose = verbose;
+ m_root = root;
}
public void configure( Configuration config )
@@ -50,59 +59,59 @@
m_config = config;
}
- /**
- * Initialize the registry.
- */
+ /**
+ * Initialize the registry.
+ */
public void initialize() throws Exception
{
- if( getLogger() == null ) throw new IllegalStateException( "Factory
logging has not been enabled." );
- if( m_config == null ) throw new IllegalStateException( "Factory has
not been configured." );
+ if( getLogger() == null ) throw new IllegalStateException("Factory
logging has not been enabled.");
+ if( m_config == null ) throw new IllegalStateException("Factory has
not been configured.");
}
- /**
- * Populates the set of available services based on a supplied
- * vector of jar files.
- * @param list a list of jar files
- */
+ /**
+ * Populates the set of available services based on a supplied
+ * vector of jar files.
+ * @param list a list of jar files
+ */
public void register( Vector list ) throws PipelineException
{
Vector registry = new Vector();
Enumeration enum = list.elements();
while( enum.hasMoreElements() )
{
- File target = (File)enum.nextElement();
+ File target = (File) enum.nextElement();
register( target );
}
}
- /**
- * Register a jar file with the registry.
- * @param file the jar file to register
- */
+ /**
+ * Register a jar file with the registry.
+ * @param file the jar file to register
+ */
public void register( File target ) throws PipelineException
{
UnitInfo[] blocks = getUnitInfo( target );
- for( int i = 0; i < blocks.length; i++ )
+ for( int i=0; i<blocks.length; i++ )
{
- UnitInfo info = blocks[ i ];
+ UnitInfo info = blocks[i];
m_repository.add( info );
}
}
- /**
- * Lookup the meta info for an implementation based
- * on a supplied service requirement.
- * @param info meta info describing the required implemenation info
- (return null if no implementation info matches the request)
- * @return UnitInfo meta information about an available implementation
- */
+ /**
+ * Lookup the meta info for an implementation based
+ * on a supplied service requirement.
+ * @param info meta info describing the required implemenation info
+ (return null if no implementation info matches the request)
+ * @return UnitInfo meta information about an available implementation
+ */
public UnitInfo lookup( DependencyInfo info )
{
Enumeration enum = m_repository.elements();
while( enum.hasMoreElements() )
{
- UnitInfo block_info = (UnitInfo)enum.nextElement();
- if( block_info.provides( info.getService() ) )
+ UnitInfo block_info = (UnitInfo) enum.nextElement();
+ if( block_info.provides( info.getService() ) )
{
Configuration config = info.getConfiguration();
return new UnitInfo( block_info, config );
@@ -111,11 +120,11 @@
return null;
}
- /**
- * Returns an array of block infos provided by a supplied jar file.
- * @param file a jar file
- * @return a <code>UnitInfo[]<code> provided by the jar file
- */
+ /**
+ * Returns an array of block infos provided by a supplied jar file.
+ * @param file a jar file
+ * @return a <code>UnitInfo[]<code> provided by the jar file
+ */
private UnitInfo[] getUnitInfo( File file ) throws PipelineException
{
Vector vector = new Vector();
@@ -123,23 +132,37 @@
{
//
// if the file contains block declarations, then pipeline and
- // blocks as a supporting service that will be provided to the
+ // blocks as a supporting service that will be provided to the
// target server
//
-
+
String[] blocks = getBlocks( file );
- for( int i = 0; i < blocks.length; i++ )
+ for( int i=0; i<blocks.length; i++ )
{
- final String path = blocks[ i ];
- vector.add( new UnitInfo( path ) );
+ final String path = blocks[i];
+ try
+ {
+ vector.add( new UnitInfo( path, m_root ) );
+ }
+ catch( Throwable e )
+ {
+ if( m_verbose )
+ {
+ getLogger().debug( "bypassing block: " + path, e );
+ }
+ else
+ {
+ getLogger().debug( "bypassing block: " + path );
+ }
+ }
}
}
catch( Throwable e )
{
throw new CascadingRuntimeException(
- "Unexpected error while attempting to load file: " + file, e
);
+ "Unexpected error while attempting to load file: " + file, e );
}
- return (UnitInfo[])vector.toArray( new UnitInfo[ 0 ] );
+ return (UnitInfo[]) vector.toArray( new UnitInfo[0] );
}
@@ -147,13 +170,13 @@
// utilities
//===============================================================================
- /**
- * Returns an array of <code>String</code>s corresponding to the set of
classnames
- * where each classname is a declared block within the supplied jar file.
- * @param file a jar file
- */
+ /**
+ * Returns an array of <code>String</code>s corresponding to the set of
classnames
+ * where each classname is a declared block within the supplied jar file.
+ * @param file a jar file
+ */
private String[] getBlocks( File file )
- throws CascadingException, IllegalArgumentException
+ throws CascadingException, IllegalArgumentException
{
final Vector vector = new Vector();
try
@@ -163,17 +186,17 @@
Iterator iterator = map.keySet().iterator();
while( iterator.hasNext() )
{
- String name = (String)iterator.next();
- Attributes attributes = (Attributes)map.get( name );
+ String name = (String) iterator.next();
+ Attributes attributes = (Attributes) map.get( name );
Iterator it = attributes.keySet().iterator();
while( it.hasNext() )
{
Object entry = it.next();
- if( entry.toString().equals( "Avalon-Block" ) )
+ if( entry.toString().equals("Avalon-Block") )
{
- if( attributes.get( entry ).equals( "true" ) )
+ if( attributes.get( entry ).equals("true") )
{
- vector.add( name.substring( 0, name.indexOf(
".class" ) ) );
+ vector.add(
name.substring(0,name.indexOf(".class")));
}
}
}
@@ -191,8 +214,9 @@
}
finally
{
- return (String[])vector.toArray( new String[ 0 ] );
+ return (String[]) vector.toArray( new String[0] );
}
}
}
+
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>