mcconnell 2002/11/19 04:24:18
Modified: assembly/src/java/org/apache/excalibur/assembly/profile
ProfileSelector.java ProfileManager.java
Added: assembly/src/java/org/apache/excalibur/assembly/profile
DefaultProfileManager.java
Log:
Updating interface so that the manager only exposes operations to
locate a profile based on depedency, addition of some utility static operations
supporting profile crreation, and enhancements to the profile selector model.
Revision Changes Path
1.2 +16 -6
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/profile/ProfileSelector.java
Index: ProfileSelector.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/profile/ProfileSelector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProfileSelector.java 18 Nov 2002 10:59:29 -0000 1.1
+++ ProfileSelector.java 19 Nov 2002 12:24:17 -0000 1.2
@@ -56,6 +56,8 @@
package org.apache.excalibur.assembly.profile;
import org.apache.excalibur.meta.model.Profile;
+import org.apache.excalibur.meta.info.StageDescriptor;
+import org.apache.excalibur.meta.info.DependencyDescriptor;
/**
* Interface implemented by a service selection implementation mechanism. Classes
@@ -72,11 +74,19 @@
{
/**
- * Returns the preferred profile form an available selection of candidate
provider profiles.
- * @param profiles the set of profiles of potential service providers
- * @return the preferred provider or null if no satisfactory provider can be
established
- * from the supplied profiles.
+ * Returns the preferred profile form an available selection of
+ * candidate profiles.
+ * @param profiles the set of candidate profiles
+ * @param dependency the service dependency
+ * @return the preferred profile or null if no satisfactory provider can be
established
*/
- Profile select( Profile[] profiles );
+ Profile select( Profile[] profiles, DependencyDescriptor dependency );
+ /**
+ * Returns the preferred profile form an available selection of candidates
+ * @param profiles the set of profiles of potential extension providers
+ * @param stage the stage dependency
+ * @return the preferred provider or null if no satisfactory provider can be
established
+ */
+ Profile select( Profile[] profiles, StageDescriptor stage );
}
1.2 +27 -40
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProfileManager.java 18 Nov 2002 10:59:29 -0000 1.1
+++ ProfileManager.java 19 Nov 2002 12:24:17 -0000 1.2
@@ -57,6 +57,8 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.excalibur.assembly.type.UnknownTypeException;
+import org.apache.excalibur.assembly.type.DuplicateTypeException;
+import org.apache.excalibur.assembly.type.TypeManager;
import org.apache.excalibur.meta.model.Profile;
import org.apache.excalibur.meta.info.Type;
import org.apache.excalibur.meta.info.DependencyDescriptor;
@@ -69,57 +71,42 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision$ $Date$
*/
-public interface ProfileManager
+public interface ProfileManager extends TypeManager
{
- /**
- * Programatically create a {@link Profile} instances from a
- * supplied profile configuration fragment. Clients using the
- * create operation should register the profile with the manager
- * in order for the profile to be generally available.
- *
- * @param config the profile description
- * @return the profile
- * @exception Exception if an error occurs during profile creation
- * @see #register( Profile )
- */
- Profile create( Configuration config )
- throws Exception;
-
- /**
- * Register a programatically created component profile.
- *
- * @param type the component type
- * @return the set of profiles packaged with the type
- * @exception Exception if a failure occurs
- * @see #create( Configuration )
- */
- void register( Profile profile ) throws ProfileException;
-
- /**
- * Install a set of packaged profiles. An implementation will create and
verify
- * the set of packaged profile instance relative to a supplied path.
- *
- * @param type the component type
- * @return the set of profiles packaged with the type
- * @exception Exception if a failure occurs
- */
- Profile[] install( Type type ) throws ProfileException;
/**
* Locate the set of {@link Profile} instances associated with the
- * supplied implementation classname.
+ * 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[] locate( Type type ) throws UnknownTypeException;
+ 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
+ */
+ public Profile[] getProfiles( DependencyDescriptor dependency );
+
+ /**
+ * 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
+ */
+ public Profile[] getProfiles( StageDescriptor stage );
/**
- * Locate a profile tied to a type capable of supporting a service
+ * 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
*/
- Profile select( DependencyDescriptor dependency, ProfileSelector selector );
+ Profile getProfile( DependencyDescriptor dependency, ProfileSelector selector );
/**
* Locate a profile tied to a type capable of supporting an extension
@@ -127,6 +114,6 @@
* @param service a service descriptor
* @return a set of types that provide the supplied service
*/
- Profile select( StageDescriptor stage, ProfileSelector selector );
+ Profile getProfile( StageDescriptor stage, ProfileSelector selector );
}
1.1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/assembly/profile/DefaultProfileManager.java
Index: DefaultProfileManager.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.assembly.profile;
import java.util.Map;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.ArrayList;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.excalibur.assembly.type.TypeException;
import org.apache.excalibur.assembly.type.DefaultTypeManager;
import org.apache.excalibur.assembly.type.UnknownTypeException;
import org.apache.excalibur.assembly.type.DuplicateTypeException;
import org.apache.excalibur.configuration.ConfigurationUtil;
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.info.ReferenceDescriptor;
import org.apache.excalibur.meta.info.ServiceDescriptor;
import org.apache.excalibur.meta.info.DependencyDescriptor;
import org.apache.excalibur.meta.info.StageDescriptor;
import org.apache.excalibur.meta.info.Type;
/**
* A profile manager implemetation provides support for the creation,
* storage and retrival of component types.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/11/19 12:24:17 $
*/
public class DefaultProfileManager extends DefaultTypeManager implements
ProfileManager
{
//==============================================================
// static
//==============================================================
/**
* The profile builder.
*/
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
//==============================================================
/**
* The classloader supplied to the manager.
*/
private final ClassLoader m_classloader;
/**
* The parent profile manager (may be null)
*/
private final ProfileManager m_parent;
/**
* Table of component profiles keyed by profile name.
*/
private final Map m_profiles = new Hashtable();
//==============================================================
// constructor
//==============================================================
/**
* Creation of a new {@link ProfileManager} based on a supplied parent
* and classloader.
* @param parent the parent profile manager (may be null)
* @param classloader the classloader
*/
public DefaultProfileManager( ProfileManager parent, ClassLoader classloader )
{
super( parent, classloader );
m_parent = parent;
m_classloader = classloader;
}
/**
* Add a profile to the manager.
* @param profile the component profile to add to the manager
* @exception DuplicateProfileException if the profile of the same name is
* already registered with the manager
*/
public void addProfile( Profile profile ) throws DuplicateProfileException
{
if( profile == null )
{
throw new NullPointerException( "profile" );
}
if( m_profiles.get( profile.getName() ) != null )
{
throw new DuplicateProfileException( profile.getName() );
}
m_profiles.put( profile.getName(), profile );
}
//==============================================================
// ProfileManager
//==============================================================
/**
* Get the set of profiles declared for a type.
* @return the set of profile matching the supplied 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
*/
public Profile[] getProfiles( Type type ) throws UnknownTypeException,
DuplicateTypeException
{
//
// check that the type is registered
//
Type local = getType( type.getInfo().getClassname() );
if( !type.equals( type ) )
{
final String error = "Supplied type is not equal to the type known by
the manager.";
throw new DuplicateTypeException( error );
}
ArrayList list = new ArrayList();
if( m_parent != null )
{
Profile[] profiles = m_parent.getProfiles( type );
for( int i=0; i<profiles.length; i++ )
{
list.add( profiles[i] );
}
}
Iterator iterator = m_profiles.entrySet().iterator();
while( iterator.hasNext() )
{
Profile profile = (Profile) iterator.next();
if( profile.getType().equals( type ) )
{
list.add( type );
}
}
return (Profile[]) list.toArray( new Profile[0] );
}
/**
* Locate the set of component profiles capable of services the supplied
* dependency.
* @param dependency a service dependency descriptor
* @return a set of profiles capable of servicing the supplied dependency
*/
public Profile[] getProfiles( DependencyDescriptor dependency )
{
ArrayList list = new ArrayList();
if( m_parent != null )
{
Profile[] profiles = m_parent.getProfiles( dependency );
for( int i=0; i<profiles.length; i++ )
{
list.add( profiles[i] );
}
}
ReferenceDescriptor reference = dependency.getReference();
Iterator iterator = m_profiles.entrySet().iterator();
while( iterator.hasNext() )
{
Profile profile = (Profile) iterator.next();
Object service = profile.getType().getService( reference );
if( service != null )
{
list.add( profile );
}
}
return (Profile[]) list.toArray( new Profile[0] );
}
/**
* 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
*/
public Profile[] getProfiles( StageDescriptor stage )
{
ArrayList list = new ArrayList();
if( m_parent != null )
{
Profile[] profiles = m_parent.getProfiles( stage );
for( int i=0; i<profiles.length; i++ )
{
list.add( profiles[i] );
}
}
Iterator iterator = m_profiles.entrySet().iterator();
while( iterator.hasNext() )
{
Profile profile = (Profile) iterator.next();
if( profile.getType().getExtension( stage ) != null )
{
list.add( profile );
}
}
return (Profile[]) list.toArray( new Profile[0] );
}
/**
* 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
*/
public Profile getProfile( DependencyDescriptor dependency, ProfileSelector
selector )
{
Profile[] profiles = getProfiles( dependency );
return selector.select( profiles, dependency );
}
/**
* 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
*/
public Profile getProfile( StageDescriptor stage, ProfileSelector selector )
{
Profile[] profiles = getProfiles( stage );
return selector.select( profiles, stage );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>