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/framework/src/test/hivemind/test/config ComplexNameItem.java
Date Thu, 15 Apr 2004 03:40:34 GMT
hlship      2004/04/14 20:40:34

  Modified:    framework/src/java/org/apache/hivemind/impl
                        RegistryBuilder.java RegistryAssemblyImpl.java
                        ModuleImpl.java RegistryAssembly.java
               framework/src/java/org/apache/hivemind
                        HiveMindMessages.properties
               common   links.xml
               xdocs    descriptor.xml
               framework/src/java/org/apache/hivemind/parse
                        ModuleDescriptor.java DescriptorParser.java
               framework/src/test/hivemind/test/config ComplexNameItem.java
  Added:       framework/src/test/hivemind/test TestSubModule.java
                        hivemind.test.outer.submodule.xml OuterModule.xml
               framework/src/java/org/apache/hivemind/parse
                        ElementParseInfo.java DescriptorParser.properties
  Log:
  Add support for <sub-module> element in module descriptors.
  
  Revision  Changes    Path
  1.3       +21 -19    jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java
  
  Index: RegistryBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RegistryBuilder.java	7 Apr 2004 20:03:08 -0000	1.2
  +++ RegistryBuilder.java	15 Apr 2004 03:40:34 -0000	1.3
  @@ -25,7 +25,6 @@
   import java.util.Locale;
   import java.util.Map;
   
  -import org.apache.hivemind.util.URLResource;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.hivemind.ApplicationRuntimeException;
  @@ -44,6 +43,7 @@
   import org.apache.hivemind.parse.InterceptorDescriptor;
   import org.apache.hivemind.parse.ModuleDescriptor;
   import org.apache.hivemind.parse.ServicePointDescriptor;
  +import org.apache.hivemind.util.URLResource;
   
   /**
    * Class used to build a {@link org.apache.hivemind.Registry} from individual
  @@ -183,7 +183,6 @@
   
           ClassLoader loader = resolver.getClassLoader();
           Enumeration e = null;
  -        int count = 0;
   
           try
           {
  @@ -202,10 +201,9 @@
           while (e.hasMoreElements())
           {
               URL descriptorURL = (URL) e.nextElement();
  -            Resource descriptorLocation = new URLResource(descriptorURL);
  +            Resource descriptorResource = new URLResource(descriptorURL);
   
  -            if (processModuleResource(resolver, descriptorLocation))
  -                count++;
  +            processModuleResource(resolver, descriptorResource);
           }
       }
   
  @@ -220,7 +218,7 @@
           processModuleResource(resolver, moduleResource);
       }
   
  -    private boolean processModuleResource(ClassResolver resolver, Resource moduleResource)
  +    private void processModuleResource(ClassResolver resolver, Resource moduleResource)
       {
           if (_parser == null)
               _parser = new DescriptorParser(_registryAssembly);
  @@ -229,9 +227,17 @@
           {
               ModuleDescriptor md = _parser.parse(moduleResource, resolver);
   
  -            processModule(resolver, md);
  +            processModule(md);
  +
  +            // After parsing a module, parse any additional modules identified
  +            // within the module (using the <sub-module> element.
   
  -            return true;
  +            while (_registryAssembly.moreQueuedModules())
  +            {
  +                md = _registryAssembly.parseNextQueued(_parser);
  +
  +                processModule(md);
  +            }
           }
           catch (RuntimeException ex)
           {
  @@ -241,8 +247,6 @@
               _parser = null;
   
               _errorHandler.handleModuleParseError(moduleResource, ex);
  -
  -            return false;
           }
       }
   
  @@ -250,10 +254,9 @@
        * Processes a parsed HiveMind module descriptor.  This may be called
        * repeatedly before invoking {@link #constructRegistry(Locale)}.
        * 
  -     * @param resolver A resolver used to access resources and classes within the module.
        * @param md the parsed module descriptor
        */
  -    public void processModule(ClassResolver resolver, ModuleDescriptor md)
  +    public void processModule(ModuleDescriptor md)
       {
           String id = md.getModuleId();
   
  @@ -279,7 +282,7 @@
   
           module.setLocation(md.getLocation());
           module.setModuleId(id);
  -        module.setResourceResolver(resolver);
  +        module.setClassResolver(md.getClassResolver());
   
           _modules.put(id, module);
   
  @@ -332,11 +335,6 @@
               point.setServiceInterfaceName(sd.getInterfaceClassName());
               point.setParametersSchema(sd.getParametersSchema());
   
  -            ServiceModelType modelType = sd.getInstanceBuilder().getServiceModelType();
  -            ServiceModel model = constructServiceModel(point, modelType);
  -
  -            point.setServiceModel(model);
  -
               point.setShutdownCoordinator(_shutdownCoordinator);
   
               module.addServicePoint(point);
  @@ -636,6 +634,10 @@
                       sep.getServiceConstructor().getContributingModule().getModuleId()));
               return;
           }
  +
  +        ServiceModel model = constructServiceModel(sep, builder.getServiceModelType());
  +
  +        sep.setServiceModel(model);
   
           sep.setServiceConstructor(builder.createConstructor(sep, sourceModule));
       }
  
  
  
  1.3       +47 -1     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssemblyImpl.java
  
  Index: RegistryAssemblyImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssemblyImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RegistryAssemblyImpl.java	28 Feb 2004 00:34:37 -0000	1.2
  +++ RegistryAssemblyImpl.java	15 Apr 2004 03:40:34 -0000	1.3
  @@ -21,7 +21,11 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.hivemind.ClassResolver;
   import org.apache.hivemind.HiveMind;
  +import org.apache.hivemind.Resource;
  +import org.apache.hivemind.parse.DescriptorParser;
  +import org.apache.hivemind.parse.ModuleDescriptor;
   import org.apache.hivemind.schema.Schema;
   
   /**
  @@ -36,6 +40,24 @@
   
       private List _runnables = new ArrayList();
       private Map _schemas = new HashMap();
  +    private List _queuedModules = new ArrayList();
  +
  +    private static class QueuedModule
  +    {
  +        private Resource _resource;
  +        private ClassResolver _resolver;
  +
  +        QueuedModule(Resource resource, ClassResolver resolver)
  +        {
  +            _resource = resource;
  +            _resolver = resolver;
  +        }
  +
  +        ModuleDescriptor parse(DescriptorParser parser)
  +        {
  +            return parser.parse(_resource, _resolver);
  +        }
  +    }
   
       public void addSchema(String schemaId, Schema schema)
       {
  @@ -82,4 +104,28 @@
           }
       }
   
  +    public void enqueueModuleParse(Resource resource, ClassResolver resolver)
  +    {
  +        QueuedModule qm = new QueuedModule(resource, resolver);
  +        _queuedModules.add(qm);
  +    }
  +
  +    /**
  +     * Returns true if there are yet more queued models to be parsed.
  +     * 
  +     */
  +    public boolean moreQueuedModules()
  +    {
  +        return !_queuedModules.isEmpty();
  +    }
  +
  +    /**
  +     * Parses the next enqueued module descripotor and returns it.
  +     */
  +    public ModuleDescriptor parseNextQueued(DescriptorParser parser)
  +    {
  +        QueuedModule qm = (QueuedModule) _queuedModules.remove(0);
  +
  +        return qm.parse(parser);
  +    }
   }
  
  
  
  1.2       +2 -2      jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java
  
  Index: ModuleImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModuleImpl.java	26 Feb 2004 23:07:40 -0000	1.1
  +++ ModuleImpl.java	15 Apr 2004 03:40:34 -0000	1.2
  @@ -146,7 +146,7 @@
           _registry = registry;
       }
   
  -    public void setResourceResolver(ClassResolver resolver)
  +    public void setClassResolver(ClassResolver resolver)
       {
           _resolver = resolver;
       }
  
  
  
  1.3       +35 -27    jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssembly.java
  
  Index: RegistryAssembly.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryAssembly.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RegistryAssembly.java	28 Feb 2004 00:34:37 -0000	1.2
  +++ RegistryAssembly.java	15 Apr 2004 03:40:34 -0000	1.3
  @@ -14,6 +14,8 @@
   
   package org.apache.hivemind.impl;
   
  +import org.apache.hivemind.ClassResolver;
  +import org.apache.hivemind.Resource;
   import org.apache.hivemind.schema.Schema;
   
   /**
  @@ -24,30 +26,36 @@
    */
   public interface RegistryAssembly
   {
  -	/**
  -	 * Records a schema that may be referenced elsewhere within a module, or by some
  -	 * other module entirely.
  -	 * 
  -	 * @param schemaId fully qualified id for the schema.
  -	 * @param schema the Schema to be recorded for later reference
  -	 */
  -	public void addSchema(String schemaId, Schema schema);
  -	
  -	/**
  -	 * Returns a reference to a schema previously recorded by
  -	 * {@link #addSchema(String, Schema)}.
  -	 * 
  -	 * @param schemaId fully qualified schema id
  -	 * @return the schema, or null if no such schema exists
  -	 */
  -	
  -	public Schema getSchema(String schemaId);
  -	
  -	/**
  -	 * Adds a {@link Runnable} object that will be called after all
  -	 * modules have been parsed. This is intended to support
  -	 * support forward references to schemas.
  -	 */
  -	
  -	public void addPostProcessor(Runnable postProcessor);
  +    /**
  +     * Records a schema that may be referenced elsewhere within a module, or by some
  +     * other module entirely.
  +     * 
  +     * @param schemaId fully qualified id for the schema.
  +     * @param schema the Schema to be recorded for later reference
  +     */
  +    public void addSchema(String schemaId, Schema schema);
  +
  +    /**
  +     * Returns a reference to a schema previously recorded by
  +     * {@link #addSchema(String, Schema)}.
  +     * 
  +     * @param schemaId fully qualified schema id
  +     * @return the schema, or null if no such schema exists
  +     */
  +
  +    public Schema getSchema(String schemaId);
  +
  +    /**
  +     * Adds a {@link Runnable} object that will be called after all
  +     * modules have been parsed. This is intended to support
  +     * support forward references to schemas.
  +     */
  +
  +    public void addPostProcessor(Runnable postProcessor);
  +
  +    /**
  +     * Enqueues another module to be parsed.
  +     */
  +
  +    public void enqueueModuleParse(Resource resource, ClassResolver resolver);
   }
  
  
  
  1.6       +3 -1      jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties
  
  Index: HiveMindMessages.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- HiveMindMessages.properties	1 Mar 2004 22:56:27 -0000	1.5
  +++ HiveMindMessages.properties	15 Apr 2004 03:40:34 -0000	1.6
  @@ -61,6 +61,8 @@
   DescriptorParser.bad-rule-class=Unable to create instance of Rule class {0} (at {1}): {2}
   DescriptorParser.invalid-id-format=Attribute {0} ({1}) of element {2} (at {3}) is not a
