mcconnell 2002/11/26 10:04:22 Modified: assembly/src/java/org/apache/avalon/assembly/appliance ApplianceManager.java assembly/src/java/org/apache/avalon/assembly/profile DefaultProfileManager.java ProfileManager.java assembly/src/test/org/apache/avalon/assembly/profile ProfileManagerTestCase.java meta/src/java/org/apache/avalon/meta/info Type.java Log: Addition of a profile selection test case and updates to the ProfileManager interface to support profile resolution based on a default selector. Revision Changes Path 1.2 +2 -2 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/ApplianceManager.java Index: ApplianceManager.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/ApplianceManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ApplianceManager.java 24 Nov 2002 12:50:44 -0000 1.1 +++ ApplianceManager.java 26 Nov 2002 18:04:22 -0000 1.2 @@ -57,7 +57,7 @@ /** * An appliance manager implemetation provides support for the - * retrival of appliance instances. + * creation and retrival of appliance instances. * * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a> * @version $Revision$ $Date$ 1.2 +30 -1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/profile/DefaultProfileManager.java Index: DefaultProfileManager.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/profile/DefaultProfileManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DefaultProfileManager.java 24 Nov 2002 12:50:45 -0000 1.1 +++ DefaultProfileManager.java 26 Nov 2002 18:04:22 -0000 1.2 @@ -123,6 +123,12 @@ */ private final Hashtable m_profiles = new Hashtable(); + /** + * The default profile selector. + */ + private final DefaultProfileSelector m_selector = new DefaultProfileSelector(); + + //============================================================== // Contextualizable //============================================================== @@ -194,6 +200,7 @@ throw new IllegalStateException("logger"); } + m_selector.enableLogging( getLogger().getChildLogger( "selector" ) ); m_initialized = true; } @@ -420,6 +427,17 @@ /** * Locate the set of profiles tied to a type capable of supporting a service + * referenced by a supplied dependency descriptor using the default selector. + * @param dependency a service depedency descriptor + * @return a set of profiles capable of servicing the supplied dependency + */ + public Profile getProfile( DependencyDescriptor dependency ) + { + return getProfile( dependency, m_selector ); + } + + /** + * 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 dependency a service depedency descriptor * @param selector a profile selector @@ -429,6 +447,17 @@ { 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 default selector. + * @param stage a stage descriptor + * @return a set of types that provide the supplied service + */ + public Profile getProfile( StageDescriptor stage ) + { + return getProfile( stage, m_selector ); } /** 1.2 +20 -1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/profile/ProfileManager.java Index: ProfileManager.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/profile/ProfileManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ProfileManager.java 24 Nov 2002 12:50:45 -0000 1.1 +++ ProfileManager.java 26 Nov 2002 18:04:22 -0000 1.2 @@ -137,6 +137,25 @@ /** * Locate the set of profiles tied to a type capable of supporting a service + * referenced by a supplied dependency descriptor using the default selector. + * + * @param dependency a service depedency descriptor + * @return a set of types capable of servicing the supplied dependency + */ + Profile getProfile( DependencyDescriptor dependency ); + + /** + * Locate a profile tied to a type capable of supporting an extension + * referenced by a supplied stage descriptor using the default selector. + * + * @param stage a stage descriptor + * @param selector the profile selector + * @return a set of types that provide the supplied service + */ + Profile getProfile( StageDescriptor stage ); + + /** + * 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 dependency a service depedency descriptor 1.4 +60 -0 avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/profile/ProfileManagerTestCase.java Index: ProfileManagerTestCase.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/profile/ProfileManagerTestCase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ProfileManagerTestCase.java 26 Nov 2002 17:12:14 -0000 1.3 +++ ProfileManagerTestCase.java 26 Nov 2002 18:04:22 -0000 1.4 @@ -127,6 +127,66 @@ } } + public void testServiceProviderSelection() throws Exception + { + final String classname = "org.apache.avalon.playground.BasicComponent"; + + ReferenceDescriptor ref = + new ReferenceDescriptor( + "org.apache.avalon.playground.BasicService", + Version.getVersion( "1.1" ) ); + + DependencyDescriptor dep = + new DependencyDescriptor( "test", ref ); + + try + { + Type type = m_types.createType( classname ); + Profile[] profiles = m_manager.loadProfiles( type ); + for( int i=0; i<profiles.length; i++ ) + { + m_manager.addProfile( profiles[i] ); + } + + Profile selection = m_manager.getProfile( dep ); + assertTrue( selection != null ); + } + catch( Throwable e ) + { + System.out.println("failure to resolve profile for : " + ref ); + e.printStackTrace(); + assertTrue( false ); + } + } + + public void testExtensionProviderSelection() throws Exception + { + final String classname = "org.apache.avalon.playground.ExploitationManager"; + + ReferenceDescriptor reference = + new ReferenceDescriptor( "org.apache.avalon.playground.Exploitable" ); + + StageDescriptor stage = new StageDescriptor( reference ); + + try + { + Type type = m_types.createType( classname ); + Profile[] profiles = m_manager.loadProfiles( type ); + for( int i=0; i<profiles.length; i++ ) + { + m_manager.addProfile( profiles[i] ); + } + + Profile selection = m_manager.getProfile( stage ); + assertTrue( selection != null ); + } + catch( Throwable e ) + { + System.out.println("failure to resolve extension handler profile for : " + reference ); + e.printStackTrace(); + assertTrue( false ); + } + } protected void tearDown() throws Exception { 1.3 +1 -23 avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Type.java Index: Type.java =================================================================== RCS file: /home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Type.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Type.java 26 Nov 2002 17:12:14 -0000 1.2 +++ Type.java 26 Nov 2002 18:04:22 -0000 1.3 @@ -328,30 +328,8 @@ * @exception Exception if an error occurs while marchalling the default * confiugration for the type */ - //public Configuration getConfiguration( ClassLoader loader ) throws Exception public Configuration getConfiguration() { - /* - if( m_loaded ) - { - return m_configuration; - } - - final String xconfig = - getInfo().getClassname().replace( '.', '/' ) + ".xconfig"; - final InputStream stream = - loader.getResourceAsStream( xconfig ); - if( stream == null ) - { - m_loaded = true; - } - else - { - final InputSource source = new InputSource( stream ); - m_configuration = ConfigurationBuilder.build( source ); - m_loaded = true; - } - */ return m_configuration; }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>