Index: framework/src/java/org/apache/hivemind/impl/ImplMessages.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java,v retrieving revision 1.24 diff -r1.24 ImplMessages.java 34a35 > import org.apache.hivemind.parse.SubModuleDescriptor; 399a401,412 > > /** Provides a formatted message for when a sub-module descriptor has been conditionally ignored. > * > * @param smd The sub-module that was ignored > * @return The formatter string > * @since 1.1 > */ > public static String subModuleContributionIgnored(SubModuleDescriptor smd) > { > return _formatter.format("sub-module-contribution-ignored", smd.getLocation()); > } > Index: framework/src/java/org/apache/hivemind/impl/ImplStrings.properties =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties,v retrieving revision 1.16 diff -r1.16 ImplStrings.properties 87a88 > sub-module-contribution-ignored=Submodule descriptor included from ''{0}'' has been conditionally ignored \ No newline at end of file Index: framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java,v retrieving revision 1.8 diff -r1.8 XmlModuleDescriptorProvider.java 31a32,35 > import org.apache.hivemind.Location; > import org.apache.hivemind.conditional.Parser; > import org.apache.hivemind.conditional.Node; > import org.apache.hivemind.conditional.EvaluationContextImpl; 41c45 < * --- > * 75a80,82 > /** @since 1.1 */ > private Parser _conditionalExpressionParser; > 209c216,262 < processResource(smd.getDescriptor()); --- > // Only include the contribution if the expression evaluates to true > if (includeSubModule(smd.getConditionalExpression(), moduleDescriptor.getClassResolver(),smd.getLocation())) > { > processResource(smd.getDescriptor()); > } > else > { > LOG.debug(ImplMessages.subModuleContributionIgnored(smd)); > } > > } > } > > /** Evaluates the specifed expression and returns a boolean for the corresponding result. > * > * @param expression The expression to evaluate > * @param classResolver The ClassResolver to use for class lookups > * @param location The location from where the expression was loaded > * @return True if the expression evaluates to true, otherwise false > */ > private boolean includeSubModule(String expression, ClassResolver classResolver, Location location) > { > // TODO: This method is a cut-n-paste job from the RegistryInfrastructureConstructor class > // Considered creating a ConditionalsUtil class to do this (and re-use it in both this and > // the RegistryInfrastructureConstructor class) but didn't make that change yet ... > > if (expression == null) > { > return true; > } > > if (_conditionalExpressionParser == null) > { > _conditionalExpressionParser = new Parser(); > } > > try > { > Node node = _conditionalExpressionParser.parse(expression); > > return node.evaluate(new EvaluationContextImpl(classResolver)); > } > catch (RuntimeException ex) > { > _errorHandler.error(LOG, ex.getMessage(), location, ex); > > return false; Index: framework/src/java/org/apache/hivemind/parse/DescriptorParser.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java,v retrieving revision 1.46 diff -r1.46 DescriptorParser.java 1132a1133 > smd.setConditionalExpression(getAttribute("if")); Index: framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties,v retrieving revision 1.17 diff -r1.17 DescriptorParser.properties 81a82 > required.sub-module.if=false Index: framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java,v retrieving revision 1.2 diff -r1.2 SubModuleDescriptor.java 30a31,33 > /** @since 1.1 */ > private String _conditionalExpression; > 46a50,65 > } > > /** > * @since 1.1 > */ > public String getConditionalExpression() > { > return _conditionalExpression; > } > > /** > * @since 1.1 > */ > public void setConditionalExpression(String conditionalExpression) > { > _conditionalExpression = conditionalExpression; Index: framework/src/test/hivemind/test/TestSubModule.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/test/hivemind/test/TestSubModule.java,v retrieving revision 1.6 diff -r1.6 TestSubModule.java 48a49,62 > public void testConditionalSubModuleIncluded() throws Exception > { > Registry r = buildFrameworkRegistry("ConditionalIncludedSubmodule.xml"); > SimpleService s = (SimpleService) r.getService("hivemind.test.outer.Simple", SimpleService.class); > assertEquals(11,s.add(4,7)); > } > > public void testConditionalSubModuleNotIncluded() throws Exception > { > interceptLogging(); > Registry r = buildFrameworkRegistry("ConditionalNotIncludedSubmodule.xml"); > assertLoggedMessagePattern("Submodule descriptor included from 'file:/.*/ConditionalNotIncludedSubmodule.xml, line \\d{1,2}, column \\d{1,2}' has been conditionally ignored"); > } > Index: framework/src/test/hivemind/test/parse/TestDescriptorParser.java =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/framework/src/test/hivemind/test/parse/TestDescriptorParser.java,v retrieving revision 1.30 diff -r1.30 TestDescriptorParser.java 40a41 > import org.apache.hivemind.parse.SubModuleDescriptor; 586a588,606 > > public void testSubModule() throws Exception > { > ModuleDescriptor md = parse("SubModule.xml"); > List l = md.getSubModules(); > assertEquals(1, l.size()); > SubModuleDescriptor smd = (SubModuleDescriptor) l.get(0); > assertNull(smd.getConditionalExpression()); > } > > public void testSubModuleIf() throws Exception > { > ModuleDescriptor md = parse("SubModuleIf.xml"); > List l = md.getSubModules(); > assertEquals(1, l.size()); > SubModuleDescriptor smd = (SubModuleDescriptor) l.get(0); > assertEquals("class foo.bar.Blat", smd.getConditionalExpression()); > } > Index: src/documentation/content/xdocs/descriptor.xml =================================================================== RCS file: /home/cvspublic/jakarta-hivemind/src/documentation/content/xdocs/descriptor.xml,v retrieving revision 1.18 diff -r1.18 descriptor.xml 626a627,632 > > if > string > no > A &conditional-expression; controlling whether the sub-module is included or ignored. >