knut 2004/09/27 08:50:47
Modified: framework/src/java/org/apache/hivemind/parse
ParseStrings.properties
framework/src/test/hivemind/test/config
TestConfigurationPoint.java
framework/src/java/org/apache/hivemind/test
HiveMindTestCase.java
framework/src/java/org/apache/hivemind/impl
RegistryBuilder.java
examples/src/java/org/apache/hivemind/examples
ExampleUtils.java
framework/src/java/org/apache/hivemind/servlet
HiveMindFilter.java
framework/src/test/hivemind/test/parse
TestDescriptorParser.java
framework/src/test/hivemind/test TestDependency.java
TestRegistryBuilder.java
framework/src/java/org/apache/hivemind/ant
ConstructRegistry.java
Added: framework/src/java/org/apache/hivemind/impl
ModuleDescriptorProvider.java
XmlModuleDescriptorProvider.java
framework/src/test/hivemind/test
SimpleModuleDescriptorProvider.java
Removed: framework/src/java/org/apache/hivemind/impl
AggregateModuleProvider.java ModuleProvider.java
XmlModuleProvider.java
framework/src/test/hivemind/test SimpleModuleProvider.java
Log:
- added method RegistryBuilder#addModuleDescriptorProvider()
- removed ModuleDescriptorProvider parameter from
RegistryBuilder#constructRegistry()
- removed AggregateModuleProvider
- renamed *ModuleProvider to *ModuleDescriptorProvider
Revision Changes Path
1.10 +1 -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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ParseStrings.properties 27 Sep 2004 14:36:35 -0000 1.9
+++ ParseStrings.properties 27 Sep 2004 15:50:47 -0000 1.10
@@ -33,6 +33,6 @@
invalid-attribute-format=Attribute {0} ({1}) of element {2} is improperly
formatted. {3}
module-id-format=Module identifiers should consist of a period-seperated
series of names, like a Java package.
id-format=Schema and extension point ids should be simple names with no
punctuation.
-version-format=Version numbers should be a sequence of three numbers
seperated by periods.
+version-format=Version numbers should be a sequence of three numbers
separated by periods.
schema-not-visible=Schema ''{0}'' is not visible to module {1}.
1.22 +6 -10
jakarta-hivemind/framework/src/test/hivemind/test/config/TestConfigurationPoint.java
Index: TestConfigurationPoint.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/config/TestConfigurationPoint.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- TestConfigurationPoint.java 27 Sep 2004 14:37:14 -0000 1.21
+++ TestConfigurationPoint.java 27 Sep 2004 15:50:47 -0000 1.22
@@ -31,11 +31,8 @@
import org.apache.hivemind.Element;
import org.apache.hivemind.Registry;
import org.apache.hivemind.Resource;
-import org.apache.hivemind.impl.AggregateModuleProvider;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.impl.XmlModuleProvider;
-import org.apache.hivemind.internal.Module;
-import org.apache.hivemind.internal.RegistryInfrastructure;
+import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
import org.apache.hivemind.util.ClasspathResource;
/**
@@ -425,13 +422,12 @@
Resource moduleResource = new ClasspathResource(_resolver,
"/hivemind/test/config/ResourceTranslator.xml");
- AggregateModuleProvider provider = new AggregateModuleProvider();
+ builder.addModuleDescriptorProvider(new
XmlModuleDescriptorProvider(_resolver,
+ XmlModuleDescriptorProvider.HIVE_MODULE_XML));
+ builder.addModuleDescriptorProvider(new
XmlModuleDescriptorProvider(_resolver,
+ moduleResource));
- provider.addModuleProvider(new XmlModuleProvider(_resolver,
- XmlModuleProvider.HIVE_MODULE_XML));
- provider.addModuleProvider(new XmlModuleProvider(_resolver,
moduleResource));
-
- Registry r = (Registry) builder.constructRegistry(provider,
Locale.FRENCH);
+ Registry r = (Registry) builder.constructRegistry(Locale.FRENCH);
List l =
r.getConfiguration("hivemind.test.config.ResourceTranslator");
1.15 +73 -76
jakarta-hivemind/framework/src/java/org/apache/hivemind/test/HiveMindTestCase.java
Index: HiveMindTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/test/HiveMindTestCase.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- HiveMindTestCase.java 13 Sep 2004 14:48:16 -0000 1.14
+++ HiveMindTestCase.java 27 Sep 2004 15:50:47 -0000 1.15
@@ -28,12 +28,11 @@
import org.apache.hivemind.Location;
import org.apache.hivemind.Registry;
import org.apache.hivemind.Resource;
-import org.apache.hivemind.impl.AggregateModuleProvider;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.LocationImpl;
-import org.apache.hivemind.impl.ModuleProvider;
+import org.apache.hivemind.impl.ModuleDescriptorProvider;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.impl.XmlModuleProvider;
+import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
import org.apache.hivemind.util.ClasspathResource;
import org.apache.hivemind.util.PropertyUtils;
import org.apache.hivemind.util.URLResource;
@@ -47,10 +46,9 @@
import org.easymock.MockControl;
/**
- * Contains some support for creating HiveMind tests; this is useful enough
that
- * has been moved into the main framework, to simplify creation of tests in
the dependent
- * libraries.
- *
+ * Contains some support for creating HiveMind tests; this is useful enough
that has been moved into
+ * the main framework, to simplify creation of tests in the dependent
libraries.
+ *
* @author Howard Lewis Ship
*/
public abstract class HiveMindTestCase extends TestCase
@@ -58,9 +56,11 @@
///CLOVER:OFF
protected String _interceptedLoggerName;
+
protected StoreAppender _appender;
private static Perl5Compiler _compiler;
+
private static Perl5Matcher _matcher;
/** List of [EMAIL PROTECTED] org.easymock.MockControl}. */
@@ -68,8 +68,8 @@
private List _controls = new ArrayList();
/**
- * Returns the given file as a [EMAIL PROTECTED] Resource} from the
classpath. Typically,
- * this is to find files in the same folder as the invoking class.
+ * Returns the given file as a [EMAIL PROTECTED] Resource}from the
classpath. Typically, this is to find
+ * files in the same folder as the invoking class.
*/
protected Resource getResource(String file)
{
@@ -91,8 +91,8 @@
}
/**
- * Asserts that the two arrays are equal; same length and all elements
- * equal. Checks the elements first, then the length.
+ * Asserts that the two arrays are equal; same length and all elements
equal. Checks the
+ * elements first, then the length.
*/
protected static void assertListsEqual(Object[] expected, Object[]
actual)
{
@@ -107,9 +107,8 @@
}
/**
- * Called when code should not be reachable (because a test is expected
- * to throw an exception); throws
- * AssertionFailedError always.
+ * Called when code should not be reachable (because a test is expected
to throw an exception);
+ * throws AssertionFailedError always.
*/
protected static void unreachable()
{
@@ -117,9 +116,8 @@
}
/**
- * Sets up a [EMAIL PROTECTED] StoreAppender} to intercept logging for
the specified
- * logger. Captured log events can be recovered via
- * [EMAIL PROTECTED] #getInterceptedLogEvents()}.
+ * Sets up a [EMAIL PROTECTED] StoreAppender}to intercept logging for
the specified logger. Captured log
+ * events can be recovered via [EMAIL PROTECTED]
#getInterceptedLogEvents()}.
*/
protected void interceptLogging(String loggerName)
{
@@ -136,8 +134,8 @@
}
/**
- * Gets the list of events most recently intercepted. This resets
- * the [EMAIL PROTECTED] StoreAppender} (it clears its list of log
events).
+ * Gets the list of events most recently intercepted. This resets the
[EMAIL PROTECTED] StoreAppender}(it
+ * clears its list of log events).
*
* @see #interceptLogging(String)
* @see StoreAppender#getEvents()
@@ -148,7 +146,7 @@
}
/**
- * Removes the [EMAIL PROTECTED] StoreAppender} that may have been setup
by
+ * Removes the [EMAIL PROTECTED] StoreAppender}that may have been setup
by
* [EMAIL PROTECTED] #interceptLogging(String)}. Also, invokes
* [EMAIL PROTECTED]
org.apache.hivemind.util.PropertyUtils#clearCache()}.
*/
@@ -180,8 +178,8 @@
int pos = message.indexOf(substring);
if (pos < 0)
- throw new AssertionFailedError(
- "Exception message (" + message + ") does not contain [" +
substring + "]");
+ throw new AssertionFailedError("Exception message (" + message +
") does not contain ["
+ + substring + "]");
}
/**
@@ -200,12 +198,8 @@
if (_matcher.contains(message, compiled))
return;
- throw new AssertionFailedError(
- "Exception message ("
- + message
- + ") does not contain regular expression ["
- + pattern
- + "].");
+ throw new AssertionFailedError("Exception message (" + message
+ + ") does not contain regular expression [" + pattern +
"].");
}
protected void assertRegexp(String pattern, String actual) throws
Exception
@@ -217,13 +211,13 @@
if (_matcher.contains(actual, compiled))
return;
- throw new AssertionFailedError(
- "\"" + actual + "\" does not contain regular expression[" +
pattern + "].");
+ throw new AssertionFailedError("\"" + actual + "\" does not contain
regular expression["
+ + pattern + "].");
}
/**
- * Digs down through (potentially) a stack of
ApplicationRuntimeExceptions until it
- * reaches the originating exception, which is returned.
+ * Digs down through (potentially) a stack of
ApplicationRuntimeExceptions until it reaches the
+ * originating exception, which is returned.
*/
protected Throwable findNestedException(ApplicationRuntimeException ex)
{
@@ -240,9 +234,13 @@
/**
* Checks to see if a specific event matches the name and message.
- * @param message exact message to search for
- * @param events the list of events [EMAIL PROTECTED]
#getInterceptedLogEvents()}
- * @param index the index to check at
+ *
+ * @param message
+ * exact message to search for
+ * @param events
+ * the list of events [EMAIL PROTECTED]
#getInterceptedLogEvents()}
+ * @param index
+ * the index to check at
*/
private void assertLoggedMessage(String message, List events, int index)
{
@@ -252,8 +250,7 @@
}
/**
- * Checks the messages for all logged events for exact match against
- * the supplied list.
+ * Checks the messages for all logged events for exact match against the
supplied list.
*/
protected void assertLoggedMessages(String[] messages)
{
@@ -275,8 +272,12 @@
/**
* Asserts that some capture log event matches the given message exactly.
- * @param message to search for; success is finding a logged message
contain the parameter as a substring
- * @param events from [EMAIL PROTECTED] #getInterceptedLogEvents()}
+ *
+ * @param message
+ * to search for; success is finding a logged message contain
the parameter as a
+ * substring
+ * @param events
+ * from [EMAIL PROTECTED] #getInterceptedLogEvents()}
*/
protected void assertLoggedMessage(String message, List events)
{
@@ -335,18 +336,19 @@
}
/**
- * Convienience method for invoking
- * [EMAIL PROTECTED] #buildFrameworkRegistry(String[])} with only a
single file.
+ * Convienience method for invoking [EMAIL PROTECTED]
#buildFrameworkRegistry(String[])}with only a single
+ * file.
*/
protected Registry buildFrameworkRegistry(String file) throws Exception
{
- return buildFrameworkRegistry(new String[] { file });
+ return buildFrameworkRegistry(new String[]
+ { file });
}
/**
- * Builds a minimal registry, containing only the specified files, plus
- * the master module descriptor (i.e., those visible on the classpath).
- * Files are resolved using [EMAIL PROTECTED]
HiveMindTestCase#getResource(String)}.
+ * Builds a minimal registry, containing only the specified files, plus
the master module
+ * descriptor (i.e., those visible on the classpath). Files are resolved
using
+ * [EMAIL PROTECTED] HiveMindTestCase#getResource(String)}.
*/
protected Registry buildFrameworkRegistry(String[] files) throws
Exception
{
@@ -360,33 +362,33 @@
descriptorResources.add(resource);
}
- ModuleProvider provider = new XmlModuleProvider(resolver,
descriptorResources);
+ ModuleDescriptorProvider provider = new
XmlModuleDescriptorProvider(resolver,
+ descriptorResources);
return buildFrameworkRegistry(provider);
}
/**
- * Builds a registry, containing only the modules delivered by the
specified
- * [EMAIL PROTECTED] org.apache.hivemind.impl.ModuleProvider}, plus
- * the master module descriptor (i.e., those visible on the classpath).
+ * Builds a registry, containing only the modules delivered by the
specified
+ * [EMAIL PROTECTED] org.apache.hivemind.impl.ModuleDescriptorProvider},
plus the master module descriptor
+ * (i.e., those visible on the classpath).
*/
- protected Registry buildFrameworkRegistry(ModuleProvider customProvider)
+ protected Registry buildFrameworkRegistry(ModuleDescriptorProvider
customProvider)
{
ClassResolver resolver = new DefaultClassResolver();
-
+
RegistryBuilder builder = new RegistryBuilder();
-
- AggregateModuleProvider provider = new AggregateModuleProvider();
-
- provider.addModuleProvider(new XmlModuleProvider(resolver,
XmlModuleProvider.HIVE_MODULE_XML));
- provider.addModuleProvider(customProvider);
-
- return builder.constructRegistry(provider, Locale.getDefault());
+
+ builder.addModuleDescriptorProvider(new
XmlModuleDescriptorProvider(resolver,
+ XmlModuleDescriptorProvider.HIVE_MODULE_XML));
+ builder.addModuleDescriptorProvider(customProvider);
+
+ return builder.constructRegistry(Locale.getDefault());
}
/**
- * Builds a registry from exactly the provided resource; this registry
- * will not include the <code>hivemind</code> module.
+ * Builds a registry from exactly the provided resource; this registry
will not include the
+ * <code>hivemind</code> module.
*/
protected Registry buildMinimalRegistry(Resource l) throws Exception
{
@@ -394,15 +396,13 @@
RegistryBuilder builder = new RegistryBuilder();
- return builder.constructRegistry(new XmlModuleProvider(resolver, l),
Locale.getDefault());
+ return builder.constructRegistry(Locale.getDefault());
}
/**
* Creates a <em>managed</em> control via
- * [EMAIL PROTECTED] MockControl#createStrictControl(java.lang.Class)}.
- * The created control is remembered, and will be
- * invoked by [EMAIL PROTECTED] #replayControls()},
- * [EMAIL PROTECTED] #verifyControls()}, etc..
+ * [EMAIL PROTECTED] MockControl#createStrictControl(java.lang.Class)}.
The created control is remembered,
+ * and will be invoked by [EMAIL PROTECTED] #replayControls()},[EMAIL
PROTECTED] #verifyControls()}, etc..
*/
protected MockControl newControl(Class mockClass)
{
@@ -414,8 +414,8 @@
}
/**
- * Adds the control to the list of managed controls used by
- * [EMAIL PROTECTED] #replayControls()} and [EMAIL PROTECTED]
#verifyControls()}.
+ * Adds the control to the list of managed controls used by [EMAIL
PROTECTED] #replayControls()}and
+ * [EMAIL PROTECTED] #verifyControls()}.
*/
protected void addControl(MockControl control)
{
@@ -423,8 +423,8 @@
}
/**
- * Convienience for invoking [EMAIL PROTECTED] #newControl(Class)} and
then
- * invoking [EMAIL PROTECTED] MockControl#getMock()} on the result.
+ * Convienience for invoking [EMAIL PROTECTED] #newControl(Class)}and
then invoking
+ * [EMAIL PROTECTED] MockControl#getMock()}on the result.
*/
protected Object newMock(Class mockClass)
{
@@ -432,8 +432,7 @@
}
/**
- * Invokes [EMAIL PROTECTED] MockControl#replay()} on all controls
- * created by [EMAIL PROTECTED] #newControl(Class)}.
+ * Invokes [EMAIL PROTECTED] MockControl#replay()}on all controls
created by [EMAIL PROTECTED] #newControl(Class)}.
*/
protected void replayControls()
{
@@ -446,8 +445,7 @@
}
/**
- * Invokes [EMAIL PROTECTED] org.easymock.MockControl#verify()} and
- * [EMAIL PROTECTED] MockControl#reset()} on all
+ * Invokes [EMAIL PROTECTED] org.easymock.MockControl#verify()}and
[EMAIL PROTECTED] MockControl#reset()}on all
* controls created by [EMAIL PROTECTED] #newControl(Class)}.
*/
@@ -463,8 +461,7 @@
}
/**
- * Invokes [EMAIL PROTECTED] org.easymock.MockControl#reset()} on all
- * controls.
+ * Invokes [EMAIL PROTECTED] org.easymock.MockControl#reset()}on all
controls.
*/
protected void resetControls()
@@ -495,4 +492,4 @@
return _matcher.matches(input, compiled);
}
-}
+}
\ No newline at end of file
1.23 +42 -18
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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- RegistryBuilder.java 27 Sep 2004 13:51:37 -0000 1.22
+++ RegistryBuilder.java 27 Sep 2004 15:50:47 -0000 1.23
@@ -14,9 +14,11 @@
package org.apache.hivemind.impl;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -32,7 +34,7 @@
/**
* Class used to build a [EMAIL PROTECTED] org.apache.hivemind.Registry}from
individual
* [EMAIL PROTECTED] org.apache.hivemind.parse.ModuleDescriptor}. The
descriptors are provided by the
- * [EMAIL PROTECTED] ModuleProvider}parameter passed to [EMAIL PROTECTED]
#constructRegistry(Locale)}method.
+ * [EMAIL PROTECTED] ModuleDescriptorProvider}parameter passed to [EMAIL
PROTECTED] #constructRegistry(Locale)}method.
* <p>
* A note about threadsafety: The assumption is that a single thread will
access the RegistryBuilder
* at one time (typically, a startup class within some form of server or
application). Code here and
@@ -91,6 +93,14 @@
private RegistryAssemblyImpl _registryAssembly;
/**
+ * A set of all [EMAIL PROTECTED] ModuleDescriptorProvider}objects used
to construct the Registry.
+ *
+ * @since 1.1
+ */
+
+ private Set _moduleDescriptorProviders;
+
+ /**
* Contains most of the logic for actually creating the registry.
*
* @since 1.1
@@ -109,36 +119,34 @@
_registryAssembly = new RegistryAssemblyImpl(handler);
+ _moduleDescriptorProviders = new HashSet();
+
_constructor = new RegistryInfrastructureConstructor(handler, LOG,
_registryAssembly);
}
/**
- * Processes a parsed HiveMind module descriptor. A corresponding
- * [EMAIL PROTECTED] org.apache.hivemind.internal.Module}is constructed.
This method is called by
- * [EMAIL PROTECTED] #constructRegistry(Locale)}.
+ * Adds a [EMAIL PROTECTED] ModuleDescriptorProvider}as a source for
+ * [EMAIL PROTECTED] ModuleDescriptor module descriptors}to this
RegistryBuilder. Adding the same provider
+ * instance multiple times has no effect.
*
- * @param md
- * the parsed module descriptor
+ * @since 1.1
*/
- private void processModule(ModuleDescriptor md)
+ public void addModuleDescriptorProvider(ModuleDescriptorProvider
provider)
{
- _constructor.addModuleDescriptor(md);
+ _moduleDescriptorProviders.add(provider);
}
/**
- * This first loads all modules provided by the ModuleProvider, then
resolves all the
+ * This first loads all modules provided by the
ModuleDescriptorProvider, then resolves all the
* contributions, then constructs and returns the Registry.
*/
- public Registry constructRegistry(ModuleProvider provider, Locale locale)
+ public Registry constructRegistry(Locale locale)
{
- List descriptors = provider.getModuleDescriptors(_errorHandler,
_registryAssembly);
-
- Iterator i = descriptors.iterator();
- while (i.hasNext())
+ for (Iterator i = _moduleDescriptorProviders.iterator();
i.hasNext();)
{
- ModuleDescriptor md = (ModuleDescriptor) i.next();
+ ModuleDescriptorProvider provider = (ModuleDescriptorProvider)
i.next();
- processModule(md);
+ processModuleDescriptorProvider(provider);
}
// Process any deferred operations. Post processing is added by
@@ -154,6 +162,19 @@
return new RegistryImpl(infrastructure);
}
+ private void processModuleDescriptorProvider(ModuleDescriptorProvider
provider)
+ {
+ List descriptors = provider.getModuleDescriptors(_errorHandler,
_registryAssembly);
+
+ Iterator i = descriptors.iterator();
+ while (i.hasNext())
+ {
+ ModuleDescriptor md = (ModuleDescriptor) i.next();
+
+ _constructor.addModuleDescriptor(md);
+ }
+ }
+
/**
* Constructs a default registry based on just the modules visible to
the thread context class
* loader (this is sufficient is the majority of cases), and using the
default locale. If you
@@ -164,9 +185,12 @@
{
ClassResolver resolver = new DefaultClassResolver();
RegistryBuilder builder = new RegistryBuilder();
- ModuleProvider provider = new XmlModuleProvider(resolver,
XmlModuleProvider.HIVE_MODULE_XML);
+ ModuleDescriptorProvider provider = new
XmlModuleDescriptorProvider(resolver,
+ XmlModuleDescriptorProvider.HIVE_MODULE_XML);
- return builder.constructRegistry(provider, Locale.getDefault());
+ builder.addModuleDescriptorProvider(provider);
+
+ return builder.constructRegistry(Locale.getDefault());
}
}
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleDescriptorProvider.java
Index: ModuleDescriptorProvider.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.impl;
import java.util.List;
import org.apache.hivemind.ErrorHandler;
/**
* A ModuleDescriptorProvider is used by the [EMAIL PROTECTED]
RegistryBuilder}(see
* [EMAIL PROTECTED]
RegistryBuilder#addModuleDescriptorProvider(ModuleDescriptorProvider)}) to load
the
* [EMAIL PROTECTED] org.apache.hivemind.parse.ModuleDescriptor}objects.
* <p>
* HiveMind's default ModuleDescriptorProvider is the [EMAIL PROTECTED]
XmlModuleDescriptorProvider}, which
* can load module descriptors from XML files or resources on the classpath.
*
* @author Knut Wannheden
* @since 1.1
*/
public interface ModuleDescriptorProvider
{
public List getModuleDescriptors(ErrorHandler handler, RegistryAssembly
assembly);
}
1.1
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/XmlModuleDescriptorProvider.java
Index: XmlModuleDescriptorProvider.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.impl;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.ErrorHandler;
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.parse.SubModuleDescriptor;
import org.apache.hivemind.util.URLResource;
/**
* Implementation of the [EMAIL PROTECTED] ModuleDescriptorProvider}interface
which uses the
* [EMAIL PROTECTED] org.apache.hivemind.parse.DescriptorParser}to provide
module descriptors defined in XML.
* The module descriptors are loaded from files or resources on the classpath.
*
* @author Knut Wannheden
* @since 1.1
*/
public class XmlModuleDescriptorProvider implements ModuleDescriptorProvider
{
private static final Log LOG =
LogFactory.getLog(XmlModuleDescriptorProvider.class);
/**
* The default path, within a JAR or the classpath, to the XML HiveMind
module deployment
* descriptor: <code>META-INF/hivemodule.xml</code>. Use this constant
with the
* [EMAIL PROTECTED] XmlModuleDescriptorProvider(ClassResolver,
String)}constructor.
*/
public static final String HIVE_MODULE_XML = "META-INF/hivemodule.xml";
/**
* Parser instance used by all parsing of module descriptors.
*/
private DescriptorParser _parser;
/**
* List of all specified resources processed by this
ModuleDescriptorProvider. Descriptors of
* sub-modules are not included.
*/
private List _resources = new ArrayList();
/**
* List of parsed [EMAIL PROTECTED] ModuleDescriptor}instances. Also
includes referenced sub-modules.
*/
private List _moduleDescriptors = new ArrayList();
private ClassResolver _resolver;
/**
* Loads all XML module descriptors found on the classpath (using the
given
* [EMAIL PROTECTED] org.apache.hivemind.ClassResolver}. Only module
descriptors matching the specified
* path are loaded. Use the [EMAIL PROTECTED]
XmlModuleDescriptorProvider#HIVE_MODULE_XML}constant to load
* all descriptors in the default location.
*/
public XmlModuleDescriptorProvider(ClassResolver resolver, String
resourcePath)
{
_resolver = resolver;
_resources.addAll(getDescriptorResources(resourcePath, _resolver));
}
/**
* Constructs an XmlModuleDescriptorProvider only loading the
ModuleDescriptor identified by the
* given [EMAIL PROTECTED] org.apache.hivemind.Resource}.
*/
public XmlModuleDescriptorProvider(ClassResolver reslover, Resource
resource)
{
_resolver = reslover;
_resources.add(resource);
}
/**
* Constructs an XmlModuleDescriptorProvider loading all ModuleDescriptor
identified by the
* given List of [EMAIL PROTECTED] org.apache.hivemind.Resource}objects.
*/
public XmlModuleDescriptorProvider(ClassResolver reslover, List resources)
{
_resolver = reslover;
_resources.addAll(resources);
}
public List getModuleDescriptors(ErrorHandler handler, RegistryAssembly
assembly)
{
for (Iterator i = _resources.iterator(); i.hasNext();)
{
Resource resource = (Resource) i.next();
processModule(resource, handler, assembly);
}
return _moduleDescriptors;
}
private List getDescriptorResources(String resourcePath, ClassResolver
resolver)
{
if (LOG.isDebugEnabled())
LOG.debug("Processing modules visible to " + resolver);
List descriptors = new ArrayList();
ClassLoader loader = resolver.getClassLoader();
Enumeration e = null;
try
{
e = loader.getResources(resourcePath);
}
catch (IOException ex)
{
throw new
ApplicationRuntimeException(ImplMessages.unableToFindModules(resolver, ex),
ex);
}
while (e.hasMoreElements())
{
URL descriptorURL = (URL) e.nextElement();
descriptors.add(new URLResource(descriptorURL));
}
return descriptors;
}
private void processModule(Resource moduleDescriptorResource,
ErrorHandler handler,
RegistryAssembly assembly)
{
if (_parser == null)
_parser = new DescriptorParser(handler, assembly);
try
{
ModuleDescriptor md = _parser.parse(moduleDescriptorResource,
_resolver);
_moduleDescriptors.add(md);
// After parsing a module, parse any additional modules identified
// within the module (using the <sub-module> element) recursively.
processSubModules(md, handler, assembly);
}
catch (RuntimeException ex)
{
// An exception may leave the parser in an unknown state, so
// give up on that instance and start with a fresh one.
_parser = null;
handler.error(LOG, ex.getMessage(), HiveMind.getLocation(ex), ex);
}
}
private void processSubModules(ModuleDescriptor moduleDescriptor,
ErrorHandler handler,
RegistryAssembly assembly)
{
List subModules = moduleDescriptor.getSubModules();
int count = size(subModules);
for (int i = 0; i < count; i++)
{
SubModuleDescriptor smd = (SubModuleDescriptor) subModules.get(i);
Resource descriptorResource = smd.getDescriptor();
if (descriptorResource.getResourceURL() == null)
{
handler.error(LOG,
ImplMessages.subModuleDoesNotExist(descriptorResource), smd
.getLocation(), null);
continue;
}
processModule(smd.getDescriptor(), handler, assembly);
}
}
private static int size(Collection c)
{
return c == null ? 0 : c.size();
}
}
1.5 +12 -11
jakarta-hivemind/examples/src/java/org/apache/hivemind/examples/ExampleUtils.java
Index: ExampleUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/examples/src/java/org/apache/hivemind/examples/ExampleUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExampleUtils.java 9 Sep 2004 16:06:46 -0000 1.4
+++ ExampleUtils.java 27 Sep 2004 15:50:47 -0000 1.5
@@ -18,15 +18,14 @@
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Registry;
-import org.apache.hivemind.impl.AggregateModuleProvider;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.impl.XmlModuleProvider;
+import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
import org.apache.hivemind.util.FileResource;
/**
* Utilities needed by the examples.
- *
+ *
* @author Howard Lewis Ship
*/
public class ExampleUtils
@@ -34,7 +33,8 @@
/**
* Builds a Registry for a file stored in the src/descriptor/META-INF
directory.
*
- * @param fileName -- the name of the module descriptor file.
+ * @param fileName --
+ * the name of the module descriptor file.
*/
public static Registry buildRegistry(String fileName)
{
@@ -48,14 +48,15 @@
ClassResolver resolver = new DefaultClassResolver();
RegistryBuilder builder = new RegistryBuilder();
- // Process the examples.xml file, which (given its non-standard
name)
- // is not visible.
- AggregateModuleProvider provider = new AggregateModuleProvider();
+ builder.addModuleDescriptorProvider(new
XmlModuleDescriptorProvider(resolver,
+ XmlModuleDescriptorProvider.HIVE_MODULE_XML));
- provider.addModuleProvider(new XmlModuleProvider(resolver,
XmlModuleProvider.HIVE_MODULE_XML));
- provider.addModuleProvider(new XmlModuleProvider(resolver, new
FileResource(path)));
+ // Register the examples.xml file, which (given its non-standard
name)
+ // is not visible.
+ builder.addModuleDescriptorProvider(new
XmlModuleDescriptorProvider(resolver,
+ new FileResource(path)));
- return builder.constructRegistry(provider, Locale.getDefault());
+ return builder.constructRegistry(Locale.getDefault());
}
-}
+}
\ No newline at end of file
1.12 +46 -39
jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java
Index: HiveMindFilter.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- HiveMindFilter.java 9 Sep 2004 16:06:46 -0000 1.11
+++ HiveMindFilter.java 27 Sep 2004 15:50:47 -0000 1.12
@@ -30,17 +30,16 @@
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.DefaultClassResolver;
-import org.apache.hivemind.impl.ModuleProvider;
+import org.apache.hivemind.impl.ModuleDescriptorProvider;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.impl.XmlModuleProvider;
+import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
/**
- * Servlet filter that constructs the Registry at startup. It ensures that
each request is
- * properly terminated with a call to
- * [EMAIL PROTECTED]
org.apache.hivemind.service.ThreadEventNotifier#fireThreadCleanup()}.
- * It also makes the Registry available during the request by
- * storing it as a request attribute.
- *
+ * Servlet filter that constructs the Registry at startup. It ensures that
each request is properly
+ * terminated with a call to
+ * [EMAIL PROTECTED]
org.apache.hivemind.service.ThreadEventNotifier#fireThreadCleanup()}. It also
makes the
+ * Registry available during the request by storing it as a request
attribute.
+ *
* @author Howard Lewis Ship
*/
public class HiveMindFilter implements Filter
@@ -56,11 +55,12 @@
static final String REBUILD_REQUEST_KEY =
"org.apache.hivemind.RebuildRegistry";
private FilterConfig _filterConfig;
+
private Registry _registry;
/**
- * Constructs a [EMAIL PROTECTED] Registry} and stores it into the
- * <code>ServletContext</code>. Any exception throws is logged.
+ * Constructs a [EMAIL PROTECTED] Registry}and stores it into the
<code>ServletContext</code>. Any
+ * exception throws is logged.
*/
public void init(FilterConfig config) throws ServletException
{
@@ -80,10 +80,8 @@
{
_registry = constructRegistry(_filterConfig);
- LOG.info(
- ServletMessages.constructedRegistry(
- _registry,
- System.currentTimeMillis() - startTime));
+ LOG.info(ServletMessages.constructedRegistry(_registry,
System.currentTimeMillis()
+ - startTime));
}
catch (Exception ex)
{
@@ -92,39 +90,48 @@
}
/**
- * Invoked from [EMAIL PROTECTED] #init(FilterConfig)} to actually
- * construct the Registry. Subclasses may override if
- * they have specific initialization needs, or have nonstandard
- * rules for finding HiveMind module deployment descriptors.
+ * Invoked from [EMAIL PROTECTED] #init(FilterConfig)}to actually
construct the Registry. Subclasses may
+ * override if they have specific initialization needs, or have
nonstandard rules for finding
+ * HiveMind module deployment descriptors.
*/
protected Registry constructRegistry(FilterConfig config)
{
- ClassResolver resolver = new DefaultClassResolver();
RegistryBuilder builder = new RegistryBuilder();
- return builder.constructRegistry(getModuleProvider(resolver),
getRegistryLocale());
+ ClassResolver resolver = new DefaultClassResolver();
+
builder.addModuleDescriptorProvider(getModuleDescriptorProvider(resolver));
+
+ return builder.constructRegistry(getRegistryLocale());
}
/**
- * Returns the default Locale. Subclasses may override to select a
particular
- * locale for the Registry.
+ * Returns the default Locale. Subclasses may override to select a
particular locale for the
+ * Registry.
*/
protected Locale getRegistryLocale()
{
return Locale.getDefault();
}
- protected ModuleProvider getModuleProvider(ClassResolver resolver)
+ /**
+ * Returns the [EMAIL PROTECTED] ModuleDescriptorProvider}to be used to
construct the Registry. This
+ * implementation returns the default [EMAIL PROTECTED]
XmlModuleDescriptorProvider}. May be overridden by
+ * subclasses.
+ *
+ * @since 1.1
+ */
+ protected ModuleDescriptorProvider
getModuleDescriptorProvider(ClassResolver resolver)
{
- return new XmlModuleProvider(resolver,
XmlModuleProvider.HIVE_MODULE_XML);
+ return new XmlModuleDescriptorProvider(resolver,
+ XmlModuleDescriptorProvider.HIVE_MODULE_XML);
}
/**
* Passes the request to the filter chain, but then invokes
- * [EMAIL PROTECTED] ThreadEventNotifier#fireThreadCleanup()} (from a
finally block).
+ * [EMAIL PROTECTED] ThreadEventNotifier#fireThreadCleanup()}(from a
finally block).
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
- throws IOException, ServletException
+ throws IOException, ServletException
{
try
{
@@ -135,8 +142,8 @@
finally
{
cleanupThread();
-
- checkRegistryRebuild(request);
+
+ checkRegistryRebuild(request);
}
}
@@ -148,15 +155,15 @@
// This is so not threadsafe, but you don't do this very often.
// This method is synchronized, but other threads may be actively
using
// the Registry we're shutting down.
-
+
// What we really need is some good concurrence support to track the
number
// of threads that may be using the old registry, set a write lock,
and wait
- // for that number to drop to one (this thread). Instead, we'll
just swap in the
+ // for that number to drop to one (this thread). Instead, we'll just
swap in the
// new Registry and hope for the best.
Registry oldRegistry = _registry;
- // Replace the old Registry with a new one. All other threads, but
this
+ // Replace the old Registry with a new one. All other threads, but
this
// one, will begin using the new Registry. Hopefully, we didn't get
// rebuild requests on multiple threads.
@@ -166,7 +173,7 @@
// to help ensure that other threads have "cleared out". If not,
we'll see some
// instability at the instant we shutdown (i.e., all the proxies
will get disabled).
- oldRegistry.shutdown();
+ oldRegistry.shutdown();
}
/**
@@ -196,21 +203,21 @@
}
/**
- * Returns the [EMAIL PROTECTED] Registry} that was stored as a request
attribute
- * inside method [EMAIL PROTECTED] #doFilter(ServletRequest,
ServletResponse, FilterChain)}.
+ * Returns the [EMAIL PROTECTED] Registry}that was stored as a request
attribute inside method
+ * [EMAIL PROTECTED] #doFilter(ServletRequest, ServletResponse,
FilterChain)}.
*/
public static Registry getRegistry(HttpServletRequest request)
{
return (Registry) request.getAttribute(REQUEST_KEY);
}
- /**
- * Sets a flag in the request that will cause the current Registry to
be shutdown
- * and replaced with a new Registry (at the end of the current request).
- */
+ /**
+ * Sets a flag in the request that will cause the current Registry to be
shutdown and replaced
+ * with a new Registry (at the end of the current request).
+ */
public static void rebuildRegistry(HttpServletRequest request)
{
request.setAttribute(REBUILD_REQUEST_KEY, Boolean.TRUE);
}
-}
+}
\ No newline at end of file
1.24 +1 -1
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- TestDescriptorParser.java 27 Sep 2004 14:37:14 -0000 1.23
+++ TestDescriptorParser.java 27 Sep 2004 15:50:47 -0000 1.24
@@ -412,7 +412,7 @@
assertLoggedMessagePattern("Attribute version \\(1\\.0\\.alpha\\) of
element module is improperly "
+ "formatted\\. Version numbers should be a sequence of
three numbers "
- + "seperated by periods\\.");
+ + "separated by periods\\.");
}
public void testSchemaDescription() throws Exception
1.3 +3 -3
jakarta-hivemind/framework/src/test/hivemind/test/TestDependency.java
Index: TestDependency.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestDependency.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestDependency.java 12 Sep 2004 18:30:56 -0000 1.2
+++ TestDependency.java 27 Sep 2004 15:50:47 -0000 1.3
@@ -37,7 +37,7 @@
null);
dependingModule.addDependency(unresolvableDependency);
- SimpleModuleProvider provider = new SimpleModuleProvider();
+ SimpleModuleDescriptorProvider provider = new
SimpleModuleDescriptorProvider();
provider.addModuleDescriptor(dependingModule);
interceptLogging();
@@ -60,7 +60,7 @@
null);
dependingModule.addDependency(unversionedDependency);
- SimpleModuleProvider provider = new SimpleModuleProvider();
+ SimpleModuleDescriptorProvider provider = new
SimpleModuleDescriptorProvider();
provider.addModuleDescriptor(dependingModule);
provider.addModuleDescriptor(requiredModule);
@@ -80,7 +80,7 @@
DependencyDescriptor dependency =
createDependencyDescriptor("required.module", "1.0.0");
dependingModule.addDependency(dependency);
- SimpleModuleProvider provider = new SimpleModuleProvider();
+ SimpleModuleDescriptorProvider provider = new
SimpleModuleDescriptorProvider();
provider.addModuleDescriptor(dependingModule);
provider.addModuleDescriptor(requiredModuleOfWrongVersion);
1.18 +5 -6
jakarta-hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java
Index: TestRegistryBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TestRegistryBuilder.java 25 Sep 2004 17:08:35 -0000 1.17
+++ TestRegistryBuilder.java 27 Sep 2004 15:50:47 -0000 1.18
@@ -25,10 +25,8 @@
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.DefaultClassResolver;
-import org.apache.hivemind.impl.ModuleProvider;
import org.apache.hivemind.impl.RegistryBuilder;
-import org.apache.hivemind.impl.XmlModuleProvider;
-import org.apache.hivemind.internal.RegistryInfrastructure;
+import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
import org.apache.hivemind.parse.ModuleDescriptor;
import org.apache.hivemind.service.ClassFactory;
@@ -61,9 +59,10 @@
RegistryBuilder b = new RegistryBuilder();
- ModuleProvider provider = new XmlModuleProvider(resolver,
XmlModuleProvider.HIVE_MODULE_XML);
+ b.addModuleDescriptorProvider(new
XmlModuleDescriptorProvider(resolver,
+ XmlModuleDescriptorProvider.HIVE_MODULE_XML));
- Registry r = b.constructRegistry(provider, Locale.getDefault());
+ Registry r = b.constructRegistry(Locale.getDefault());
List l = r.getConfiguration("hivemind.test.config.Symbols");
assertEquals(1, l.size());
@@ -92,7 +91,7 @@
ModuleDescriptor firstModule =
createModuleDescriptor(duplicateModuleId, null);
ModuleDescriptor duplicateModule =
createModuleDescriptor(duplicateModuleId, null);
- SimpleModuleProvider provider = new SimpleModuleProvider();
+ SimpleModuleDescriptorProvider provider = new
SimpleModuleDescriptorProvider();
provider.addModuleDescriptor(firstModule);
provider.addModuleDescriptor(duplicateModule);
1.1
jakarta-hivemind/framework/src/test/hivemind/test/SimpleModuleDescriptorProvider.java
Index: SimpleModuleDescriptorProvider.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 java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.impl.ModuleDescriptorProvider;
import org.apache.hivemind.impl.RegistryAssembly;
import org.apache.hivemind.parse.ModuleDescriptor;
/**
* An implementation of the [EMAIL PROTECTED]
org.apache.hivemind.impl.ModuleDescriptorProvider}
* interface convenient for testing purposes. This provider simply provides
* ModuleDescriptors registered with it beforehand.
*
* @author Knut Wannheden
* @since 1.1
*/
class SimpleModuleDescriptorProvider implements ModuleDescriptorProvider
{
private Set _moduleDescriptors = new HashSet();
public void addModuleDescriptor(ModuleDescriptor moduleDescriptor)
{
_moduleDescriptors.add(moduleDescriptor);
}
public List getModuleDescriptors(ErrorHandler handler, RegistryAssembly
assembly)
{
return new ArrayList(_moduleDescriptors);
}
}
1.14 +2 -2
jakarta-hivemind/framework/src/java/org/apache/hivemind/ant/ConstructRegistry.java
Index: ConstructRegistry.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/ant/ConstructRegistry.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ConstructRegistry.java 9 Sep 2004 16:06:46 -0000 1.13
+++ ConstructRegistry.java 27 Sep 2004 15:50:47 -0000 1.14
@@ -30,7 +30,7 @@
import javax.xml.parsers.ParserConfigurationException;
import org.apache.hivemind.Resource;
-import org.apache.hivemind.impl.XmlModuleProvider;
+import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
import org.apache.hivemind.util.FileResource;
import org.apache.hivemind.util.URLResource;
import org.apache.tools.ant.BuildException;
@@ -198,7 +198,7 @@
Resource jarResource = new URLResource(jarRootURL);
- enqueueIfExists(jarResource, XmlModuleProvider.HIVE_MODULE_XML);
+ enqueueIfExists(jarResource,
XmlModuleDescriptorProvider.HIVE_MODULE_XML);
}
private void enqueueIfExists(Resource jarResource, String path)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]