valid id.
   DescriptorParser.unable-to-resolve-schema=Unable to resolve reference to schema ''{0}''
at {1}.
  +DescriptorParser.unable-to-initialize=Unable to initialize from properties: {0}
  +DescriptorParser.invalid-translator-class=Invalid translator class ''{0}'': {1}
   
   ConversionDescriptor.dupe-attribute-mapping=Mapping for attribute {0} (at {1}) conflicts
with a previous mapping (at {2}) and has been ignored.
   ConversionDescriptor.extra-mappings=Mappings for unknown attribute(s) {0} (for element
{1} at {2}) have been ignored.
  
  
  
  1.21      +4 -1      jakarta-hivemind/common/links.xml
  
  Index: links.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/common/links.xml,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- links.xml	7 Apr 2004 23:40:12 -0000	1.20
  +++ links.xml	15 Apr 2004 03:40:34 -0000	1.21
  @@ -70,6 +70,8 @@
   <!ENTITY _rules '<code>&lt;rules&gt;</code>'>
   <!ENTITY rules '<a href="&projectroot;descriptor.html#rules">&_rules;</a>'>
   
  +<!ENTITY _sub-module '<code>&lt;sub-module&gt;</code>'>
  +<!ENTITY sub-module '<a href="&projectroot;descriptor.html#sub-module">&_sub-module;</a>'>
   
   <!-- XML entities for the XML processing rules (documented seperately from the rest).
