hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/hivebuild/hivedoc-xsl hivemind.xsl
Date Thu, 30 Dec 2004 18:55:33 GMT
hlship      2004/12/30 10:55:33

  Modified:    framework/src/test/hivemind/test/parse
                        TestDescriptorParser.java
               framework/src/test/org/apache/hivemind/impl
                        TestRegistryInfrastructureConstructor.java
               src/documentation/content/xdocs site.xml descriptor.xml
               framework/src/java/org/apache/hivemind/parse
                        ImplementationDescriptor.java DescriptorParser.java
                        DescriptorParser.properties
                        ContributionDescriptor.java
               framework/src/java/org/apache/hivemind/impl
                        RegistryInfrastructureConstructor.java
               library/src/descriptor/META-INF hivemodule.xml
               .        build.xml status.xml
               framework/src/java/org/apache/hivemind/ant
                        RegistrySerializer.java
               hivebuild/hivedoc-xsl hivemind.xsl
  Added:       framework/src/test/hivemind/test/parse ImplementationIf.xml
                        ContributionIf.xml
               src/documentation/content/xdocs conditional.xml
  Log:
  Finish implemenation of conditional contributions.
  
  Revision  Changes    Path
  1.29      +24 -0     jakarta-hivemind/framework/src/test/hivemind/test/parse/TestDescriptorParser.java
  
  Index: TestDescriptorParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/parse/TestDescriptorParser.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- TestDescriptorParser.java	20 Dec 2004 15:25:23 -0000	1.28
  +++ TestDescriptorParser.java	30 Dec 2004 18:55:32 -0000	1.29
  @@ -560,4 +560,28 @@
           assertEquals("hivemind.test.parse", s.getModuleId());
           assertEquals(Visibility.PRIVATE, s.getVisibility());
       }
  +
  +    /** @since 1.1 */
  +
  +    public void testContributionIf() throws Exception
  +    {
  +        ModuleDescriptor md = parse("ContributionIf.xml");
  +
  +        List l = md.getContributions();
  +        ContributionDescriptor cd = (ContributionDescriptor) l.get(0);
  +
  +        assertEquals("class foo.bar.Blat", cd.getConditionalExpression());
  +    }
  +
  +    /** @since 1.1 */
  +
  +    public void testImplementationIf() throws Exception
  +    {
  +        ModuleDescriptor md = parse("ImplementationIf.xml");
  +
  +        List l = md.getImplementations();
  +        ImplementationDescriptor id = (ImplementationDescriptor) l.get(0);
  +
  +        assertEquals("class foo.bar.Blat", id.getConditionalExpression());
  +    }
   }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/parse/ImplementationIf.xml
  
  Index: ImplementationIf.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004 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">
  
    <implementation service-id="foo.bar.Baz" if="class foo.bar.Blat">
      <interceptor service-id="hivemind.LoggingInterceptor"/>
    </implementation>
  
  </module>
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/parse/ContributionIf.xml
  
  Index: ContributionIf.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004 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">
  
    <contribution configuration-id="foo.bar.Baz" if="class foo.bar.Blat">
      <zip zap="zoom"/>
    </contribution>
  
  </module>
  
  
  
  1.3       +145 -0    jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructureConstructor.java
  
  Index: TestRegistryInfrastructureConstructor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestRegistryInfrastructureConstructor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestRegistryInfrastructureConstructor.java	20 Dec 2004 15:25:21 -0000	1.2
  +++ TestRegistryInfrastructureConstructor.java	30 Dec 2004 18:55:32 -0000	1.3
  @@ -14,18 +14,24 @@
   
   package org.apache.hivemind.impl;
   
  +import java.util.List;
   import java.util.Locale;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.hivemind.Element;
   import org.apache.hivemind.ErrorHandler;
   import org.apache.hivemind.Location;
   import org.apache.hivemind.internal.ConfigurationPoint;
   import org.apache.hivemind.internal.RegistryInfrastructure;
   import org.apache.hivemind.parse.ConfigurationPointDescriptor;
  +import org.apache.hivemind.parse.ContributionDescriptor;
   import org.apache.hivemind.parse.ModuleDescriptor;
   import org.apache.hivemind.schema.Schema;
  +import org.apache.hivemind.test.AggregateArgumentsMatcher;
  +import org.apache.hivemind.test.ArgumentMatcher;
   import org.apache.hivemind.test.HiveMindTestCase;
  +import org.apache.hivemind.test.TypeMatcher;
   import org.easymock.MockControl;
   
   /**
  @@ -157,6 +163,145 @@
           ric.addModuleDescriptor(zipZoop);
   
           ric.constructRegistryInfrastructure(Locale.getDefault());
  +
  +        verifyControls();
  +    }
  +
  +    private Element newElement(String name)
  +    {
  +        ElementImpl e = new ElementImpl();
  +
  +        e.setElementName(name);
  +
  +        return e;
  +    }
  +
  +    public void testConditionalExpressionTrue()
  +    {
  +        MockControl ehControl = newControl(ErrorHandler.class);
  +        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
  +
  +        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
  +
  +        replayControls();
  +
  +        ModuleDescriptor md = new ModuleDescriptor(new DefaultClassResolver(), eh);
  +        md.setModuleId("zip.zoop");
  +
  +        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
  +
  +        cpd.setId("Fred");
  +
  +        md.addConfigurationPoint(cpd);
  +
  +        ContributionDescriptor cd = new ContributionDescriptor();
  +        cd.setConfigurationId("Fred");
  +        cd.setConditionalExpression("class " + Location.class.getName());
  +
  +        cd.addElement(newElement("foo"));
  +
  +        md.addContribution(cd);
  +
  +        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
  +
  +        ric.addModuleDescriptor(md);
  +
  +        RegistryInfrastructure ri = ric.constructRegistryInfrastructure(Locale.getDefault());
  +
  +        List l = ri.getConfiguration("zip.zoop.Fred", null);
  +
  +        Element e = (Element) l.get(0);
  +
  +        assertEquals("foo", e.getElementName());
  +
  +        verifyControls();
  +    }
  +
  +    public void testConditionalExpressionFalse()
  +    {
  +        MockControl ehControl = newControl(ErrorHandler.class);
  +        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
  +
  +        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
  +
  +        replayControls();
  +
  +        ModuleDescriptor md = new ModuleDescriptor(new DefaultClassResolver(), eh);
  +        md.setModuleId("zip.zoop");
  +
  +        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
  +
  +        cpd.setId("Fred");
  +
  +        md.addConfigurationPoint(cpd);
  +
  +        ContributionDescriptor cd = new ContributionDescriptor();
  +        cd.setConfigurationId("Fred");
  +        cd.setConditionalExpression("class foo.bar.Baz");
  +
  +        cd.addElement(newElement("bar"));
  +
  +        md.addContribution(cd);
  +
  +        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
  +
  +        ric.addModuleDescriptor(md);
  +
  +        RegistryInfrastructure ri = ric.constructRegistryInfrastructure(Locale.getDefault());
  +
  +        List l = ri.getConfiguration("zip.zoop.Fred", null);
  +
  +        assertTrue(l.isEmpty());
  +
  +        verifyControls();
  +    }
  +
  +    public void testConditionalExpressionError()
  +    {
  +        MockControl ehControl = newControl(ErrorHandler.class);
  +        ErrorHandler eh = (ErrorHandler) ehControl.getMock();
  +
  +        Log log = LogFactory.getLog(TestRegistryInfrastructureConstructor.class);
  +
  +        Location location = fabricateLocation(1);
  +
  +        eh.error(
  +                log,
  +                "Unexpected token <AND> in expression 'and class foo'.",
  +                location,
  +                new RuntimeException());
  +        ehControl.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[]
  +        { null, null, null, new TypeMatcher() }));
  +
  +        replayControls();
  +
  +        ModuleDescriptor md = new ModuleDescriptor(new DefaultClassResolver(), eh);
  +        md.setModuleId("zip.zoop");
  +
  +        ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
  +
  +        cpd.setId("Fred");
  +
  +        md.addConfigurationPoint(cpd);
  +
  +        ContributionDescriptor cd = new ContributionDescriptor();
  +        cd.setConfigurationId("Fred");
  +        cd.setConditionalExpression("and class foo");
  +        cd.setLocation(location);
  +
  +        cd.addElement(newElement("bar"));
  +
  +        md.addContribution(cd);
  +
  +        RegistryInfrastructureConstructor ric = new RegistryInfrastructureConstructor(eh,
log, null);
  +
  +        ric.addModuleDescriptor(md);
  +
  +        RegistryInfrastructure ri = ric.constructRegistryInfrastructure(Locale.getDefault());
  +
  +        List l = ri.getConfiguration("zip.zoop.Fred", null);
  +
  +        assertTrue(l.isEmpty());
   
           verifyControls();
       }
  
  
  
  1.35      +1 -0      jakarta-hivemind/src/documentation/content/xdocs/site.xml
  
  Index: site.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/src/documentation/content/xdocs/site.xml,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- site.xml	19 Nov 2004 20:28:49 -0000	1.34
  +++ site.xml	30 Dec 2004 18:55:32 -0000	1.35
  @@ -34,6 +34,7 @@
   			<descriptor label="Module  Descriptor" href="descriptor.html"/>
   			<rules label="Contribution Processing Rules" href="rules.html"/>
         <dependencies label="Dependencies" href="dependencies.html"/>
  +      <conditional label="Conditional Contributions" href="conditional.html"/>
    		</reference>
   
       <project-info label="Project Information">
  
  
  
  1.17      +13 -0     jakarta-hivemind/src/documentation/content/xdocs/descriptor.xml
  
  Index: descriptor.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/src/documentation/content/xdocs/descriptor.xml,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- descriptor.xml	20 Dec 2004 15:25:23 -0000	1.16
  +++ descriptor.xml	30 Dec 2004 18:55:32 -0000	1.17
  @@ -17,6 +17,7 @@
   <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.3//EN"
   	"http://xml.apache.org/forrest/dtd/document-v13.dtd" [
   	<!ENTITY % common-links SYSTEM "links.ent">
  +  <!ENTITY conditional-expression '<link href="site:conditional">conditional expression</link>'>
   	%common-links;
   	]>
   <document>
  @@ -150,6 +151,12 @@
   						the fully qualified id of an &_configuration-point; in another
   						module.</td>
   				</tr>
  +        <tr>
  +          <td>if</td>
  +          <td>string</td>
  +          <td>no</td>
  +          <td>A &conditional-expression; controlling whether the contribution
is used or ignored.</td>
  +        </tr>
   			</table>
   			<p>The content of the &_contribution; consists of elements. These elements
   				are converted, in accordance with the configuration point's &schema;,
  @@ -313,6 +320,12 @@
   					<td>The id of the service to extend; this may be a fully qualified id,
   						or the local id of a service within the same module.</td>
   				</tr>
  +       <tr>
  +          <td>if</td>
  +          <td>string</td>
  +          <td>no</td>
  +          <td>A &conditional-expression; controlling whether the contribution
is used or ignored.</td>
  +        </tr>        
   			</table>
   			<p>Contains: &create-instance;, &interceptor;, &invoke-factory; </p>
   		</section>
  
  
  
  1.1                  jakarta-hivemind/src/documentation/content/xdocs/conditional.xml
  
  Index: conditional.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004 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.
  -->
  <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.3//EN"
  	"http://xml.apache.org/forrest/dtd/document-v13.dtd" [
  	<!ENTITY % common-links SYSTEM "links.ent">
  	%common-links;
  	]>
  <document>
    <header>
      <title>Conditional Contributions</title>
    </header>
    
    <body>
      <p>
        In certain cases, it is desirable to <em>conditionally contribute</em>
to a configuration point, or to a
        service point. One way of doing this is to factor the contributions into their own
module, and control whether that
        module (and its descriptor) is on the classpath at runtime. This can be cumbersome,
however.
      </p>
      
      <p>
        A second method is to mark certain contributions (&contribution; and &implementation;
elements) as conditional, using the
        <code>if</code> attribute.
      </p>
      
      <p>
        When the <code>if</code> attribute is non-null, it is evaluated as a <em>conditional
expression</em>.  If the expression
        evaluates to true, then the contribution is used.  If false, the the contribution
is silently discarded.  The expression
        evaluation occurs while the Registry is being constructed.
      </p>
      
      <p>
        This mechanism allows you to test for certain conditions, such as the presense of
a 
        particular class or a particular JVM system property.  These basic conditions can
be combined with
        and, or and not operators, and parenthesis to control order of evaluation.
      </p>
      
      <p>
        For example, the expression <code>class org.springframework.beans.factory.BeanFactory</code>
would evaluate to true if the BeanFactory
        class was on the classpath.
      </p>
      
      <p>
        The format for conditional expressions is:
      </p>
      
  <source>
  expression := <em>term</em> <code>or</code> <em>expression</em>
             := <em>term</em> <code>and</code> <em>expression</em>
             := <em>term</em>
             
  term       := ( <em>expression</em> )
             := <code>not</code> ( <em>expression</em> )
             := <code>property</code> <em>symbol</em>
             := <code>class</code> <em>symbol</em>
  </source>
             
  <p>
  The keywords ("and", "or", "not", "property", "class") are <em>not</em> case
sensitive.
  </p>  
  
  <p>
  Symbols are Java identifiers ... they are either JVM system properties or fully qualified
Java class names.
  </p>
  
  <p>
  Whitespace is ignored.
  </p>
  
  <p>
  The <code>property</code> keyword treats its symbol as a JVM system property,
as with <code>Boolean.getBoolean()</code>.
  </p>
  
  <p>
  The <code>class</code> keyword treats its symbol as a Java class name, evaluating
to true if such a class exists.
  </p>
      
      
    </body>
    
  </document>
  
  
  1.5       +17 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ImplementationDescriptor.java
  
  Index: ImplementationDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ImplementationDescriptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ImplementationDescriptor.java	19 Dec 2004 15:43:07 -0000	1.4
  +++ ImplementationDescriptor.java	30 Dec 2004 18:55:32 -0000	1.5
  @@ -25,6 +25,10 @@
   {
       private String _serviceId;
   
  +    /** @since 1.1 */
  +
  +    private String _conditionalExpression;
  +
       public String getServiceId()
       {
           return _serviceId;
  @@ -38,5 +42,18 @@
       protected void extendDescription(ToStringBuilder builder)
       {
           builder.append("serviceId", _serviceId);
  +        builder.append("conditionalExpression", _conditionalExpression);
  +    }
  +
  +    /** @since 1.1 */
  +    public String getConditionalExpression()
  +    {
  +        return _conditionalExpression;
  +    }
  +
  +    /** @since 1.1 */
  +    public void setConditionalExpression(String conditionalExpression)
  +    {
  +        _conditionalExpression = conditionalExpression;
       }
   }
  
  
  
  1.45      +2 -0      jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java
  
  Index: DescriptorParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- DescriptorParser.java	28 Dec 2004 22:43:15 -0000	1.44
  +++ DescriptorParser.java	30 Dec 2004 18:55:32 -0000	1.45
  @@ -763,6 +763,7 @@
           checkAttributes();
   
           cd.setConfigurationId(getAttribute("configuration-id"));
  +        cd.setConditionalExpression(getAttribute("if"));
   
           md.addContribution(cd);
       }
  @@ -907,6 +908,7 @@
           checkAttributes();
   
           id.setServiceId(getAttribute("service-id"));
  +        id.setConditionalExpression(getAttribute("if"));
   
           md.addImplementation(id);
       }
  
  
  
  1.16      +2 -0      jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties
  
  Index: DescriptorParser.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DescriptorParser.properties	20 Dec 2004 15:25:23 -0000	1.15
  +++ DescriptorParser.properties	30 Dec 2004 18:55:32 -0000	1.16
  @@ -22,6 +22,7 @@
   required.module.version=true
   
   required.contribution.configuration-id=true
  +required.contribution.if=false
   
   required.configuration-point.id=true
   required.configuration-point.occurs=false
  @@ -35,6 +36,7 @@
   required.service-point.visibility=false
   
   required.implementation.service-id=true
  +required.implementation.if=false
   
   required.create-instance.class=true
   required.create-instance.model=false
  
  
  
  1.5       +19 -4     jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ContributionDescriptor.java
  
  Index: ContributionDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ContributionDescriptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContributionDescriptor.java	14 Oct 2004 14:31:31 -0000	1.4
  +++ ContributionDescriptor.java	30 Dec 2004 18:55:32 -0000	1.5
  @@ -23,7 +23,7 @@
   
   /**
    * Descriptor for &lt;contribution&gt; element.
  - *
  + * 
    * @author Howard Lewis Ship
    */
   public final class ContributionDescriptor extends BaseAnnotationHolder
  @@ -32,9 +32,12 @@
   
       private List _elements;
   
  +    /** @since 1.1 */
  +    private String _conditionalExpression;
  +
       /**
  -     * Returns the extension id, which may be a local id (simple name)
  -     * or an extended id (including a module id prefix).
  +     * Returns the extension id, which may be a local id (simple name) or an extended id
(including
  +     * a module id prefix).
        */
       public String getConfigurationId()
       {
  @@ -50,6 +53,7 @@
       {
           ToStringBuilder builder = new ToStringBuilder(this);
           builder.append("configurationId", _configurationId);
  +        builder.append("conditionalExpression", _conditionalExpression);
   
           return builder.toString();
       }
  @@ -70,4 +74,15 @@
           return _elements;
       }
   
  -}
  +    /** @since 1.1 */
  +    public String getConditionalExpression()
  +    {
  +        return _conditionalExpression;
  +    }
  +
  +    /** @since 1.1 */
  +    public void setConditionalExpression(String conditionalExpression)
  +    {
  +        _conditionalExpression = conditionalExpression;
  +    }
  +}
  \ No newline at end of file
  
  
  
  1.8       +50 -4     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java
  
  Index: RegistryInfrastructureConstructor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureConstructor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RegistryInfrastructureConstructor.java	19 Dec 2004 15:43:07 -0000	1.7
  +++ RegistryInfrastructureConstructor.java	30 Dec 2004 18:55:32 -0000	1.8
  @@ -26,6 +26,9 @@
   import org.apache.hivemind.Location;
   import org.apache.hivemind.Occurances;
   import org.apache.hivemind.ShutdownCoordinator;
  +import org.apache.hivemind.conditional.EvaluationContextImpl;
  +import org.apache.hivemind.conditional.Node;
  +import org.apache.hivemind.conditional.Parser;
   import org.apache.hivemind.internal.ConfigurationPoint;
   import org.apache.hivemind.internal.Module;
   import org.apache.hivemind.internal.RegistryInfrastructure;
  @@ -59,6 +62,10 @@
   
       private RegistryAssembly _assembly;
   
  +    /** @since 1.1 */
  +
  +    private Parser _conditionalExpressionParser;
  +
       public RegistryInfrastructureConstructor(ErrorHandler errorHandler, Log log,
               RegistryAssembly assembly)
       {
  @@ -397,6 +404,10 @@
           {
               ImplementationDescriptor impl = (ImplementationDescriptor) implementations.get(i);
   
  +            if (!includeContribution(impl.getConditionalExpression(), sourceModule, impl
  +                    .getLocation()))
  +                continue;
  +
               String pointId = impl.getServiceId();
               String qualifiedId = IdUtils.qualify(moduleId, pointId);
   
  @@ -417,6 +428,9 @@
           {
               ContributionDescriptor cd = (ContributionDescriptor) contributions.get(i);
   
  +            if (!includeContribution(cd.getConditionalExpression(), sourceModule, cd.getLocation()))
  +                continue;
  +
               String pointId = cd.getConfigurationId();
               String qualifiedId = IdUtils.qualify(moduleId, pointId);
   
  @@ -542,6 +556,7 @@
           for (int i = 0; i < count; i++)
           {
               InterceptorDescriptor ind = (InterceptorDescriptor) interceptors.get(i);
  +
               addInterceptor(sourceModule, pointId, ind);
           }
       }
  @@ -577,8 +592,6 @@
               return;
           }
   
  -        
  -        
           if (point.getServiceConstructor(isDefault) != null)
           {
               _errorHandler.error(
  @@ -589,8 +602,7 @@
   
               return;
           }
  -        
  -        
  +
           point.setServiceModel(builder.getServiceModel());
           point.setServiceConstructor(builder.createConstructor(point, sourceModule), isDefault);
       }
  @@ -678,6 +690,40 @@
                       expected), point.getLocation(), null);
           }
   
  +    }
  +
  +    /**
  +     * Filters a contribution based on an 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
  +     *            to parse and evaluate
  +     * @param location
  +     *            of the expression (used if an error is reported)
  +     * @since 1.1
  +     */
  +
  +    private boolean includeContribution(String expression, Module module, Location location)
  +    {
  +        if (expression == null)
  +            return true;
  +
  +        if (_conditionalExpressionParser == null)
  +            _conditionalExpressionParser = new Parser();
  +
  +        try
  +        {
  +            Node node = _conditionalExpressionParser.parse(expression);
  +
  +            return node.evaluate(new EvaluationContextImpl(module.getClassResolver()));
  +        }
  +        catch (RuntimeException ex)
  +        {
  +            _errorHandler.error(_log, ex.getMessage(), location, ex);
  +
  +            return false;
  +        }
       }
   
       private static int size(Collection c)
  
  
  
  1.18      +1 -1      jakarta-hivemind/library/src/descriptor/META-INF/hivemodule.xml
  
  Index: hivemodule.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/library/src/descriptor/META-INF/hivemodule.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- hivemodule.xml	19 Dec 2004 15:41:45 -0000	1.17
  +++ hivemodule.xml	30 Dec 2004 18:55:32 -0000	1.18
  @@ -15,7 +15,7 @@
      limitations under the License.
   -->
   
  -<module id="hivemind.lib" version="1.0.0">
  +<module id="hivemind.lib" version="1.1.0">
     
     Standard library for HiveMind, providing commonly used services.
       
  
  
  
  1.12      +1 -3      jakarta-hivemind/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/build.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.xml	28 Oct 2004 22:09:53 -0000	1.11
  +++ build.xml	30 Dec 2004 18:55:32 -0000	1.12
  @@ -32,9 +32,7 @@
          descriptors.  -->
     
     <path id="hivedoc.classpath">
  -    <fileset dir="${target.dir}" includes="*.jar"/>
  -    <!-- Pick up some hivemind dependencies -->
  -    <fileset dir="${external.lib.dir}" includes="**/*.jar"/>
  +    <fileset dir="${external.lib.dir}" includes="*.jar"/>
     </path>  
     
   	<import file="${hivebuild.dir}/hivedoc-report.xml"/>
  
  
  
  1.88      +4 -1      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- status.xml	22 Dec 2004 00:11:02 -0000	1.87
  +++ status.xml	30 Dec 2004 18:55:32 -0000	1.88
  @@ -124,8 +124,11 @@
        <action type="update" dev="HLS">
         Move ContextResource from Tapestry to HiveMind.
        </action>
  -     <action type="change" dev="HLS">
  +     <action type="update" dev="HLS">
         Change HiveMindFilter load WEB-INF/hivemodule.xml if present.
  +     </action>
  +     <action type="add" dev="HLS">
  +      Add support for conditional contributions.
        </action>
       </release>
   
  
  
  
  1.8       +6 -0      jakarta-hivemind/framework/src/java/org/apache/hivemind/ant/RegistrySerializer.java
  
  Index: RegistrySerializer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/ant/RegistrySerializer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RegistrySerializer.java	28 Dec 2004 22:43:15 -0000	1.7
  +++ RegistrySerializer.java	30 Dec 2004 18:55:33 -0000	1.8
  @@ -381,6 +381,9 @@
   
           contribution.setAttribute("configuration-id", qualify(cd.getConfigurationId()));
   
  +        if (cd.getConditionalExpression() != null)
  +            contribution.setAttribute("if", cd.getConditionalExpression());
  +
           contribution.setAttribute("uid", Integer.toString(_uid++));
   
           List parameters = cd.getElements();
  @@ -407,6 +410,9 @@
           Element implementation = _document.createElement("implementation");
   
           implementation.setAttribute("service-id", qualify(id.getServiceId()));
  +
  +        if (id.getConditionalExpression() != null)
  +            implementation.setAttribute("if", id.getConditionalExpression());
   
           implementation.setAttribute("uid", Integer.toString(_uid++));
   
  
  
  
  1.6       +12 -0     jakarta-hivemind/hivebuild/hivedoc-xsl/hivemind.xsl
  
  Index: hivemind.xsl
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/hivebuild/hivedoc-xsl/hivemind.xsl,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- hivemind.xsl	27 Sep 2004 14:37:35 -0000	1.5
  +++ hivemind.xsl	30 Dec 2004 18:55:33 -0000	1.6
  @@ -260,6 +260,9 @@
               <xsl:sort select="../@id"/>
               <h3>Contributions from module <a href="../module/{../@id}.html#{@uid}">
