knut 2004/09/06 02:19:47
Modified: framework/src/java/org/apache/hivemind/parse
ParseStrings.properties DescriptorParser.java
ModuleDescriptor.java ParseMessages.java
framework/src/test/hivemind/test/parse
TestDescriptorParser.java
framework/src/test/hivemind/test TestSubModule.java
OuterModule.xml
framework/src/java/org/apache/hivemind/impl
RegistryAssemblyImpl.java ImplStrings.properties
RegistryAssembly.java ImplMessages.java
RegistryBuilder.java
Added: framework/src/java/org/apache/hivemind/parse
SubModuleDescriptor.java
framework/src/test/hivemind/test Submodule.xml
MissingSubModule.xml NestedSubmodule.xml
Removed: framework/src/test/hivemind/test/parse MissingSubModule.xml
framework/src/test/hivemind/test
hivemind.test.outer.submodule.xml
Log:
Reassigned responsibility of driving submodule parsing and checking for
missing submodules from DescriptorParser to RegistryBuilder.
Implementation of drive of submodule parsing is recursive (in
RegistryBuilder#processModule(ClassResolver, Resource)).
Revision Changes Path
1.7 +0 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseStrings.properties
Index: ParseStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseStrings.properties,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ParseStrings.properties 19 Aug 2004 23:24:55 -0000 1.6
+++ ParseStrings.properties 6 Sep 2004 09:19:47 -0000 1.7
@@ -26,7 +26,6 @@
bad-rule-class=Unable to create instance of Rule class {0} (at {1}): {2}
error-reading-descriptor=Unable to read descriptor {0}: {1}
missing-resource=Unable to locate {0}.
-sub-module-does-not-exist=Sub-module {0} does not exist.
unexpected-element=Unexpected element {0} within {1}.
1.32 +9 -18
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.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- DescriptorParser.java 19 Aug 2004 23:24:55 -0000 1.31
+++ DescriptorParser.java 6 Sep 2004 09:19:47 -0000 1.32
@@ -192,9 +192,6 @@
public static final String VERSION_PATTERN = "[0-9]+(\\.[0-9]+){2}$";
/**
- *
- */
- /**
* Temporary storage of the current [EMAIL PROTECTED] Attributes}.
*/
private Map _attributes = new HashMap();
@@ -211,7 +208,7 @@
private ErrorHandler _errorHandler;
/**
- * Used to resolve schema references during the parse.
+ * Used to resolve and link schema references during the parse.
*/
private RegistryAssembly _registryAssembly;
@@ -1106,25 +1103,19 @@
private void enterSubModule(String elementName)
{
- push(elementName, null, STATE_NO_CONTENT);
+ ModuleDescriptor md = (ModuleDescriptor) peekObject();
- checkAttributes();
+ SubModuleDescriptor smd = new SubModuleDescriptor();
+
+ push(elementName, smd, STATE_NO_CONTENT);
- String path = getAttribute("descriptor");
+ checkAttributes();
- Resource subModuleDescriptor =
getResource().getRelativeResource(path);
+ Resource descriptor =
getResource().getRelativeResource(getAttribute("descriptor"));
- if (subModuleDescriptor.getResourceURL() == null)
- {
- _errorHandler.error(
- LOG,
- ParseMessages.subModuleDoesNotExist(subModuleDescriptor),
- getLocation(),
- null);
- return;
- }
+ smd.setDescriptor(descriptor);
- _registryAssembly.enqueueModuleParse(subModuleDescriptor, _resolver);
+ md.addSubModule(smd);
}
private String getAttribute(String name)
1.5 +14 -0
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ModuleDescriptor.java 25 Jun 2004 20:20:02 -0000 1.4
+++ ModuleDescriptor.java 6 Sep 2004 09:19:47 -0000 1.5
@@ -36,6 +36,7 @@
private List _implementations;
private List _configurationPoints;
private List _contributions;
+ private List _subModules;
private ClassResolver _resolver;
public String toString()
@@ -98,6 +99,19 @@
public List getContributions()
{
return _contributions;
+ }
+
+ public void addSubModule(SubModuleDescriptor subModule)
+ {
+ if (_subModules == null)
+ _subModules = new ArrayList();
+
+ _subModules.add(subModule);
+ }
+
+ public List getSubModules()
+ {
+ return _subModules;
}
public String getModuleId()
1.9 +0 -4
jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseMessages.java
Index: ParseMessages.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/ParseMessages.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ParseMessages.java 19 Aug 2004 23:24:55 -0000 1.8
+++ ParseMessages.java 6 Sep 2004 09:19:47 -0000 1.9
@@ -120,8 +120,4 @@
new Object[] { attributeName, value, elementPath,
inputValueFormat });
}
- public static String subModuleDoesNotExist(Resource subModuleDescriptor)
- {
- return _formatter.format("sub-module-does-not-exist",
subModuleDescriptor);
- }
}
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/SubModuleDescriptor.java
Index: SubModuleDescriptor.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 org.apache.hivemind.Resource;
import org.apache.hivemind.impl.BaseLocatable;
import org.apache.hivemind.util.ToStringBuilder;
/**
* Descriptor for <sub-module> element.
*
* @author Knut Wannheden
*/
public final class SubModuleDescriptor extends BaseLocatable
{
private Resource _descriptor;
public Resource getDescriptor()
{
return _descriptor;
}
public void setDescriptor(Resource descriptor)
{
_descriptor = descriptor;
}
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
builder.append("descriptor", _descriptor);
return builder.toString();
}
}
1.19 +0 -36
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- TestDescriptorParser.java 19 Aug 2004 23:24:54 -0000 1.18
+++ TestDescriptorParser.java 6 Sep 2004 09:19:47 -0000 1.19
@@ -22,19 +22,13 @@
import junit.framework.AssertionFailedError;
-import org.apache.commons.logging.Log;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Attribute;
import org.apache.hivemind.Element;
-import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.Location;
import org.apache.hivemind.Occurances;
-import org.apache.hivemind.Resource;
-import org.apache.hivemind.impl.RegistryAssemblyImpl;
import org.apache.hivemind.parse.ConfigurationPointDescriptor;
import org.apache.hivemind.parse.ContributionDescriptor;
import org.apache.hivemind.parse.CreateInstanceDescriptor;
-import org.apache.hivemind.parse.DescriptorParser;
import org.apache.hivemind.parse.ImplementationDescriptor;
import org.apache.hivemind.parse.InterceptorDescriptor;
import org.apache.hivemind.parse.ModuleDescriptor;
@@ -470,34 +464,4 @@
assertEquals("foo", rule.getAttributeName());
}
- private String _errorHandlerMessage;
-
- private class ErrorHandlerFixture implements ErrorHandler
- {
-
- public void error(Log log, String message, Location location,
Throwable cause)
- {
- _errorHandlerMessage = message;
- }
- }
-
- public void testMissingSubModule() throws Exception
- {
- Resource location = getResource("MissingSubModule.xml");
-
- ErrorHandler eh = new ErrorHandlerFixture();
-
- RegistryAssemblyImpl assembly = new RegistryAssemblyImpl(eh);
-
- DescriptorParser p = new DescriptorParser(eh, assembly);
-
- p.parse(location, _resolver);
-
- assembly.performPostProcessing();
-
- assertRegexp(
- "Sub-module .*?/DoesNotExist\\.xml does not exist\\.",
- _errorHandlerMessage);
-
- }
}
1.4 +10 -1
jakarta-hivemind/framework/src/test/hivemind/test/TestSubModule.java
Index: TestSubModule.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestSubModule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestSubModule.java 25 Jun 2004 20:20:04 -0000 1.3
+++ TestSubModule.java 6 Sep 2004 09:19:47 -0000 1.4
@@ -25,7 +25,7 @@
*/
public class TestSubModule extends FrameworkTestCase
{
- public void testSubModule() throws Exception
+ public void testNestedSubModule() throws Exception
{
Registry r = buildFrameworkRegistry("OuterModule.xml");
@@ -34,6 +34,15 @@
assertEquals(11, s.add(4, 7));
+ }
+
+ public void testMissingSubModule() throws Exception
+ {
+ interceptLogging();
+
+ Registry r = buildFrameworkRegistry("MissingSubModule.xml");
+
+ assertLoggedMessagePattern("Sub-module .*?/DoesNotExist\\.xml does
not exist\\.");
}
}
1.3 +2 -2
jakarta-hivemind/framework/src/test/hivemind/test/OuterModule.xml
Index: OuterModule.xml
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/OuterModule.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- OuterModule.xml 25 Jun 2004 20:20:03 -0000 1.2
+++ OuterModule.xml 6 Sep 2004 09:19:47 -0000 1.3
@@ -18,8 +18,8 @@
id="hivemind.test.outer"
version="1.0.0">
- <sub-module descriptor="hivemind.test.outer.submodule.xml"/>
-
+ <sub-module descriptor="Submodule.xml"/>
+
<service-point id="Simple"
interface="hivemind.test.services.SimpleService"/>
</module>
1.1
jakarta-hivemind/framework/src/test/hivemind/test/Submodule.xml
Index: 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.
-->
<module
id="hivemind.test.outer.submodule"
version="1.0.0">
<sub-module descriptor="NestedSubmodule.xml"/>
</module>
1.1
jakarta-hivemind/framework/src/test/hivemind/test/MissingSubModule.xml
Index: MissingSubModule.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">
<sub-module descriptor="DoesNotExist.xml"/>
</module>
1.1
jakarta-hivemind/framework/src/test/hivemind/test/NestedSubmodule.xml
Index: NestedSubmodule.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.
-->
<module
id="hivemind.test.outer.submodule.nested"
version="1.0.0">
<implementation service-id="hivemind.test.outer.Simple">
<create-instance
class="hivemind.test.services.impl.SimpleServiceImpl"/>
</implementation>
</module>
1.7 +0 -45
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RegistryAssemblyImpl.java 29 Jul 2004 13:18:49 -0000 1.6
+++ RegistryAssemblyImpl.java 6 Sep 2004 09:19:47 -0000 1.7
@@ -21,11 +21,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.Resource;
-import org.apache.hivemind.parse.DescriptorParser;
-import org.apache.hivemind.parse.ModuleDescriptor;
import org.apache.hivemind.schema.Schema;
/**
@@ -47,23 +43,6 @@
_errorHandler = errorHandler;
}
- 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)
{
Schema existing = getSchema(schemaId);
@@ -108,28 +87,4 @@
}
}
- 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.10 +1 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties
Index: ImplStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplStrings.properties,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ImplStrings.properties 18 Aug 2004 19:34:09 -0000 1.9
+++ ImplStrings.properties 6 Sep 2004 09:19:47 -0000 1.10
@@ -60,6 +60,7 @@
interface-required=Service points must provide an interface type: {0} is a
class (for service {1}).
service-wrong-interface=Service {0} does not implement the requested
interface ({1}). The declared service interface type is {2}.
shutdown-coordinator-failure=Unable to shutdown {0}: {1}
+sub-module-does-not-exist=Sub-module {0} does not exist.
unlocated-error=Error: {0}
located-error=Error at {0}: {1}
1.5 +0 -7
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- RegistryAssembly.java 25 Jun 2004 20:19:59 -0000 1.4
+++ RegistryAssembly.java 6 Sep 2004 09:19:47 -0000 1.5
@@ -14,8 +14,6 @@
package org.apache.hivemind.impl;
-import org.apache.hivemind.ClassResolver;
-import org.apache.hivemind.Resource;
import org.apache.hivemind.schema.Schema;
/**
@@ -52,9 +50,4 @@
public void addPostProcessor(Runnable postProcessor);
- /**
- * Enqueues another module to be parsed.
- */
-
- public void enqueueModuleParse(Resource resource, ClassResolver
resolver);
}
1.17 +5 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java
Index: ImplMessages.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ImplMessages.java 19 Aug 2004 14:11:42 -0000 1.16
+++ ImplMessages.java 6 Sep 2004 09:19:47 -0000 1.17
@@ -363,4 +363,9 @@
{
return _formatter.format("schema-stack-violation",
processor.getElementPath());
}
+
+ public static String subModuleDoesNotExist(Resource subModuleDescriptor)
+ {
+ return _formatter.format("sub-module-does-not-exist",
subModuleDescriptor);
+ }
}
1.19 +19 -4
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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- RegistryBuilder.java 18 Aug 2004 19:34:09 -0000 1.18
+++ RegistryBuilder.java 6 Sep 2004 09:19:47 -0000 1.19
@@ -44,6 +44,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.util.IdUtils;
import org.apache.hivemind.util.URLResource;
@@ -218,13 +219,27 @@
processModule(md);
// After parsing a module, parse any additional modules
identified
- // within the module (using the <sub-module> element.
+ // within the module (using the <sub-module> element recursively.
+ List subModules = md.getSubModules();
+ int count = size(subModules);
- while (_registryAssembly.moreQueuedModules())
+ for (int i = 0; i < count; i++)
{
- md = _registryAssembly.parseNextQueued(_parser);
+ SubModuleDescriptor smd = (SubModuleDescriptor)
subModules.get(i);
+
+ Resource descriptorResource = smd.getDescriptor();
+
+ if (descriptorResource.getResourceURL() == null)
+ {
+ _errorHandler.error(
+ LOG,
+
ImplMessages.subModuleDoesNotExist(descriptorResource),
+ smd.getLocation(),
+ null);
+ continue;
+ }
- processModule(md);
+ processModule(resolver, smd.getDescriptor());
}
}
catch (RuntimeException ex)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]