You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2004/02/01 02:04:45 UTC
cvs commit: avalon/fortress/container/src/impl/org/apache/avalon/fortress/util Service.java
hammett 2004/01/31 17:04:44
Modified: fortress/container/src/impl/org/apache/avalon/fortress/impl/role
ServiceMetaManager.java
fortress/container/src/impl/org/apache/avalon/fortress/util
Service.java
Log:
Patch for use context classloader to obtain info files (meta and etc)
Revision Changes Path
1.10 +2 -2 avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java
Index: ServiceMetaManager.java
===================================================================
RCS file: /home/cvs/avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/role/ServiceMetaManager.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ServiceMetaManager.java 2 Jul 2003 12:28:42 -0000 1.9
+++ ServiceMetaManager.java 1 Feb 2004 01:04:44 -0000 1.10
@@ -196,7 +196,7 @@
private void setupImplementations( final String role )
throws ClassNotFoundException
{
- final Iterator it = Service.providers( getLoader().loadClass( role ) );
+ final Iterator it = Service.providers( getLoader().loadClass( role ), getLoader() );
while ( it.hasNext() )
{
1.9 +88 -75 avalon/fortress/container/src/impl/org/apache/avalon/fortress/util/Service.java
Index: Service.java
===================================================================
RCS file: /home/cvs/avalon/fortress/container/src/impl/org/apache/avalon/fortress/util/Service.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Service.java 18 Jun 2003 13:16:48 -0000 1.8
+++ Service.java 1 Feb 2004 01:04:44 -0000 1.9
@@ -82,6 +82,93 @@
{
}
+ /**
+ * Get all the providers for the specified services.
+ *
+ * @param klass the interface <code>Class</code>
+ * @param loader the <code>ClassLoader to be used.</code>
+ *
+ * @return an <code>Iterator</code> for the providers.
+ */
+ public static synchronized Iterator providers( final Class klass, ClassLoader loader )
+ {
+ final String serviceFile = SERVICES + klass.getName();
+
+ if ( null == loader )
+ {
+ loader = klass.getClassLoader();
+ }
+
+ Set providerSet = (Set) providers.get( serviceFile );
+
+ if ( null == providerSet )
+ {
+ providerSet = new HashSet();
+ Enumeration enum = null;
+ boolean errorOccurred = false;
+
+ providers.put( serviceFile, providerSet );
+
+ try
+ {
+ enum = loader.getResources( serviceFile );
+ }
+ catch ( IOException ioe )
+ {
+ errorOccurred = true;
+ }
+
+ if ( !errorOccurred )
+ {
+ while ( enum.hasMoreElements() )
+ {
+ try
+ {
+ final URL url = (URL) enum.nextElement();
+ final InputStream is = url.openStream();
+ final BufferedReader reader = new BufferedReader(
+ new InputStreamReader( is,
+ "UTF-8" ) );
+
+ String line = reader.readLine();
+ while ( null != line )
+ {
+ try
+ {
+ final int comment = line.indexOf( '#' );
+
+ if ( comment > -1 )
+ {
+ line = line.substring( 0, comment );
+ }
+
+ line.trim();
+
+ if ( line.length() > 0 )
+ {
+ // We just want the types, not the instances
+ providerSet.add( loader.loadClass( line ) );
+ }
+ }
+ catch ( Exception e )
+ {
+ // try the next line
+ }
+
+ line = reader.readLine();
+ }
+ }
+ catch ( Exception e )
+ {
+ // try the next file
+ }
+ }
+ }
+ }
+
+ return providerSet.iterator();
+ }
+
/**
* Get all the providers for the specified services.
*
@@ -91,82 +178,8 @@
*/
public static synchronized Iterator providers( final Class klass )
{
- final String serviceFile = SERVICES + klass.getName();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if ( null == loader )
- {
- loader = klass.getClassLoader();
- }
-
- Set providerSet = (Set) providers.get( serviceFile );
-
- if ( null == providerSet )
- {
- providerSet = new HashSet();
- Enumeration enum = null;
- boolean errorOccurred = false;
-
- providers.put( serviceFile, providerSet );
-
- try
- {
- enum = loader.getResources( serviceFile );
- }
- catch ( IOException ioe )
- {
- errorOccurred = true;
- }
-
- if ( !errorOccurred )
- {
- while ( enum.hasMoreElements() )
- {
- try
- {
- final URL url = (URL) enum.nextElement();
- final InputStream is = url.openStream();
- final BufferedReader reader = new BufferedReader(
- new InputStreamReader( is,
- "UTF-8" ) );
-
- String line = reader.readLine();
- while ( null != line )
- {
- try
- {
- final int comment = line.indexOf( '#' );
-
- if ( comment > -1 )
- {
- line = line.substring( 0, comment );
- }
-
- line.trim();
-
- if ( line.length() > 0 )
- {
- // We just want the types, not the instances
- providerSet.add( loader.loadClass( line ) );
- }
- }
- catch ( Exception e )
- {
- // try the next line
- }
-
- line = reader.readLine();
- }
- }
- catch ( Exception e )
- {
- // try the next file
- }
- }
- }
- }
-
- return providerSet.iterator();
+ return providers( klass, loader );
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org