You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by kn...@apache.org on 2006/06/22 16:42:40 UTC
svn commit: r416385 - in /jakarta/hivemind/trunk: ./
framework/src/java/org/apache/hivemind/impl/
framework/src/java/org/apache/hivemind/parse/
framework/src/test/hivemind/test/ framework/src/test/hivemind/test/parse/
src/documentation/content/xdocs/
Author: knut
Date: Thu Jun 22 07:42:39 2006
New Revision: 416385
URL: http://svn.apache.org/viewvc?rev=416385&view=rev
Log:
adds "if" attribute to <sub-module> (see HIVEMIND-85)
Added:
jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalIncludedSubmodule.xml
jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalNotIncludedSubmodule.xml
jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/IncludeSubModule.xml
jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModule.xml
jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModuleIf.xml
Modified:
jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java
jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties
jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java
jakarta/hivemind/trunk/framework/src/test/hivemind/test/TestSubModule.java
jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/TestDescriptorParser.java
jakarta/hivemind/trunk/src/documentation/content/xdocs/conditional.xml
jakarta/hivemind/trunk/src/documentation/content/xdocs/descriptor.xml
jakarta/hivemind/trunk/status.xml
Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java (original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java Thu Jun 22 07:42:39 2006
@@ -27,8 +27,12 @@
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.HiveMind;
+import org.apache.hivemind.Location;
import org.apache.hivemind.ModuleDescriptorProvider;
import org.apache.hivemind.Resource;
+import org.apache.hivemind.conditional.EvaluationContextImpl;
+import org.apache.hivemind.conditional.Node;
+import org.apache.hivemind.conditional.Parser;
import org.apache.hivemind.parse.ModuleDescriptor;
import org.apache.hivemind.parse.SubModuleDescriptor;
import org.apache.hivemind.parse.XmlResourceProcessor;
@@ -73,6 +77,8 @@
*/
private XmlResourceProcessor _processor;
+ private Parser _conditionalExpressionParser;
+
/**
* Convenience constructor. Equivalent to using
* {@link #XmlModuleDescriptorProvider(ClassResolver, String)}with {@link #HIVE_MODULE_XML} as
@@ -206,7 +212,46 @@
continue;
}
- processResource(smd.getDescriptor());
+ // Only include the sub-module if the expression evaluates to true
+ if (includeSubModule(smd.getConditionalExpression(), moduleDescriptor
+ .getClassResolver(), smd.getLocation()))
+ processResource(smd.getDescriptor());
+ }
+ }
+
+ /**
+ * Filters a sub-module based on a condition expression. Returns true if the expression is null,
+ * or evaluates to true. Returns false if the expression if non-null and evaluates to false, or
+ * an exception occurs evaluating the expression.
+ *
+ * @param expression
+ * The expression to evaluate
+ * @param classResolver
+ * The <code>ClassResolver</code> to use for class lookups
+ * @param location
+ * The location from where the expression was loaded
+ * @since 1.1
+ */
+ private boolean includeSubModule(String expression, ClassResolver classResolver,
+ Location location)
+ {
+ 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;
}
}
Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java (original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java Thu Jun 22 07:42:39 2006
@@ -1171,6 +1171,7 @@
Resource descriptor = getResource().getRelativeResource(getAttribute("descriptor"));
smd.setDescriptor(descriptor);
+ smd.setConditionalExpression(getAttribute("if"));
md.addSubModule(smd);
}
Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties (original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties Thu Jun 22 07:42:39 2006
@@ -82,6 +82,7 @@
required.map.property=true
required.sub-module.descriptor=true
+required.sub-module.if=false
required.set-property.property=true
required.set-property.value=true
Modified: jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java (original)
+++ jakarta/hivemind/trunk/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java Thu Jun 22 07:42:39 2006
@@ -20,7 +20,7 @@
/**
* Descriptor for <sub-module> element.
- *
+ *
* @author Knut Wannheden
*/
public final class SubModuleDescriptor extends BaseLocatable
@@ -28,6 +28,8 @@
private Resource _descriptor;
+ private String _conditionalExpression;
+
public Resource getDescriptor()
{
return _descriptor;
@@ -36,6 +38,22 @@
public void setDescriptor(Resource descriptor)
{
_descriptor = descriptor;
+ }
+
+ /**
+ * @since 1.1.2
+ */
+ public String getConditionalExpression()
+ {
+ return _conditionalExpression;
+ }
+
+ /**
+ * @since 1.1.2
+ */
+ public void setConditionalExpression(String conditionalExpression)
+ {
+ _conditionalExpression = conditionalExpression;
}
public String toString()
Added: jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalIncludedSubmodule.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalIncludedSubmodule.xml?rev=416385&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalIncludedSubmodule.xml (added)
+++ jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalIncludedSubmodule.xml Thu Jun 22 07:42:39 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<module
+ id="hivemind.test.conditional.included.submodule"
+ version="1.0.0">
+
+ <sub-module descriptor="OuterModule.xml" if="class hivemind.test.IUniqueService"/>
+
+</module>
\ No newline at end of file
Added: jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalNotIncludedSubmodule.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalNotIncludedSubmodule.xml?rev=416385&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalNotIncludedSubmodule.xml (added)
+++ jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalNotIncludedSubmodule.xml Thu Jun 22 07:42:39 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2006 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<module
+ id="hivemind.test.conditional.not.included.submodule"
+ version="1.0.0">
+
+ <sub-module descriptor="OuterModule.xml" if="class hivemind.test.NonExistantClass"/>
+
+</module>
\ No newline at end of file
Modified: jakarta/hivemind/trunk/framework/src/test/hivemind/test/TestSubModule.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/test/hivemind/test/TestSubModule.java?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/hivemind/test/TestSubModule.java (original)
+++ jakarta/hivemind/trunk/framework/src/test/hivemind/test/TestSubModule.java Thu Jun 22 07:42:39 2006
@@ -16,6 +16,7 @@
import hivemind.test.services.SimpleService;
+import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Registry;
/**
@@ -44,6 +45,31 @@
buildFrameworkRegistry("MissingSubModule.xml");
assertLoggedMessagePattern("Sub-module .*?/DoesNotExist\\.xml does not exist\\.");
+ }
+
+ 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
+ {
+ Registry r = buildFrameworkRegistry("ConditionalNotIncludedSubmodule.xml");
+
+ try
+ {
+ r.getService("hivemind.test.outer.Simple", SimpleService.class);
+
+ fail("Service point hivemind.test.outer.Simple should not exist.");
+ }
+ catch (ApplicationRuntimeException e)
+ {
+ assertEquals("Service point hivemind.test.outer.Simple does not exist.", e.getMessage());
+ }
}
}
Added: jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/IncludeSubModule.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/IncludeSubModule.xml?rev=416385&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/IncludeSubModule.xml (added)
+++ jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/IncludeSubModule.xml Thu Jun 22 07:42:39 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2006 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<module id="hivemind.test.parse.include" version="1.0.0">
+
+ <service-point id="Barney" interface="package.MyService"/>
+
+</module>
Added: jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModule.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModule.xml?rev=416385&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModule.xml (added)
+++ jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModule.xml Thu Jun 22 07:42:39 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2006 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<module id="hivemind.test.parse" version="1.0.0">
+
+ <sub-module descriptor="IncludeSubModule.xml"/>
+
+</module>
Added: jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModuleIf.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModuleIf.xml?rev=416385&view=auto
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModuleIf.xml (added)
+++ jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModuleIf.xml Thu Jun 22 07:42:39 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 2006 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<module id="hivemind.test.parse" version="1.0.0">
+
+ <sub-module descriptor="IncludeSubModule.xml" if="class foo.bar.Blat"/>
+
+</module>
Modified: jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/TestDescriptorParser.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/TestDescriptorParser.java?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/TestDescriptorParser.java (original)
+++ jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/TestDescriptorParser.java Thu Jun 22 07:42:39 2006
@@ -37,6 +37,7 @@
import org.apache.hivemind.parse.InterceptorDescriptor;
import org.apache.hivemind.parse.ModuleDescriptor;
import org.apache.hivemind.parse.ServicePointDescriptor;
+import org.apache.hivemind.parse.SubModuleDescriptor;
import org.apache.hivemind.parse.XmlResourceProcessor;
import org.apache.hivemind.schema.AttributeModel;
import org.apache.hivemind.schema.ElementModel;
@@ -639,5 +640,25 @@
ServicePointDescriptor spd = (ServicePointDescriptor) md.getServicePoints().get(0);
assertEquals("hivemind.test.NoInterface", spd.getInterfaceClassName());
+ }
+
+ /** @since 1.1.2 */
+ 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());
+ }
+
+ /** @since 1.1.2 */
+ 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());
}
}
Modified: jakarta/hivemind/trunk/src/documentation/content/xdocs/conditional.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/src/documentation/content/xdocs/conditional.xml?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/src/documentation/content/xdocs/conditional.xml (original)
+++ jakarta/hivemind/trunk/src/documentation/content/xdocs/conditional.xml Thu Jun 22 07:42:39 2006
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
- Copyright 2004, 2005 The Apache Software Foundation
+ Copyright 2004, 2005, 2006 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -33,8 +33,8 @@
</p>
<p>
- A second method is to mark certain contributions (&contribution; and &implementation; elements) as conditional, using the
- <code>if</code> attribute.
+ A second method is to mark certain contributions (&contribution;, &implementation;, and &sub-module; elements) as
+ conditional, using the <code>if</code> attribute.
</p>
<p>
Modified: jakarta/hivemind/trunk/src/documentation/content/xdocs/descriptor.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/src/documentation/content/xdocs/descriptor.xml?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/src/documentation/content/xdocs/descriptor.xml (original)
+++ jakarta/hivemind/trunk/src/documentation/content/xdocs/descriptor.xml Thu Jun 22 07:42:39 2006
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
- Copyright 2004, 2005 The Apache Software Foundation
+ Copyright 2004, 2005, 2006 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -668,6 +668,12 @@
<td>yes</td>
<td>Location of the module descriptor.</td>
</tr>
+ <tr>
+ <td>if</td>
+ <td>string</td>
+ <td>no</td>
+ <td>A &conditional-expression; controlling whether the sub-module is included or ignored.</td>
+ </tr>
</table>
<p>The descriptor should be specified as a relative path, either the name
of another module descriptor within the same folder, or within a child
Modified: jakarta/hivemind/trunk/status.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/trunk/status.xml?rev=416385&r1=416384&r2=416385&view=diff
==============================================================================
--- jakarta/hivemind/trunk/status.xml (original)
+++ jakarta/hivemind/trunk/status.xml Thu Jun 22 07:42:39 2006
@@ -39,6 +39,8 @@
ServicePropertyFactory doesn't work</action>
<action type="add" dev="KW" fixes-bug="HIVEMIND-137">New "default" attribute for <attribute> element.</action>
<action type="add" dev="JC" fixes-bug="HIVEMIND-177">Allow for customization of "parameter index" in StrategyFactory.</action>
+ <action type="add" dev="KW" fixes-bug="HIVEMIND-85" due-to="Johan Lindquist">
+ New conditional "if" attribute to <sub-modules></action>
</release>
<release version="1.1.1" date="Jan 28 2006">
<action type="fix" dev="HLS" fixes-bug="HIVEMIND-162">Performance bottleneck with threaded
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org