mcconnell 2002/11/23 09:46:28
Modified: assembly/src/java/org/apache/excalibur/assembly/profile
DefaultProfileManager.java ProfileManager.java
Log:
Updates to ProfileManager following unit test validation.
Revision Changes Path
1.4 +153 -68
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/profile/DefaultProfileManager.java
Index: DefaultProfileManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/profile/DefaultProfileManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultProfileManager.java 23 Nov 2002 16:32:00 -0000 1.3
+++ DefaultProfileManager.java 23 Nov 2002 17:46:28 -0000 1.4
@@ -59,6 +59,7 @@
import java.util.Hashtable;
import java.util.Iterator;
import java.util.ArrayList;
+import java.util.Enumeration;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
@@ -75,6 +76,7 @@
import org.apache.excalibur.meta.model.Profile;
import org.apache.excalibur.meta.model.builder.ProfileBuilder;
import org.apache.excalibur.meta.model.builder.ProfileCreator;
+import org.apache.excalibur.meta.model.verifier.ProfileVerifier;
import org.apache.excalibur.meta.info.ReferenceDescriptor;
import org.apache.excalibur.meta.info.ServiceDescriptor;
import org.apache.excalibur.meta.info.DependencyDescriptor;
@@ -88,7 +90,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision$ $Date$
*/
-public class DefaultProfileManager extends AbstractLogEnabled implements
Contextualizable, Initializable
+public class DefaultProfileManager extends AbstractLogEnabled implements
ProfileManager, Contextualizable, Initializable
{
//==============================================================
// static
@@ -99,60 +101,6 @@
*/
private static final ProfileBuilder m_builder = new ProfileBuilder();
- /**
- * Load a set of packaged profiles associated with the supplied class.
- *
- * @param class the component implementation class
- * @return the set of packaged component profiles
- */
- public static Profile[] loadProfiles( Class clazz, Type type ) throws
ProfileException, TypeException
- {
- if( clazz == null )
- {
- throw new NullPointerException("clazz");
- }
-
- if( type == null )
- {
- throw new NullPointerException("type");
- }
-
- Profile[] profiles;
- try
- {
- return m_builder.build( clazz.getClassLoader(), type );
- }
- catch( Throwable e )
- {
- final String error =
- "Build error while attempting to create packaged profiles for class:
"
- + clazz.getName();
- throw new ProfileException( error, e );
- }
- }
-
- /**
- * Create a profile from a supplied configuration.
- *
- * @param class the component implementation class
- * @return the set of packaged component profiles
- */
- public static Profile createProfile( Type type, Configuration config )
- throws ProfileException, TypeException
- {
- try
- {
- return m_builder.build( type, config );
- }
- catch( Throwable e )
- {
- final String error =
- "Profile build error while constructing a profile from supplied
configuration:\n"
- + ConfigurationUtil.list( config );
- throw new ProfileException( error, e );
- }
- }
-
//==============================================================
// state
//==============================================================
@@ -185,7 +133,7 @@
/**
* Table of component profiles keyed by profile name.
*/
- private final Map m_profiles = new Hashtable();
+ private final Hashtable m_profiles = new Hashtable();
//==============================================================
// Contextualizable
@@ -266,8 +214,130 @@
//==============================================================
/**
- * Get the set of profiles declared for a type.
- * @return the set of profile matching the supplied type.
+ * Load a set of packaged profiles associated with the supplied class.
+ * Profiles returned from this operation are not included within the
+ * manager. To register a profile with the manager use the {@link #addProfile}
+ * operation.
+ *
+ * @param type the component type used to locate an packaged profiles
+ * @return the set of packaged component profiles
+ */
+ public Profile[] loadProfiles( Type type ) throws ProfileException
+ {
+ if( type == null )
+ {
+ throw new NullPointerException("type");
+ }
+
+ try
+ {
+ return m_builder.build( m_classloader, type );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Build error while attempting to create packaged profiles for type: "
+ + type.getInfo().getClassname();
+ throw new ProfileException( error, e );
+ }
+ }
+
+ /**
+ * Create a profile from a supplied configuration.
+ *
+ * @param type the component type that the profile qualifies
+ * @param config a configuration fragment describing the deployment profile
+ * @return the deployment profile
+ */
+ public Profile createProfile( Type type, Configuration config )
+ throws ProfileException
+ {
+ try
+ {
+ return m_builder.build( type, config );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Profile build error while constructing a profile from supplied
configuration:\n"
+ + ConfigurationUtil.list( config );
+ throw new ProfileException( error, e );
+ }
+ }
+
+ /**
+ * Add a profile to the manager.
+ * @param profile the depployment profile to add to the manager
+ * @exception DuplicateProfileException if a profile of the same name
+ * is already registered with the manager
+ * @exception ProfileException if a profile verification failure occurs
+ * @see #createProfile
+ */
+ public void addProfile( Profile profile ) throws DuplicateProfileException,
ProfileException
+ {
+ if( profile == null )
+ {
+ throw new NullPointerException("profile");
+ }
+
+ if( !m_initialized )
+ {
+ throw new IllegalStateException("initialization");
+ }
+
+ try
+ {
+ getNamedProfile( profile.getName() );
+ throw new DuplicateProfileException(
+ profile.getType().getInfo().getClassname()
+ + "/" + profile.getName() );
+ }
+ catch( UnknownProfileException upe )
+ {
+ try
+ {
+ verify( profile );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Could not register the profile: " + profile
+ + " due to a verification failure.";
+ throw new ProfileException( error, e );
+ }
+
+ if( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug(
+ "registering profile: " + profile.getName()
+ + " for the type: " + profile.getType().getInfo().getClassname()
);
+ }
+
+ m_profiles.put( profile.getName(), profile );
+ }
+ }
+
+ /**
+ * Returns a profile held locally by the manager based on the profile name.
+ * @param type the component type
+ * @return the set of profile matching the type.
+ * @exception UnknownProfileException if the profile name is unknown within
+ * the scope of the manager
+ */
+ public Profile getNamedProfile( String name ) throws UnknownProfileException
+ {
+ Profile profile = (Profile) m_profiles.get( name );
+ if( profile == null )
+ {
+ throw new UnknownProfileException( name );
+ }
+ return profile;
+ }
+
+ /**
+ * Get the set of profiles declared for a particular type.
+ * @param type the component type
+ * @return the set of profile matching the type.
* @exception UnknownTypeException if the type is unknown to the manager
* @exception DuplicateTypeException if the supplied type does not match the
* type held by the repository
@@ -284,10 +354,10 @@
}
}
- Iterator iterator = m_profiles.entrySet().iterator();
- while( iterator.hasNext() )
+ Enumeration enum = m_profiles.elements();
+ while( enum.hasMoreElements() )
{
- Profile profile = (Profile) iterator.next();
+ Profile profile = (Profile) enum.nextElement();
if( profile.getType().equals( type ) )
{
list.add( type );
@@ -316,10 +386,10 @@
}
ReferenceDescriptor reference = dependency.getReference();
- Iterator iterator = m_profiles.entrySet().iterator();
- while( iterator.hasNext() )
+ Enumeration enum = m_profiles.elements();
+ while( enum.hasMoreElements() )
{
- Profile profile = (Profile) iterator.next();
+ Profile profile = (Profile) enum.nextElement();
Object service = profile.getType().getService( reference );
if( service != null )
{
@@ -347,10 +417,10 @@
}
}
- Iterator iterator = m_profiles.entrySet().iterator();
- while( iterator.hasNext() )
+ Enumeration enum = m_profiles.elements();
+ while( enum.hasMoreElements() )
{
- Profile profile = (Profile) iterator.next();
+ Profile profile = (Profile) enum.nextElement();
if( profile.getType().getExtension( stage ) != null )
{
list.add( profile );
@@ -384,4 +454,19 @@
return selector.select( profiles, stage );
}
+ private void verify( Profile profile ) throws ProfileException
+ {
+ ProfileVerifier verifier = new ProfileVerifier();
+ try
+ {
+ verifier.verifyType( profile, m_classloader );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Verification failure for profile: "
+ + profile.getName() + " from type: "
+ + profile.getType().getInfo().getClassname();
+ throw new ProfileException( error, e );
+ }
+ }
}
1.4 +45 -2
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/profile/ProfileManager.java
Index: ProfileManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/profile/ProfileManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ProfileManager.java 22 Nov 2002 23:42:37 -0000 1.3
+++ ProfileManager.java 23 Nov 2002 17:46:28 -0000 1.4
@@ -73,21 +73,61 @@
*/
public interface ProfileManager
{
+ /**
+ * Load a set of packaged profiles associated with the supplied class.
+ *
+ * @param type the component type used to locate an packaged profiles
+ * @return the set of packaged component profiles
+ */
+ public Profile[] loadProfiles( Type type ) throws ProfileException;
+
+ /**
+ * Create a profile from a supplied configuration.
+ *
+ * @param type the component type that the profile qualifies
+ * @param config a configuration fragment describing the deployment profile
+ * @return the deployment profile
+ */
+ public Profile createProfile( Type type, Configuration config )
+ throws ProfileException;
+
+ /**
+ * Add a profile to the manager.
+ * @param profile the depployment profile to add to the manager
+ * @exception DuplicateProfileException if the supplied type is already
registered
+ * @exception ProfileException if a profile verification failure occurs
+ * @see #createProfile
+ */
+ public void addProfile( Profile profile )
+ throws DuplicateProfileException, ProfileException;
+
+ /**
+ * Returns a profile held locally by the manager based on the profile name.
+ * @param type the component type
+ * @return the set of profile matching the type.
+ * @exception UnknownProfileException if the profile name is unknown within
+ * the scope of the manager
+ */
+ public Profile getNamedProfile( String name )
+ throws UnknownProfileException;
/**
* Locate the set of {@link Profile} instances associated with the
* supplied component type.
+ *
* @param type the component type
* @return the profiles for the supplied classname.
* @exception UnknownTypeException if a matching type cannot be found
* @exception DuplicateTypeException if the supplied type does not match the
* type held by the repository
*/
- Profile[] getProfiles( Type type ) throws UnknownTypeException,
DuplicateTypeException;
+ Profile[] getProfiles( Type type )
+ throws UnknownTypeException, DuplicateTypeException;
/**
* Locate the set of component profiles capable of services the supplied
* dependency.
+ *
* @param a service dependency descriptor
* @return a set of profiles capable of servicing the supplied dependency
*/
@@ -95,6 +135,7 @@
/**
* Locate the set of component profiles that provide the supplied extension.
+ *
* @param service a service descriptor
* @return a set of types that provide the supplied service
*/
@@ -103,6 +144,7 @@
/**
* Locate the set of profiles tied to a type capable of supporting a service
* referenced by a supplied dependency descriptor using a supplied selector.
+ *
* @param a service depedency descriptor
* @return a set of types capable of servicing the supplied dependency
*/
@@ -111,6 +153,7 @@
/**
* Locate a profile tied to a type capable of supporting an extension
* referenced by a supplied stage descriptor usign the a suplied selector.
+ *
* @param service a service descriptor
* @return a set of types that provide the supplied service
*/
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>