mcconnell 2002/11/11 02:37:42
Added: meta/src/java/org/apache/excalibur/meta/model
ModelException.java ModelRuntimeException.java
package.html
meta/src/java/org/apache/excalibur/meta/model/verifier
ProfileVerifier.java Resources.properties
package.html
Log:
Initial commit of supporting resources including exceptions, factories and
package documentation.
Revision Changes Path
1.1
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/ModelException.java
Index: ModelException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.excalibur.meta.model;
import org.apache.avalon.framework.CascadingException;
/**
* Exception to indicate that there was a model related error.
*
* @author <a href="mailto:mcconnell@;apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/11 10:37:41 $
*/
public final class ModelException
extends CascadingException
{
/**
* Construct a new <code>ModelException</code> instance.
*
* @param message The detail message for this exception.
*/
public ModelException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>ModelException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public ModelException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/ModelRuntimeException.java
Index: ModelRuntimeException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.excalibur.meta.model;
import org.apache.avalon.framework.CascadingRuntimeException;
/**
* Exception to indicate that there was a model related runtime error.
*
* @author <a href="mailto:mcconnell@;apache.org">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/11 10:37:41 $
*/
public final class ModelRuntimeException
extends CascadingRuntimeException
{
/**
* Construct a new <code>ModelRuntimeException</code> instance.
*
* @param message The detail message for this exception.
*/
public ModelRuntimeException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>ModelRuntimeException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public ModelRuntimeException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/package.html
Index: package.html
===================================================================
<body>
<p>
The <code>model</code> package contains the formal meta data model. These classes
define the criteria used to populate a Profile, including context management,
configuration management, and logging category management.
</p>
<h3>Object Model (UML)</h3>
<p><img src=doc-files/uml.gif border=0></p>
</body>
1.1
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/verifier/ProfileVerifier.java
Index: ProfileVerifier.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software
* itself, if and wherever such third-party acknowledgments
* normally appear.
*
* 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.excalibur.meta.model.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.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.excalibur.meta.model.Profile;
import org.apache.excalibur.meta.info.ContextDescriptor;
import org.apache.excalibur.meta.info.ReferenceDescriptor;
import org.apache.excalibur.meta.info.ServiceDescriptor;
import org.apache.excalibur.meta.info.StageDescriptor;
import org.apache.excalibur.meta.info.Type;
import org.apache.excalibur.meta.verifier.ComponentVerifier;
import org.apache.excalibur.meta.verifier.VerifyException;
/**
* This Class verifies that an implementation is valid wrt the
* Profile. It performs a number of checks to make sure
* that the implementation class is consistent with MetaData.
* 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 {@link 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@;apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/11 10:37:42 $
*/
public class ProfileVerifier
extends AbstractLogEnabled
{
private static final Resources REZ =
ResourceManager.getPackageResources( ProfileVerifier.class );
/**
* The verifier for components in assembly.
*/
private final ComponentVerifier m_verifier;
/**
* Create an MetaDataVerifier using base Componert ComponentVerifier.
*/
public ProfileVerifier()
{
this( new ComponentVerifier() );
}
/**
* Create an AssemblyVerifier using specified Component ComponentVerifier.
* @param verifier the component verifier used by the meta-data verifier
*/
public ProfileVerifier( final ComponentVerifier verifier )
{
if( null == verifier )
{
throw new NullPointerException( "verifier" );
}
m_verifier = verifier;
}
/**
* Assign a logging channel to the verifier.
* @param logger the logging channel
*/
public void enableLogging( final Logger logger )
{
super.enableLogging( logger );
setupLogger( m_verifier );
}
/**
* Verfiy that specified components designate classes that implement the
* advertised interfaces. And conforms to expectations of MetaData.
*
* @param profile the Profile object for the components
* @param classLoader the ClassLoader to load profile from
* @throws VerifyException if an error occurs
*/
public void verifyType( final Profile profile,
final ClassLoader classLoader )
throws VerifyException
{
final Class clazz = getClass( classLoader, profile );
verifyType( profile, clazz );
}
/**
* Verfiy that specified components designate classes that implement the
* advertised interfaces. And confrorm to expectations of MetaData.
*
* @param profile the Profile object for the components
* @param clazz the implemetation class
* @throws VerifyException if an error occurs
*/
public void verifyType( final Profile profile,
final Class clazz )
throws VerifyException
{
final String name = profile.getName();
final Class[] interfaces =
getServiceClasses( name,
profile.getType().getServices(),
clazz.getClassLoader() );
final Class[] phases =
getPhaseClasses( name,
profile.getType().getStages(),
clazz.getClassLoader() );
m_verifier.verifyType( name, clazz, interfaces, phases );
verifyContextPresence( profile, clazz );
}
/**
* Verify that the component does not include redundant context entries
* and implemets Contextulizable
*
* @param profile the profile metadata
* @param clazz the class implementing profile
* @throws VerifyException if fails verification check
*/
protected void verifyContextPresence( final Profile profile,
final Class clazz )
throws VerifyException
{
final Type info = profile.getType();
final ContextDescriptor context = info.getContext();
final int count = context.getEntrys().length;
if( !Contextualizable.class.isAssignableFrom( clazz ) )
{
if( 0 != count )
{
final String message =
REZ.getString( "metadata.declare-uneeded-entrys.error",
profile.getName(),
getClassname( profile ) );
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 profile
* @param services the services the profile 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 ReferenceDescriptor service = services[ i ].getReference();
final String classname = service.getClassname();
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;
}
/**
* Retrieve an array of Classes for all the phases that a Component
* is depenent on.
*
* @param name the name of profile
* @param phases the set of stage depedencies
* @param classLoader the classLoader
* @return an array of Classes for all the services
* @throws VerifyException if an error occurs
*/
protected Class[] getPhaseClasses( final String name,
final StageDescriptor[] phases,
final ClassLoader classLoader )
throws VerifyException
{
final Class[] classes = new Class[ phases.length ];
for( int i = 0; i < phases.length; i++ )
{
final ReferenceDescriptor service = phases[ i ].getReference();
final String classname = service.getClassname();
try
{
classes[ i ] = classLoader.loadClass( classname );
}
catch( final Throwable t )
{
final String message =
REZ.getString( "metadata.bad-phase-class.error",
name,
classname,
t.toString() );
throw new VerifyException( message, t );
}
}
return classes;
}
/**
* Load class object for specified Profile.
*
* @param classLoader the ClassLoader to use
* @param profile the meta data associate with profile
* @return the Class object
* @throws VerifyException if unable to aquire class object
*/
private Class getClass( final ClassLoader classLoader,
final Profile profile )
throws VerifyException
{
Class clazz = null;
try
{
clazz = classLoader.loadClass( getClassname( profile ) );
}
catch( final Exception e )
{
final String message =
REZ.getString( "assembly.bad-class.error",
profile.getName(),
getClassname( profile ),
e.toString() );
throw new VerifyException( message );
}
return clazz;
}
/**
* Utility method to aquire classname for profile.
*
* @param profile the profile
* @return the classname for profile
*/
private String getClassname( final Profile profile )
{
return profile.getType().getInfo().getImplementationKey();
}
}
1.1
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/verifier/Resources.properties
Index: Resources.properties
===================================================================
#Assembly Verifier
assembly.valid-names.notice=Verifying that the names specified for component are
valid.
assembly.unique-names.notice=Verifying that the names specified for the components
are unique.
assembly.dependencies-mapping.notice=Verifying that the dependency mapping is valid
according to the type.
assembly.dependency-references.notice=Verifying that the dependency mapping for
every component is valid with respect to other components.
assembly.nocircular-dependencies.notice=Verifying that there are no circular
dependencies between components.
assembly.component-type.notice=Verifying that the specified Components have valid
types.
assembly.circular-dependency.error=Component named "{0}" has a circular dependency
via path: {1}.
assembly.missing-dependency.error=Component "{1}" that satisfies the dependency with
role "{0}" of component "{2}" does not exist.
assembly.dependency-missing-service.error=Profile {0}" is associated to profile
"{1}" under the role "{2}" however, the provider does not supply the required service
"{3}".
assembly.bad-class.error=Unable to load class "{1}" for type named "{0}". (Reason:
{2}).
assembly.bad-name.error=The component name "{0}" is invalid. Valid names contain
only letters, digits and the '-' character.
assembly.duplicate-name.error=The name "{0}" is used by multiple Components in
assembly.
assembly.unknown-dependency.error=Unknown dependency named "{0}" with role "{1}"
declared for Component {2}.
assembly.unspecified-dependency.error=Dependency for role "{0}" not specified for
the Component named "{1}".
#MetaData Verifier
metadata.bad-service-class.error=Unable to load service class "{1}" for Component
named "{0}". (Reason: {2}).
metadata.bad-phase-class.error=Unable to load phase 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.error=Component named "{0}" of type "{1}" is not
Contextualizable but declares Context Entrys.
1.1
jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/model/verifier/package.html
Index: package.html
===================================================================
<body>
A set of classes supporting verification of components and component
assemblies using class and component meta-data information.
<h3>Overview</h3>
<p>This package includes a set of classes supporting the verification of the
integrity of a component profile based on supplied meta data. The
{@link org.apache.excalibur.meta.verifier.ComponentVerifier} provides
support for the validation of a component class. It includes validation
functions that check for structural and best-practice integrity related to
the class, lifecycle patterns and service.
</body>
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>