-->
   
  @@ -95,3 +97,4 @@
   
   <!ENTITY _custom '<code>&lt;custom&gt;</code>'>
   <!ENTITY custom '<a href="&projectroot;rules.html#custom">&_custom;</a>'>
  +
  
  
  
  1.34      +36 -2     jakarta-hivemind/xdocs/descriptor.xml
  
  Index: descriptor.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/xdocs/descriptor.xml,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- descriptor.xml	7 Apr 2004 23:40:12 -0000	1.33
  +++ descriptor.xml	15 Apr 2004 03:40:34 -0000	1.34
  @@ -463,7 +463,8 @@
   			</table>
   			
   			<p>
  -				Contains: &description;, &service-point;, &contribution;, &configuration-point;,
&implementation;
  +				Contains: &description;, &contribution;, &configuration-point;, &implementation;,
&service-point;,
  +									&sub-module;
   				</p>
   				
   			<p>
  @@ -574,5 +575,38 @@
   			
   		</section>
   		
  +  <section name="sub-module">
  +  
  +  <p>The &_sub-module; element is used to identify an additional HiveMind module
deployment descriptor. This is used when
  +  	a single JAR file contains logically distinct packages, each of which should be treated
as an individual HiveMind module. This can
  +  	also be useful as a way to reduce developer conflict against a single, large, central
module descriptor by effectively breaking it into
  +  	smaller pieces. Sub-modules identified in this way must still have their own unique
