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 2003/07/15 00:02:38 UTC
cvs commit: avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl DefaultTypeRepository.java
mcconnell 2003/07/14 15:02:38
Modified: merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl
DefaultTypeRepository.java
Log:
Additional checks when loading a type that verify that the extensions that a component declares that it provides are in fact loadable - patch by Vinay Chandran.
Revision Changes Path
1.6 +45 -2 avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl/DefaultTypeRepository.java
Index: DefaultTypeRepository.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/assembly/src/java/org/apache/avalon/assembly/engine/impl/DefaultTypeRepository.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultTypeRepository.java 12 Jul 2003 21:10:45 -0000 1.5
+++ DefaultTypeRepository.java 14 Jul 2003 22:02:37 -0000 1.6
@@ -65,6 +65,7 @@
import org.apache.avalon.meta.info.ReferenceDescriptor;
import org.apache.avalon.meta.info.ServiceDescriptor;
import org.apache.avalon.meta.info.StageDescriptor;
+import org.apache.avalon.meta.info.ExtensionDescriptor;
import org.apache.avalon.meta.info.Type;
import org.apache.avalon.meta.info.builder.TypeBuilder;
import org.apache.avalon.meta.verifier.ComponentVerifier;
@@ -376,10 +377,52 @@
String name = type.getInfo().getName();
Class clazz = getComponentClass( type );
Class[] classes = getServiceClasses( type );
+ Class[] lifecycleExtensions = getExtensionClasses( type );
ComponentVerifier verifier = new ComponentVerifier();
verifier.verifyComponent( name, clazz, classes );
}
+ /**
+ * Return the set of lifecycle extension classes provided by the given type.
+ *
+ * @param type the component type
+ * @return an array of classes represnting the lifecycle extension interfaces
+ * provided by the type
+ */
+ private Class[] getExtensionClasses( Type type )
+ {
+ ArrayList list = new ArrayList();
+ ExtensionDescriptor[] extensions = type.getExtensions();
+ for( int i = 0; i < extensions.length; i++ )
+ {
+ ExtensionDescriptor extension = extensions[i];
+ list.add( getExtensionClass( extension ) );
+ }
+ return (Class[]) list.toArray( new Class[0] );
+ }
+
+ /**
+ * Returns the lifecycle extension class provided by the type.
+ * @param extension the lifecycle extension type
+ * @return the class implementing the extension type
+ * @exception TypeRuntimeException if a classloader error occurs
+ */
+ private Class getExtensionClass( ExtensionDescriptor extension ) throws TypeRuntimeException
+ {
+ final String classname = extension.getReference().getClassname();
+ try
+ {
+ return m_classloader.loadClass( classname );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Could not load lifecycle extension class of type: "
+ + classname;
+ throw new TypeRuntimeException( error, e );
+ }
+ }
+
/**
* Return the set of interface classes for a given type that are declared
* or default to the "native" service access protocol and where the
@@ -400,7 +443,7 @@
"urn:avalon:service.protocol", "native" ).equals( "native" ))
&& (service.getAttribute( "urn:avalon:service.accessor", null ) == null) )
{
- list.add( getServiceClass( services[i] ) );
+ list.add( getServiceClass( service ) );
}
}
return (Class[]) list.toArray( new Class[0] );
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org