<xsl:value-of select="../@id"/> 
                 </a> </h3>
  +            <xsl:if test="@if">
  +              <p><em>If: <xsl:value-of select="@if"/></em></p>
  +            </xsl:if>  
               <ul>
                 <xsl:apply-templates select="*" mode="raw"/>
               </ul>
  @@ -392,6 +395,9 @@
     <xsl:template match="contribution">
       <h2> <xsl:attribute name="id"><xsl:value-of select="@uid"/></xsl:attribute>
Contribution to <xsl:apply-templates 
         select="/registry/module/configuration-point[@id = current()/@configuration-id]"
mode="link"/> </h2>
  +    <xsl:if test="@if">
  +      <p><em>If: <xsl:value-of select="@if"/></em></p>
  +    </xsl:if>       
       <ul>
         <xsl:apply-templates mode="raw"/>
       </ul>
  @@ -460,6 +466,9 @@
               <xsl:sort select="../@id"/>
               <h3>Implementations from module <a href="../module/{../@id}.html#{@uid}">
<xsl:value-of select="../@id"/> 
                 </a> </h3>
  +              <xsl:if test="@if">
  +                <p><em>If: <xsl:value-of select="@if"/></em></p>
  +              </xsl:if>                     
               <ul>
                 <xsl:apply-templates/>
               </ul>
  @@ -477,6 +486,9 @@
     <xsl:template match="implementation">
       <h2> <xsl:attribute name="id"><xsl:value-of select="@uid"/></xsl:attribute>
Service Implementation 
         <xsl:apply-templates select="/registry/module/service-point[@id = current()/@service-id]"
mode="link"/> </h2>
  +      <xsl:if test="@if">
  +        <p><em>If: <xsl:value-of select="@if"/></em></p>
  +      </xsl:if>       
       <ul>
         <xsl:apply-templates/>
       </ul>
  
  
  

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


Mime
View raw message