Hi, Heres some changes to refactor phoenix to use ContainerKit internallly. The reason for this is to make it easier to move to auto-assembly and other more advanced management features. It does not change the external interface to blocks (still use BlockInfo and BlockMetaData) but internally it uses the richer interface.
There needs to be one patch applied to containerkit (ck.txt). The rest of this needs to be done on branch and then when it stabilizes we can vote on its reintegration with the trunk. To do this you need to do something like $ cvs co jakarta-avalon-phoenix $ cd jakarta-avalon-phoenix $ cvs tag -b AUTO_ASSEMBLY-branch $ cvs up -r AUTO_ASSEMBLY-branch This will create a source tree with correct branch. Then next apply the phoenix-ck.txt patch and add the following files; src/java/org/apache/avalon/phoenix/components/assembler/Assembler.java src/java/org/apache/avalon/phoenix/components/assembler/AssemblyException.java src/java/org/apache/avalon/phoenix/components/assembler/Resources.properties Update the ContainerKit/Info jars to latest version and move them from lib/container to lib And remove the following files; src/documentation/README.txt src/java/org/apache/avalon/phoenix/tools/assembler/Assembler.java src/java/org/apache/avalon/phoenix/tools/assembler/AssemblyException.java src/java/org/apache/avalon/phoenix/tools/assembler/Resources.properties src/java/org/apache/avalon/phoenix/tools/assembler/package.html src/java/org/apache/avalon/phoenix/tools/infobuilder/BlockInfoBuilder.java src/java/org/apache/avalon/phoenix/tools/infobuilder/Resources.properties src/java/org/apache/avalon/phoenix/tools/infobuilder/package.html src/java/org/apache/avalon/phoenix/tools/metagenerate/AbstractHelper.java src/java/org/apache/avalon/phoenix/tools/metagenerate/XinfoFactory.java src/java/org/apache/avalon/phoenix/tools/metagenerate/XinfoHelper.java The only issue may be that BlockInfoBuilder is used outside the package. So it may be best to deprecate it but given how little chance that it actually was used it may be best to just delete it all together. -- Cheers, Peter Donald -------------------------------------------------- "An intellectual is someone who has been educated beyond their intelligence." --------------------------------------------------
Index: src/java/org/apache/excalibur/containerkit/factory/DefaultComponentFactory.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/factory/DefaultComponentFactory.java,v retrieving revision 1.13 diff -u -r1.13 DefaultComponentFactory.java --- src/java/org/apache/excalibur/containerkit/factory/DefaultComponentFactory.java 4 Oct 2002 00:44:57 -0000 1.13 +++ src/java/org/apache/excalibur/containerkit/factory/DefaultComponentFactory.java 2 Dec 2002 10:56:22 -0000 @@ -73,9 +73,7 @@ ComponentBundle bundle = (ComponentBundle)m_infos.get( implementationKey ); if( null == bundle ) { - final ComponentInfo info = - m_infoBuilder.buildComponentInfo( implementationKey, m_classLoader ); - bundle = new DefaultComponentBundle( info, m_classLoader ); + bundle = newBundle( implementationKey ); m_infos.put( implementationKey, bundle ); } @@ -91,7 +89,49 @@ public Object createComponent( final String implementationKey ) throws Exception { - final Class clazz = m_classLoader.loadClass( implementationKey ); + final Class clazz = getClassLoader().loadClass( implementationKey ); return clazz.newInstance(); + } + + + + /** + * Create a bundle for specified key. + * Note that this does not cache bundle in any way. + * + * @param implementationKey the implementationKey + * @return the new ComponentBundle + * @throws Exception if unable to create bundle + */ + protected ComponentBundle newBundle( final String implementationKey ) + throws Exception + { + ComponentBundle bundle; + final ComponentInfo info = createComponentInfo( implementationKey ); + bundle = new DefaultComponentBundle( info, getClassLoader() ); + return bundle; + } + + /** + * Create a [EMAIL PROTECTED] ComponentInfo} for component with specified implementationKey. + * + * @param implementationKey the implementationKey + * @return the created [EMAIL PROTECTED] ComponentInfo} + * @throws Exception if unabel to create componentInfo + */ + protected ComponentInfo createComponentInfo( final String implementationKey ) + throws Exception + { + return m_infoBuilder.buildComponentInfo( implementationKey, getClassLoader() ); + } + + /** + * Retrieve ClassLoader associated with ComponentFactory. + * + * @return + */ + protected ClassLoader getClassLoader() + { + return m_classLoader; } }
/* * 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.phoenix.components.assembler; import java.util.ArrayList; import java.util.Map; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.info.Attribute; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.phoenix.components.ContainerConstants; import org.apache.excalibur.containerkit.metadata.ComponentMetaData; import org.apache.excalibur.containerkit.metadata.DependencyMetaData; import org.apache.excalibur.containerkit.metadata.MetaDataBuilder; import org.apache.excalibur.containerkit.metadata.PartitionMetaData; /** * Assemble a [EMAIL PROTECTED] PartitionMetaData} object from a Configuration * object. The Configuration object represents the assembly descriptor * and is in the format specified for <tt>assembly.xml</tt> files. * * @author <a href="mailto:peter at apache.org">Peter Donald</a> * @version $Revision: 1.22 $ $Date: 2002/10/01 07:04:05 $ */ public class Assembler extends AbstractLogEnabled implements MetaDataBuilder { private static final Resources REZ = ResourceManager.getPackageResources( Assembler.class ); /** * Create a [EMAIL PROTECTED] PartitionMetaData} object based on specified * name and assembly configuration. This implementation takes two * parameters. [EMAIL PROTECTED] ContainerConstants#ASSEMBLY_NAME} specifies * the name of the assembly and * [EMAIL PROTECTED] ContainerConstants#ASSEMBLY_CONFIG} specifies the configuration * tree to use when assembling Partition. * * @param parameters the parameters for constructing assembly * @return the new PartitionMetaData * @throws AssemblyException if an error occurs */ public PartitionMetaData buildAssembly( final Map parameters ) throws Exception { final String name = (String)parameters.get( ContainerConstants.ASSEMBLY_NAME ); final Configuration configuration = (Configuration)parameters.get( ContainerConstants.ASSEMBLY_CONFIG ); return assembleSar( name, configuration ); } /** * Create a [EMAIL PROTECTED] PartitionMetaData} object based on specified * name and assembly configuration. * * @param name the name of Sar * @param assembly the assembly configuration object * @return the new PartitionMetaData * @throws AssemblyException if an error occurs */ private PartitionMetaData assembleSar( final String name, final Configuration assembly ) throws AssemblyException { final Configuration[] blockConfig = assembly.getChildren( "block" ); final ComponentMetaData[] blocks = buildBlocks( blockConfig ); final PartitionMetaData blockPartition = new PartitionMetaData( ContainerConstants.BLOCK_PARTITION, new String[]{ContainerConstants.LISTENER_PARTITION}, PartitionMetaData.EMPTY_SET, blocks, Attribute.EMPTY_SET ); final Configuration[] listenerConfig = assembly.getChildren( "listeners" ); final ComponentMetaData[] listeners = buildBlockListeners( listenerConfig ); final PartitionMetaData listenerPartition = new PartitionMetaData( ContainerConstants.LISTENER_PARTITION, new String[ 0 ], PartitionMetaData.EMPTY_SET, listeners, Attribute.EMPTY_SET ); final PartitionMetaData[] partitions = new PartitionMetaData[]{blockPartition, listenerPartition}; return new PartitionMetaData( name, new String[ 0 ], partitions, new ComponentMetaData[ 0 ], Attribute.EMPTY_SET ); } /** * Create an array of [EMAIL PROTECTED] ComponentMetaData} objects to represent * the <block .../> sections in <tt>assembly.xml</tt>. * * @param blocks the list of Configuration objects for blocks * @return the BlockMetaData array * @throws AssemblyException if an error occurs */ private ComponentMetaData[] buildBlocks( final Configuration[] blocks ) throws AssemblyException { final ArrayList blockSet = new ArrayList(); for( int i = 0; i < blocks.length; i++ ) { blockSet.add( buildBlock( blocks[ i ] ) ); } return (ComponentMetaData[])blockSet.toArray( new ComponentMetaData[ blockSet.size() ] ); } /** * Create a single [EMAIL PROTECTED] ComponentMetaData} object to represent * specified <block .../> section. * * @param block the Configuration object for block * @return the BlockMetaData object * @throws AssemblyException if an error occurs */ private ComponentMetaData buildBlock( final Configuration block ) throws AssemblyException { try { final String name = block.getAttribute( "name" ); final String classname = block.getAttribute( "class" ); final Configuration proxy = block.getChild( "proxy" ); final ArrayList attributeSet = new ArrayList(); final boolean disableProxy = proxy.getAttributeAsBoolean( "disable", false ); if( disableProxy ) { final Attribute attribute = new Attribute( ContainerConstants.DISABLE_PROXY_ATTR, null ); attributeSet.add( attribute ); } final Configuration[] provides = block.getChildren( "provide" ); final DependencyMetaData[] dependencys = buildDependencies( provides ); final Attribute[] attributes = (Attribute[])attributeSet.toArray( new Attribute[ attributeSet.size() ] ); return new ComponentMetaData( name, classname, dependencys, null, null, attributes ); } catch( final ConfigurationException ce ) { final String message = REZ.getString( "block-entry-malformed", block.getLocation(), ce.getMessage() ); throw new AssemblyException( message ); } } /** * Create an array of [EMAIL PROTECTED] ComponentMetaData} objects to represent * the <listener .../> sections in <tt>assembly.xml</tt>. * * @param config the list of Configuration objects for config * @return the ComponentMetaData array * @throws AssemblyException if an error occurs */ private ComponentMetaData[] buildBlockListeners( final Configuration[] config ) throws AssemblyException { final ArrayList listeners = new ArrayList(); for( int i = 0; i < config.length; i++ ) { final ComponentMetaData listener = buildBlockListener( config[ i ] ); listeners.add( listener ); } return (ComponentMetaData[])listeners.toArray( new ComponentMetaData[ listeners.size() ] ); } /** * Create a [EMAIL PROTECTED] ComponentMetaData} object to represent * the specified <listener .../> section. * * @param listener the Configuration object for listener * @return the BlockListenerMetaData object * @throws AssemblyException if an error occurs */ private ComponentMetaData buildBlockListener( final Configuration listener ) throws AssemblyException { try { final String name = listener.getAttribute( "name" ); final String className = listener.getAttribute( "class" ); return new ComponentMetaData( name, className, new DependencyMetaData[ 0 ], null, null, null ); } catch( final ConfigurationException ce ) { final String message = REZ.getString( "listener-entry-malformed", listener.getLocation(), ce.getMessage() ); throw new AssemblyException( message ); } } /** * Helper method to build an array of DependencyMetaDatas from input config data. * * @param provides the set of provides elements for block * @return the created DependencyMetaData array * @throws ConfigurationException if config data is malformed */ private DependencyMetaData[] buildDependencies( final Configuration[] provides ) throws ConfigurationException { final ArrayList dependencies = new ArrayList(); for( int j = 0; j < provides.length; j++ ) { final Configuration provide = provides[ j ]; final String requiredName = provide.getAttribute( "name" ); final String alias = provide.getAttribute( "alias", requiredName ); final String key = provide.getAttribute( "role" ); dependencies.add( new DependencyMetaData( key, requiredName, alias, Attribute.EMPTY_SET ) ); } return (DependencyMetaData[])dependencies.toArray( new DependencyMetaData[ 0 ] ); } }
/* * 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.phoenix.components.assembler; import org.apache.avalon.framework.CascadingException; /** * Exception to indicate that there was an error Assembling SarMetaData. * * @author <a href="mailto:peter at apache.org">Peter Donald</a> * @version $Revision: 1.5 $ $Date: 2002/08/06 11:57:42 $ */ public final class AssemblyException extends CascadingException { /** * Construct a new <code>AssemblyException</code> instance. * * @param message The detail message for this exception. */ public AssemblyException( final String message ) { this( message, null ); } /** * Construct a new <code>AssemblyException</code> instance. * * @param message The detail message for this exception. * @param throwable the root cause of the exception */ public AssemblyException( final String message, final Throwable throwable ) { super( message, throwable ); } }
? ContainerKitEmbeddor2.java ? dynamic-rmi.html ? mx4j-tools-temp ? phoenix-ck.txt ? resources.txt ? lib/log4j-1.2.4.jar ? lib/container/excalibur-containerkit-1.0a.jar ? src/java/org/apache/avalon/phoenix/components/assembler ? src/java/org/apache/avalon/phoenix/components/deployer/PhoenixComponentFactory.java Index: lib/container/excalibur-info-1.0a.jar =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/lib/container/excalibur-info-1.0a.jar,v retrieving revision 1.3 diff -u -r1.3 excalibur-info-1.0a.jar Binary files /tmp/cvsujHJd8 and excalibur-info-1.0a.jar differ Index: src/java/org/apache/avalon/phoenix/BlockEvent.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/BlockEvent.java,v retrieving revision 1.10 diff -u -r1.10 BlockEvent.java --- src/java/org/apache/avalon/phoenix/BlockEvent.java 11 Sep 2002 12:47:26 -0000 1.10 +++ src/java/org/apache/avalon/phoenix/BlockEvent.java 2 Dec 2002 11:22:52 -0000 @@ -21,9 +21,7 @@ extends EventObject { private final String m_name; - private final Object m_block; - private final BlockInfo m_blockInfo; /** @@ -41,15 +39,15 @@ if( null == name ) { - throw new NullPointerException( "name property is null" ); + throw new NullPointerException( "name" ); } if( null == block ) { - throw new NullPointerException( "block property is null" ); + throw new NullPointerException( "block" ); } if( null == blockInfo ) { - throw new NullPointerException( "blockInfo property is null" ); + throw new NullPointerException( "blockInfo" ); } m_name = name; @@ -86,7 +84,7 @@ */ public Block getBlock() { - return (Block)m_block; + return (Block)getObject(); } /** Index: src/java/org/apache/avalon/phoenix/components/ContainerConstants.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/ContainerConstants.java,v retrieving revision 1.1 diff -u -r1.1 ContainerConstants.java --- src/java/org/apache/avalon/phoenix/components/ContainerConstants.java 27 Nov 2002 07:03:53 -0000 1.1 +++ src/java/org/apache/avalon/phoenix/components/ContainerConstants.java 2 Dec 2002 11:22:52 -0000 @@ -20,4 +20,9 @@ String DATE = "@@DATE@@"; String DISABLE_PROXY_ATTR = "phoenix:disable-proxy"; + String ASSEMBLY_NAME = "phoenix:assembly-name"; + String ASSEMBLY_CONFIG = "phoenix:config"; + + String BLOCK_PARTITION = "block"; + String LISTENER_PARTITION = "listener"; } Index: src/java/org/apache/avalon/phoenix/components/application/BlockEntry.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockEntry.java,v retrieving revision 1.22 diff -u -r1.22 BlockEntry.java --- src/java/org/apache/avalon/phoenix/components/application/BlockEntry.java 11 Oct 2002 05:59:51 -0000 1.22 +++ src/java/org/apache/avalon/phoenix/components/application/BlockEntry.java 2 Dec 2002 11:22:53 -0000 @@ -7,9 +7,11 @@ */ package org.apache.avalon.phoenix.components.application; -import org.apache.avalon.phoenix.metadata.BlockMetaData; -import org.apache.avalon.phoenix.metainfo.BlockInfo; -import org.apache.avalon.phoenix.metainfo.ServiceDescriptor; +import org.apache.avalon.phoenix.components.ContainerConstants; +import org.apache.avalon.framework.info.Attribute; +import org.apache.avalon.framework.info.ComponentInfo; +import org.apache.avalon.framework.info.ServiceDescriptor; +import org.apache.excalibur.containerkit.registry.ComponentProfile; /** * This is the structure describing each block before it is loaded. @@ -19,23 +21,23 @@ class BlockEntry { private Object m_object; - private BlockMetaData m_blockMetaData; + private ComponentProfile m_componentProfile; private BlockInvocationHandler m_invocationHandler; - public BlockEntry( final BlockMetaData blockMetaData ) + public BlockEntry( final ComponentProfile componentProfile ) { invalidate(); - m_blockMetaData = blockMetaData; + m_componentProfile = componentProfile; } public String getName() { - return getMetaData().getName(); + return getProfile().getMetaData().getName(); } - public BlockMetaData getMetaData() + public ComponentProfile getProfile() { - return m_blockMetaData; + return m_componentProfile; } public synchronized Object getObject() @@ -47,9 +49,9 @@ { invalidate(); - if( null != object && ! getMetaData().isDisableProxy() ) + if( null != object && ! isDisableProxy() ) { - final BlockInfo blockInfo = getMetaData().getBlockInfo(); + final ComponentInfo blockInfo = m_componentProfile.getInfo(); final Class[] interfaces = getServiceClasses( object, blockInfo.getServices() ); m_invocationHandler = new BlockInvocationHandler( object, interfaces ); } @@ -58,7 +60,7 @@ public synchronized Object getProxy() { - if ( getMetaData().isDisableProxy() ) + if ( isDisableProxy() ) { return m_object; } @@ -75,6 +77,20 @@ } } + private boolean isDisableProxy() + { + final Attribute[] attributes = getProfile().getMetaData().getAttributes(); + for( int i = 0; i < attributes.length; i++ ) + { + final Attribute attribute = attributes[ i ]; + if( attribute.getName().equals( ContainerConstants.DISABLE_PROXY_ATTR ) ) + { + return true; + } + } + return false; + } + protected synchronized void invalidate() { if( null != m_invocationHandler ) @@ -85,7 +101,8 @@ m_object = null; } - private Class[] getServiceClasses( final Object block, final ServiceDescriptor[] services ) + private Class[] getServiceClasses( final Object block, + final ServiceDescriptor[] services ) { final Class[] classes = new Class[ services.length + 1 ]; final ClassLoader classLoader = block.getClass().getClassLoader(); @@ -94,7 +111,7 @@ { try { - classes[ i ] = classLoader.loadClass( services[ i ].getName() ); + classes[ i ] = classLoader.loadClass( services[ i ].getType() ); } catch( final Throwable throwable ) { Index: src/java/org/apache/avalon/phoenix/components/application/BlockResourceProvider.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockResourceProvider.java,v retrieving revision 1.12 diff -u -r1.12 BlockResourceProvider.java --- src/java/org/apache/avalon/phoenix/components/application/BlockResourceProvider.java 7 Nov 2002 16:37:16 -0000 1.12 +++ src/java/org/apache/avalon/phoenix/components/application/BlockResourceProvider.java 2 Dec 2002 11:22:53 -0000 @@ -16,13 +16,12 @@ import java.util.Map; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; -import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentManager; -import org.apache.avalon.framework.component.DefaultComponentManager; import org.apache.avalon.framework.component.WrapperComponentManager; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.context.Context; +import org.apache.avalon.framework.info.DependencyDescriptor; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.parameters.Parameters; @@ -30,11 +29,9 @@ import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.phoenix.interfaces.Application; import org.apache.avalon.phoenix.interfaces.ApplicationContext; -import org.apache.avalon.phoenix.metadata.BlockMetaData; -import org.apache.avalon.phoenix.metadata.DependencyMetaData; -import org.apache.avalon.phoenix.metainfo.DependencyDescriptor; -import org.apache.avalon.phoenix.metainfo.ServiceDescriptor; import org.apache.excalibur.containerkit.lifecycle.ResourceProvider; +import org.apache.excalibur.containerkit.metadata.DependencyMetaData; +import org.apache.excalibur.containerkit.registry.ComponentProfile; /** * The accessor used to access resources for a particular @@ -88,9 +85,9 @@ public Object createObject( final Object entry ) throws Exception { - final BlockMetaData metaData = getMetaDataFor( entry ); + final ComponentProfile profile = getProfileFor( entry ); final ClassLoader classLoader = m_context.getClassLoader(); - String classname = metaData.getBlockInfo().getBlockDescriptor().getImplementationKey(); + String classname = profile.getInfo().getDescriptor().getImplementationKey(); final Class clazz = classLoader.loadClass( classname ); return clazz.newInstance(); } @@ -105,8 +102,8 @@ public Logger createLogger( final Object entry ) throws Exception { - final BlockMetaData metaData = getMetaDataFor( entry ); - final String name = metaData.getName(); + final ComponentProfile profile = getProfileFor( entry ); + final String name = profile.getMetaData().getName(); return m_context.getLogger( name ); } @@ -119,8 +116,8 @@ public Context createContext( final Object entry ) throws Exception { - final BlockMetaData metaData = getMetaDataFor( entry ); - return new DefaultBlockContext( metaData.getName(), + final ComponentProfile profile = getProfileFor( entry ); + return new DefaultBlockContext( profile.getMetaData().getName(), m_context ); } @@ -171,24 +168,23 @@ private Map createServiceMap( final Object entry ) throws Exception { - final BlockMetaData metaData = getMetaDataFor( entry ); + final ComponentProfile metaData = getProfileFor( entry ); final HashMap map = new HashMap(); final HashMap sets = new HashMap(); - final DependencyMetaData[] roles = metaData.getDependencies(); + final DependencyMetaData[] roles = metaData.getMetaData().getDependencies(); for( int i = 0; i < roles.length; i++ ) { final DependencyMetaData role = roles[ i ]; - final Object dependency = m_application.getBlock( role.getName() ); + final Object dependency = m_application.getBlock( role.getProviderName() ); final DependencyDescriptor candidate = - metaData.getBlockInfo().getDependency( role.getRole() ); + metaData.getInfo().getDependency( role.getKey() ); - final String key = role.getRole(); + final String key = role.getKey(); - final ServiceDescriptor service = candidate.getService(); - if( service.isArray() ) + if( candidate.isArray() ) { ArrayList list = (ArrayList)sets.get( key ); if( null == list ) @@ -199,7 +195,7 @@ list.add( dependency ); } - else if( service.isMap() ) + else if( candidate.isMap() ) { HashMap smap = (HashMap)sets.get( key ); if( null == smap ) @@ -224,16 +220,15 @@ if( value instanceof List ) { final List list = (List)value; - final ServiceDescriptor service = - metaData.getBlockInfo().getDependency( key ).getService(); + final DependencyDescriptor dependency = metaData.getInfo().getDependency( key ); - final Object[] result = toArray( list, service.getComponentType() ); + final Object[] result = toArray( list, dependency.getComponentType() ); map.put( key, result ); - if( key.equals( service.getName() ) ) + if( key.equals( dependency.getType() ) ) { final String classname = - "[L" + service.getComponentType() + ";"; + "[L" + dependency.getComponentType() + ";"; map.put( classname, result ); } } @@ -272,8 +267,8 @@ public Configuration createConfiguration( final Object entry ) throws Exception { - final BlockMetaData metaData = getMetaDataFor( entry ); - final String name = metaData.getName(); + final ComponentProfile metaData = getProfileFor( entry ); + final String name = metaData.getMetaData().getName(); try { return m_context.getConfiguration( name ); @@ -306,8 +301,8 @@ * @param entry the entry * @return the MetaData for entry */ - private BlockMetaData getMetaDataFor( final Object entry ) + private ComponentProfile getProfileFor( final Object entry ) { - return ( (BlockEntry)entry ).getMetaData(); + return ( (BlockEntry)entry ).getProfile(); } } Index: src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java,v retrieving revision 1.38 diff -u -r1.38 DefaultApplication.java --- src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java 23 Oct 2002 03:21:49 -0000 1.38 +++ src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java 2 Dec 2002 11:22:55 -0000 @@ -7,6 +7,7 @@ */ package org.apache.avalon.phoenix.components.application; +import java.io.File; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -19,15 +20,17 @@ import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.phoenix.ApplicationListener; import org.apache.avalon.phoenix.BlockListener; +import org.apache.avalon.phoenix.components.ContainerConstants; +import org.apache.avalon.phoenix.components.util.ComponentMetaDataConverter; import org.apache.avalon.phoenix.interfaces.Application; import org.apache.avalon.phoenix.interfaces.ApplicationContext; import org.apache.avalon.phoenix.interfaces.ApplicationException; import org.apache.avalon.phoenix.interfaces.ApplicationMBean; -import org.apache.avalon.phoenix.metadata.BlockListenerMetaData; -import org.apache.avalon.phoenix.metadata.BlockMetaData; import org.apache.avalon.phoenix.metadata.SarMetaData; import org.apache.excalibur.containerkit.lifecycle.LifecycleException; import org.apache.excalibur.containerkit.lifecycle.LifecycleHelper; +import org.apache.excalibur.containerkit.registry.ComponentProfile; +import org.apache.excalibur.containerkit.registry.PartitionProfile; import org.apache.excalibur.threadcontext.ThreadContext; /** @@ -127,10 +130,12 @@ { try { - final BlockMetaData[] blocks = m_context.getMetaData().getBlocks(); + final PartitionProfile partition = + m_context.getPartitionProfile().getPartition( ContainerConstants.BLOCK_PARTITION ); + final ComponentProfile[] blocks = partition.getComponents(); for( int i = 0; i < blocks.length; i++ ) { - final String blockName = blocks[ i ].getName(); + final String blockName = blocks[ i ].getMetaData().getName(); final BlockEntry blockEntry = new BlockEntry( blocks[ i ] ); m_entries.put( blockName, blockEntry ); } @@ -250,7 +255,7 @@ */ public String getName() { - return getMetaData().getName(); + return m_context.getPartitionProfile().getMetaData().getName(); } /** @@ -260,7 +265,7 @@ */ public String getDisplayName() { - return getMetaData().getName(); + return m_context.getPartitionProfile().getMetaData().getName(); } /** @@ -280,7 +285,7 @@ */ public String getHomeDirectory() { - return getMetaData().getHomeDirectory().getPath(); + return m_context.getHomeDirectory().getPath(); } /** @@ -294,11 +299,6 @@ return m_running; } - protected final SarMetaData getMetaData() - { - return m_context.getMetaData(); - } - ///////////////////////////// // Private Utility Methods // ///////////////////////////// @@ -327,7 +327,8 @@ private void doLoadBlockListeners() throws Exception { - final BlockListenerMetaData[] listeners = m_context.getMetaData().getListeners(); + final ComponentProfile[] listeners = + getComponentsInPartition( ContainerConstants.LISTENER_PARTITION ); for( int i = 0; i < listeners.length; i++ ) { try @@ -336,7 +337,7 @@ } catch( final Exception e ) { - final String name = listeners[ i ].getName(); + final String name = listeners[ i ].getMetaData().getName(); final String message = REZ.getString( "bad-listener", "startup", name, e.getMessage() ); getLogger().error( message, e ); @@ -345,6 +346,13 @@ } } + private ComponentProfile[] getComponentsInPartition( final String key ) + { + final PartitionProfile partition = + m_context.getPartitionProfile().getPartition( key ); + return partition.getComponents(); + } + /** * Run a phase for application. * Each phase transitions application into new state and processes @@ -381,7 +389,8 @@ private final void doRunPhase( final String name ) throws Exception { - final BlockMetaData[] blocks = m_context.getMetaData().getBlocks(); + final ComponentProfile[] blocks = + getComponentsInPartition( ContainerConstants.BLOCK_PARTITION ); final String[] order = DependencyGraph.walkGraph( PHASE_STARTUP == name, blocks ); //Log message describing the number of blocks @@ -400,7 +409,11 @@ if( PHASE_STARTUP == name ) { //... for startup, so indicate to applicable listeners - m_listenerSupport.fireApplicationStartingEvent( getMetaData() ); + final PartitionProfile partition = m_context.getPartitionProfile(); + final File homeDirectory = m_context.getHomeDirectory(); + final SarMetaData sarMetaData = + ComponentMetaDataConverter.toSarMetaData( partition, homeDirectory ); + m_listenerSupport.fireApplicationStartingEvent( sarMetaData ); } else { @@ -484,7 +497,7 @@ m_blockAccessor ); m_exportHelper.exportBlock( m_context, - entry.getMetaData(), + entry.getProfile(), block ); entry.setObject( block ); @@ -511,7 +524,7 @@ { //Remove block from Management system m_exportHelper.unexportBlock( m_context, - entry.getMetaData(), + entry.getProfile(), object ); entry.invalidate(); @@ -529,17 +542,17 @@ * This will involve creation of BlockListener object and configuration of * object if appropriate. * - * @param metaData the BlockListenerMetaData + * @param profile the BlockListenerMetaData * @throws Exception if an error occurs when listener passes * through a specific lifecycle stage */ - public void startupListener( final BlockListenerMetaData metaData ) + public void startupListener( final ComponentProfile profile ) throws Exception { - final String name = metaData.getName(); + final String name = profile.getMetaData().getName(); final Object listener = m_lifecycleHelper.startup( name, - metaData, + profile, m_listenerAccessor ); // However onky ApplicationListners can avail of block events. @@ -556,7 +569,7 @@ final String message = REZ.getString( "helper.isa-blocklistener.error", name, - metaData.getClassname() ); + profile.getMetaData().getImplementationKey() ); getLogger().error( message ); System.err.println( message ); } Index: src/java/org/apache/avalon/phoenix/components/application/DefaultBlockContext.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/DefaultBlockContext.java,v retrieving revision 1.20 diff -u -r1.20 DefaultBlockContext.java --- src/java/org/apache/avalon/phoenix/components/application/DefaultBlockContext.java 1 Nov 2002 08:23:30 -0000 1.20 +++ src/java/org/apache/avalon/phoenix/components/application/DefaultBlockContext.java 2 Dec 2002 11:22:55 -0000 @@ -13,7 +13,6 @@ import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.phoenix.BlockContext; import org.apache.avalon.phoenix.interfaces.ApplicationContext; -import org.apache.avalon.phoenix.metadata.SarMetaData; /** * Context via which Blocks communicate with container. @@ -36,14 +35,13 @@ public Object get( Object key ) throws ContextException { - final SarMetaData metaData = m_applicationContext.getMetaData(); if( BlockContext.APP_NAME.equals( key ) ) { - return metaData.getName(); + return m_applicationContext.getPartitionProfile().getMetaData().getName(); } else if( BlockContext.APP_HOME_DIR.equals( key ) ) { - return metaData.getHomeDirectory(); + return m_applicationContext.getHomeDirectory(); } else if( BlockContext.NAME.equals( key ) ) { @@ -62,7 +60,7 @@ */ public File getBaseDirectory() { - return m_applicationContext.getMetaData().getHomeDirectory(); + return m_applicationContext.getHomeDirectory(); } /** Index: src/java/org/apache/avalon/phoenix/components/application/DependencyGraph.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/DependencyGraph.java,v retrieving revision 1.8 diff -u -r1.8 DependencyGraph.java --- src/java/org/apache/avalon/phoenix/components/application/DependencyGraph.java 6 Aug 2002 11:57:39 -0000 1.8 +++ src/java/org/apache/avalon/phoenix/components/application/DependencyGraph.java 2 Dec 2002 11:22:55 -0000 @@ -8,9 +8,9 @@ package org.apache.avalon.phoenix.components.application; import java.util.ArrayList; -import org.apache.avalon.phoenix.metadata.BlockMetaData; -import org.apache.avalon.phoenix.metadata.DependencyMetaData; -import org.apache.avalon.phoenix.metainfo.DependencyDescriptor; +import org.apache.excalibur.containerkit.registry.ComponentProfile; +import org.apache.excalibur.containerkit.metadata.DependencyMetaData; +import org.apache.avalon.framework.info.DependencyDescriptor; /** * @@ -33,7 +33,8 @@ * @param blocks the blocks to traverse * @return the ordered node names */ - public static String[] walkGraph( final boolean forward, final BlockMetaData[] blocks ) + public static String[] walkGraph( final boolean forward, + final ComponentProfile[] blocks ) { final ArrayList result = new ArrayList(); @@ -49,14 +50,14 @@ return (String[])result.toArray( new String[ 0 ] ); } - private static void visitBlock( final BlockMetaData block, - final BlockMetaData[] blocks, + private static void visitBlock( final ComponentProfile block, + final ComponentProfile[] blocks, final boolean forward, final ArrayList done, final ArrayList order ) { //If already visited this block then bug out early - final String name = block.getName(); + final String name = block.getMetaData().getName(); if( done.contains( name ) ) { return; @@ -80,16 +81,17 @@ * * @param block the BlockMetaData */ - private static void visitDependencies( final BlockMetaData block, - final BlockMetaData[] blocks, + private static void visitDependencies( final ComponentProfile block, + final ComponentProfile[] blocks, final ArrayList done, final ArrayList order ) { - final DependencyDescriptor[] descriptors = block.getBlockInfo().getDependencies(); + final DependencyDescriptor[] descriptors = block.getInfo().getDependencies(); for( int i = 0; i < descriptors.length; i++ ) { - final DependencyMetaData dependency = block.getDependency( descriptors[ i ].getRole() ); - final BlockMetaData other = getBlock( dependency.getName(), blocks ); + final String key = descriptors[ i ].getKey(); + final DependencyMetaData dependency = block.getMetaData().getDependency( key ); + final ComponentProfile other = getBlock( dependency.getProviderName(), blocks ); visitBlock( other, blocks, true, done, order ); } } @@ -98,23 +100,23 @@ * Traverse all reverse dependencies of specified block. * A reverse dependency are those that dependend on block. * - * @param block the BlockMetaData + * @param block the ComponentProfile */ - private static void visitReverseDependencies( final BlockMetaData block, - final BlockMetaData[] blocks, + private static void visitReverseDependencies( final ComponentProfile block, + final ComponentProfile[] blocks, final ArrayList done, final ArrayList order ) { - final String name = block.getName(); + final String name = block.getMetaData().getName(); for( int i = 0; i < blocks.length; i++ ) { - final BlockMetaData other = blocks[ i ]; - final DependencyMetaData[] roles = other.getDependencies(); + final ComponentProfile other = blocks[ i ]; + final DependencyMetaData[] roles = other.getMetaData().getDependencies(); for( int j = 0; j < roles.length; j++ ) { - final String depends = roles[ j ].getName(); + final String depends = roles[ j ].getProviderName(); if( depends.equals( name ) ) { visitBlock( other, blocks, false, done, order ); @@ -130,11 +132,12 @@ * @param blocks the Block array * @return the Block */ - private static BlockMetaData getBlock( final String name, final BlockMetaData[] blocks ) + private static ComponentProfile getBlock( final String name, + final ComponentProfile[] blocks ) { for( int i = 0; i < blocks.length; i++ ) { - if( blocks[ i ].getName().equals( name ) ) + if( blocks[ i ].getMetaData().getName().equals( name ) ) { return blocks[ i ]; } Index: src/java/org/apache/avalon/phoenix/components/application/ExportHelper.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ExportHelper.java,v retrieving revision 1.3 diff -u -r1.3 ExportHelper.java --- src/java/org/apache/avalon/phoenix/components/application/ExportHelper.java 6 Aug 2002 11:57:39 -0000 1.3 +++ src/java/org/apache/avalon/phoenix/components/application/ExportHelper.java 2 Dec 2002 11:22:55 -0000 @@ -10,10 +10,12 @@ import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; import org.apache.avalon.framework.CascadingException; +import org.apache.avalon.framework.tools.infobuilder.LegacyUtil; +import org.apache.avalon.framework.info.ServiceDescriptor; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.phoenix.interfaces.ApplicationContext; -import org.apache.avalon.phoenix.metadata.BlockMetaData; -import org.apache.avalon.phoenix.metainfo.ServiceDescriptor; +import org.apache.excalibur.containerkit.registry.ComponentProfile; +import java.util.ArrayList; /** * Utility class to help with exporting Blocks to management subsystem. @@ -32,12 +34,12 @@ * services, into management system. */ void exportBlock( final ApplicationContext context, - final BlockMetaData metaData, + final ComponentProfile profile, final Object block ) throws CascadingException { - final ServiceDescriptor[] services = metaData.getBlockInfo().getManagementAccessPoints(); - final String name = metaData.getName(); + final ServiceDescriptor[] services = getMxServices( profile ); + final String name = profile.getMetaData().getName(); final ClassLoader classLoader = block.getClass().getClassLoader(); final Class[] serviceClasses = new Class[ services.length ]; @@ -47,13 +49,13 @@ final ServiceDescriptor service = services[ i ]; try { - serviceClasses[ i ] = classLoader.loadClass( service.getName() ); + serviceClasses[ i ] = classLoader.loadClass( service.getType() ); } catch( final Exception e ) { final String reason = e.toString(); final String message = - REZ.getString( "bad-mx-service.error", name, service.getName(), reason ); + REZ.getString( "bad-mx-service.error", name, service.getType(), reason ); getLogger().error( message ); throw new CascadingException( message, e ); } @@ -74,14 +76,36 @@ } /** + * Return an array of all Management services for profile. + * + * @param profile the component profile + * @return the management services. + */ + private ServiceDescriptor[] getMxServices( final ComponentProfile profile ) + { + final ArrayList mxServices = new ArrayList(); + final ServiceDescriptor[] services = profile.getInfo().getServices(); + for( int i = 0; i < services.length; i++ ) + { + final ServiceDescriptor service = services[ i ]; + if( LegacyUtil.isMxService( service ) ) + { + mxServices.add( service ); + } + } + + return (ServiceDescriptor[])mxServices.toArray( new ServiceDescriptor[ mxServices.size() ] ); + } + + /** * Unxport the services of block, declared to be management * services, into management system. */ void unexportBlock( final ApplicationContext context, - final BlockMetaData metaData, + final ComponentProfile profile, final Object block ) { - final String name = metaData.getName(); + final String name = profile.getMetaData().getName(); try { context.unexportObject( name ); Index: src/java/org/apache/avalon/phoenix/components/application/ListenerResourceProvider.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ListenerResourceProvider.java,v retrieving revision 1.3 diff -u -r1.3 ListenerResourceProvider.java --- src/java/org/apache/avalon/phoenix/components/application/ListenerResourceProvider.java 6 Aug 2002 11:57:39 -0000 1.3 +++ src/java/org/apache/avalon/phoenix/components/application/ListenerResourceProvider.java 2 Dec 2002 11:22:56 -0000 @@ -63,7 +63,7 @@ final BlockListenerMetaData metaData = getMetaData( entry ); final ClassLoader classLoader = m_context.getClassLoader(); final Class clazz = - classLoader.loadClass( metaData.getClassname() ); + classLoader.loadClass( metaData.getImplementationKey() ); return clazz.newInstance(); } Index: src/java/org/apache/avalon/phoenix/components/application/ListenerSupport.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ListenerSupport.java,v retrieving revision 1.4 diff -u -r1.4 ListenerSupport.java --- src/java/org/apache/avalon/phoenix/components/application/ListenerSupport.java 6 Sep 2002 12:01:07 -0000 1.4 +++ src/java/org/apache/avalon/phoenix/components/application/ListenerSupport.java 2 Dec 2002 11:22:56 -0000 @@ -11,8 +11,10 @@ import org.apache.avalon.phoenix.ApplicationListener; import org.apache.avalon.phoenix.BlockEvent; import org.apache.avalon.phoenix.BlockListener; -import org.apache.avalon.phoenix.metadata.BlockMetaData; +import org.apache.avalon.phoenix.metainfo.BlockInfo; +import org.apache.avalon.phoenix.components.util.ComponentInfoConverter; import org.apache.avalon.phoenix.metadata.SarMetaData; +import org.apache.excalibur.containerkit.registry.ComponentProfile; /** * Manage a set of [EMAIL PROTECTED] ApplicationListener} objects and propogate @@ -75,11 +77,12 @@ */ private BlockEvent createEvent( final BlockEntry entry ) { - final BlockMetaData metaData = entry.getMetaData(); + final ComponentProfile profile = entry.getProfile(); + final BlockInfo blockInfo = ComponentInfoConverter.toBlockInfo( profile.getInfo() ); final BlockEvent event = - new BlockEvent( metaData.getName(), + new BlockEvent( profile.getMetaData().getName(), entry.getProxy(), - metaData.getBlockInfo() ); + blockInfo ); return event; } Index: src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java,v retrieving revision 1.62 diff -u -r1.62 DefaultDeployer.java --- src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java 2 Nov 2002 00:29:27 -0000 1.62 +++ src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java 2 Dec 2002 11:22:58 -0000 @@ -10,6 +10,8 @@ import java.io.File; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Set; @@ -19,14 +21,22 @@ import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.context.DefaultContext; +import org.apache.avalon.framework.info.ComponentInfo; +import org.apache.avalon.framework.info.SchemaDescriptor; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; -import org.apache.avalon.framework.context.DefaultContext; +import org.apache.avalon.framework.tools.infobuilder.LegacyUtil; +import org.apache.avalon.phoenix.BlockContext; +import org.apache.avalon.phoenix.components.ContainerConstants; +import org.apache.avalon.phoenix.components.assembler.Assembler; +import org.apache.avalon.phoenix.components.assembler.AssemblyException; import org.apache.avalon.phoenix.interfaces.Application; import org.apache.avalon.phoenix.interfaces.ClassLoaderManager; +import org.apache.avalon.phoenix.interfaces.ClassLoaderSet; import org.apache.avalon.phoenix.interfaces.ConfigurationRepository; import org.apache.avalon.phoenix.interfaces.ConfigurationValidator; import org.apache.avalon.phoenix.interfaces.Deployer; @@ -37,17 +47,15 @@ import org.apache.avalon.phoenix.interfaces.Installer; import org.apache.avalon.phoenix.interfaces.Kernel; import org.apache.avalon.phoenix.interfaces.LogManager; -import org.apache.avalon.phoenix.interfaces.ClassLoaderSet; -import org.apache.avalon.phoenix.metadata.BlockListenerMetaData; -import org.apache.avalon.phoenix.metadata.BlockMetaData; -import org.apache.avalon.phoenix.metadata.SarMetaData; -import org.apache.avalon.phoenix.metainfo.BlockDescriptor; -import org.apache.avalon.phoenix.tools.assembler.Assembler; -import org.apache.avalon.phoenix.tools.assembler.AssemblyException; import org.apache.avalon.phoenix.tools.configuration.ConfigurationBuilder; import org.apache.avalon.phoenix.tools.verifier.SarVerifier; import org.apache.avalon.phoenix.tools.verifier.VerifyException; -import org.apache.avalon.phoenix.BlockContext; +import org.apache.excalibur.containerkit.factory.ComponentBundle; +import org.apache.excalibur.containerkit.factory.ComponentFactory; +import org.apache.excalibur.containerkit.metadata.ComponentMetaData; +import org.apache.excalibur.containerkit.metadata.PartitionMetaData; +import org.apache.excalibur.containerkit.registry.ComponentProfile; +import org.apache.excalibur.containerkit.registry.PartitionProfile; /** * Deploy .sar files into a kernel using this class. @@ -248,7 +256,7 @@ final Configuration environment = getConfigurationFor( installation.getEnvironment() ); final Configuration assembly = getConfigurationFor( installation.getAssembly() ); - final File directory = installation.getDirectory(); + final File directory = installation.getHomeDirectory(); final DefaultContext context = new DefaultContext(); context.put( BlockContext.APP_NAME, name ); @@ -256,19 +264,20 @@ final ClassLoaderSet classLoaderSet = m_classLoaderManager.createClassLoaderSet( environment, - installation.getDirectory(), + installation.getHomeDirectory(), installation.getWorkDirectory() ); final ClassLoader classLoader = classLoaderSet.getDefaultClassLoader(); context.put( "classloader", classLoader ); - //assemble all the blocks for application - final SarMetaData metaData = - m_assembler.assembleSar( name, assembly, directory, classLoader ); + final PartitionMetaData metaData = assembleSar( name, assembly ); - storeConfigurationSchemas( metaData, classLoader ); + final ComponentFactory factory = new PhoenixComponentFactory( classLoader ); + setupLogger( factory, "factory" ); + final PartitionProfile profile = assembleSarProfile( metaData, factory ); - verify( metaData, classLoader ); + storeConfigurationSchemas( profile, classLoader ); + verify( profile, classLoader ); //Setup configuration for all the applications blocks setupConfiguration( metaData, config.getChildren() ); @@ -278,7 +287,8 @@ m_logManager.createHierarchy( logs, context ); //Finally add application to kernel - m_kernel.addApplication( metaData, + m_kernel.addApplication( profile, + installation.getHomeDirectory(), installation.getWorkDirectory(), classLoader, logger, @@ -321,47 +331,139 @@ } } + private PartitionProfile assembleSarProfile( final PartitionMetaData metaData, + final ComponentFactory factory ) + throws Exception + { + final PartitionMetaData blockPartition = + metaData.getPartition( ContainerConstants.BLOCK_PARTITION ); + final PartitionMetaData listenerPartition = + metaData.getPartition( ContainerConstants.LISTENER_PARTITION ); + + final PartitionProfile blockProfile = assembleProfile( blockPartition, factory ); + final PartitionProfile listenerProfile = + assembleListenerProfile( listenerPartition ); + + final PartitionProfile[] profiles = new PartitionProfile[]{blockProfile, listenerProfile}; + return new PartitionProfile( metaData, + profiles, + new ComponentProfile[ 0 ] ); + } + + private PartitionProfile assembleListenerProfile( final PartitionMetaData metaData ) + throws Exception + { + final ArrayList componentSet = new ArrayList(); + final ComponentMetaData[] components = metaData.getComponents(); + for( int i = 0; i < components.length; i++ ) + { + final ComponentMetaData component = components[ i ]; + final ComponentInfo info = + LegacyUtil.createListenerInfo( component.getImplementationKey() ); + final ComponentProfile profile = new ComponentProfile( info, component ); + componentSet.add( profile ); + } + + final ComponentProfile[] profiles = + (ComponentProfile[])componentSet.toArray( new ComponentProfile[ componentSet.size() ] ); + return new PartitionProfile( metaData, PartitionProfile.EMPTY_SET, profiles ); + } + + private PartitionProfile assembleProfile( final PartitionMetaData metaData, + final ComponentFactory factory ) + throws Exception + { + final ArrayList partitionSet = new ArrayList(); + final PartitionMetaData[] partitions = metaData.getPartitions(); + for( int i = 0; i < partitions.length; i++ ) + { + final PartitionMetaData partition = partitions[ i ]; + final PartitionProfile profile = assembleProfile( partition, factory ); + partitionSet.add( profile ); + } + + final ArrayList componentSet = new ArrayList(); + final ComponentMetaData[] components = metaData.getComponents(); + for( int i = 0; i < components.length; i++ ) + { + final ComponentMetaData component = components[ i ]; + final ComponentBundle bundle = + factory.createBundle( component.getImplementationKey() ); + final ComponentInfo info = bundle.getComponentInfo(); + final ComponentProfile profile = new ComponentProfile( info, component ); + componentSet.add( profile ); + } + + final PartitionProfile[] partitionProfiles = + (PartitionProfile[])partitionSet.toArray( new PartitionProfile[ partitionSet.size() ] ); + final ComponentProfile[] componentProfiles = + (ComponentProfile[])componentSet.toArray( new ComponentProfile[ componentSet.size() ] ); + return new PartitionProfile( metaData, partitionProfiles, componentProfiles ); + } + + private PartitionMetaData assembleSar( final String name, + final Configuration assembly ) + throws Exception + { + final Map parameters = new HashMap(); + parameters.put( ContainerConstants.ASSEMBLY_NAME, name ); + parameters.put( ContainerConstants.ASSEMBLY_CONFIG, assembly ); + //assemble all the blocks for application + return m_assembler.buildAssembly( parameters ); + } + /** * Verify that the application conforms to our requirements. * - * @param metaData the application metaData - * @param classLoader the ClassLoader associated with app + * @param profile the application profile * @throws VerifyException on error */ - protected void verify( final SarMetaData metaData, - final ClassLoader classLoader ) + private void verify( final PartitionProfile profile, + final ClassLoader classLoader ) throws VerifyException { - m_verifier.verifySar( metaData, classLoader ); + try + { + m_verifier.verifySar( profile, classLoader ); + } + catch( org.apache.avalon.framework.tools.verifier.VerifyException e ) + { + throw new VerifyException( e.getMessage(), e.getCause() ); + } } /** * Store the configuration schemas for this application * - * @param metaData the application metaData + * @param profile the application profile * @throws DeploymentException upon invalid schema */ - private void storeConfigurationSchemas( final SarMetaData metaData, ClassLoader classLoader ) + private void storeConfigurationSchemas( final PartitionProfile profile, + final ClassLoader classLoader ) throws DeploymentException { - final BlockMetaData[] blocks = metaData.getBlocks(); + final String application = profile.getMetaData().getName(); + final PartitionProfile partition = profile.getPartition( ContainerConstants.BLOCK_PARTITION ); + final ComponentProfile[] blocks = partition.getComponents(); int i = 0; + final ComponentProfile block = blocks[ i ]; + final String implementationKey = + block.getInfo().getDescriptor().getImplementationKey(); + final String name = block.getMetaData().getName(); try { for( i = 0; i < blocks.length; i++ ) { - final String name = blocks[ i ].getName(); - final BlockDescriptor descriptor = blocks[ i ].getBlockInfo().getBlockDescriptor(); - final String type = descriptor.getSchemaType(); + final SchemaDescriptor descriptor = block.getInfo().getConfigurationSchema(); - if( null != type ) + if( null != descriptor && !descriptor.getType().equals( "" ) ) { - m_validator.addSchema( metaData.getName(), + m_validator.addSchema( application, name, - type, + descriptor.getType(), getConfigurationSchemaURL( name, - descriptor.getImplementationKey(), + implementationKey, classLoader ) ); } @@ -370,14 +472,15 @@ catch( ConfigurationException e ) { //uh-oh, bad schema bad bad! - final String message = REZ.getString( "deploy.error.config.schema.invalid", - blocks[ i ].getName() ); + final String message = + REZ.getString( "deploy.error.config.schema.invalid", + implementationKey ); //back out any schemas that we have already stored for this app while( --i >= 0 ) { - m_validator.removeSchema( metaData.getName(), - blocks[ i ].getName() ); + m_validator.removeSchema( name, + implementationKey ); } throw new DeploymentException( message, e ); @@ -395,9 +498,11 @@ if( null == resource ) { - throw new DeploymentException( REZ.getString( "deploy.error.config.schema.missing", - name, - resourceName ) ); + final String message = + REZ.getString( "deploy.error.config.schema.missing", + name, + resourceName ); + throw new DeploymentException( message ); } else { @@ -434,19 +539,24 @@ * @param configurations the block configurations. * @throws DeploymentException if an error occurs */ - private void setupConfiguration( final SarMetaData metaData, + private void setupConfiguration( final PartitionMetaData metaData, final Configuration[] configurations ) throws DeploymentException { final String application = metaData.getName(); - + final PartitionMetaData listenerPartition = + metaData.getPartition( ContainerConstants.LISTENER_PARTITION ); + final PartitionMetaData blockPartition = + metaData.getPartition( ContainerConstants.BLOCK_PARTITION ); for( int i = 0; i < configurations.length; i++ ) { final Configuration configuration = configurations[ i ]; final String name = configuration.getName(); - final boolean listener = hasBlockListener( name, metaData.getListeners() ); - - if( !hasBlock( name, metaData.getBlocks() ) && !listener ) + final boolean listener = + null != listenerPartition.getComponent( name ); + final boolean block = + null != blockPartition.getComponent( name ); + if( !block && !listener ) { final String message = REZ.getString( "deploy.error.extra.config", @@ -465,8 +575,8 @@ } else { - final String message = REZ.getString( "deploy.error.config.invalid", name ); - + final String message = + REZ.getString( "deploy.error.config.invalid", name ); throw new DeploymentException( message ); } } @@ -475,47 +585,5 @@ throw new DeploymentException( ce.getMessage(), ce ); } } - } - - /** - * Return true if specified array contains entry with specified name. - * - * @param name the blocks name - * @param blocks the set of BlockMetaData objects to search - * @return true if block present, false otherwise - */ - private boolean hasBlock( final String name, final BlockMetaData[] blocks ) - { - for( int i = 0; i < blocks.length; i++ ) - { - final String other = blocks[ i ].getName(); - if( other.equals( name ) ) - { - return true; - } - } - - return false; - } - - /** - * Return true if specified array contains entry with specified name. - * - * @param name the blocks name - * @param listeners the set of BlockListenerMetaData objects to search - * @return true if block present, false otherwise - */ - private boolean hasBlockListener( final String name, - final BlockListenerMetaData[] listeners ) - { - for( int i = 0; i < listeners.length; i++ ) - { - if( listeners[ i ].getName().equals( name ) ) - { - return true; - } - } - - return false; } } Index: src/java/org/apache/avalon/phoenix/components/embeddor/EmbeddorEntry.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/EmbeddorEntry.java,v retrieving revision 1.3 diff -u -r1.3 EmbeddorEntry.java --- src/java/org/apache/avalon/phoenix/components/embeddor/EmbeddorEntry.java 26 Jul 2002 09:49:21 -0000 1.3 +++ src/java/org/apache/avalon/phoenix/components/embeddor/EmbeddorEntry.java 2 Dec 2002 11:22:58 -0000 @@ -15,13 +15,9 @@ public class EmbeddorEntry { private final String m_role; - private final String m_classname; - private final String m_loggerName; - private final Configuration m_configuration; - private Object m_object; public EmbeddorEntry( final String role, Index: src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java,v retrieving revision 1.31 diff -u -r1.31 DefaultApplicationContext.java --- src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java 1 Nov 2002 08:23:30 -0000 1.31 +++ src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java 2 Dec 2002 11:22:59 -0000 @@ -23,6 +23,7 @@ import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.phoenix.components.ContainerConstants; import org.apache.avalon.phoenix.components.util.ResourceUtil; import org.apache.avalon.phoenix.interfaces.ApplicationContext; import org.apache.avalon.phoenix.interfaces.ConfigurationRepository; @@ -30,8 +31,8 @@ import org.apache.avalon.phoenix.interfaces.Kernel; import org.apache.avalon.phoenix.interfaces.ManagerException; import org.apache.avalon.phoenix.interfaces.SystemManager; -import org.apache.avalon.phoenix.metadata.BlockListenerMetaData; -import org.apache.avalon.phoenix.metadata.SarMetaData; +import org.apache.excalibur.containerkit.metadata.PartitionMetaData; +import org.apache.excalibur.containerkit.registry.PartitionProfile; import org.apache.excalibur.threadcontext.ThreadContext; import org.apache.excalibur.threadcontext.impl.DefaultThreadContextPolicy; @@ -68,8 +69,9 @@ private SystemManager m_blockManager; - private final SarMetaData m_metaData; + private final PartitionProfile m_profile; private final File m_workDirectory; + private final File m_homeDirectory; /** * The map containing all the named loaders. @@ -81,15 +83,16 @@ */ private Kernel m_kernel; - protected DefaultApplicationContext( final SarMetaData metaData, + protected DefaultApplicationContext( final PartitionProfile profile, + final File homeDirectory, final File workDirectory, final ClassLoader classLoader, final Logger hierarchy, final Map loaders ) { - if( null == metaData ) + if( null == profile ) { - throw new NullPointerException( "metaData" ); + throw new NullPointerException( "profile" ); } if( null == classLoader ) { @@ -103,11 +106,15 @@ { throw new NullPointerException( "workDirectory" ); } - - m_metaData = metaData; + if( null == homeDirectory ) + { + throw new NullPointerException( "homeDirectory" ); + } + m_profile = profile; m_classLoader = classLoader; m_hierarchy = hierarchy; m_workDirectory = workDirectory; + m_homeDirectory = homeDirectory; m_loaders = loaders; final DefaultThreadContextPolicy policy = new DefaultThreadContextPolicy(); @@ -138,7 +145,7 @@ { final File file = ResourceUtil.getFileForResource( name, - m_metaData.getHomeDirectory(), + getHomeDirectory(), m_workDirectory ); if( !file.exists() ) { @@ -158,9 +165,9 @@ } } - public SarMetaData getMetaData() + public PartitionProfile getPartitionProfile() { - return m_metaData; + return m_profile; } public ThreadContext getThreadContext() @@ -189,17 +196,22 @@ //return and do whatever it needs to be //done Thread.sleep( 2 ); - m_kernel.removeApplication( m_metaData.getName() ); + m_kernel.removeApplication( getName() ); } catch( Exception e ) { final String message = REZ.getString( "applicationcontext.error.noremove", - m_metaData.getName() ); + getName() ); getLogger().error( message, e ); } } + public File getHomeDirectory() + { + return m_homeDirectory; + } + /** * Get ClassLoader for the current application. * @@ -260,15 +272,18 @@ throws ConfigurationException { final Configuration configuration = - m_repository.getConfiguration( m_metaData.getName(), + m_repository.getConfiguration( getName(), component ); //no validation of listeners just yet.. - if( hasBlockListener( component, this.m_metaData.getListeners() ) ) + final PartitionMetaData partition = + m_profile.getMetaData().getPartition( ContainerConstants.LISTENER_PARTITION ); + final boolean isListener = null != partition.getComponent( component ); + if( isListener ) { return configuration; } - else if( m_validator.isValid( m_metaData.getName(), + else if( m_validator.isValid( getName(), component, configuration ) ) { @@ -299,27 +314,6 @@ } /** - * Return true if specified array contains entry with specified name. - * - * @param name the blocks name - * @param listeners the set of BlockListenerMetaData objects to search - * @return true if block present, false otherwise - */ - private boolean hasBlockListener( final String name, - final BlockListenerMetaData[] listeners ) - { - for( int i = 0; i < listeners.length; i++ ) - { - if( listeners[ i ].getName().equals( name ) ) - { - return true; - } - } - - return false; - } - - /** * Returns the local SystemManager where the blocks should be registered * for management. * @@ -330,6 +324,11 @@ { final SystemManager appContext = m_systemManager.getSubContext( null, "application" ); - return appContext.getSubContext( m_metaData.getName(), "block" ); + return appContext.getSubContext( getName(), "block" ); + } + + private String getName() + { + return m_profile.getMetaData().getName(); } } Index: src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java,v retrieving revision 1.82 diff -u -r1.82 DefaultKernel.java --- src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java 1 Nov 2002 08:23:30 -0000 1.82 +++ src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java 2 Dec 2002 11:23:00 -0000 @@ -34,7 +34,8 @@ import org.apache.avalon.phoenix.interfaces.Kernel; import org.apache.avalon.phoenix.interfaces.KernelMBean; import org.apache.avalon.phoenix.interfaces.SystemManager; -import org.apache.avalon.phoenix.metadata.SarMetaData; +import org.apache.excalibur.containerkit.metadata.PartitionMetaData; +import org.apache.excalibur.containerkit.registry.PartitionProfile; /** * The ServerKernel is the core of the Phoenix system. @@ -142,7 +143,7 @@ //lock for application startup and shutdown synchronized( entry ) { - final String name = entry.getMetaData().getName(); + final String name = entry.getProfile().getMetaData().getName(); Application application = entry.getApplication(); if( null == application ) @@ -170,7 +171,7 @@ final String message = REZ.getString( "kernel.error.entry.initialize", - entry.getMetaData().getName() ); + entry.getProfile().getMetaData().getName() ); throw new CascadingException( message, t ); } @@ -181,7 +182,8 @@ catch( final Throwable t ) { final String message = - REZ.getString( "kernel.error.entry.start", entry.getMetaData().getName() ); + REZ.getString( "kernel.error.entry.start", + entry.getProfile().getMetaData().getName() ); if( m_addInvalidApplications ) { @@ -232,22 +234,25 @@ { final String message = REZ.getString( "kernel.error.entry.nostop", - entry.getMetaData().getName() ); + entry.getProfile().getMetaData().getName() ); getLogger().warn( message ); } } } - public void addApplication( final SarMetaData metaData, + public void addApplication( final PartitionProfile profile, + final File homeDirectory, final File workDirectory, final ClassLoader classLoader, final Logger logger, final Map classloaders ) throws Exception { - final String name = metaData.getName(); + + final String name = profile.getMetaData().getName(); final SarEntry entry = - new SarEntry( metaData, workDirectory, classLoader, + new SarEntry( profile, homeDirectory, + workDirectory, classLoader, logger, classloaders ); m_entries.put( name, entry ); @@ -266,11 +271,11 @@ private ApplicationContext createApplicationContext( final SarEntry entry ) throws Exception { - final SarMetaData metaData = entry.getMetaData(); - final String name = metaData.getName(); + final String name = entry.getProfile().getMetaData().getName(); final DefaultApplicationContext context = - new DefaultApplicationContext( metaData, + new DefaultApplicationContext( entry.getProfile(), + entry.getHomeDirectory(), entry.getWorkDirectory(), entry.getClassLoader(), entry.getLogger(), Index: src/java/org/apache/avalon/phoenix/components/kernel/SarEntry.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/SarEntry.java,v retrieving revision 1.17 diff -u -r1.17 SarEntry.java --- src/java/org/apache/avalon/phoenix/components/kernel/SarEntry.java 1 Nov 2002 08:23:30 -0000 1.17 +++ src/java/org/apache/avalon/phoenix/components/kernel/SarEntry.java 2 Dec 2002 11:23:00 -0000 @@ -11,7 +11,7 @@ import java.util.Map; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.phoenix.interfaces.Application; -import org.apache.avalon.phoenix.metadata.SarMetaData; +import org.apache.excalibur.containerkit.registry.PartitionProfile; /** * This is the structure describing each server application before it is loaded. @@ -20,22 +20,24 @@ */ final class SarEntry { - private final SarMetaData m_metaData; + private final PartitionProfile m_profile; private final ClassLoader m_classLoader; private final Logger m_logger; + private final File m_homeDirectory; private final File m_workDirectory; private final Map m_classLoaders; private Application m_application; - protected SarEntry( final SarMetaData metaData, + protected SarEntry( final PartitionProfile profile, + final File homeDirectory, final File workDirectory, final ClassLoader classLoader, final Logger logger, final Map classLoaders ) { - if( null == metaData ) + if( null == profile ) { - throw new NullPointerException( "metaData" ); + throw new NullPointerException( "profile" ); } if( null == classLoader ) { @@ -49,18 +51,28 @@ { throw new NullPointerException( "workDirectory" ); } + if( null == homeDirectory ) + { + throw new NullPointerException( "homeDirectory" ); + } if( null == classLoaders ) { throw new NullPointerException( "classLoaders" ); } - m_metaData = metaData; + m_profile = profile; m_classLoader = classLoader; m_logger = logger; + m_homeDirectory = homeDirectory; m_workDirectory = workDirectory; m_classLoaders = classLoaders; } + public File getHomeDirectory() + { + return m_homeDirectory; + } + public File getWorkDirectory() { return m_workDirectory; @@ -76,9 +88,9 @@ m_application = application; } - public SarMetaData getMetaData() + public PartitionProfile getProfile() { - return m_metaData; + return m_profile; } public Logger getLogger() Index: src/java/org/apache/avalon/phoenix/components/kernel/beanshell/BeanShellKernelProxy.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/beanshell/BeanShellKernelProxy.java,v retrieving revision 1.7 diff -u -r1.7 BeanShellKernelProxy.java --- src/java/org/apache/avalon/phoenix/components/kernel/beanshell/BeanShellKernelProxy.java 1 Nov 2002 08:23:30 -0000 1.7 +++ src/java/org/apache/avalon/phoenix/components/kernel/beanshell/BeanShellKernelProxy.java 2 Dec 2002 11:23:00 -0000 @@ -28,7 +28,7 @@ m_kernel = kernel; } - public void addApplication( final SarMetaData metaData, + public void addApplication( final PartitionMetaData metaData, final File workDirectory, final ClassLoader classLoader, final Logger logger, Index: src/java/org/apache/avalon/phoenix/components/util/ComponentInfoConverter.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/util/ComponentInfoConverter.java,v retrieving revision 1.7 diff -u -r1.7 ComponentInfoConverter.java --- src/java/org/apache/avalon/phoenix/components/util/ComponentInfoConverter.java 16 Nov 2002 14:47:25 -0000 1.7 +++ src/java/org/apache/avalon/phoenix/components/util/ComponentInfoConverter.java 2 Dec 2002 11:23:01 -0000 @@ -9,10 +9,10 @@ import java.util.ArrayList; import org.apache.avalon.framework.Version; -import org.apache.avalon.framework.info.Attribute; import org.apache.avalon.framework.info.ComponentDescriptor; import org.apache.avalon.framework.info.ComponentInfo; -import org.apache.avalon.framework.info.FeatureDescriptor; +import org.apache.avalon.framework.info.SchemaDescriptor; +import org.apache.avalon.framework.tools.infobuilder.LegacyUtil; import org.apache.avalon.phoenix.metainfo.BlockDescriptor; import org.apache.avalon.phoenix.metainfo.BlockInfo; import org.apache.avalon.phoenix.metainfo.DependencyDescriptor; @@ -38,12 +38,9 @@ */ public static BlockInfo toBlockInfo( final ComponentInfo component ) { - final BlockDescriptor descriptor = - toBlockDescriptor( component ); - final ServiceDescriptor[] services = - toPhoenixServices( component.getServices() ); - final ServiceDescriptor[] mxServices = - getMXServices( component.getServices() ); + final BlockDescriptor descriptor = toBlockDescriptor( component ); + final ServiceDescriptor[] services = toPhoenixServices( component.getServices() ); + final ServiceDescriptor[] mxServices = getMXServices( component.getServices() ); final DependencyDescriptor[] dependencys = toPhoenixDependencys( component.getDependencies() ); @@ -65,8 +62,7 @@ final ArrayList serviceSet = new ArrayList(); for( int i = 0; i < services.length; i++ ) { - final Attribute tag = services[ i ].getAttribute( "mx" ); - if( null != tag ) + if( LegacyUtil.isMxService( services[ i ] ) ) { serviceSet.add( toPhoenixService( services[ i ] ) ); } @@ -86,7 +82,10 @@ final ArrayList serviceSet = new ArrayList(); for( int i = 0; i < services.length; i++ ) { - serviceSet.add( toPhoenixService( services[ i ] ) ); + if( !LegacyUtil.isMxService( services[ i ] ) ) + { + serviceSet.add( toPhoenixService( services[ i ] ) ); + } } return (ServiceDescriptor[])serviceSet.toArray( new ServiceDescriptor[ serviceSet.size() ] ); } @@ -100,9 +99,8 @@ private static ServiceDescriptor toPhoenixService( final org.apache.avalon.framework.info.ServiceDescriptor service ) { - final Version version = toVersion( service ); - final String classname = service.getImplementationKey(); - return new ServiceDescriptor( classname, version ); + final Version version = LegacyUtil.toVersion( service ); + return new ServiceDescriptor( service.getType(), version ); } /** @@ -131,7 +129,7 @@ private static DependencyDescriptor toPhoenixDependency( final org.apache.avalon.framework.info.DependencyDescriptor dependency ) { - final Version version = toVersion( dependency ); + final Version version = LegacyUtil.toVersion( dependency ); final ServiceDescriptor service = new ServiceDescriptor( dependency.getType(), version ); return new DependencyDescriptor( dependency.getKey(), service ); @@ -146,38 +144,18 @@ private static BlockDescriptor toBlockDescriptor( final ComponentInfo component ) { final ComponentDescriptor descriptor = component.getDescriptor(); - final Version version = toVersion( descriptor ); + final Version version = LegacyUtil.toVersion( descriptor ); - String schemaType = component.getSchema().getType(); - if( "".equals( schemaType ) ) + final SchemaDescriptor schema = component.getConfigurationSchema(); + String schemaType = null; + if( null != schema ) { - schemaType = null; + schemaType = schema.getType(); } return new BlockDescriptor( null, descriptor.getImplementationKey(), schemaType, version ); - } - - /** - * Create a version for a feature. Defaults to 1.0 if not specified. - * - * @param feature the feature - * @return the Version object - */ - private static Version toVersion( final FeatureDescriptor feature ) - { - final Attribute tag = feature.getAttribute( "avalon" ); - Version version = new Version( 1, 0, 0 ); - if( null != tag ) - { - final String versionString = tag.getParameter( "version" ); - if( null != versionString ) - { - version = Version.getVersion( versionString ); - } - } - return version; } } Index: src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java,v retrieving revision 1.19 diff -u -r1.19 ApplicationContext.java --- src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java 1 Nov 2002 08:23:30 -0000 1.19 +++ src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java 2 Dec 2002 11:23:01 -0000 @@ -7,11 +7,13 @@ */ package org.apache.avalon.phoenix.interfaces; +import java.io.File; import java.io.InputStream; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.Logger; -import org.apache.avalon.phoenix.metadata.SarMetaData; +import org.apache.excalibur.containerkit.metadata.PartitionMetaData; +import org.apache.excalibur.containerkit.registry.PartitionProfile; import org.apache.excalibur.threadcontext.ThreadContext; /** @@ -23,7 +25,9 @@ { String ROLE = ApplicationContext.class.getName(); - SarMetaData getMetaData(); + File getHomeDirectory(); + + PartitionProfile getPartitionProfile(); ThreadContext getThreadContext(); Index: src/java/org/apache/avalon/phoenix/interfaces/Installation.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/Installation.java,v retrieving revision 1.2 diff -u -r1.2 Installation.java --- src/java/org/apache/avalon/phoenix/interfaces/Installation.java 1 Nov 2002 01:15:40 -0000 1.2 +++ src/java/org/apache/avalon/phoenix/interfaces/Installation.java 2 Dec 2002 11:23:02 -0000 @@ -24,7 +24,7 @@ private final File m_source; ///Directory in which application is installed - private final File m_directory; + private final File m_homeDirectory; ///Directory in which application temporary/work data is stored private final File m_workDirectory; @@ -46,7 +46,7 @@ final String environment ) { m_source = source; - m_directory = directory; + m_homeDirectory = directory; m_workDirectory = workDirectory; m_config = config; m_assembly = assembly; @@ -69,9 +69,9 @@ * * @return the applications base directory */ - public File getDirectory() + public File getHomeDirectory() { - return m_directory; + return m_homeDirectory; } /** Index: src/java/org/apache/avalon/phoenix/interfaces/Kernel.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/Kernel.java,v retrieving revision 1.17 diff -u -r1.17 Kernel.java --- src/java/org/apache/avalon/phoenix/interfaces/Kernel.java 1 Nov 2002 08:23:31 -0000 1.17 +++ src/java/org/apache/avalon/phoenix/interfaces/Kernel.java 2 Dec 2002 11:23:02 -0000 @@ -10,7 +10,8 @@ import java.io.File; import java.util.Map; import org.apache.avalon.framework.logger.Logger; -import org.apache.avalon.phoenix.metadata.SarMetaData; +import org.apache.excalibur.containerkit.metadata.PartitionMetaData; +import org.apache.excalibur.containerkit.registry.PartitionProfile; /** * @author <a href="mailto:peter at apache.org">Peter Donald</a> @@ -22,8 +23,8 @@ /** * Adds an application to the container */ - void addApplication( SarMetaData metaData, - File workDirectory, + void addApplication( PartitionProfile profile, + File homeDirectory, File workDirectory, ClassLoader classLoader, Logger logger, Map classloaders ) Index: src/java/org/apache/avalon/phoenix/metadata/BlockListenerMetaData.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/metadata/BlockListenerMetaData.java,v retrieving revision 1.6 diff -u -r1.6 BlockListenerMetaData.java --- src/java/org/apache/avalon/phoenix/metadata/BlockListenerMetaData.java 6 Aug 2002 11:57:41 -0000 1.6 +++ src/java/org/apache/avalon/phoenix/metadata/BlockListenerMetaData.java 2 Dec 2002 11:23:02 -0000 @@ -15,18 +15,26 @@ public final class BlockListenerMetaData { private final String m_name; + private final String m_implementationKey; - private final String m_classname; - - public BlockListenerMetaData( final String name, final String classname ) + public BlockListenerMetaData( final String name, + final String implementationKey ) { m_name = name; - m_classname = classname; + m_implementationKey = implementationKey; + } + + public String getImplementationKey() + { + return m_implementationKey; } + /** + * @deprecated Use getImplementationKey() instead. + */ public String getClassname() { - return m_classname; + return getImplementationKey(); } public String getName() Index: src/java/org/apache/avalon/phoenix/tools/metagenerate/MetaGenerateTask.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/metagenerate/MetaGenerateTask.java,v retrieving revision 1.3 diff -u -r1.3 MetaGenerateTask.java --- src/java/org/apache/avalon/phoenix/tools/metagenerate/MetaGenerateTask.java 22 Oct 2002 06:41:12 -0000 1.3 +++ src/java/org/apache/avalon/phoenix/tools/metagenerate/MetaGenerateTask.java 2 Dec 2002 11:23:02 -0000 @@ -7,81 +7,72 @@ */ package org.apache.avalon.phoenix.tools.metagenerate; -import com.thoughtworks.qdox.ant.AbstractQdoxTask; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; -import java.io.File; import java.io.IOException; +import java.io.File; +import org.apache.avalon.framework.tools.ant.FormatEnum; import org.apache.tools.ant.BuildException; /** * MetaInfo Generation Ant Taskdef - * @author Paul Hammant + * @author Paul Hammant */ -public class MetaGenerateTask extends AbstractQdoxTask +public class MetaGenerateTask + extends org.apache.avalon.framework.tools.ant.MetaGenerateTask { - - private File m_destDir; - private boolean m_inheritance = true; + //private boolean m_inheritance = true; /** - * Execute + * Inheritence : should parent classes of blocks be queried too? + * @param inheritance */ - public void execute() + public void setInheritance( boolean inheritance ) { - super.execute(); - try - { - m_destDir.mkdirs(); - outputClasses(); - } - catch (IOException e) - { - e.printStackTrace(); - throw new BuildException("IOException " + e.getMessage()); - } + //TODO: Do inheritance based on markup rather than based on task run + //m_inheritance = inheritance; } - /** - * Set the desitation - * @param destinationDir The destination directory - */ - public void setDest(File destinationDir) + public void setDest( File destDir ) { - m_destDir = destinationDir; + super.setDestDir( destDir ); } - /** - * Inheritence : should parent classes of blocks be queried too? - * @param inheritance - */ - public void setInheritance(boolean inheritance) + public void execute() + throws BuildException { - m_inheritance = inheritance; + final FormatEnum format = new FormatEnum(); + format.setValue( "legacy" ); + setFormat( format); + super.execute(); + outputClasses(); } /** * Output the classes - * @throws IOException If a problem writing output + * + * @throws BuildException If a problem writing output */ - protected void outputClasses() throws IOException + private void outputClasses() + throws BuildException { - - for (int i = 0; i < allClasses.size(); i++) + final int size = allClasses.size(); + for( int i = 0; i < size; i++ ) { - JavaClass javaClass = (JavaClass) allClasses.get(i); - DocletTag block = javaClass.getTagByName("phoenix:block"); - if (block != null) - { - XinfoFactory factory = new XinfoFactory(m_destDir, javaClass, - allClasses, m_inheritance); - factory.generate(); - } - DocletTag topic = javaClass.getTagByName("phoenix:mx-topic"); - if (topic != null) + final JavaClass javaClass = (JavaClass)allClasses.get( i ); + final DocletTag topic = javaClass.getTagByName( "phoenix:mx-topic" ); + if( topic != null ) { - MxinfoFactory factory = new MxinfoFactory(m_destDir, javaClass); - factory.generate(); + final MxinfoFactory factory = + new MxinfoFactory( getDestDir(), javaClass ); + try + { + factory.generate(); + } + catch( final IOException ioe ) + { + throw new BuildException( ioe.getMessage(), ioe ); + } } } } Index: src/java/org/apache/avalon/phoenix/tools/metagenerate/MxinfoHelper.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/metagenerate/MxinfoHelper.java,v retrieving revision 1.2 diff -u -r1.2 MxinfoHelper.java --- src/java/org/apache/avalon/phoenix/tools/metagenerate/MxinfoHelper.java 2 Oct 2002 11:11:58 -0000 1.2 +++ src/java/org/apache/avalon/phoenix/tools/metagenerate/MxinfoHelper.java 2 Dec 2002 11:23:03 -0000 @@ -18,11 +18,8 @@ * A Xinfo Helper. * @author Paul Hammant */ -public class MxinfoHelper extends AbstractHelper +public class MxinfoHelper { - - private FileWriter m_output; - private static final String HEADER[] = new String[]{ "<?xml version=\"1.0\"?>", "<!DOCTYPE mxinfo PUBLIC \"-//PHOENIX/Mx Info DTD Version 1.0//EN\"", @@ -48,23 +45,23 @@ private static final String OPERATIONS_HEADER[] = new String[]{ "", " <!-- operations -->", - "" }; + ""}; private static final String OPERATION_HEADER[] = new String[]{ " <operation", " name=\"@[EMAIL PROTECTED]"", " description=\"@[EMAIL PROTECTED]"", - " type=\"@[EMAIL PROTECTED]">" }; + " type=\"@[EMAIL PROTECTED]">"}; private static final String PARAMETER[] = new String[]{ " <param", " name=\"@[EMAIL PROTECTED]"", " description=\"@[EMAIL PROTECTED]"", " type=\"@[EMAIL PROTECTED]"", - " />" }; + " />"}; private static final String OPERATION_FOOTER[] = new String[]{ - " </operation>" }; + " </operation>"}; private static final String FOOTER[] = new String[]{ "", @@ -72,14 +69,16 @@ "", "</mxinfo>"}; + private FileWriter m_output; + /** * Construct * @param file The File to create * @throws IOException If a problem writing output */ - public MxinfoHelper(File file) throws IOException + public MxinfoHelper( final File file ) throws IOException { - m_output = new FileWriter(file); + m_output = new FileWriter( file ); } /** @@ -87,23 +86,23 @@ * @param topic The topic * @throws IOException If a problem writing output */ - public void writeHeader(String topic) throws IOException + public void writeHeader( String topic ) throws IOException { - for (int i = 0; i < HEADER.length; i++) + for( int i = 0; i < HEADER.length; i++ ) { - m_output.write(HEADER[i] + "\n"); + m_output.write( HEADER[ i ] + "\n" ); } - for (int i = 0; i < TOPIC.length; i++) + for( int i = 0; i < TOPIC.length; i++ ) { - String line = TOPIC[i]; - line = replaceString(line, "\"@[EMAIL PROTECTED]"", topic); - m_output.write(line + "\n"); + String line = TOPIC[ i ]; + line = replaceString( line, "\"@[EMAIL PROTECTED]"", topic ); + m_output.write( line + "\n" ); } - for (int i = 0; i < ATTR_HEADER.length; i++) + for( int i = 0; i < ATTR_HEADER.length; i++ ) { - m_output.write(ATTR_HEADER[i] + "\n"); + m_output.write( ATTR_HEADER[ i ] + "\n" ); } } @@ -115,19 +114,19 @@ * @param type The type * @throws IOException If a problem writing output */ - public NamedXmlSnippet makeAttrLines(String attrName, String description, String type) - throws IOException + public NamedXmlSnippet makeAttrLines( String attrName, String description, String type ) + throws IOException { String xml = ""; - for (int i = 0; i < ATTRIBUTE.length; i++) + for( int i = 0; i < ATTRIBUTE.length; i++ ) { - String line = ATTRIBUTE[i]; - line = replaceString(line, "@NAME@", attrName); - line = replaceString(line, "\"@[EMAIL PROTECTED]"", description); - line = replaceString(line, "@RETURN@", type); + String line = ATTRIBUTE[ i ]; + line = replaceString( line, "@NAME@", attrName ); + line = replaceString( line, "\"@[EMAIL PROTECTED]"", description ); + line = replaceString( line, "@RETURN@", type ); xml = xml + line + "\n"; } - return new NamedXmlSnippet(attrName, xml); + return new NamedXmlSnippet( attrName, xml ); } /** @@ -135,26 +134,25 @@ * @param attributes A list of attributes * @throws IOException If a problem writing output */ - public void writeAttributes(List attributes) throws IOException + public void writeAttributes( List attributes ) throws IOException { - Collections.sort(attributes); - for (Iterator iterator = attributes.iterator(); iterator.hasNext();) + Collections.sort( attributes ); + for( Iterator iterator = attributes.iterator(); iterator.hasNext(); ) { - NamedXmlSnippet attribute = (NamedXmlSnippet) iterator.next(); - m_output.write(attribute.getXml()); + NamedXmlSnippet attribute = (NamedXmlSnippet)iterator.next(); + m_output.write( attribute.getXml() ); } } - /** * Write the operations headers * @throws IOException If a problem writing output */ public void writeOperationsHeader() throws IOException { - for (int i = 0; i < OPERATIONS_HEADER.length; i++) + for( int i = 0; i < OPERATIONS_HEADER.length; i++ ) { - m_output.write(OPERATIONS_HEADER[i] + "\n"); + m_output.write( OPERATIONS_HEADER[ i ] + "\n" ); } } @@ -165,16 +163,16 @@ * @param type The type * @throws IOException If a problem writing output */ - public String makeOperationHeader(String operName, String description, String type) - throws IOException + public String makeOperationHeader( String operName, String description, String type ) + throws IOException { String xml = ""; - for (int i = 0; i < OPERATION_HEADER.length; i++) + for( int i = 0; i < OPERATION_HEADER.length; i++ ) { - String line = OPERATION_HEADER[i]; - line = replaceString(line, "@NAME@", operName); - line = replaceString(line, "@DESCRIPTION@", description); - line = replaceString(line, "@RETURN@", type); + String line = OPERATION_HEADER[ i ]; + line = replaceString( line, "@NAME@", operName ); + line = replaceString( line, "@DESCRIPTION@", description ); + line = replaceString( line, "@RETURN@", type ); xml = xml + line + "\n"; } return xml; @@ -187,9 +185,9 @@ public String makeOperationFooter() throws IOException { String xml = ""; - for (int i = 0; i < OPERATION_FOOTER.length; i++) + for( int i = 0; i < OPERATION_FOOTER.length; i++ ) { - xml = xml + OPERATION_FOOTER[i] + "\n"; + xml = xml + OPERATION_FOOTER[ i ] + "\n"; } return xml; } @@ -201,16 +199,16 @@ * @param type The type * @throws IOException If a problem writing output */ - public String makeOperationParameter(String paramName, String description, String type) - throws IOException + public String makeOperationParameter( String paramName, String description, String type ) + throws IOException { String xml = ""; - for (int i = 0; i < PARAMETER.length; i++) + for( int i = 0; i < PARAMETER.length; i++ ) { - String line = PARAMETER[i]; - line = replaceString(line, "@NAME@", paramName); - line = replaceString(line, "@DESCRIPTION@", description); - line = replaceString(line, "@TYPE@", type); + String line = PARAMETER[ i ]; + line = replaceString( line, "@NAME@", paramName ); + line = replaceString( line, "@DESCRIPTION@", description ); + line = replaceString( line, "@TYPE@", type ); xml = xml + line + "\n"; } return xml; @@ -221,26 +219,25 @@ * @param operations A list of operations * @throws IOException If a problem writing output */ - public void writeOperations(List operations) throws IOException + public void writeOperations( List operations ) throws IOException { - Collections.sort(operations); - for (Iterator iterator = operations.iterator(); iterator.hasNext();) + Collections.sort( operations ); + for( Iterator iterator = operations.iterator(); iterator.hasNext(); ) { - NamedXmlSnippet operation = (NamedXmlSnippet) iterator.next(); - m_output.write(operation.getXml()); + NamedXmlSnippet operation = (NamedXmlSnippet)iterator.next(); + m_output.write( operation.getXml() ); } } - /** * Write footer * @throws IOException If a problem writing output */ public void writeFooter() throws IOException { - for (int i = 0; i < FOOTER.length; i++) + for( int i = 0; i < FOOTER.length; i++ ) { - m_output.write(FOOTER[i] + "\n"); + m_output.write( FOOTER[ i ] + "\n" ); } } @@ -253,5 +250,24 @@ m_output.close(); } - + /** + * Replace a test with another in a string + * @param source The string to be changed. + * @param term The term to replace. + * @param replacement To replace with. + * @return The resulting string. + */ + protected String replaceString( final String source, String term, String replacement ) + { + String retval = source; + int ix = retval.indexOf( term ); + if( ix != -1 ) + { + retval = + retval.substring( 0, ix ) + + replacement + + retval.substring( ix + term.length(), retval.length() ); + } + return retval; + } } Index: src/java/org/apache/avalon/phoenix/tools/tasks/Sar.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/tasks/Sar.java,v retrieving revision 1.17 diff -u -r1.17 Sar.java --- src/java/org/apache/avalon/phoenix/tools/tasks/Sar.java 25 Aug 2002 05:36:22 -0000 1.17 +++ src/java/org/apache/avalon/phoenix/tools/tasks/Sar.java 2 Dec 2002 11:23:03 -0000 @@ -42,12 +42,16 @@ if( !m_config.exists() ) { - throw new BuildException( "Config descriptor: " + m_config + " does not exist." ); + final String message = + "Config descriptor: " + m_config + " does not exist."; + throw new BuildException( message, getLocation() ); } if( !m_config.isFile() ) { - throw new BuildException( "Config descriptor: " + m_config + " is not a file." ); + final String message = + "Config descriptor: " + m_config + " is not a file."; + throw new BuildException( message, getLocation() ); } } @@ -57,12 +61,16 @@ if( !m_assembly.exists() ) { - throw new BuildException( "Assembly descriptor: " + m_assembly + " does not exist." ); + final String message = + "Assembly descriptor: " + m_assembly + " does not exist."; + throw new BuildException( message, getLocation() ); } if( !m_assembly.isFile() ) { - throw new BuildException( "Assembly descriptor: " + m_assembly + " is not a file." ); + final String message = + "Assembly descriptor: " + m_assembly + " is not a file."; + throw new BuildException( message, getLocation() ); } } @@ -78,16 +86,16 @@ if( !m_environment.exists() ) { - final String message = "Environment descriptor: " - + m_environment + " does not exist."; - throw new BuildException( message ); + final String message = "Environment descriptor: " + + m_environment + " does not exist."; + throw new BuildException( message, getLocation() ); } if( !m_environment.isFile() ) { - final String message = "Environment descriptor: " - + m_environment + " is not a file."; - throw new BuildException( message ); + final String message = "Environment descriptor: " + + m_environment + " is not a file."; + throw new BuildException( message, getLocation() ); } } @@ -108,15 +116,18 @@ { if( null == m_config ) { - throw new BuildException( "config attribute is required", location ); + final String message = "config attribute is required"; + throw new BuildException( message, getLocation() ); } if( null == m_assembly ) { - throw new BuildException( "assembly attribute is required", location ); + final String message = "assembly attribute is required"; + throw new BuildException( message, getLocation() ); } if( null == m_environment ) { - throw new BuildException( "environment attribute is required", location ); + final String message = "environment attribute is required"; + throw new BuildException( message, getLocation() ); } pushFile( "SAR-INF/config.xml", m_config ); Index: src/java/org/apache/avalon/phoenix/tools/verifier/SarVerifier.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/verifier/SarVerifier.java,v retrieving revision 1.29 diff -u -r1.29 SarVerifier.java --- src/java/org/apache/avalon/phoenix/tools/verifier/SarVerifier.java 15 Sep 2002 02:07:31 -0000 1.29 +++ src/java/org/apache/avalon/phoenix/tools/verifier/SarVerifier.java 2 Dec 2002 11:23:04 -0000 @@ -7,29 +7,18 @@ */ package org.apache.avalon.phoenix.tools.verifier; -import java.util.ArrayList; -import java.util.Stack; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; -import org.apache.avalon.framework.activity.Disposable; -import org.apache.avalon.framework.activity.Initializable; -import org.apache.avalon.framework.activity.Startable; -import org.apache.avalon.framework.component.Composable; -import org.apache.avalon.framework.configuration.Configurable; -import org.apache.avalon.framework.context.Contextualizable; -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.logger.LogEnabled; -import org.apache.avalon.framework.parameters.Parameterizable; -import org.apache.avalon.framework.service.Serviceable; +import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.tools.verifier.InfoVerifier; +import org.apache.avalon.framework.tools.verifier.VerifyException; import org.apache.avalon.phoenix.Block; import org.apache.avalon.phoenix.BlockListener; -import org.apache.avalon.phoenix.metadata.BlockListenerMetaData; -import org.apache.avalon.phoenix.metadata.BlockMetaData; -import org.apache.avalon.phoenix.metadata.DependencyMetaData; -import org.apache.avalon.phoenix.metadata.SarMetaData; -import org.apache.avalon.phoenix.metainfo.BlockInfo; -import org.apache.avalon.phoenix.metainfo.DependencyDescriptor; -import org.apache.avalon.phoenix.metainfo.ServiceDescriptor; +import org.apache.avalon.phoenix.components.ContainerConstants; +import org.apache.excalibur.containerkit.metadata.ComponentMetaData; +import org.apache.excalibur.containerkit.registry.ComponentProfile; +import org.apache.excalibur.containerkit.registry.PartitionProfile; +import org.apache.excalibur.containerkit.verifier.AssemblyVerifier; /** * This Class verifies that Sars are valid. It performs a number @@ -60,65 +49,49 @@ * @version $Revision: 1.29 $ $Date: 2002/09/15 02:07:31 $ */ public class SarVerifier - extends AbstractLogEnabled + extends AssemblyVerifier { private static final Resources REZ = ResourceManager.getPackageResources( SarVerifier.class ); - private static final Class[] FRAMEWORK_CLASSES = new Class[] + private final InfoVerifier m_infoVerifier = new InfoVerifier(); + + public void enableLogging( final Logger logger ) { - LogEnabled.class, - Contextualizable.class, - Composable.class, - Serviceable.class, - Configurable.class, - Parameterizable.class, - Initializable.class, - Startable.class, - Disposable.class - }; + super.enableLogging( logger ); + m_infoVerifier.enableLogging( logger ); + } /** - * Verify the specified [EMAIL PROTECTED] SarMetaData} object. - * The rules used to verify [EMAIL PROTECTED] SarMetaData} are specified + * Verify the specified [EMAIL PROTECTED] PartitionProfile} object. + * The rules used to verify [EMAIL PROTECTED] PartitionProfile} are specified * in the Class javadocs. * - * @param sar the SarMetaDat object - * @param classLoader the ClassLoader used to load types. This is used - * to verify that specified Class objects exist and - * implement the correct interfaces. + * @param profile the Sar profile * @throws VerifyException if an error occurs */ - public void verifySar( final SarMetaData sar, final ClassLoader classLoader ) + public void verifySar( final PartitionProfile profile, + final ClassLoader classLoader ) throws VerifyException { - final BlockMetaData[] blocks = sar.getBlocks(); - final BlockListenerMetaData[] listeners = sar.getListeners(); + final ComponentProfile[] blocks = + profile.getPartition( ContainerConstants.BLOCK_PARTITION ).getComponents(); + final ComponentProfile[] listeners = + profile.getPartition( ContainerConstants.LISTENER_PARTITION ).getComponents(); String message = null; message = REZ.getString( "verify-valid-names" ); getLogger().info( message ); - verifySarName( sar.getName() ); - verifyValidNames( blocks ); + verifySarName( profile.getMetaData().getName() ); verifyValidNames( listeners ); + super.verifyAssembly( blocks ); + message = REZ.getString( "verify-unique-names" ); getLogger().info( message ); checkNamesUnique( blocks, listeners ); - message = REZ.getString( "verify-dependencies-mapping" ); - getLogger().info( message ); - verifyValidDependencies( blocks ); - - message = REZ.getString( "verify-dependency-references" ); - getLogger().info( message ); - verifyDependencyReferences( blocks ); - - message = REZ.getString( "verify-nocircular-dependencies" ); - getLogger().info( message ); - verifyNoCircularDependencies( blocks ); - message = REZ.getString( "verify-block-type" ); getLogger().info( message ); verifyBlocksType( blocks, classLoader ); @@ -129,276 +102,69 @@ } /** - * Verfiy that all Blocks have the needed dependencies specified correctly. - * - * @param blocks the BlockMetaData objects for the blocks - * @throws VerifyException if an error occurs - */ - private void verifyValidDependencies( final BlockMetaData[] blocks ) - throws VerifyException - { - for( int i = 0; i < blocks.length; i++ ) - { - verifyDependenciesMap( blocks[ i ] ); - } - } - - /** - * Verfiy that there are no circular references between Blocks. - * - * @param blocks the BlockMetaData objects for the blocks - * @throws VerifyException if an error occurs - */ - private void verifyNoCircularDependencies( final BlockMetaData[] blocks ) - throws VerifyException - { - for( int i = 0; i < blocks.length; i++ ) - { - final BlockMetaData block = blocks[ i ]; - - final Stack stack = new Stack(); - stack.push( block ); - verifyNoCircularDependencies( block, blocks, stack ); - stack.pop(); - } - } - - /** - * Verfiy that there are no circular references between Blocks. - * - * @param blocks the BlockMetaData objects for the blocks - * @throws VerifyException if an error occurs - */ - private void verifyNoCircularDependencies( final BlockMetaData block, - final BlockMetaData[] blocks, - final Stack stack ) - throws VerifyException - { - final BlockMetaData[] dependencies = getDependencies( block, blocks ); - - for( int i = 0; i < dependencies.length; i++ ) - { - final BlockMetaData dependency = dependencies[ i ]; - if( stack.contains( dependency ) ) - { - final String trace = getDependencyTrace( dependency, stack ); - final String message = - REZ.getString( "dependency-circular", block.getName(), trace ); - throw new VerifyException( message ); - } - - stack.push( dependency ); - verifyNoCircularDependencies( dependency, blocks, stack ); - stack.pop(); - } - } - - /** - * Get a string defining path from top of stack till it reaches specified block. - * - * @param block the block - * @param stack the Stack - * @return the path of dependency - */ - private String getDependencyTrace( final BlockMetaData block, - final Stack stack ) - { - final StringBuffer sb = new StringBuffer(); - sb.append( "[ " ); - - final String name = block.getName(); - final int size = stack.size(); - final int top = size - 1; - for( int i = top; i >= 0; i-- ) - { - final BlockMetaData other = (BlockMetaData)stack.get( i ); - if( top != i ) - { - sb.append( ", " ); - } - sb.append( other.getName() ); - - if( other.getName().equals( name ) ) - { - break; - } - } - - sb.append( ", " ); - sb.append( name ); - - sb.append( " ]" ); - return sb.toString(); - } - - /** - * Get array of dependencies for specified Block from specified Block array. - * - * @param block the block to get dependencies of - * @param blocks the total set of blocks in application - * @return the dependencies of block - */ - private BlockMetaData[] getDependencies( final BlockMetaData block, - final BlockMetaData[] blocks ) - { - final ArrayList dependencies = new ArrayList(); - final DependencyMetaData[] deps = block.getDependencies(); - - for( int i = 0; i < deps.length; i++ ) - { - final String name = deps[ i ].getName(); - final BlockMetaData other = getBlock( name, blocks ); - dependencies.add( other ); - } - - return (BlockMetaData[])dependencies.toArray( new BlockMetaData[ 0 ] ); - } - - /** - * Verfiy that the inter-Block dependencies are valid. + * Verfiy that all Blocks specify classes that implement the + * advertised interfaces. * - * @param blocks the BlockMetaData objects for the blocks + * @param blocks the ComponentProfile objects for the blocks * @throws VerifyException if an error occurs */ - private void verifyDependencyReferences( final BlockMetaData[] blocks ) + private void verifyBlocksType( final ComponentProfile[] blocks, + final ClassLoader classLoader ) throws VerifyException { for( int i = 0; i < blocks.length; i++ ) { - verifyDependencyReferences( blocks[ i ], blocks ); + verifyBlockType( blocks[ i ], classLoader ); } } /** - * Verfiy that the inter-Block dependencies are valid for specified Block. + * Verfiy that specified Block designate classes that implement the + * advertised interfaces. * - * @param block the BlockMetaData object for the block - * @param others the BlockMetaData objects for the other blocks + * @param block the BlockMetaData object for the blocks * @throws VerifyException if an error occurs */ - private void verifyDependencyReferences( final BlockMetaData block, - final BlockMetaData[] others ) + private void verifyBlockType( final ComponentProfile block, + final ClassLoader classLoader ) throws VerifyException { - final BlockInfo info = block.getBlockInfo(); - final DependencyMetaData[] roles = block.getDependencies(); + final ComponentMetaData metaData = block.getMetaData(); + final Class clazz = loadClass( "block", metaData, classLoader ); - for( int i = 0; i < roles.length; i++ ) - { - final String blockName = roles[ i ].getName(); - final String roleName = roles[ i ].getRole(); - final ServiceDescriptor service = - info.getDependency( roleName ).getService(); - - //Get the other block that is providing service - final BlockMetaData other = getBlock( blockName, others ); - if( null == other ) - { - final String message = - REZ.getString( "dependency-noblock", blockName, block.getName() ); - throw new VerifyException( message ); - } - - //make sure that the block offers service - //that user expects it to be providing - final ServiceDescriptor[] services = other.getBlockInfo().getServices(); - if( !hasMatchingService( service, services ) ) - { - final String message = - REZ.getString( "dependency-noservice", blockName, service, block.getName() ); - throw new VerifyException( message ); - } - } - } + m_infoVerifier.verifyType( metaData.getName(), + metaData.getImplementationKey(), + block.getInfo(), + classLoader ); - /** - * Get Block with specified name from specified Block array. - * - * @param name the name of block to get - * @param blocks the array of Blocks to search - * @return the Block if found, else null - */ - private BlockMetaData getBlock( final String name, final BlockMetaData[] blocks ) - { - for( int i = 0; i < blocks.length; i++ ) - { - if( blocks[ i ].getName().equals( name ) ) - { - return blocks[ i ]; - } - } - - return null; - } - - /** - * Verfiy that all Blocks specify classes that implement the - * advertised interfaces. - * - * @param blocks the BlockMetaData objects for the blocks - * @throws VerifyException if an error occurs - */ - private void verifyBlocksType( final BlockMetaData[] blocks, final ClassLoader classLoader ) - throws VerifyException - { - for( int i = 0; i < blocks.length; i++ ) + if( Block.class.isAssignableFrom( clazz ) ) { - verifyBlockType( blocks[ i ], classLoader ); + final String message = + REZ.getString( "verifier.implements-block.error", + metaData.getName(), + metaData.getImplementationKey() ); + getLogger().error( message ); + System.err.println( message ); } } - /** - * Verfiy that specified Block designate classes that implement the - * advertised interfaces. - * - * @param block the BlockMetaData object for the blocks - * @throws VerifyException if an error occurs - */ - private void verifyBlockType( final BlockMetaData block, final ClassLoader classLoader ) + private Class loadClass( final String type, + final ComponentMetaData metaData, + final ClassLoader classLoader ) throws VerifyException { - final String name = block.getName(); - final String classname = block.getImplementationKey(); - Class clazz = null; try { - clazz = classLoader.loadClass( classname ); + return classLoader.loadClass( metaData.getImplementationKey() ); } catch( final Exception e ) { - final String message = REZ.getString( "bad-block-class", - name, - classname, + final String message = REZ.getString( "bad-" + type + "-class", + metaData.getName(), + metaData.getImplementationKey(), e.getMessage() ); throw new VerifyException( message ); } - - final Class[] interfaces = - getServiceClasses( name, - block.getBlockInfo().getServices(), - classLoader ); - - for( int i = 0; i < interfaces.length; i++ ) - { - if( !interfaces[ i ].isAssignableFrom( clazz ) ) - { - final String message = REZ.getString( "block-noimpl-service", - name, - classname, - interfaces[ i ].getName() ); - throw new VerifyException( message ); - } - } - - if( Block.class.isAssignableFrom( clazz ) ) - { - final String message = - REZ.getString( "verifier.implements-block.error", - name, - classname ); - getLogger().error( message ); - System.err.println( message ); - } } /** @@ -407,7 +173,7 @@ * @param listeners the BlockListenerMetaData objects for the listeners * @throws VerifyException if an error occurs */ - private void verifyListenersType( final BlockListenerMetaData[] listeners, + private void verifyListenersType( final ComponentProfile[] listeners, final ClassLoader classLoader ) throws VerifyException { @@ -423,30 +189,18 @@ * @param listener the BlockListenerMetaData object for the listener * @throws VerifyException if an error occurs */ - private void verifyListenerType( final BlockListenerMetaData listener, + private void verifyListenerType( final ComponentProfile listener, final ClassLoader classLoader ) throws VerifyException { - Class clazz = null; - try - { - clazz = classLoader.loadClass( listener.getClassname() ); - } - catch( final Exception e ) - { - final String message = - REZ.getString( "bad-listener-class", - listener.getName(), - listener.getClassname(), - e.getMessage() ); - throw new VerifyException( message, e ); - } - + final ComponentMetaData metaData = listener.getMetaData(); + final Class clazz = loadClass( "listener", metaData, classLoader ); if( !BlockListener.class.isAssignableFrom( clazz ) ) { - final String message = REZ.getString( "listener-noimpl-listener", - listener.getName(), - listener.getClassname() ); + final String message = + REZ.getString( "listener-noimpl-listener", + metaData, + metaData ); throw new VerifyException( message ); } } @@ -468,53 +222,13 @@ } /** - * Verify that the names of the specified blocks are valid. - * - * @param blocks the Blocks - * @throws VerifyException if an error occurs - */ - private void verifyValidNames( final BlockMetaData[] blocks ) - throws VerifyException - { - for( int i = 0; i < blocks.length; i++ ) - { - final String name = blocks[ i ].getName(); - if( !isValidName( name ) ) - { - final String message = REZ.getString( "invalid-block-name", name ); - throw new VerifyException( message ); - } - } - } - - /** - * Verify that the names of the specified listeners are valid. - * - * @param listeners the listeners - * @throws VerifyException if an error occurs - */ - private void verifyValidNames( final BlockListenerMetaData[] listeners ) - throws VerifyException - { - for( int i = 0; i < listeners.length; i++ ) - { - final String name = listeners[ i ].getName(); - if( !isValidName( name ) ) - { - final String message = REZ.getString( "invalid-listener-name", name ); - throw new VerifyException( message ); - } - } - } - - /** * Return true if specified name is valid. * Valid names consist of letters, digits or the '-' & '.' characters. * * @param name the name to check * @return true if valid, false otherwise */ - private boolean isValidName( final String name ) + public boolean isValidName( final String name ) { final int size = name.length(); for( int i = 0; i < size; i++ ) @@ -539,19 +253,19 @@ * @param listeners the listeners * @throws VerifyException if an error occurs */ - private void checkNamesUnique( final BlockMetaData[] blocks, - final BlockListenerMetaData[] listeners ) + private void checkNamesUnique( final ComponentProfile[] blocks, + final ComponentProfile[] listeners ) throws VerifyException { for( int i = 0; i < blocks.length; i++ ) { - final String name = blocks[ i ].getName(); + final String name = blocks[ i ].getMetaData().getName(); checkNameUnique( name, blocks, listeners, i, -1 ); } for( int i = 0; i < listeners.length; i++ ) { - final String name = listeners[ i ].getName(); + final String name = listeners[ i ].getMetaData().getName(); checkNameUnique( name, blocks, listeners, -1, i ); } } @@ -570,8 +284,8 @@ * @throws VerifyException if an error occurs */ private void checkNameUnique( final String name, - final BlockMetaData[] blocks, - final BlockListenerMetaData[] listeners, + final ComponentProfile[] blocks, + final ComponentProfile[] listeners, final int blockIndex, final int listenerIndex ) throws VerifyException @@ -579,7 +293,7 @@ //Verify no blocks have the same name for( int i = 0; i < blocks.length; i++ ) { - final String other = blocks[ i ].getName(); + final String other = blocks[ i ].getMetaData().getName(); if( blockIndex != i && name.equals( other ) ) { final String message = REZ.getString( "duplicate-name", name ); @@ -590,157 +304,12 @@ //Verify no listeners have the same name for( int i = 0; i < listeners.length; i++ ) { - final String other = listeners[ i ].getName(); + final String other = listeners[ i ].getMetaData().getName(); if( listenerIndex != i && name.equals( other ) ) { final String message = REZ.getString( "duplicate-name", name ); throw new VerifyException( message ); } } - } - - /** - * Retrieve a list of DependencyMetaData objects for BlockMetaData - * and verify that there is a 1 to 1 map with dependencies specified - * in BlockInfo. - * - * @param block the BlockMetaData describing the block - * @throws VerifyException if an error occurs - */ - private void verifyDependenciesMap( final BlockMetaData block ) - throws VerifyException - { - //Make sure all role entries specified in config file are valid - final DependencyMetaData[] roles = block.getDependencies(); - for( int i = 0; i < roles.length; i++ ) - { - final String roleName = roles[ i ].getRole(); - final DependencyDescriptor descriptor = block.getBlockInfo().getDependency( roleName ); - - //If there is no dependency descriptor in BlockInfo then - //user has specified an uneeded dependency. - if( null == descriptor ) - { - final String message = REZ.getString( "unknown-dependency", - roles[ i ].getName(), - roleName, - block.getName() ); - throw new VerifyException( message ); - } - } - - //Make sure all dependencies in BlockInfo file are satisfied - final DependencyDescriptor[] dependencies = block.getBlockInfo().getDependencies(); - for( int i = 0; i < dependencies.length; i++ ) - { - final DependencyMetaData role = block.getDependency( dependencies[ i ].getRole() ); - - //If there is no Role then the user has failed - //to specify a needed dependency. - if( null == role ) - { - final String message = REZ.getString( "unspecified-dependency", - dependencies[ i ].getRole(), - block.getName() ); - throw new VerifyException( message ); - } - } - } - - /** - * Retrieve an array of Classes for all the services (+ the Block interface) - * that a Block offers. This method also makes sure all services offered are - * interfaces. - * - * @param name the name of block - * @param services the services the Block offers - * @param classLoader the classLoader - * @return an array of Classes for all the services - * @throws VerifyException if an error occurs - */ - private 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 ].getName(); - try - { - classes[ i ] = classLoader.loadClass( classname ); - } - catch( final Throwable t ) - { - final String message = - REZ.getString( "bad-service-class", name, classname, t.getMessage() ); - throw new VerifyException( message, t ); - } - - if( !classes[ i ].isInterface() ) - { - final String message = - REZ.getString( "service-not-interface", name, classname ); - throw new VerifyException( message ); - } - - checkNotFrameworkInterface( name, classname, classes[ i ] ); - } - - return classes; - } - - /** - * Warn the user if any of the service interfaces extend - * a Lifecycle interface (a generally unrecomended approach). - * - * @param name the name of block - * @param classname the classname of block - * @param clazz the service implemented by block - */ - private void checkNotFrameworkInterface( final String name, - final String classname, - final Class clazz ) - { - for( int i = 0; i < FRAMEWORK_CLASSES.length; i++ ) - { - final Class lifecycle = FRAMEWORK_CLASSES[ i ]; - if( lifecycle.isAssignableFrom( clazz ) ) - { - final String message = - REZ.getString( "verifier.service-isa-lifecycle.error", - name, - classname, - clazz.getName(), - lifecycle.getName() ); - getLogger().warn( message ); - System.err.println( message ); - } - } - } - - /** - * Return true if specified service matches any of the - * candidate services. - * - * @param candidates an array of candidate services - * @param service the service - * @return true if candidate services contains a service that matches - * specified service, false otherwise - */ - private boolean hasMatchingService( final ServiceDescriptor service, - final ServiceDescriptor[] candidates ) - { - for( int i = 0; i < candidates.length; i++ ) - { - if( service.matches( candidates[ i ] ) ) - { - return true; - } - } - - return false; } } Index: src/test/org/apache/avalon/phoenix/components/application/test/MockApplicationContext.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/components/application/test/MockApplicationContext.java,v retrieving revision 1.3 diff -u -r1.3 MockApplicationContext.java --- src/test/org/apache/avalon/phoenix/components/application/test/MockApplicationContext.java 1 Nov 2002 08:23:31 -0000 1.3 +++ src/test/org/apache/avalon/phoenix/components/application/test/MockApplicationContext.java 2 Dec 2002 11:23:04 -0000 @@ -36,7 +36,7 @@ m_logger = logger; } - public SarMetaData getMetaData() + public SarMetaData getPartitionProfile() { return m_sarMetaData; } Index: src/test/org/apache/avalon/phoenix/test/AbstractContainerTestCase.java =================================================================== RCS file: /home/cvspublic/jakarta-avalon-phoenix/src/test/org/apache/avalon/phoenix/test/AbstractContainerTestCase.java,v retrieving revision 1.2 diff -u -r1.2 AbstractContainerTestCase.java --- src/test/org/apache/avalon/phoenix/test/AbstractContainerTestCase.java 2 Oct 2002 11:25:56 -0000 1.2 +++ src/test/org/apache/avalon/phoenix/test/AbstractContainerTestCase.java 2 Dec 2002 11:23:05 -0000 @@ -7,13 +7,15 @@ */ package org.apache.avalon.phoenix.test; -import java.io.File; import java.net.URL; +import java.util.HashMap; +import java.util.Map; import junit.framework.TestCase; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.logger.ConsoleLogger; +import org.apache.avalon.phoenix.components.ContainerConstants; import org.apache.avalon.phoenix.metadata.SarMetaData; -import org.apache.avalon.phoenix.tools.assembler.Assembler; +import org.apache.avalon.phoenix.components.assembler.Assembler; import org.apache.avalon.phoenix.tools.configuration.ConfigurationBuilder; /** @@ -35,10 +37,11 @@ { final Assembler assembler = new Assembler(); assembler.enableLogging( new ConsoleLogger() ); - final ClassLoader classLoader = getClass().getClassLoader(); final Configuration assembly = loadConfig( config ); - return assembler.assembleSar( "test", assembly, - new File( "." ), classLoader ); + final Map parameters = new HashMap(); + parameters.put( ContainerConstants.ASSEMBLY_NAME, "test" ); + parameters.put( ContainerConstants.ASSEMBLY_CONFIG, assembly ); + return assembler.buildAssembly( parameters ); } protected Configuration loadConfig( final String config )
block-entry-malformed=Malformed block entry in assembly.xml at "{0}". (Reason: {1}). listener-entry-malformed=Malformed listener entry in assembly.xml at "{0}". (Reason: {1}). blockinfo-nocreate=Failed to create BlockInfo for Block named "{0}" from resource "{1}" (Reason: {2}). loading-blockinfo=Creating BlockInfo from {0}. blockinfo-missing=Unable to create BlockInfo as are unable to locate resource "{1}".
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>