You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/11/23 14:00:18 UTC
cvs commit: jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/type DefaultTypeManager.java
mcconnell 2002/11/23 05:00:17
Modified: assembly/src/java/org/apache/excalibur/assembly/service
DefaultServiceManager.java
assembly/src/java/org/apache/excalibur/assembly/type
DefaultTypeManager.java
Log:
Updates to service and type manager resulting from unit test validation.
Revision Changes Path
1.4 +60 -34 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/DefaultServiceManager.java
Index: DefaultServiceManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/service/DefaultServiceManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultServiceManager.java 22 Nov 2002 23:42:37 -0000 1.3
+++ DefaultServiceManager.java 23 Nov 2002 13:00:17 -0000 1.4
@@ -113,13 +113,67 @@
/**
* The service builder.
*/
- private final ServiceBuilder m_builder = new ServiceBuilder();
+ private static final ServiceBuilder m_builder = new ServiceBuilder();
/**
* Table of component types keyed by implementation classname.
*/
private Hashtable m_services = new Hashtable();
+ /**
+ * Create a services associated from a supplied path.
+ *
+ * @param clazz the service class
+ * @return the service defintions
+ */
+ public static Service createService( Class clazz ) throws ServiceException
+ {
+ if( clazz == null )
+ {
+ throw new NullPointerException("clazz");
+ }
+
+ try
+ {
+ return m_builder.build( clazz.getName(), clazz.getClassLoader() );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Could not create a service relative to the path: "
+ + clazz.getName() + " due to a service build error.";
+ throw new ServiceException( error, e );
+ }
+ }
+
+ /**
+ * Create a service instance based on a supplied classname.
+ *
+ * @param classname the component implementation classname
+ * @param loader the classloader to use
+ * @return the component type
+ */
+ public static Service createService( String classname, ClassLoader loader ) throws ServiceException
+ {
+ if( classname == null )
+ {
+ throw new NullPointerException("classname");
+ }
+
+ try
+ {
+ Class clazz = loader.loadClass( classname );
+ return createService( clazz );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to build a service from the classname: " + classname;
+ throw new ServiceException( error, e );
+ }
+ }
+
+
//==============================================================
// Contextualizable
//==============================================================
@@ -205,11 +259,11 @@
/**
* Locate a {@link Service} instances associated with the
- * supplied classname and version. If a formal service defintion is
- * unknown the method returns a default service defintion based on
- * the supplied classname and version.
+ * supplied classname and version. If a service defintion is not
+ * found locally, the implementation redirects the request to
+ * the parent service manager.
*
- * @return the service matching the supplied implementation classname.
+ * @return the service matching the supplied classname and version.
* @exception UnknownServiceException if a matching service cannot be found
*/
public Service getService( String classname, Version version ) throws UnknownServiceException
@@ -296,34 +350,6 @@
map.put( version, service );
}
-
- /**
- * Add a services associated with the supplied path.
- *
- * @param path the service class name
- * @return the service defintions
- */
- public Service addService( String path ) throws ServiceException
- {
- final String classname = path.replace( '/', '.' );
-
- Service service;
- try
- {
- service = m_builder.build( classname, m_classloader );
- }
- catch( Throwable e )
- {
- final String error =
- "Could not register a service relative to the path: "
- + path + " due to a service build error.";
- throw new ServiceException( error, e );
- }
-
- addService( service );
- return service;
- }
-
/**
* Internal utility that returns a map of services keyed by version. The
1.6 +2 -2 jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/type/DefaultTypeManager.java
Index: DefaultTypeManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/type/DefaultTypeManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultTypeManager.java 22 Nov 2002 23:42:37 -0000 1.5
+++ DefaultTypeManager.java 23 Nov 2002 13:00:17 -0000 1.6
@@ -124,7 +124,7 @@
}
/**
- * Register a type instance based on a supplied classname.
+ * Create a type instance based on a supplied classname and classloader.
*
* @param classname the component implementation classname
* @param loader the classloader to use
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>