donaldp 2003/04/06 04:23:22
Modified: src/conf kernel.xml
src/java/org/apache/avalon/phoenix/components/application
BlockResourceProvider.java
ListenerResourceProvider.java
src/java/org/apache/avalon/phoenix/components/assembler
Assembler.java
src/java/org/apache/avalon/phoenix/components/configuration
DefaultConfigurationRepository.java
FileSystemPersistentConfigurationRepository.java
src/java/org/apache/avalon/phoenix/components/configuration/validator
NoopConfigurationValidator.java
src/java/org/apache/avalon/phoenix/components/deployer
DefaultDeployer.java
src/java/org/apache/avalon/phoenix/components/embeddor
ManagementRegistration.java
src/java/org/apache/avalon/phoenix/components/kernel
DefaultApplicationContext.java
src/java/org/apache/avalon/phoenix/interfaces
ApplicationContext.java
ConfigurationRepository.java
ConfigurationValidator.java ContainerConstants.java
src/java/org/apache/avalon/phoenix/tools/configuration
ConfigurationBuilder.java
src/test/org/apache/avalon/phoenix/components/application/test
MockApplicationContext.java
src/test/org/apache/avalon/phoenix/test
AbstractContainerTestCase.java
Added: src/java/org/apache/avalon/phoenix/components/configuration/validator
DefaultConfigurationValidator.java
Removed: src/java/org/apache/avalon/phoenix/components/configuration
ConfigurationKey.java
src/java/org/apache/avalon/phoenix/components/configuration/validator
DelegateEntry.java
DelegatingConfigurationValidator.java
JarvConfigurationValidator.java
src/java/org/apache/avalon/phoenix/interfaces
ConfigurationRepositoryMBean.java
ConfigurationValidatorMBean.java
src/java/org/apache/avalon/phoenix/tools/verifier
VerifyException.java
Log:
Rework the way that configuration and configuration validation is
handled internally to Phoenix.
Now configuration is all associated with the ComponentProfile. So no
longer does any of the code rely on the ConfigurationRepository managing
configuration. The ConfigurationRepository now acts more like a config
interceptor that gets a chance to manipulate or rewrite configuration
(thus supporting the existing use cases and also opening up future use
cases such as jelly-ification of applications config files).
ConfigurationValidator no longer stores or manages schemas it simply
loads the schemas just prior to validation. The validator also does not
try to do delegation but assumes that the jarv interface along with
msv and jing is sufficient for all validation purposes.
DefaultConfigurationValidator is now enabled by default so all components
that declare schema type are now passed through validator. This means that
malformed configurations that were previous accepted may no longer be
accepted.
PR: PNIX-21
Revision Changes Path
1.33 +4 -13 avalon-phoenix/src/conf/kernel.xml
Index: kernel.xml
===================================================================
RCS file: /home/cvs/avalon-phoenix/src/conf/kernel.xml,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- kernel.xml 5 Apr 2003 04:41:03 -0000 1.32
+++ kernel.xml 6 Apr 2003 11:23:21 -0000 1.33
@@ -118,19 +118,10 @@
-->
<component
role="org.apache.avalon.phoenix.interfaces.ConfigurationValidator"
-
class="org.apache.avalon.phoenix.components.configuration.validator.NoopConfigurationValidator"
- logger="validator"/>
-
- <!--
- <component
role="org.apache.avalon.phoenix.interfaces.ConfigurationValidator"
-
class="org.apache.avalon.phoenix.components.configuration.validator.DelegatingConfigurationValidator"
- logger="validator">
- <delegate schema-type="relax-ng"
-
class="org.apache.avalon.phoenix.components.configuration.validator.JarvConfigurationValidator">
-
<schema-language>http://relaxng.org/ns/structure/1.0</schema-language>
- </delegate>
- </component>
- -->
+
class="org.apache.avalon.phoenix.components.configuration.validator.DefaultConfigurationValidator"
+ logger="validator">
+ <schema-type name="relax-ng" uri="http://relaxng.org/ns/structure/1.0"/>
+ </component>
<component role="org.apache.avalon.phoenix.interfaces.ClassLoaderManager"
class="org.apache.avalon.phoenix.components.classloader.DefaultClassLoaderManager"
1.22 +2 -21
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockResourceProvider.java
Index: BlockResourceProvider.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/BlockResourceProvider.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- BlockResourceProvider.java 5 Apr 2003 04:25:41 -0000 1.21
+++ BlockResourceProvider.java 6 Apr 2003 11:23:21 -0000 1.22
@@ -57,12 +57,9 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.apache.avalon.excalibur.i18n.ResourceManager;
-import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.component.ComponentManager;
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.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
@@ -88,9 +85,6 @@
extends AbstractLogEnabled
implements ResourceProvider
{
- private static final Resources REZ =
- ResourceManager.getPackageResources( BlockResourceProvider.class );
-
/**
* Context in which Blocks/Listeners operate.
*/
@@ -340,20 +334,7 @@
throws Exception
{
final ComponentProfile metaData = getProfileFor( entry );
- final String name = metaData.getMetaData().getName();
- try
- {
- return m_context.getConfiguration( name );
- }
- catch( final ConfigurationException ce )
- {
- //Note that this shouldn't ever happen once we
- //create a Config validator
- final String message =
- REZ.getString( "missing-block-configuration",
- name );
- throw new ConfigurationException( message, ce );
- }
+ return metaData.getMetaData().getConfiguration();
}
public Parameters createParameters( final Object entry )
1.12 +2 -20
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ListenerResourceProvider.java
Index: ListenerResourceProvider.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ListenerResourceProvider.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ListenerResourceProvider.java 22 Mar 2003 12:07:08 -0000 1.11
+++ ListenerResourceProvider.java 6 Apr 2003 11:23:21 -0000 1.12
@@ -50,8 +50,6 @@
package org.apache.avalon.phoenix.components.application;
-import org.apache.avalon.excalibur.i18n.ResourceManager;
-import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -77,9 +75,6 @@
extends AbstractLogEnabled
implements ResourceProvider
{
- private static final Resources REZ =
- ResourceManager.getPackageResources( ListenerResourceProvider.class );
-
/**
* Context in which Blocks/Listeners operate.
*/
@@ -185,20 +180,7 @@
throws Exception
{
final ComponentMetaData metaData = getMetaData( entry );
- final String name = metaData.getName();
- try
- {
- return m_context.getConfiguration( name );
- }
- catch( final ConfigurationException ce )
- {
- //Note that this shouldn't ever happen once we
- //create a Config validator
- final String message =
- REZ.getString( "missing-listener-configuration",
- name );
- throw new ConfigurationException( message, ce );
- }
+ return metaData.getConfiguration();
}
public Parameters createParameters( final Object entry )
1.10 +28 -19
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/assembler/Assembler.java
Index: Assembler.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/assembler/Assembler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Assembler.java 5 Apr 2003 04:25:42 -0000 1.9
+++ Assembler.java 6 Apr 2003 11:23:21 -0000 1.10
@@ -85,7 +85,7 @@
* name and assembly configuration. This implementation takes two
* parameters. [EMAIL PROTECTED]
org.apache.avalon.phoenix.interfaces.ContainerConstants#ASSEMBLY_NAME} specifies
* the name of the assembly and
- * [EMAIL PROTECTED]
org.apache.avalon.phoenix.interfaces.ContainerConstants#ASSEMBLY_CONFIG} specifies the
configuration
+ * [EMAIL PROTECTED]
org.apache.avalon.phoenix.interfaces.ContainerConstants#ASSEMBLY_DESCRIPTOR} specifies
the configuration
* tree to use when assembling Partition.
*
* @param parameters the parameters for constructing assembly
@@ -97,9 +97,11 @@
{
final String name =
(String)parameters.get( ContainerConstants.ASSEMBLY_NAME );
- final Configuration configuration =
- (Configuration)parameters.get( ContainerConstants.ASSEMBLY_CONFIG );
- return assembleSar( name, configuration );
+ final Configuration assembly =
+ (Configuration)parameters.get( ContainerConstants.ASSEMBLY_DESCRIPTOR );
+ final Configuration config =
+ (Configuration)parameters.get( ContainerConstants.CONFIG_DESCRIPTOR );
+ return assembleSar( name, config, assembly );
}
/**
@@ -112,11 +114,12 @@
* @throws AssemblyException if an error occurs
*/
private PartitionMetaData assembleSar( final String name,
+ final Configuration config,
final Configuration assembly )
throws AssemblyException
{
final Configuration[] blockConfig = assembly.getChildren( "block" );
- final ComponentMetaData[] blocks = buildBlocks( blockConfig );
+ final ComponentMetaData[] blocks = buildBlocks( blockConfig, config );
final PartitionMetaData blockPartition =
new PartitionMetaData( ContainerConstants.BLOCK_PARTITION,
new
String[]{ContainerConstants.LISTENER_PARTITION},
@@ -124,7 +127,7 @@
blocks, Attribute.EMPTY_SET );
final Configuration[] listenerConfig = assembly.getChildren( "listener" );
- final ComponentMetaData[] listeners = buildBlockListeners( listenerConfig );
+ final ComponentMetaData[] listeners = buildBlockListeners( listenerConfig,
config );
final PartitionMetaData listenerPartition =
new PartitionMetaData( ContainerConstants.LISTENER_PARTITION,
new String[ 0 ],
@@ -146,13 +149,14 @@
* @return the BlockMetaData array
* @throws AssemblyException if an error occurs
*/
- private ComponentMetaData[] buildBlocks( final Configuration[] blocks )
+ private ComponentMetaData[] buildBlocks( final Configuration[] blocks,
+ final Configuration config )
throws AssemblyException
{
final ArrayList blockSet = new ArrayList();
for( int i = 0; i < blocks.length; i++ )
{
- blockSet.add( buildBlock( blocks[ i ] ) );
+ blockSet.add( buildBlock( blocks[ i ], config ) );
}
return (ComponentMetaData[])blockSet.toArray( new ComponentMetaData[
blockSet.size() ] );
@@ -166,7 +170,8 @@
* @return the BlockMetaData object
* @throws AssemblyException if an error occurs
*/
- private ComponentMetaData buildBlock( final Configuration block )
+ private ComponentMetaData buildBlock( final Configuration block,
+ final Configuration config )
throws AssemblyException
{
try
@@ -190,9 +195,11 @@
final Attribute[] attributes =
(Attribute[])attributeSet.toArray( new Attribute[
attributeSet.size() ] );
+ final Configuration configuration = config.getChild( name );
+
return new ComponentMetaData( name, classname,
- dependencys,
- null, null, attributes );
+ dependencys, null,
+ configuration, attributes );
}
catch( final ConfigurationException ce )
{
@@ -206,17 +213,18 @@
* 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
+ * @param listenerConfigs the list of Configuration objects for listenerConfigs
* @return the array of listeners
* @throws AssemblyException if an error occurs
*/
- private ComponentMetaData[] buildBlockListeners( final Configuration[] config )
+ private ComponentMetaData[] buildBlockListeners( final Configuration[]
listenerConfigs,
+ final Configuration config )
throws AssemblyException
{
final List listeners = new ArrayList();
- for( int i = 0; i < config.length; i++ )
+ for( int i = 0; i < listenerConfigs.length; i++ )
{
- final ComponentMetaData listener = buildBlockListener( config[ i ] );
+ final ComponentMetaData listener = buildBlockListener( listenerConfigs[
i ], config );
listeners.add( listener );
}
return (ComponentMetaData[])listeners.
@@ -231,17 +239,18 @@
* @return the BlockListenerMetaData object
* @throws AssemblyException if an error occurs
*/
- private ComponentMetaData buildBlockListener( final Configuration listener )
+ private ComponentMetaData buildBlockListener( final Configuration listener,
+ final Configuration config )
throws AssemblyException
{
try
{
final String name = listener.getAttribute( "name" );
final String classname = listener.getAttribute( "class" );
-
+ final Configuration configuration = config.getChild( name );
return new ComponentMetaData( name, classname,
new DependencyMetaData[ 0 ],
- null, null, Attribute.EMPTY_SET );
+ null, configuration, Attribute.EMPTY_SET
);
}
catch( final ConfigurationException ce )
{
1.14 +7 -49
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/DefaultConfigurationRepository.java
Index: DefaultConfigurationRepository.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/DefaultConfigurationRepository.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DefaultConfigurationRepository.java 22 Mar 2003 12:07:08 -0000 1.13
+++ DefaultConfigurationRepository.java 6 Apr 2003 11:23:21 -0000 1.14
@@ -47,16 +47,11 @@
Apache Software Foundation, please see <http://www.apache.org/>.
*/
-
package org.apache.avalon.phoenix.components.configuration;
-import java.util.HashMap;
-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.phoenix.interfaces.ConfigurationRepository;
-import org.apache.avalon.phoenix.interfaces.ConfigurationRepositoryMBean;
/**
* Repository from which all configuration data is retrieved.
@@ -64,56 +59,19 @@
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
*/
public class DefaultConfigurationRepository
- implements ConfigurationRepository, ConfigurationRepositoryMBean
+ implements ConfigurationRepository
{
- private static final Resources REZ =
- ResourceManager.getPackageResources( DefaultConfigurationRepository.class );
-
- private final HashMap m_configurations = new HashMap();
-
- public synchronized void storeConfiguration( final String application,
- final String block,
- final Configuration configuration )
- throws ConfigurationException
- {
- final String name = application + "." + block;
- if( null == configuration )
- {
- m_configurations.remove( name );
- }
- else
- {
- m_configurations.put( name, configuration );
- }
- }
-
- public synchronized void removeConfiguration( final String application,
- final String block )
+ public Configuration processConfiguration( final String application,
+ final String block,
+ final Configuration configuration )
throws ConfigurationException
{
- m_configurations.remove( application + "." + block );
- }
-
- public synchronized Configuration getConfiguration( final String application,
- final String block )
- throws ConfigurationException
- {
- final String name = application + "." + block;
- final Configuration configuration = (Configuration)m_configurations.get(
name );
-
- if( null == configuration )
- {
- final String message = REZ.getString( "config.error.noconfig", block,
application );
- throw new ConfigurationException( message );
- }
-
return configuration;
}
- public boolean hasConfiguration( final String application, final String block )
+ public void removeConfiguration( final String application,
+ final String block )
+ throws ConfigurationException
{
- final String name = application + "." + block;
-
- return m_configurations.containsKey( name );
}
}
1.19 +38 -43
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/FileSystemPersistentConfigurationRepository.java
Index: FileSystemPersistentConfigurationRepository.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/FileSystemPersistentConfigurationRepository.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- FileSystemPersistentConfigurationRepository.java 4 Apr 2003 10:59:48 -0000
1.18
+++ FileSystemPersistentConfigurationRepository.java 6 Apr 2003 11:23:21 -0000
1.19
@@ -52,10 +52,11 @@
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.excalibur.io.FileUtil;
-import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -69,7 +70,6 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.phoenix.components.util.PropertyUtil;
import org.apache.avalon.phoenix.interfaces.ConfigurationRepository;
-import org.apache.avalon.phoenix.interfaces.ConfigurationRepositoryMBean;
import org.apache.excalibur.configuration.merged.ConfigurationMerger;
import org.apache.excalibur.configuration.merged.ConfigurationSplitter;
import org.xml.sax.SAXException;
@@ -95,18 +95,14 @@
*/
public class FileSystemPersistentConfigurationRepository
extends AbstractLogEnabled
- implements ConfigurationRepository, Contextualizable, Configurable,
Initializable,
- ConfigurationRepositoryMBean
+ implements ConfigurationRepository, Contextualizable, Configurable,
Initializable
{
private static final Resources REZ =
ResourceManager.getPackageResources(
FileSystemPersistentConfigurationRepository.class );
- private final DefaultConfigurationRepository m_persistedConfigurations =
- new DefaultConfigurationRepository();
- private final DefaultConfigurationRepository
- m_transientConfigurations = new DefaultConfigurationRepository();
- private final DefaultConfigurationRepository
- m_mergedConfigurations = new DefaultConfigurationRepository();
+ private final Map m_persistedConfigurations = new HashMap();
+ private final Map m_transientConfigurations = new HashMap();
+ private final Map m_mergedConfigurations = new HashMap();
private Context m_context;
@@ -136,6 +132,15 @@
}
}
+ public Configuration processConfiguration( String application,
+ String block,
+ Configuration configuration )
+ throws ConfigurationException
+ {
+ storeConfiguration( application, block, configuration );
+ return getConfiguration( application, block );
+ }
+
private String constructStoragePath( final Configuration configuration )
throws ConfigurationException
{
@@ -194,9 +199,8 @@
final String block =
blocks[ i ].getName().substring( 0, blocks[ i ].getName().indexOf(
".xml" ) );
- m_persistedConfigurations.storeConfiguration( app,
- block,
- builder.buildFromFile(
blocks[ i ] ) );
+ m_persistedConfigurations.put( genKey( app, block ),
+ builder.buildFromFile( blocks[ i ] ) );
if( getLogger().isDebugEnabled() )
{
@@ -206,6 +210,11 @@
}
}
+ private String genKey( final String app, final String block )
+ {
+ return app + '-' + block;
+ }
+
private void persistConfiguration( final String application,
final String block,
final Configuration configuration )
@@ -229,8 +238,8 @@
public void removeConfiguration( final String application, final String block )
throws ConfigurationException
{
- m_transientConfigurations.removeConfiguration( application, block );
- m_mergedConfigurations.removeConfiguration( application, block );
+ m_transientConfigurations.remove( genKey( application, block ) );
+ m_mergedConfigurations.remove( genKey( application, block ) );
}
public synchronized void storeConfiguration( final String application,
@@ -239,7 +248,7 @@
throws ConfigurationException
{
- if( m_transientConfigurations.hasConfiguration( application, block ) )
+ if( m_transientConfigurations.containsKey( genKey( application, block ) ) )
{
if( !ConfigurationUtil.equals( configuration, getConfiguration(
application, block ) ) )
{
@@ -249,8 +258,8 @@
block,
m_transientConfigurations ) );
- m_persistedConfigurations.storeConfiguration( application, block,
layer );
- m_mergedConfigurations.removeConfiguration( application, block );
+ m_persistedConfigurations.put( genKey( application, block ), layer
);
+ m_mergedConfigurations.remove( genKey( application, block ) );
try
{
@@ -274,7 +283,7 @@
}
else
{
- m_transientConfigurations.storeConfiguration( application, block,
configuration );
+ m_transientConfigurations.put( genKey( application, block ),
configuration );
}
}
@@ -282,15 +291,16 @@
final String block )
throws ConfigurationException
{
- if( m_mergedConfigurations.hasConfiguration( application, block ) )
+ final String key = genKey( application, block );
+ if( m_mergedConfigurations.containsKey( key ) )
{
- return m_mergedConfigurations.getConfiguration( application, block );
+ return (Configuration)m_mergedConfigurations.get( key );
}
else
{
final Configuration configuration = createMergedConfiguration(
application, block );
- m_mergedConfigurations.storeConfiguration( application, block,
configuration );
+ m_mergedConfigurations.put( key, configuration );
return configuration;
}
@@ -325,31 +335,16 @@
private Configuration getConfiguration( final String application,
final String block,
- final DefaultConfigurationRepository
repository )
+ final Map repository )
{
- if( repository.hasConfiguration( application, block ) )
- {
- try
- {
- return repository.getConfiguration( application, block );
- }
- catch( ConfigurationException e )
- {
- final String message = REZ.getString( "config.error.noconfig",
block, application );
-
- throw new CascadingRuntimeException( message, e );
- }
- }
- else
- {
- return null;
- }
+ return (Configuration)repository.get( genKey( application, block ) );
}
public boolean hasConfiguration( final String application, final String block )
{
- return m_mergedConfigurations.hasConfiguration( application, block ) ||
- m_transientConfigurations.hasConfiguration( application, block ) ||
- m_persistedConfigurations.hasConfiguration( application, block );
+ final String key = genKey( application, block );
+ return m_mergedConfigurations.containsKey( key ) ||
+ m_transientConfigurations.containsKey( key ) ||
+ m_persistedConfigurations.containsKey( key );
}
}
1.8 +3 -35
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/validator/NoopConfigurationValidator.java
Index: NoopConfigurationValidator.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/validator/NoopConfigurationValidator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- NoopConfigurationValidator.java 22 Mar 2003 12:07:09 -0000 1.7
+++ NoopConfigurationValidator.java 6 Apr 2003 11:23:21 -0000 1.8
@@ -50,10 +50,9 @@
package org.apache.avalon.phoenix.components.configuration.validator;
-import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.phoenix.containerkit.profile.ComponentProfile;
import org.apache.avalon.phoenix.interfaces.ConfigurationValidator;
-import org.apache.avalon.phoenix.interfaces.ConfigurationValidatorMBean;
/**
* A ConfigurationValidator that always says everything is okay
@@ -61,41 +60,10 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Royal</a>
*/
public class NoopConfigurationValidator
- implements ConfigurationValidator, ConfigurationValidatorMBean
+ implements ConfigurationValidator
{
- public void addSchema( final String application, final String block, final
String schemaType, final String url )
+ public boolean isValid( ComponentProfile component, ClassLoader classLoader )
throws ConfigurationException
- {
- }
-
- public void removeSchema( final String application, final String block )
- {
- }
-
- public boolean isValid( final String application, final String block, final
Configuration configuration )
- throws ConfigurationException
- {
- return true;
- }
-
- public boolean isFeasiblyValid( final String application, final String block,
final Configuration configuration )
- throws ConfigurationException
- {
- return true;
- }
-
- public String getSchema( final String application, final String block )
- {
- return null;
- }
-
- public String getSchemaType( final String application, final String block )
- {
- return null;
- }
-
- public boolean isValid( final String application, final String block, final
String configurationXml )
-
{
return true;
}
1.1
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/configuration/validator/DefaultConfigurationValidator.java
Index: DefaultConfigurationValidator.java
===================================================================
/*
* Copyright (C) The Spice Group. All rights reserved.
*
* This software is published under the terms of the Spice
* 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.configuration.validator;
import org.apache.avalon.phoenix.interfaces.ConfigurationValidator;
import org.apache.avalon.phoenix.containerkit.profile.ComponentProfile;
import org.apache.avalon.phoenix.framework.info.SchemaDescriptor;
import org.apache.avalon.phoenix.tools.configuration.ConfigurationBuilder;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.ConfigurationUtil;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.xml.sax.InputSource;
import org.realityforge.configkit.ConfigValidator;
import org.realityforge.configkit.ConfigValidatorFactory;
import org.realityforge.configkit.ValidationResult;
import org.w3c.dom.Element;
import java.util.Map;
import java.util.HashMap;
import java.io.InputStream;
/**
* This component validates the components configuration using
* the ConfigKit toolkit. For backwards compatability it also
* allows users to specify a map between short types and formal
* schema uris. The previous implementation of ConfigurationValidator
* allowed arbitary strings designate a uri and by default was configured
* with "relax-ng" mapped to "http://relaxng.org/ns/structure/1.0". However
* this made components that had schemas dependent on kernel configuration.
* To make components configuration independent components should not specify
* the full uri for schema language but backwards compatability can be
* supported via configuration such as;
*
* <pre>
* <schema-type name="relax-ng" uri="http://relaxng.org/ns/structure/1.0"/>
* </pre>
*
* @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
* @author <a href="mailto:proyal at apache.org">Peter Royal</a>
* @version $Revision: 1.1 $ $Date: 2003/04/06 11:23:21 $
* @phoenix.component
*/
public class DefaultConfigurationValidator
extends AbstractLogEnabled
implements ConfigurationValidator, Configurable
{
/**
* A map between short-names and long URIs.
*/
private final Map m_uriMap = new HashMap();
/**
* Setup mapping from short-types to long types.
*
* @param configuration the configuration
* @throws ConfigurationException if configuration is invalid
*/
public void configure( Configuration configuration )
throws ConfigurationException
{
final Configuration[] children = configuration.getChildren();
for( int i = 0; i < children.length; i++ )
{
final Configuration child = children[ i ];
final String key = child.getAttribute( "name" );
final String uri = child.getAttribute( "uri" );
m_uriMap.put( key, uri );
}
}
public boolean isValid( final ComponentProfile component,
final ClassLoader classLoader )
throws ConfigurationException
{
final SchemaDescriptor schema = component.getInfo().getConfigurationSchema();
if( null == schema )
{
return true;
}
if( getLogger().isDebugEnabled() )
{
final String message =
"Validating component " + component.getMetaData().getName() +
" of type " +
component.getInfo().getDescriptor().getImplementationKey() +
" with schema " + schema.getLocation() + " of type " +
schema.getType();
getLogger().debug( message );
}
//Get the uri of configuration schema type
final String type = getType( schema );
if( !type.equals( schema.getType() ) )
{
final String message =
"Schema type specified as " + schema.getType() +
" was translated to URI " + type + ". It is " +
"recomended that the components Info specify the" +
"URI rather than the type for compatability reasons.";
System.err.println( message );
getLogger().warn( message );
}
//Get the InputSource for schema
final InputSource inputSource =
getSchemaInputSource( component, classLoader );
//Actually perform the validation
try
{
final ConfigValidator validator = ConfigValidatorFactory.create( type,
inputSource );
final Configuration configuration =
component.getMetaData().getConfiguration();
final DefaultConfiguration newConfiguration = new DefaultConfiguration(
"root", configuration.getLocation() );
newConfiguration.addAll( configuration );
final Element element = ConfigurationUtil.toElement( newConfiguration );
final ValidationResult result = validator.validate( element );
ConfigurationBuilder.processValidationResults( result, getLogger() );
return true;
}
catch( Exception e )
{
getLogger().warn( "Failed validation due to: " + e.getMessage(), e );
return false;
}
}
/**
* Get the uri of schema type.
* It will attempt to use the type specified by the
* SchemaDescriptor unless the configuration explicitly
* maps that type to another URI.
*
* @param schema the SchemaDescriptor
* @return the URI of schema type
*/
private String getType( final SchemaDescriptor schema )
{
final String type = schema.getType();
final String uri = (String)m_uriMap.get( type );
if( null != uri )
{
return uri;
}
else
{
return type;
}
}
/**
* Get the input source for schema specified by ComponentInfo object.
*
* @param component the component profile
* @param classLoader the classloader to load schema from
* @return the InputSource for schema
* @throws ConfigurationException if unable to locate schema
*/
private InputSource getSchemaInputSource( final ComponentProfile component,
final ClassLoader classLoader ) throws ConfigurationException
{
final SchemaDescriptor schema = component.getInfo().getConfigurationSchema();
final String resource = calcSchemaResource( component );
final InputStream inputStream = classLoader.getResourceAsStream( resource );
if( null == inputStream )
{
final String message = "Unable to find Schema for component " +
component.getMetaData().getName() + " of type " +
component.getInfo().getDescriptor().getImplementationKey() +
" at location " + resource;
throw new ConfigurationException( message );
}
final InputSource inputSource = new InputSource( inputStream );
inputSource.setSystemId( schema.getLocation() );
return inputSource;
}
/**
* Determine the absolute name of the resource that contains schema.
* If the location starts with a '/' then the location is absolute
* otherwise the location is relative to the components class.
*
* @param component the component profile
* @return the absolute name of schema resource
*/
private String calcSchemaResource( final ComponentProfile component )
{
final SchemaDescriptor schema = component.getInfo().getConfigurationSchema();
final String location = schema.getLocation();
if( location.startsWith( "/" ) )
{
return location;
}
else
{
final String classname =
component.getInfo().getDescriptor().getImplementationKey();
String resource = classname;
final int index = classname.lastIndexOf( '.' );
resource = classname;
if( -1 != index )
{
resource = classname.substring( 0, index + 1 );
}
resource = resource.replace( '.', '/' );
resource += location;
return resource;
}
}
}
1.80 +92 -138
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java
Index: DefaultDeployer.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeployer.java,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- DefaultDeployer.java 6 Apr 2003 03:29:49 -0000 1.79
+++ DefaultDeployer.java 6 Apr 2003 11:23:21 -0000 1.80
@@ -63,6 +63,7 @@
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.configuration.DefaultConfiguration;
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
@@ -70,11 +71,9 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.phoenix.BlockContext;
-import org.apache.avalon.phoenix.containerkit.metadata.PartitionMetaData;
import org.apache.avalon.phoenix.containerkit.profile.ComponentProfile;
import org.apache.avalon.phoenix.containerkit.profile.PartitionProfile;
import org.apache.avalon.phoenix.containerkit.profile.ProfileBuilder;
-import org.apache.avalon.phoenix.framework.info.SchemaDescriptor;
import org.apache.avalon.phoenix.interfaces.Application;
import org.apache.avalon.phoenix.interfaces.ClassLoaderManager;
import org.apache.avalon.phoenix.interfaces.ClassLoaderSet;
@@ -90,7 +89,6 @@
import org.apache.avalon.phoenix.interfaces.LogManager;
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.xml.sax.InputSource;
/**
@@ -224,9 +222,7 @@
for( int i = 0; i < blocks.length; i++ )
{
- //remove configuration and schema from repository and validator
m_repository.removeConfiguration( name, blocks[ i ] );
- m_validator.removeSchema( name, blocks[ i ] );
}
m_installer.uninstall( installation );
@@ -323,19 +319,23 @@
context.put( "classloader", classLoader );
+ final Configuration newConfig = processConfiguration( name, config );
+
final Map parameters = new HashMap();
parameters.put( ContainerConstants.ASSEMBLY_NAME, name );
- parameters.put( ContainerConstants.ASSEMBLY_CONFIG, assembly );
+ parameters.put( ContainerConstants.ASSEMBLY_DESCRIPTOR, assembly );
+ parameters.put( ContainerConstants.CONFIG_DESCRIPTOR, newConfig );
parameters.put( ContainerConstants.ASSEMBLY_CLASSLOADER, classLoader );
//assemble all the blocks for application
final PartitionProfile profile = m_builder.buildProfile( parameters );
- storeConfigurationSchemas( profile, classLoader );
- verify( profile, classLoader );
+ m_verifier.verifySar( profile, classLoader );
//Setup configuration for all the applications blocks
- setupConfiguration( profile.getMetaData(), config.getChildren() );
+ verifyConfiguration( profile, newConfig );
+
+ validateConfiguration( profile, classLoader );
//Finally add application to kernel
m_kernel.addApplication( profile,
@@ -379,181 +379,135 @@
}
/**
- * Verify that the application conforms to our requirements.
+ * Helper method to load configuration data.
*
- * @param profile the application profile
- * @throws VerifyException on error
+ * @param install the install data
+ * @param key the key under which config data is stored in install data
+ * @return the Configuration
+ * @throws DeploymentException if an error occurs
*/
- private void verify( final PartitionProfile profile,
- final ClassLoader classLoader )
- throws VerifyException
+ private Configuration getConfigurationFor( final Map install, final String key,
final String schema )
+ throws DeploymentException
{
+ final String location = (String)install.get( key );
try
{
- m_verifier.verifySar( profile, classLoader );
+ return ConfigurationBuilder.build( new InputSource( location ), schema,
getLogger() );
}
- catch( org.apache.avalon.phoenix.framework.tools.verifier.VerifyException e
)
+ catch( final Exception e )
{
- throw new VerifyException( e.getMessage(), e.getCause() );
+ final String message = REZ.getString( "deploy.error.config.create",
location );
+ getLogger().error( message, e );
+ throw new DeploymentException( message, e );
}
}
/**
- * Store the configuration schemas for this application
+ * Pass the configuration to the configurationManager
+ * and give it a chance to process the configuration in
+ * one form or another.
*
- * @param profile the application profile
- * @throws DeploymentException upon invalid schema
+ * @param configuration the block configurations.
+ * @throws DeploymentException if an error occurs
*/
- private void storeConfigurationSchemas( final PartitionProfile profile,
- final ClassLoader classLoader )
+ private Configuration processConfiguration( final String application,
+ final Configuration configuration )
throws DeploymentException
{
- final String application = profile.getMetaData().getName();
- final PartitionProfile partition = profile.getPartition(
ContainerConstants.BLOCK_PARTITION );
- final ComponentProfile[] blocks = partition.getComponents();
- int i = 0;
- String name = null;
-
- try
+ final DefaultConfiguration newConfiguration = new DefaultConfiguration(
"config" );
+ final Configuration[] configurations = configuration.getChildren();
+ for( int i = 0; i < configurations.length; i++ )
{
- for( i = 0; i < blocks.length; i++ )
+ final Configuration config = configurations[ i ];
+ try
{
- final ComponentProfile block = blocks[ i ];
- final SchemaDescriptor descriptor =
block.getInfo().getConfigurationSchema();
- name = block.getMetaData().getName();
-
- if( null != descriptor && !descriptor.getType().equals( "" ) )
- {
- final String implementationKey =
- block.getInfo().getDescriptor().getImplementationKey();
-
- m_validator.addSchema( application,
- name,
- descriptor.getType(),
- getConfigurationSchemaURL( name,
-
implementationKey,
- classLoader )
- );
- }
+ final Configuration newConfig =
+ m_repository.processConfiguration( application,
+ config.getName(),
+ config );
+ newConfiguration.addChild( newConfig );
}
- }
- catch( ConfigurationException e )
- {
- //uh-oh, bad schema bad bad!
- final String message =
- REZ.getString( "deploy.error.config.schema.invalid",
- name );
-
- //back out any schemas that we have already stored for this app
- while( --i >= 0 )
+ catch( final ConfigurationException ce )
{
- m_validator.removeSchema( application,
- blocks[ i ].getMetaData().getName() );
+ throw new DeploymentException( ce.getMessage(), ce );
}
-
- throw new DeploymentException( message, e );
- }
- }
-
- private String getConfigurationSchemaURL( final String name,
- final String classname,
- final ClassLoader classLoader )
- throws DeploymentException
- {
- final String resourceName = classname.replace( '.', '/' ) + "-schema.xml";
-
- final URL resource = classLoader.getResource( resourceName );
- if( null == resource )
- {
-
- final String message =
- REZ.getString( "deploy.error.config.schema.missing",
- name,
- resourceName );
- throw new DeploymentException( message );
- }
- else
- {
- return resource.toString();
}
+ return newConfiguration;
}
/**
- * Helper method to load configuration data.
+ * Verify that configuration present in config file is valid for this assembly.
*
- * @param install the install data
- * @param key the key under which config data is stored in install data
- * @return the Configuration
+ * @param profile the PartitionProfile
+ * @param config the block configurations.
* @throws DeploymentException if an error occurs
*/
- private Configuration getConfigurationFor( final Map install, final String key,
final String schema )
+ private void verifyConfiguration( final PartitionProfile profile,
+ final Configuration config )
throws DeploymentException
{
- final String location = (String)install.get( key );
- try
- {
- return ConfigurationBuilder.build( new InputSource( location ), schema,
getLogger() );
- }
- catch( final Exception e )
+ final Configuration[] configurations = config.getChildren();
+ final PartitionProfile listenerPartition =
+ profile.getPartition( ContainerConstants.LISTENER_PARTITION );
+ final PartitionProfile blockPartition =
+ profile.getPartition( ContainerConstants.BLOCK_PARTITION );
+ for( int i = 0; i < configurations.length; i++ )
{
- final String message = REZ.getString( "deploy.error.config.create",
location );
- getLogger().error( message, e );
- throw new DeploymentException( message, e );
+ final Configuration configuration = configurations[ i ];
+ final String name = configuration.getName();
+ ComponentProfile component = listenerPartition.getComponent( name );
+ if( null == component )
+ {
+ component = blockPartition.getComponent( name );
+ }
+ if( null == component )
+ {
+ final String message =
+ REZ.getString( "deploy.error.extra.config",
+ name );
+ throw new DeploymentException( message );
+ }
}
}
/**
- * Setup Configuration for all the Blocks/BlockListeners in Sar.
+ * Verify that configuration conforms to schema for all components in this
assembly.
*
- * @param metaData the SarMetaData.
- * @param configurations the block configurations.
+ * @param profile the PartitionProfile
+ * @param classLoader the classloader application is loaded in
* @throws DeploymentException if an error occurs
*/
- private void setupConfiguration( final PartitionMetaData metaData,
- final Configuration[] configurations )
+ private void validateConfiguration( final PartitionProfile profile,
+ final ClassLoader classLoader )
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 PartitionProfile[] partitions = profile.getPartitions();
+ for( int i = 0; i < partitions.length; i++ )
{
- final Configuration configuration = configurations[ i ];
- final String name = configuration.getName();
- final boolean listener =
- null != listenerPartition.getComponent( name );
- final boolean block =
- null != blockPartition.getComponent( name );
- if( !block && !listener )
+ validateConfiguration( partitions[ i ], classLoader );
+ }
+ final ComponentProfile[] components = profile.getComponents();
+ for( int i = 0; i < components.length; i++ )
+ {
+ final ComponentProfile component = components[ i ];
+ boolean isValid = false;
+ try
{
- final String message =
- REZ.getString( "deploy.error.extra.config",
- name );
- throw new DeploymentException( message );
+ isValid = m_validator.isValid( component, classLoader );
}
-
- try
+ catch( ConfigurationException e )
{
- //No way to validate listener configuration--yet
- if( listener || m_validator.isFeasiblyValid( application, name,
configuration ) )
- {
- m_repository.storeConfiguration( application,
- name,
- configuration );
- }
- else
- {
- final String message =
- REZ.getString( "deploy.error.config.invalid", name );
- throw new DeploymentException( message );
- }
+ getLogger().warn( e.getMessage(), e );
}
- catch( final ConfigurationException ce )
+ if( !isValid )
{
- throw new DeploymentException( ce.getMessage(), ce );
+ final String message =
+ "Unable to validate configuration of component " +
+ component.getMetaData().getName() + " of type " +
+ component.getInfo().getDescriptor().getImplementationKey();
+ throw new DeploymentException( message );
}
}
}
+
}
1.12 +0 -12
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/ManagementRegistration.java
Index: ManagementRegistration.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/ManagementRegistration.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ManagementRegistration.java 22 Mar 2003 12:07:09 -0000 1.11
+++ ManagementRegistration.java 6 Apr 2003 11:23:22 -0000 1.12
@@ -53,10 +53,6 @@
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.excalibur.packagemanager.ExtensionManager;
-import org.apache.avalon.phoenix.interfaces.ConfigurationRepository;
-import org.apache.avalon.phoenix.interfaces.ConfigurationRepositoryMBean;
-import org.apache.avalon.phoenix.interfaces.ConfigurationValidator;
-import org.apache.avalon.phoenix.interfaces.ConfigurationValidatorMBean;
import org.apache.avalon.phoenix.interfaces.Deployer;
import org.apache.avalon.phoenix.interfaces.DeployerMBean;
import org.apache.avalon.phoenix.interfaces.Embeddor;
@@ -87,14 +83,6 @@
new ManagementRegistration( Deployer.ROLE, "Deployer", new
Class[]{DeployerMBean.class} );
public static final ManagementRegistration LOG_MANAGER =
new ManagementRegistration( LogManager.ROLE, "LogManager", new Class[]{} );
- public static final ManagementRegistration CONFIGURATION_REPOSITORY =
- new ManagementRegistration( ConfigurationRepository.ROLE,
- "ConfigurationManager",
- new Class[]{ConfigurationRepositoryMBean.class}
);
- public static final ManagementRegistration CONFIGURATION_VALIDATOR =
- new ManagementRegistration( ConfigurationValidator.ROLE,
- "ConfigurationValidator",
- new Class[]{ConfigurationValidatorMBean.class}
);
//TODO: Need information for SystemManager?
private final String m_role;
1.41 +0 -52
avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java
Index: DefaultApplicationContext.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultApplicationContext.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- DefaultApplicationContext.java 5 Apr 2003 04:25:42 -0000 1.40
+++ DefaultApplicationContext.java 6 Apr 2003 11:23:22 -0000 1.41
@@ -59,19 +59,14 @@
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
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.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.phoenix.components.util.ResourceUtil;
-import org.apache.avalon.phoenix.containerkit.metadata.PartitionMetaData;
import org.apache.avalon.phoenix.containerkit.profile.PartitionProfile;
import org.apache.avalon.phoenix.interfaces.ApplicationContext;
-import org.apache.avalon.phoenix.interfaces.ConfigurationRepository;
-import org.apache.avalon.phoenix.interfaces.ConfigurationValidator;
import org.apache.avalon.phoenix.interfaces.ContainerConstants;
import org.apache.avalon.phoenix.interfaces.Kernel;
import org.apache.avalon.phoenix.interfaces.ManagerException;
@@ -102,12 +97,6 @@
///ThreadContext for application
private final ThreadContext m_threadContext;
- //Repository of configuration data to access
- private ConfigurationRepository m_repository;
-
- //Validator to validate configuration against
- private ConfigurationValidator m_validator;
-
//InstrumentManager to register instruments with
private InstrumentManager m_instrumentManager;
@@ -173,12 +162,8 @@
public void service( final ServiceManager serviceManager )
throws ServiceException
{
- m_repository = (ConfigurationRepository)serviceManager.
- lookup( ConfigurationRepository.ROLE );
m_systemManager = (SystemManager)serviceManager.
lookup( SystemManager.ROLE );
- m_validator = (ConfigurationValidator)serviceManager.
- lookup( ConfigurationValidator.ROLE );
m_kernel = (Kernel)serviceManager.lookup( Kernel.ROLE );
m_instrumentManager = (InstrumentManager)serviceManager.lookup(
InstrumentManager.ROLE );
}
@@ -308,43 +293,6 @@
throws Exception
{
m_blockManager.unregister( name );
- }
-
- /**
- * Get the Configuration for specified component.
- *
- * @param component the component
- * @return the Configuration
- */
- public Configuration getConfiguration( final String component )
- throws ConfigurationException
- {
- final Configuration configuration =
- m_repository.getConfiguration( getName(),
- component );
-
- //no validation of listeners just yet..
- 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( getName(),
- component,
- configuration ) )
- {
-
- return configuration;
- }
- else
- {
- final String message =
- REZ.getString( "applicationcontext.error.invalidconfig",
- component );
- throw new ConfigurationException( message );
- }
}
public ClassLoader getClassLoader( final String name )
1.27 +0 -11
avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java
Index: ApplicationContext.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ApplicationContext.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- ApplicationContext.java 5 Apr 2003 04:25:44 -0000 1.26
+++ ApplicationContext.java 6 Apr 2003 11:23:22 -0000 1.27
@@ -52,8 +52,6 @@
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.containerkit.profile.PartitionProfile;
import org.apache.excalibur.instrument.InstrumentManager;
@@ -122,15 +120,6 @@
* the resource named "data/main.html" or similar.
*/
InputStream getResourceAsStream( String name );
-
- /**
- * Get the Configuration for specified component.
- *
- * @param component the component
- * @return the Configuration
- */
- Configuration getConfiguration( String component )
- throws ConfigurationException;
/**
* Get logger with category for application.
1.18 +4 -17
avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ConfigurationRepository.java
Index: ConfigurationRepository.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ConfigurationRepository.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ConfigurationRepository.java 22 Mar 2003 12:07:14 -0000 1.17
+++ ConfigurationRepository.java 6 Apr 2003 11:23:22 -0000 1.18
@@ -63,20 +63,7 @@
String ROLE = ConfigurationRepository.class.getName();
/**
- * Retrieve configuration information from the repository
- *
- * @param application Application name
- * @param block Block name to get configuration for
- *
- * @return Configuration information
- *
- * @throws ConfigurationException if no configuration could be found
- */
- Configuration getConfiguration( String application, String block )
- throws ConfigurationException;
-
- /**
- * Store configuration information in the repository
+ * Process configuration information
*
* @param application Application name
* @param block Block name to store configuration for
@@ -84,9 +71,9 @@
*
* @throws ConfigurationException if configuration could not be stored
*/
- void storeConfiguration( String application,
- String block,
- Configuration configuration )
+ Configuration processConfiguration( String application,
+ String block,
+ Configuration configuration )
throws ConfigurationException;
/**
1.8 +7 -50
avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ConfigurationValidator.java
Index: ConfigurationValidator.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ConfigurationValidator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ConfigurationValidator.java 22 Mar 2003 12:07:14 -0000 1.7
+++ ConfigurationValidator.java 6 Apr 2003 11:23:22 -0000 1.8
@@ -47,11 +47,10 @@
Apache Software Foundation, please see <http://www.apache.org/>.
*/
-
package org.apache.avalon.phoenix.interfaces;
-import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.phoenix.containerkit.profile.ComponentProfile;
/**
* Handles parsing of configuration schema and validation against schema
@@ -64,55 +63,13 @@
String ROLE = ConfigurationValidator.class.getName();
/**
- * Add configuration schema to validator
- *
- * @param application Application name
- * @param block Block name to store configuration for
- * @param url url that the schema may be located at
- *
- * @throws ConfigurationException if schema is invalid
- */
- void addSchema( String application, String block, String schemaType, String url
)
- throws ConfigurationException;
-
- /**
- * Add configuration schema to validator
- *
- * @param application Application name
- * @param block Block name to store configuration for
- */
- void removeSchema( String application, String block );
-
- /**
- * Check to see if configuration is feasibly valid. That is, does this
configuration match
- * the schema in its current state, but not neccessarily fullfill the
requirements of the
- * schema.
- *
- * Implementations are not required to support checking feasibility. If
feasibility cannot
- * be checked, the implementation should always return true
- *
- * @param application Application name
- * @param block Block name to store configuration for
- * @param configuration Configuration to check
- *
- * @return true if configuration is feasibly valid
- *
- * @throws ConfigurationException if no schema is found
- */
- boolean isFeasiblyValid( String application, String block, Configuration
configuration )
- throws ConfigurationException;
-
- /**
- * Check to see if configuration is valid.
- *
- * @param application Application name
- * @param block Block name to store configuration for
- * @param configuration Configuration to check
+ * Check to see if configuration is valid for specified component.
*
+ * @param component the ComponentProfile
+ * @param classLoader the ClassLoader (to load schema from if necessary)
* @return true if configuration is valid
- *
- * @throws ConfigurationException if no schema is found
+ * @throws ConfigurationException if expected schema is missing
*/
- boolean isValid( String application, String block, Configuration configuration )
+ boolean isValid( ComponentProfile component, ClassLoader classLoader )
throws ConfigurationException;
}
1.4 +7 -1
avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ContainerConstants.java
Index: ContainerConstants.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/interfaces/ContainerConstants.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContainerConstants.java 23 Mar 2003 00:37:25 -0000 1.3
+++ ContainerConstants.java 6 Apr 2003 11:23:22 -0000 1.4
@@ -87,9 +87,15 @@
/**
* The name of the config file which is used
+ * to load config data.
+ */
+ String CONFIG_DESCRIPTOR = "phoenix:config";
+
+ /**
+ * The name of the config file which is used
* to load assembly data.
*/
- String ASSEMBLY_CONFIG = "phoenix:config";
+ String ASSEMBLY_DESCRIPTOR = "phoenix:assembly";
/**
* The default classloader to use to load components.
1.18 +36 -22
avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/configuration/ConfigurationBuilder.java
Index: ConfigurationBuilder.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/configuration/ConfigurationBuilder.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ConfigurationBuilder.java 5 Apr 2003 11:21:10 -0000 1.17
+++ ConfigurationBuilder.java 6 Apr 2003 11:23:22 -0000 1.18
@@ -121,31 +121,46 @@
final ConfigValidator validator =
ConfigValidatorFactory.create( inputSource, c_resolver );
final ValidationResult result = validator.validate( input,
(ContentHandler)handler );
- if( !result.isValid() )
+ processValidationResults( result, logger );
+ }
+ return handler.getConfiguration();
+ }
+
+ /**
+ * Process validation results. Print out any warnings or
+ * errors and if validation failed then throw an exception.
+ *
+ * @param result the validation results
+ * @param logger the logger to print messages to
+ * @throws Exception if validation failed
+ */
+ public static void processValidationResults( final ValidationResult result,
+ final Logger logger )
+ throws Exception
+ {
+ if( !result.isValid() )
+ {
+ final ValidationIssue[] issues = result.getIssues();
+ for( int i = 0; i < issues.length; i++ )
{
- final ValidationIssue[] issues = result.getIssues();
- for( int i = 0; i < issues.length; i++ )
+ final ValidationIssue issue = issues[ i ];
+ final String message = issue.getException().getMessage();
+ if( issue.isWarning() )
{
- final ValidationIssue issue = issues[ i ];
- final String message = issue.getException().getMessage();
- if( issue.isWarning() )
- {
- logger.info( message );
- }
- else if( issue.isError() )
- {
- logger.warn( message );
- }
- else if( issue.isFatalError() )
- {
- logger.error( message );
- }
+ logger.info( message );
+ }
+ else if( issue.isError() )
+ {
+ logger.warn( message );
+ }
+ else if( issue.isFatalError() )
+ {
+ logger.error( message );
}
- final ValidateException exception = result.getException();
- throw new Exception( exception.getMessage(), exception );
}
+ final ValidateException exception = result.getException();
+ throw new Exception( exception.getMessage(), exception );
}
- return handler.getConfiguration();
}
private static void setupResolver()
@@ -157,5 +172,4 @@
ResolverFactory.createResolver(
ConfigurationBuilder.class.getClassLoader() );
}
}
-
}
1.11 +1 -9
avalon-phoenix/src/test/org/apache/avalon/phoenix/components/application/test/MockApplicationContext.java
Index: MockApplicationContext.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/test/org/apache/avalon/phoenix/components/application/test/MockApplicationContext.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MockApplicationContext.java 5 Apr 2003 04:25:44 -0000 1.10
+++ MockApplicationContext.java 6 Apr 2003 11:23:22 -0000 1.11
@@ -53,8 +53,6 @@
import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
-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.containerkit.profile.PartitionProfile;
import org.apache.avalon.phoenix.interfaces.ApplicationContext;
@@ -117,12 +115,6 @@
public InputStream getResourceAsStream( final String name )
{
return getClassLoader().getResourceAsStream( name );
- }
-
- public Configuration getConfiguration( String component )
- throws ConfigurationException
- {
- throw new ConfigurationException( "I can't do that dave!" );
}
public File getHomeDirectory()
1.12 +4 -2
avalon-phoenix/src/test/org/apache/avalon/phoenix/test/AbstractContainerTestCase.java
Index: AbstractContainerTestCase.java
===================================================================
RCS file:
/home/cvs/avalon-phoenix/src/test/org/apache/avalon/phoenix/test/AbstractContainerTestCase.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractContainerTestCase.java 5 Apr 2003 11:21:10 -0000 1.11
+++ AbstractContainerTestCase.java 6 Apr 2003 11:23:22 -0000 1.12
@@ -55,6 +55,7 @@
import java.util.Map;
import junit.framework.TestCase;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.phoenix.components.deployer.PhoenixProfileBuilder;
import org.apache.avalon.phoenix.containerkit.profile.PartitionProfile;
@@ -89,7 +90,8 @@
new ConsoleLogger() );
final Map parameters = new HashMap();
parameters.put( ContainerConstants.ASSEMBLY_NAME, "test" );
- parameters.put( ContainerConstants.ASSEMBLY_CONFIG, assembly );
+ parameters.put( ContainerConstants.ASSEMBLY_DESCRIPTOR, assembly );
+ parameters.put( ContainerConstants.CONFIG_DESCRIPTOR, new
DefaultConfiguration( "config" ) );
parameters.put( ContainerConstants.ASSEMBLY_CLASSLOADER,
getClass().getClassLoader() );
return assembler.buildProfile( parameters );
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]