module id.
  +  </p>	
  +  
  +  			<table>
  +				<tr>
  +					<th>Attribute</th>
  +					<th>Type</th>
  +					<th>Required ?</th>
  +					<th>Description</th>
  +				</tr>
  +				
  +				<tr>
  +				<td>descriptor</td>
  +				<td>string</td>	
  +				<td>yes</td>
  +				<td>Location of the module descriptor.</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 folder.
  +</p>
  +
  +</section>
  +
   	</body>
   </document>
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/TestSubModule.java
  
  Index: TestSubModule.java
  ===================================================================
  //  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.
  
  package hivemind.test;
  
  import hivemind.test.services.SimpleService;
  
  import org.apache.hivemind.Registry;
  
  /**
   * Tests the ability for a module to include &lt;sub-module&gt;s.
   *
   * @author Howard Lewis Ship
   * @version $Id: TestSubModule.java,v 1.1 2004/04/15 03:40:34 hlship Exp $
   */
  public class TestSubModule extends FrameworkTestCase
  {
      public void testSubModule() throws Exception
      {
          Registry r = buildFrameworkRegistry("OuterModule.xml");
  
          SimpleService s =
              (SimpleService) r.getService("hivemind.test.outer.Simple", SimpleService.class);
  
          assertEquals(11, s.add(4, 7));
  
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/hivemind.test.outer.submodule.xml
  
  Index: hivemind.test.outer.submodule.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!-- 
     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.
  -->
  <!-- $Id: hivemind.test.outer.submodule.xml,v 1.1 2004/04/15 03:40:34 hlship Exp $ -->
  <module
  	id="hivemind.test.outer.submodule" 
  	version="1.0.0">
  	
  	<implementation service-id="hivemind.test.outer.Simple">
  	  <create-instance class="hivemind.test.services.impl.SimpleServiceImpl"/>	
  	</implementation>
  	  
  </module>
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/OuterModule.xml
  
  Index: OuterModule.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!-- 
     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.
  -->
  <!-- $Id: OuterModule.xml,v 1.1 2004/04/15 03:40:34 hlship Exp $ -->
  <module
  	id="hivemind.test.outer" 
  	version="1.0.0">
  	
  	<sub-module descriptor="hivemind.test.outer.submodule.xml"/>
  	
  	<service-point id="Simple" interface="hivemind.test.services.SimpleService"/>
  	  
  </module>
  
  
  1.2       +13 -1     jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ModuleDescriptor.java
  
  Index: ModuleDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ModuleDescriptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModuleDescriptor.java	26 Feb 2004 23:07:44 -0000	1.1
  +++ ModuleDescriptor.java	15 Apr 2004 03:40:34 -0000	1.2
  @@ -18,6 +18,7 @@
   import java.util.List;
   
   import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.hivemind.ClassResolver;
   import org.apache.hivemind.impl.BaseLocatable;
   
   /**
  @@ -36,6 +37,7 @@
       private List _implementations;
       private List _configurationPoints;
       private List _contributions;
  +    private ClassResolver _resolver;
   
       public String toString()
       {
  @@ -117,6 +119,16 @@
       public void setVersion(String string)
       {
           _version = string;
  +    }
  +
  +    public ClassResolver getClassResolver()
  +    {
  +        return _resolver;
  +    }
  +
  +    public void setClassResolver(ClassResolver resolver)
  +    {
  +        _resolver = resolver;
       }
   
   }
  
  
  
  1.6       +156 -189  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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DescriptorParser.java	7 Apr 2004 20:03:08 -0000	1.5
  +++ DescriptorParser.java	15 Apr 2004 03:40:34 -0000	1.6
  @@ -14,13 +14,18 @@
   
   package org.apache.hivemind.parse;
   
  +import java.io.BufferedInputStream;
  +import java.io.IOException;
  +import java.io.InputStream;
   import java.lang.reflect.Constructor;
   import java.net.URL;
   import java.util.ArrayList;
  +import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.Properties;
   
   import javax.xml.parsers.FactoryConfigurationError;
   import javax.xml.parsers.ParserConfigurationException;
  @@ -48,23 +53,12 @@
   import org.apache.hivemind.schema.impl.AttributeModelImpl;
   import org.apache.hivemind.schema.impl.ElementModelImpl;
   import org.apache.hivemind.schema.impl.SchemaImpl;
  -import org.apache.hivemind.schema.rules.BooleanTranslator;
  -import org.apache.hivemind.schema.rules.ClassTranslator;
  -import org.apache.hivemind.schema.rules.ConfigurationTranslator;
   import org.apache.hivemind.schema.rules.CreateObjectRule;
  -import org.apache.hivemind.schema.rules.DoubleTranslator;
  -import org.apache.hivemind.schema.rules.EnumerationTranslator;
  -import org.apache.hivemind.schema.rules.IntTranslator;
   import org.apache.hivemind.schema.rules.InvokeParentRule;
  -import org.apache.hivemind.schema.rules.LongTranslator;
  -import org.apache.hivemind.schema.rules.ObjectTranslator;
   import org.apache.hivemind.schema.rules.ReadAttributeRule;
   import org.apache.hivemind.schema.rules.ReadContentRule;
  -import org.apache.hivemind.schema.rules.ResourceTranslator;
  -import org.apache.hivemind.schema.rules.ServiceTranslator;
   import org.apache.hivemind.schema.rules.SetModuleRule;
   import org.apache.hivemind.schema.rules.SetParentRule;
  -import org.apache.hivemind.schema.rules.SmartTranslator;
   import org.apache.hivemind.util.PropertyUtils;
   import org.xml.sax.Attributes;
   import org.xml.sax.InputSource;
  @@ -201,139 +195,14 @@
   
       private static final int STATE_NO_CONTENT = 300;
   
  -    private final Map MODULE_ATTRIBUTES = new HashMap();
  -
  -    {
  -        MODULE_ATTRIBUTES.put("id", Boolean.TRUE);
  -        MODULE_ATTRIBUTES.put("version", Boolean.TRUE);
  -    }
  -
  -    private final Map CONTRIBUTION_ATTRIBUTES = new HashMap();
  -
  -    {
  -        CONTRIBUTION_ATTRIBUTES.put("configuration-id", Boolean.TRUE);
  -    }
  -
  -    private final Map CONFIGURATION_POINT_ATTRIBUTES = new HashMap();
  -
  -    {
  -        CONFIGURATION_POINT_ATTRIBUTES.put("id", Boolean.TRUE);
  -        CONFIGURATION_POINT_ATTRIBUTES.put("occurs", Boolean.FALSE);
  -    }
  -
  -    private final Map SERVICE_POINT_ATTRIBUTES = new HashMap();
  -
  -    {
  -        SERVICE_POINT_ATTRIBUTES.put("id", Boolean.TRUE);
  -        SERVICE_POINT_ATTRIBUTES.put("interface", Boolean.TRUE);
  -    }
  -
  -    private final Map IMPLEMENTATION_ATTRIBUTES = new HashMap();
  -
  -    {
  -        IMPLEMENTATION_ATTRIBUTES.put("service-id", Boolean.TRUE);
  -    }
  -
  -    private final Map CREATE_INSTANCE_ATTRIBUTES = new HashMap();
  -
  -    {
  -        CREATE_INSTANCE_ATTRIBUTES.put("class", Boolean.TRUE);
  -        CREATE_INSTANCE_ATTRIBUTES.put("model", Boolean.FALSE);
  -    }
  -
  -    private final Map INTERCEPTOR_ATTRIBUTES = new HashMap();
  -
  -    {
  -        INTERCEPTOR_ATTRIBUTES.put("order", Boolean.FALSE);
  -        INTERCEPTOR_ATTRIBUTES.put("service-id", Boolean.TRUE);
  -    }
  -
  -    private final Map ELEMENT_ATTRIBUTES = new HashMap();
  -
  -    {
  -        ELEMENT_ATTRIBUTES.put("name", Boolean.TRUE);
  -    }
  -
  -    private final Map ATTRIBUTE_ATTRIBUTES = new HashMap();
  -
  -    {
  -        ATTRIBUTE_ATTRIBUTES.put("name", Boolean.TRUE);
  -        ATTRIBUTE_ATTRIBUTES.put("required", Boolean.FALSE);
  -    }
  -
  -    private final Map CREATE_OBJECT_ATTRIBUTES = CREATE_INSTANCE_ATTRIBUTES;
  -
  -    private final Map INVOKE_PARENT_ATTRIBUTES = new HashMap();
  -
  -    {
  -        INVOKE_PARENT_ATTRIBUTES.put("method", Boolean.TRUE);
  -        INVOKE_PARENT_ATTRIBUTES.put("depth", Boolean.FALSE);
  -    }
  -
  -    private final Map SET_PARENT_ATTRIBUTES = new HashMap();
  -
  -    {
  -        SET_PARENT_ATTRIBUTES.put("property", Boolean.TRUE);
  -    }
  -
  -    private final Map READ_ATTRIBUTE_ATTRIBUTES = new HashMap();
  -
  -    {
  -        READ_ATTRIBUTE_ATTRIBUTES.put("property", Boolean.TRUE);
  -        READ_ATTRIBUTE_ATTRIBUTES.put("attribute", Boolean.TRUE);
  -        READ_ATTRIBUTE_ATTRIBUTES.put("skip-if-null", Boolean.FALSE);
  -        READ_ATTRIBUTE_ATTRIBUTES.put("translator", Boolean.FALSE);
  -    }
  -
  -    private final Map READ_CONTENT_ATTRIBUTES = new HashMap();
  -
  -    {
  -        READ_CONTENT_ATTRIBUTES.put("property", Boolean.TRUE);
  -        READ_CONTENT_ATTRIBUTES.put("translator", Boolean.FALSE);
  -    }
  -
  -    private final Map INVOKE_FACTORY_ATTRIBUTES = new HashMap();
  -
  -    {
  -        INVOKE_FACTORY_ATTRIBUTES.put("service-id", Boolean.TRUE);
  -        INVOKE_FACTORY_ATTRIBUTES.put("model", Boolean.FALSE);
  -    }
  -
       /**
  -     * Applies to schema and parameter-schema elements.
  +     * Built from DescriptorParser.properties.  Key is
  +     * element name, value is an instance of {@link ElementParseInfo}.
        */
  -    private final Map SCHEMA_ATTRIBUTES = new HashMap();
  -
  -    {
  -        SCHEMA_ATTRIBUTES.put("id", Boolean.FALSE);
  -        SCHEMA_ATTRIBUTES.put("ref-id", Boolean.FALSE);
  -    }
  -
  -    private final Map SET_MODULE_ATTRIBUTES = new HashMap();
  -
  -    {
  -        SET_MODULE_ATTRIBUTES.put("property", Boolean.TRUE);
  -    }
   
  -    private final Map CUSTOM_ATTRIBUTES = new HashMap();
  +    private Map _elementParseInfo = new HashMap();
   
  -    {
  -        CUSTOM_ATTRIBUTES.put("class", Boolean.TRUE);
  -    }
  -
  -    private final Map CONVERSION_ATTRIBUTES = new HashMap();
  -    {
  -        CONVERSION_ATTRIBUTES.put("class", Boolean.TRUE);
  -        CONVERSION_ATTRIBUTES.put("parent-method", Boolean.FALSE);
  -    }
  -
  -    private final Map MAP_ATTRIBUTES = new HashMap();
  -
  -    {
  -        MAP_ATTRIBUTES.put("attribute", Boolean.TRUE);
  -        MAP_ATTRIBUTES.put("property", Boolean.FALSE);
  -        MAP_ATTRIBUTES.put("translator", Boolean.FALSE);
  -    }
  +    private final Map _requiredMap = new HashMap();
   
       private final Map OCCURS_MAP = new HashMap();
   
  @@ -369,23 +238,6 @@
        */
       private final Map _ruleMap = new HashMap();
   
  -    // Seed the translator map with shared instances of built-in
  -    // translators.
  -
  -    {
  -        _translatorClasses.put("boolean", BooleanTranslator.class);
  -        _translatorClasses.put("object", ObjectTranslator.class);
  -        _translatorClasses.put("int", IntTranslator.class);
  -        _translatorClasses.put("service", ServiceTranslator.class);
  -        _translatorClasses.put("enumeration", EnumerationTranslator.class);
  -        _translatorClasses.put("configuration", ConfigurationTranslator.class);
  -        _translatorClasses.put("resource", ResourceTranslator.class);
  -        _translatorClasses.put("long", LongTranslator.class);
  -        _translatorClasses.put("double", DoubleTranslator.class);
  -        _translatorClasses.put("class", ClassTranslator.class);
  -        _translatorClasses.put("smart", SmartTranslator.class);
  -    }
  -
       /**
        * The parser is built around a stack of these Items.  This used to figure
        * out the current state, the element being processed, and the matching descriptor
  @@ -430,6 +282,8 @@
       public DescriptorParser(RegistryAssembly assembly)
       {
           _registryAssembly = assembly;
  +
  +        initializeFromPropertiesFile();
       }
   
       /**
  @@ -610,17 +464,24 @@
        * 
        */
   
  -    private void checkAttributes(Map expectedAttributes)
  +    private void checkAttributes()
       {
           Iterator i = _attributes.keySet().iterator();
   
  +        String elementName = _top._elementName;
  +
  +        ElementParseInfo epi = (ElementParseInfo) _elementParseInfo.get(elementName);
  +
  +        // if (epi == null)
  +        //    throw new IllegalStateException("Unknown element name: " + elementName +
".");
  +
           // First, check that each attribute is in the set of expected attributes.
   
           while (i.hasNext())
           {
               String name = (String) i.next();
   
  -            if (!expectedAttributes.containsKey(name))
  +            if (!epi.isKnown(name))
                   LOG.error(
                       HiveMind.format(
                           "DescriptorParser.unknown-attribute",
  @@ -631,21 +492,16 @@
   
           // Now check that all required attributes have been specified.
   
  -        i = expectedAttributes.entrySet().iterator();
  +        i = epi.getRequiredNames();
           while (i.hasNext())
           {
  -            Map.Entry entry = (Map.Entry) i.next();
  -
  -            Boolean b = (Boolean) entry.getValue();
  -
  -            if (!b.booleanValue())
  -                continue;
  +            String name = (String) i.next();
   
  -            if (!_attributes.containsKey(entry.getKey()))
  +            if (!_attributes.containsKey(name))
                   throw new ApplicationRuntimeException(
                       HiveMind.format(
                           "DescriptorParser.required-attribute",
  -                        entry.getKey(),
  +                        name,
                           getElementPath(),
                           getLocation()));
           }
  @@ -871,9 +727,11 @@
   
           ModuleDescriptor md = new ModuleDescriptor();
   
  +        md.setClassResolver(_resolver);
  +
           push(elementName, md, STATE_MODULE);
   
  -        checkAttributes(MODULE_ATTRIBUTES);
  +        checkAttributes();
   
           md.setModuleId(getAttribute("id"));
           md.setVersion(getAttribute("version"));
  @@ -903,7 +761,7 @@
   
               push(elementName, cpd, STATE_CONFIGURATION_POINT);
   
  -            checkAttributes(CONFIGURATION_POINT_ATTRIBUTES);
  +            checkAttributes();
   
               cpd.setId(extractId("id"));
   
  @@ -923,7 +781,7 @@
   
               push(elementName, cd, STATE_CONTRIBUTION);
   
  -            checkAttributes(CONTRIBUTION_ATTRIBUTES);
  +            checkAttributes();
   
               cd.setConfigurationId(getAttribute("configuration-id"));
   
  @@ -937,7 +795,7 @@
   
               push(elementName, spd, STATE_SERVICE_POINT);
   
  -            checkAttributes(SERVICE_POINT_ATTRIBUTES);
  +            checkAttributes();
   
               spd.setId(extractId("id"));
               spd.setInterfaceClassName(getAttribute("interface"));
  @@ -953,7 +811,7 @@
   
               push(elementName, id, STATE_IMPLEMENTATION);
   
  -            checkAttributes(IMPLEMENTATION_ATTRIBUTES);
  +            checkAttributes();
   
               id.setServiceId(getAttribute("service-id"));
   
  @@ -962,6 +820,21 @@
               return;
           }
   
  +        if (elementName.equals("sub-module"))
  +        {
  +            push(elementName, null, STATE_NO_CONTENT);
  +
  +            checkAttributes();
  +
  +            String path = getAttribute("descriptor");
  +
  +            Resource subModuleDescriptor = _resource.getRelativeResource(path);
  +
  +            _registryAssembly.enqueueModuleParse(subModuleDescriptor, _resolver);
  +
  +            return;
  +        }
  +
           // TODO: dependency
   
           unexpectedElement(elementName);
  @@ -1002,7 +875,7 @@
   
           push(elementName, result, STATE_SCHEMA);
   
  -        checkAttributes(SCHEMA_ATTRIBUTES);
  +        checkAttributes();
   
           String refId = getAttribute("ref-id");
   
  @@ -1133,7 +1006,7 @@
   
               push(elementName, cid, STATE_CREATE_INSTANCE);
   
  -            checkAttributes(CREATE_INSTANCE_ATTRIBUTES);
  +            checkAttributes();
   
               cid.setInstanceClassName(getAttribute("class"));
   
  @@ -1153,7 +1026,7 @@
   
               push(elementName, ifd, STATE_COLLECT_SERVICE_PARAMETERS);
   
  -            checkAttributes(INVOKE_FACTORY_ATTRIBUTES);
  +            checkAttributes();
   
               ifd.setFactoryServiceId(getAttribute("service-id"));
   
  @@ -1175,7 +1048,7 @@
   
               push(elementName, id, STATE_COLLECT_SERVICE_PARAMETERS);
   
  -            checkAttributes(INTERCEPTOR_ATTRIBUTES);
  +            checkAttributes();
   
               id.setFactoryServiceId(getAttribute("service-id"));
   
  @@ -1213,7 +1086,7 @@
   
           push(elementName, result, STATE_ELEMENT);
   
  -        checkAttributes(ELEMENT_ATTRIBUTES);
  +        checkAttributes();
   
           result.setElementName(getAttribute("name"));
   
  @@ -1236,7 +1109,7 @@
   
               push(elementName, attributeModel, STATE_ALLOW_DESCRIPTION);
   
  -            checkAttributes(ATTRIBUTE_ATTRIBUTES);
  +            checkAttributes();
   
               attributeModel.setName(getAttribute("name"));
               attributeModel.setRequired(getBooleanAttribute("required", false));
  @@ -1252,7 +1125,7 @@
   
               push(elementName, cd, STATE_CONVERSION);
   
  -            checkAttributes(CONVERSION_ATTRIBUTES);
  +            checkAttributes();
   
               cd.setClassName(getAttribute("class"));
   
  @@ -1291,7 +1164,7 @@
   
               push(elementName, amd, STATE_NO_CONTENT);
   
  -            checkAttributes(MAP_ATTRIBUTES);
  +            checkAttributes();
   
               amd.setAttributeName(getAttribute("attribute"));
               amd.setPropertyName(getAttribute("property"));
  @@ -1326,7 +1199,7 @@
               CreateObjectRule rule = new CreateObjectRule();
               push(elementName, rule, STATE_NO_CONTENT);
   
  -            checkAttributes(CREATE_OBJECT_ATTRIBUTES);
  +            checkAttributes();
   
               rule.setClassName(getAttribute("class"));
   
  @@ -1340,7 +1213,7 @@
   
               push(elementName, rule, STATE_NO_CONTENT);
   
  -            checkAttributes(INVOKE_PARENT_ATTRIBUTES);
  +            checkAttributes();
   
               rule.setMethodName(getAttribute("method"));
   
  @@ -1357,7 +1230,7 @@
   
               push(elementName, rule, STATE_NO_CONTENT);
   
  -            checkAttributes(SET_PARENT_ATTRIBUTES);
  +            checkAttributes();
   
               rule.setPropertyName(getAttribute("property"));
   
  @@ -1371,7 +1244,7 @@
   
               push(elementName, rule, STATE_NO_CONTENT);
   
  -            checkAttributes(READ_ATTRIBUTE_ATTRIBUTES);
  +            checkAttributes();
   
               rule.setPropertyName(getAttribute("property"));
               rule.setAttributeName(getAttribute("attribute"));
  @@ -1388,7 +1261,7 @@
   
               push(elementName, rule, STATE_NO_CONTENT);
   
  -            checkAttributes(READ_CONTENT_ATTRIBUTES);
  +            checkAttributes();
   
               rule.setPropertyName(getAttribute("property"));
               rule.setTranslator(getTranslator());
  @@ -1403,7 +1276,7 @@
   
               push(elementName, rule, STATE_NO_CONTENT);
   
  -            checkAttributes(SET_MODULE_ATTRIBUTES);
  +            checkAttributes();
   
               rule.setPropertyName(getAttribute("property"));
   
  @@ -1418,7 +1291,7 @@
   
               push(elementName, null, STATE_NO_CONTENT);
   
  -            checkAttributes(CUSTOM_ATTRIBUTES);
  +            checkAttributes();
   
               String ruleClassName = getAttribute("class");
   
  @@ -1641,5 +1514,99 @@
           }
   
           return result;
  +    }
  +
  +    /**
  +     * Invoked from the constructor to read the properties file that defines
  +     * certain aspects of the operation of the parser.
  +     * 
  +     */
  +    private void initializeFromPropertiesFile()
  +    {
  +        Properties p = new Properties();
  +
  +        try
  +        {
  +
  +            InputStream propertiesIn =
  +                getClass().getResourceAsStream("DescriptorParser.properties");
  +            InputStream bufferedIn = new BufferedInputStream(propertiesIn);
  +
  +            p.load(bufferedIn);
  +
  +            bufferedIn.close();
  +        }
  +        catch (IOException ex)
  +        {
  +            LOG.error(
  +                HiveMind.format("DescriptorParser.unable-to-initialize", ex.getMessage()),
  +                ex);
  +        }
  +
  +        initializeFromProperties(p);
  +    }
  +
  +    private void initializeFromProperties(Properties p)
  +    {
  +        Enumeration e = p.propertyNames();
  +
  +        while (e.hasMoreElements())
  +        {
  +            String key = (String) e.nextElement();
  +            String value = p.getProperty(key);
  +
  +            initializeFromProperty(key, value);
  +        }
  +    }
  +
  +    private void initializeFromProperty(String key, String value)
  +    {
  +        if (key.startsWith("required."))
  +        {
  +            initializeRequired(key, value);
  +            return;
  +        }
  +
  +        if (key.startsWith("translator."))
  +        {
  +            initializeTranslator(key, value);
  +            return;
  +        }
  +    }
  +
  +    private void initializeRequired(String key, String value)
  +    {
  +        boolean required = value.equals("true");
  +
  +        int lastdotx = key.lastIndexOf('.');
  +
  +        String elementName = key.substring(9, lastdotx);
  +        String attributeName = key.substring(lastdotx + 1);
  +
  +        ElementParseInfo epi = (ElementParseInfo) _elementParseInfo.get(elementName);
  +
  +        if (epi == null)
  +        {
  +            epi = new ElementParseInfo();
  +            _elementParseInfo.put(elementName, epi);
  +        }
  +
  +        epi.addAttribute(attributeName, required);
  +    }
  +
  +    private void initializeTranslator(String key, String value)
  +    {
  +        String name = key.substring(11);
  +
  +        try
  +        {
  +            Class translatorClass = Class.forName(value);
  +
  +            _translatorClasses.put(name, translatorClass);
  +        }
  +        catch (Exception ex)
  +        {
  +            HiveMind.format("DescriptorParser.invalid-translator-class", name, ex.getMessage(),
ex);
  +        }
       }
   }
  
  
  
  1.1                  jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ElementParseInfo.java
  
  Index: ElementParseInfo.java
  ===================================================================
  //  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.
  
  package org.apache.hivemind.parse;
  
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.Set;
  
  public class ElementParseInfo
  {
      private Set _knownAttributes = new HashSet();
      private Set _requiredAttributes = new HashSet();
  
      public void addAttribute(String name, boolean required)
      {
          _knownAttributes.add(name);
  
          if (required)
              _requiredAttributes.add(name);
      }
      
      public boolean isKnown(String attributeName)
      {
      	return _knownAttributes.contains(attributeName);
      }
      
      /**
       * Returns all the required attribute names as
       * an Iterator (of String).
       */
      public Iterator getRequiredNames()
      {
      	return _requiredAttributes.iterator();
      }
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties
  
  Index: DescriptorParser.properties
  ===================================================================
  # $Id: DescriptorParser.properties,v 1.1 2004/04/15 03:40:34 hlship Exp $
  #
  # 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.
  #
  # Contains information needed by DescriptorParser.
  
  # required.element-name.attribute-name=true|false
  #   Defines the allowed attributes for each element, and whether the attribute
  #   is optional or required.
  
  required.module.id=true
  required.module.version=true
  
  required.contribution.configuration-id=true
  
  required.configuration-point.id=true
  required.configuration-point.occurs=false
  
  required.service-point.id=true
  required.service-point.interface=true
  
  required.implementation.service-id=true
  
  required.create-instance.class=true
  required.create-instance.model=false
  
  required.interceptor.order=false
  required.interceptor.service-id=true
  
  required.element.name=true
  
  required.attribute.name=true
  required.attribute.required=false
  
  required.create-object.class=true
  
  required.invoke-parent.method=true
  required.invoke-parent.depth=false
  
  required.set-parent.property=true
  
  required.read-attribute.property=true
  required.read-attribute.attribute=true
  required.read-attribute.skip-if-null=false
  required.read-attribute.translator=false
  
  required.read-content.property=true
  required.read-content.translator=false
  
  required.invoke-factory.service-id=true
  required.invoke-factory.model=false
  
  required.schema.id=false
  required.schema.ref-id=false
  
  required.parameters-schema.id=false
  required.parameters-schema.ref-id=false
  
  required.set-module.property=true
  
  required.custom.class=true
  
  required.conversion.class=true
  required.conversion.parent-method=false
  
  required.map.attribute=true
  required.map.property=false
  required.map.translator=false
  
  
  required.sub-module.descriptor=true
  
  
  # translator.name=class-name
  #   Defines the basic set of translators recognized by the parser.
  
  translator.boolean=org.apache.hivemind.schema.rules.BooleanTranslator
  translator.object=org.apache.hivemind.schema.rules.ObjectTranslator
  translator.int=org.apache.hivemind.schema.rules.IntTranslator
  translator.service=org.apache.hivemind.schema.rules.ServiceTranslator
  translator.enumeration=org.apache.hivemind.schema.rules.EnumerationTranslator
  translator.configuration=org.apache.hivemind.schema.rules.ConfigurationTranslator
  translator.resource=org.apache.hivemind.schema.rules.ResourceTranslator
  translator.long=org.apache.hivemind.schema.rules.LongTranslator
  translator.double=org.apache.hivemind.schema.rules.DoubleTranslator
  translator.class=org.apache.hivemind.schema.rules.ClassTranslator
  translator.smart=org.apache.hivemind.schema.rules.SmartTranslator
  
  
  1.2       +14 -0     jakarta-hivemind/framework/src/test/hivemind/test/config/ComplexNameItem.java
  
  Index: ComplexNameItem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/config/ComplexNameItem.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComplexNameItem.java	1 Mar 2004 22:56:27 -0000	1.1
  +++ ComplexNameItem.java	15 Apr 2004 03:40:34 -0000	1.2
  @@ -1,3 +1,17 @@
  +//  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.
  +
   package hivemind.test.config;
   
   import org.apache.hivemind.impl.BaseLocatable;
  
  
  

---------------------------------------------------------------------
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