mcconnell 2002/06/13 00:43:19
Modified: merlin/src/java/org/apache/excalibur/configuration
ConfigurationUtil.java
merlin/src/java/org/apache/excalibur/merlin UnitInfo.java
Log:
more selection options
Revision Changes Path
1.4 +38 -16
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/configuration/ConfigurationUtil.java
Index: ConfigurationUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/configuration/ConfigurationUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConfigurationUtil.java 13 Jun 2002 07:11:39 -0000 1.3
+++ ConfigurationUtil.java 13 Jun 2002 07:43:19 -0000 1.4
@@ -14,6 +14,8 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
/**
* General utility supporting static operations for generating string
@@ -83,7 +85,7 @@
* @param value the attribute value to match (null will match any
attribute value)
* @return an array of configuration instances matching the query
*/
- public Configuration[] match( Configuration config, String element,
String attribute )
+ public static Configuration[] match( Configuration config, String
element, String attribute )
{
return match( config, element, attribute, null );
}
@@ -96,7 +98,7 @@
* @param value the attribute value to match (null will match any
attribute value)
* @return an array of configuration instances matching the query
*/
- public Configuration[] match(
+ public static Configuration[] match(
final Configuration config, final String element, final String
attribute, final String value )
{
Vector vector = new Vector();
@@ -118,16 +120,42 @@
}
/**
- * Return the first occurance of a configuration child containing the
supplied attribute name and value.
+ * Return the first occurance of a configuration child containing the
supplied attribute name and value
+ * or create a new empty configuration if no match found.
* @param config the configuration
* @param element the name of child elements to select from the
configuration
* @param attribute the attribute name to filter
* @param value the attribute value to match (null will match any
attribute value)
- * @return a configuration instances matching the query
- * @exception ConfigurationException if no matching children
+ * @return a configuration instances matching the query or empty
configuration
*/
- public Configuration matchFirstOccurance(
+ public static Configuration matchFirstOccurance(
Configuration config, String element, String attribute, String value )
+ {
+ try
+ {
+ return matchFirstOccurance( config, element, attribute, value,
true );
+ }
+ catch( ConfigurationException e )
+ {
+ // will not happen
+ throw new CascadingRuntimeException("Unexpected exception
condition.", e );
+ }
+ }
+
+
+ /**
+ * Return the first occurance of a configuration child containing the
supplied attribute
+ * name and value. If the supplied creation policy if TRUE and no match
is found, an
+ * empty configuration instance is returned, otherwise a null will
returned.
+ * @param config the configuration
+ * @param element the name of child elements to select from the
configuration
+ * @param attribute the attribute name to filter
+ * @param value the attribute value to match (null will match any
attribute value)
+ * @param create the creation policy if no match
+ * @return a configuration instances matching the query
+ */
+ public static Configuration matchFirstOccurance(
+ Configuration config, String element, String attribute, String value,
boolean create )
throws ConfigurationException
{
Configuration[] children = config.getChildren( element );
@@ -143,16 +171,10 @@
}
}
}
- if( value == null )
- {
- throw new ConfigurationException("No match for element named '"
+ element
- + "' with an attribute name of '" + attribute + "'.");
- }
- else
- {
- throw new ConfigurationException("No match for element named '"
+ element
- + " with an attribute name of '" + attribute + "' and value '"
+ value + "'.");
- }
+
+ if( create )
+ return new DefaultConfiguration( element, null );
+ return null;
}
}
1.7 +9 -10
jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/UnitInfo.java
Index: UnitInfo.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/merlin/src/java/org/apache/excalibur/merlin/UnitInfo.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- UnitInfo.java 13 Jun 2002 05:27:51 -0000 1.6
+++ UnitInfo.java 13 Jun 2002 07:43:19 -0000 1.7
@@ -210,28 +210,27 @@
}
}
- // get the default context
-
- Context context = new ServiceContext( new String[ 0 ], root );
+ // get any context declaration in the xinfo
Configuration contextConfig = xinfo.getChild( "context", false );
- // get any context declarations from the runtime profile
-
- Configuration contextConfig2 = conf.getChild( m_name ).getChild(
"context", false );
- if( contextConfig2 != null )
+ // get any context declarations from the component profile
+ Configuration componentConfig =
ConfigurationUtil.matchFirstOccurance(
+ conf, "component", "class", block.getName() );
+ Configuration profileContextConfig = componentConfig.getChild(
"context", false );
+ if( null != profileContextConfig )
{
if( contextConfig != null )
{
- contextConfig = new CascadingConfiguration( contextConfig,
contextConfig2 );
+ contextConfig = new CascadingConfiguration( contextConfig,
profileContextConfig );
}
else
{
- contextConfig = contextConfig2;
+ contextConfig = profileContextConfig;
}
}
// create the context value
-
+ Context context = new ServiceContext( new String[ 0 ], root );
if( contextConfig != null )
{
m_context = ContextFactory.createContextFromConfiguration(
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>