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:54:05 UTC

svn commit: r416387 - in /jakarta/hivemind/branches/branch-1-1: ./ 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/co...

Author: knut
Date: Thu Jun 22 07:54:04 2006
New Revision: 416387

URL: http://svn.apache.org/viewvc?rev=416387&view=rev
Log:
ported r416385 (new "if" attribute for <sub-module>) from trunk to 1.1.2 release

Added:
    jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/ConditionalIncludedSubmodule.xml
      - copied unchanged from r416385, jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalIncludedSubmodule.xml
    jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/ConditionalNotIncludedSubmodule.xml
      - copied unchanged from r416385, jakarta/hivemind/trunk/framework/src/test/hivemind/test/ConditionalNotIncludedSubmodule.xml
    jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/IncludeSubModule.xml
      - copied unchanged from r416385, jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/IncludeSubModule.xml
    jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/SubModule.xml
      - copied unchanged from r416385, jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModule.xml
    jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/SubModuleIf.xml
      - copied unchanged from r416385, jakarta/hivemind/trunk/framework/src/test/hivemind/test/parse/SubModuleIf.xml
Modified:
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties
    jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java
    jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/TestSubModule.java
    jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/TestDescriptorParser.java
    jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/conditional.xml
    jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/descriptor.xml
    jakarta/hivemind/branches/branch-1-1/status.xml

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java (original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java Thu Jun 22 07:54:04 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.2
+     */
+    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/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java (original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java Thu Jun 22 07:54:04 2006
@@ -1170,6 +1170,7 @@
         Resource descriptor = getResource().getRelativeResource(getAttribute("descriptor"));
 
         smd.setDescriptor(descriptor);
+        smd.setConditionalExpression(getAttribute("if"));
 
         md.addSubModule(smd);
     }

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties (original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties Thu Jun 22 07:54:04 2006
@@ -81,6 +81,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/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java (original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java Thu Jun 22 07:54:04 2006
@@ -20,7 +20,7 @@
 
 /**
  * Descriptor for &lt;sub-module&gt; 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()

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/TestSubModule.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/TestSubModule.java?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/TestSubModule.java (original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/TestSubModule.java Thu Jun 22 07:54:04 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());
+        }
     }
 
 }

Modified: jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/TestDescriptorParser.java
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/TestDescriptorParser.java?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/TestDescriptorParser.java (original)
+++ jakarta/hivemind/branches/branch-1-1/framework/src/test/hivemind/test/parse/TestDescriptorParser.java Thu Jun 22 07:54:04 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;
@@ -638,5 +639,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/branches/branch-1-1/src/documentation/content/xdocs/conditional.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/conditional.xml?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/conditional.xml (original)
+++ jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/conditional.xml Thu Jun 22 07:54:04 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/branches/branch-1-1/src/documentation/content/xdocs/descriptor.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/descriptor.xml?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/descriptor.xml (original)
+++ jakarta/hivemind/branches/branch-1-1/src/documentation/content/xdocs/descriptor.xml Thu Jun 22 07:54:04 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.
@@ -659,6 +659,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/branches/branch-1-1/status.xml
URL: http://svn.apache.org/viewvc/jakarta/hivemind/branches/branch-1-1/status.xml?rev=416387&r1=416386&r2=416387&view=diff
==============================================================================
--- jakarta/hivemind/branches/branch-1-1/status.xml (original)
+++ jakarta/hivemind/branches/branch-1-1/status.xml Thu Jun 22 07:54:04 2006
@@ -35,7 +35,9 @@
       <action type="fix" dev="AH" fixes-bug="HIVEMIND-171">JMX Support does not work if you use the class directly as the interface</action>
       <action type="fix" dev="AH" >Start script of example classes not working because of wrong packages</action>
       <action type="add" dev="JC" fixes-bug="HIVEMIND-177">Allow for customization of &quot;parameter index&quot; in StrategyFactory.</action>
-    </release> 
+      <action type="add" dev="KW" fixes-bug="HIVEMIND-85" due-to="Johan Lindquist">
+        New conditional &quot;if&quot; attribute to &lt;sub-modules&gt;</action>
+    </release>
     <release version="1.1.1" date="Jan 28 2006">
       <action type="fix" dev="HLS" fixes-bug="HIVEMIND-162">Performance bottleneck with threaded services</action>
       <action type="fix" dev="HLS" fixes-bug="HIVEMIND-161">ThreadLocal object is never removed in ThreadEventNotifierImpl and holds the classloader</action>



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org