donaldp 2002/09/13 23:07:18
Modified: info/src/java/org/apache/avalon/framework/tools/verifier
ComponentVerifier.java Resources.properties
Added: info/src/java/org/apache/avalon/framework/tools/verifier
InfoVerifier.java
Log:
Migrate the MetaDataVerifier here, remove dependencies on MetaData and rename
it to InfoVerifier.
Revision Changes Path
1.2 +27 -2
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/verifier/ComponentVerifier.java
Index: ComponentVerifier.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/verifier/ComponentVerifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ComponentVerifier.java 9 Sep 2002 11:35:16 -0000 1.1
+++ ComponentVerifier.java 14 Sep 2002 06:07:17 -0000 1.2
@@ -78,7 +78,32 @@
final Class[] services )
throws VerifyException
{
- verifyClass( name, implementation );
+ verifyComponent( name, implementation, services, true );
+ }
+
+ /**
+ * Verify that the supplied implementation class
+ * and service classes are valid for a component.
+ *
+ * @param name the name of component
+ * @param implementation the implementation class of component
+ * @param services the classes representing services
+ * @param buildable if true will verify that it is instantiateable
+ * via class.newInstance(). May not be required for
+ * some components that are created via a factory.
+ * @throws VerifyException if error thrown on failure and
+ * component fails check
+ */
+ public void verifyComponent( final String name,
+ final Class implementation,
+ final Class[] services,
+ final boolean buildable )
+ throws VerifyException
+ {
+ if( buildable )
+ {
+ verifyClass( name, implementation );
+ }
verifyLifecycles( name, implementation );
verifyServices( name, services );
verifyImplementsServices( name, implementation, services );
1.2 +6 -0
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/verifier/Resources.properties
Index: Resources.properties
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/verifier/Resources.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Resources.properties 9 Sep 2002 11:35:16 -0000 1.1
+++ Resources.properties 14 Sep 2002 06:07:17 -0000 1.2
@@ -11,3 +11,9 @@
verifier.incompat-serviceable.error=The implementation class {1} for
component named "{0}" is both Serviceable and Composable (incompatible
lifecycle interfaces).
verifier.incompat-config.error=The implementation class {1} for component
named "{0}" is both Configurable and Parameterizable (incompatible lifecycle
interfaces).
verifier.noimpl-service.error=The implementation class {1} for component
named "{0}" does not implement the service interface {2} which it declares it
supports.
+
+#ComponentInfo Verifier
+metadata.bad-service-class.error=Unable to load service class "{1}" for
Component named "{0}". (Reason: {2}).
+metadata.nodeclare-deps.error=Component named "{0}" of type "{1}" is
Composable or Serviceable but does not declare any dependencies.
+metadata.declare-uneeded-deps.error=Component named "{0}" of type "{1}" is
not Composable or Serviceable but declares dependencies.
+metadata.declare-uneeded-entrys.
\ No newline at end of file
1.1
jakarta-avalon-excalibur/info/src/java/org/apache/avalon/framework/tools/verifier/InfoVerifier.java
Index: InfoVerifier.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.framework.tools.verifier;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.info.ComponentInfo;
import org.apache.avalon.framework.info.ContextDescriptor;
import org.apache.avalon.framework.info.ServiceDescriptor;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.tools.verifier.VerifyException;
import org.apache.avalon.framework.tools.verifier.ComponentVerifier;
/**
* This Class verifies that an implementation is valid wrt the
* ComponentMetaData. It performs a number of checks to make sure
* that the implementation class is consistent with ComponentMetaData.
* Some of the checks it performs include;
*
* <ul>
* <li>Verify that the Class objects for Component implement the
* service interfaces.</li>
* <li>Verify that the Class is a valid Avalon Component as per the
* rules in [EMAIL PROTECTED] ComponentVerifier} object.</li>
* <li>Verify that the Class is Composable/Serviceable if and only if
* dependencies are declared.</li>
* <li>Verify that the Class is Contextualizable if and context
* entrys are declared.</li>
* </ul>
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/09/14 06:07:17 $
*/
public class InfoVerifier
extends AbstractLogEnabled
{
private static final Resources REZ =
ResourceManager.getPackageResources( InfoVerifier.class );
/**
* The verifier for components in assembly.
*/
private final ComponentVerifier m_verifier;
/**
* Create an InfoVerifier using base Componern ComponentVerifier.
*/
public InfoVerifier()
{
this( new ComponentVerifier() );
}
/**
* Create an AssemblyVerifier using specified Component ComponentVerifier.
*/
public InfoVerifier( final ComponentVerifier verifier )
{
if( null == verifier )
{
throw new NullPointerException( "verifier" );
}
m_verifier = verifier;
}
public void enableLogging( final Logger logger )
{
super.enableLogging( logger );
setupLogger( m_verifier );
}
/**
* Verfiy that specified components designate classes that implement the
* advertised interfaces. And confrorm to expectations of [EMAIL
PROTECTED] ComponentInfo}.
*
* @param name the name of component
* @param implementationKey the implementationKey of component
* @param classLoader the ClassLoader to load component from
* @throws VerifyException if an error occurs
*/
public void verifyType( final String name,
final String implementationKey,
final ComponentInfo info,
final ClassLoader classLoader )
throws VerifyException
{
final Class clazz = getClass( classLoader, name, implementationKey );
verifyType( name, implementationKey, info, clazz );
}
/**
* Verfiy that specified components designate classes that implement the
* advertised interfaces. And confrorm to expectations of [EMAIL
PROTECTED] ComponentInfo}.
*
* @param name the name of component
* @param implementationKey the implementationKey of component
* @throws VerifyException if an error occurs
*/
public void verifyType( final String name,
final String implementationKey,
final ComponentInfo info,
final Class implementation )
throws VerifyException
{
final Class[] interfaces =
getServiceClasses( name,
info.getServices(),
implementation.getClassLoader() );
m_verifier.verifyComponent( name, implementation, interfaces, false );
verifyDependencyPresence( name, implementationKey, info,
implementation );
verifyContextPresence( name, implementationKey, info, implementation
);
}
/**
* Verify that the if the component is not Contextualizable that it
* does not declare Context Entrys.
*
* @param name the name of component
* @param implementationKey the implementationKey of component
* @param implementation the class implementing component
* @throws VerifyException if fails verification check
*/
protected void verifyContextPresence( final String name,
final String implementationKey,
final ComponentInfo info,
final Class implementation )
throws VerifyException
{
final ContextDescriptor context = info.getContextDescriptor();
final int count = context.getEntrys().length;
if( !Contextualizable.class.isAssignableFrom( implementation ) )
{
if( 0 != count )
{
final String message =
REZ.getString( "metadata.declare-uneeded-entrys.error",
name,
implementationKey );
throw new VerifyException( message );
}
}
}
/**
* Verify the component assembly logic.
* The implications verifies that the component:
* <p>Is not Composable/Serviceable and does not declare dependencys</p>
* <p>or</p>
* <p>Is Composable/Serviceable and does declare dependencys</p>
*
* @param name the name of component
* @param implementationKey the implementationKey of component
* @param implementation the class implementing component
* @throws VerifyException if fails verification check
*/
protected void verifyDependencyPresence( final String name,
final String implementationKey,
final ComponentInfo info,
final Class implementation )
throws VerifyException
{
final int count = info.getDependencies().length;
final boolean aquiresServices =
Composable.class.isAssignableFrom( implementation ) ||
Serviceable.class.isAssignableFrom( implementation );
if( !aquiresServices )
{
if( 0 != count )
{
final String message =
REZ.getString( "metadata.declare-uneeded-deps.error",
name,
implementationKey );
throw new VerifyException( message );
}
}
}
/**
* Retrieve an array of Classes for all the services that a Component
* offers. This method also makes sure all services offered are
* interfaces.
*
* @param name the name of component
* @param services the services the component offers
* @param classLoader the classLoader
* @return an array of Classes for all the services
* @throws VerifyException if an error occurs
*/
protected Class[] getServiceClasses( final String name,
final ServiceDescriptor[] services,
final ClassLoader classLoader )
throws VerifyException
{
final Class[] classes = new Class[ services.length ];
for( int i = 0; i < services.length; i++ )
{
final String classname = services[ i ].getImplementationKey();
try
{
classes[ i ] = classLoader.loadClass( classname );
}
catch( final Throwable t )
{
final String message =
REZ.getString( "metadata.bad-service-class.error",
name,
classname,
t.toString() );
throw new VerifyException( message, t );
}
}
return classes;
}
/**
* Load class object for specified component.
*
* @param classLoader the ClassLoader to use
* @param name the name of component
* @param implementationKey the implementationKey of component
* @return the Class object
* @throws VerifyException if unable to aquire class object
*/
private Class getClass( final ClassLoader classLoader,
final String name,
final String implementationKey )
throws VerifyException
{
Class clazz = null;
try
{
clazz = classLoader.loadClass( implementationKey );
}
catch( final Exception e )
{
final String message =
REZ.getString( "assembly.bad-class.error",
name,
implementationKey,
e.toString() );
throw new VerifyException( message );
}
return clazz;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>