You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by ah...@apache.org on 2006/11/03 09:52:41 UTC
svn commit: r470725 - in
/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl:
RegistryProvider.java RegistryProviderAutoDetector.java
Author: ahuegen
Date: Fri Nov 3 00:52:40 2006
New Revision: 470725
URL: http://svn.apache.org/viewvc?view=rev&rev=470725
Log:
hivemind-provider attribute in MANIFEST.MF renamed to hivemind-providers
Now supports a comma separated list of providers
Modified:
hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProvider.java
hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java
Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProvider.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProvider.java?view=diff&rev=470725&r1=470724&r2=470725
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProvider.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProvider.java Fri Nov 3 00:52:40 2006
@@ -3,8 +3,24 @@
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.definition.RegistryDefinition;
+/**
+ * A registry provider contributes module definitions to a {@link RegistryDefinition}.
+ * It must be implemented to participate in the registry autoloading mechanism
+ * triggered by {@link RegistryBuilder#autoDetectModules()} and described in
+ * {@link RegistryProviderAutoDetector}.
+ * The implementations must have a no arguments constructor.
+ *
+ * @author Achim Huegen
+ */
public interface RegistryProvider
{
+ /**
+ * Called during the registry definition phase, before the registry is constructed.
+ * New module definitions can be added to the registry and existing can be altered.
+ *
+ * @param registryDefinition the registry definition
+ * @param errorHandler an error handler to call when errors occur.
+ */
public void process(RegistryDefinition registryDefinition, ErrorHandler errorHandler);
}
Modified: hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java
URL: http://svn.apache.org/viewvc/hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java?view=diff&rev=470725&r1=470724&r2=470725
==============================================================================
--- hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java (original)
+++ hivemind/branches/branch-2-0-annot/framework/src/java/org/apache/hivemind/impl/RegistryProviderAutoDetector.java Fri Nov 3 00:52:40 2006
@@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
+import java.util.StringTokenizer;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
@@ -18,7 +19,10 @@
/**
* Searches for {@link org.apache.hivemind.impl.RegistryProvider} implementations
* that are defined in manifest files. Creates an instance of each
- * implementation and returns them.
+ * implementation and returns them in the getProviders method.
+ * The manifest file must contain a global attribute <code>hivemind-providers</code>
+ * which contains a comma separated list of classes that implement
+ * the {@link org.apache.hivemind.impl.RegistryProvider} interface.
*
* @author Achim Huegen
*/
@@ -27,7 +31,7 @@
private static final Log LOG = LogFactory.getLog(RegistryProviderAutoDetector.class);
public static final String MANIFEST = "META-INF/MANIFEST.MF";
public static final String HIVEMIND_SECTION_NAME = "hivemind";
- public static final String PROVIDER_ATTRIBUTE_NAME = "hivemind-provider";
+ public static final String PROVIDER_ATTRIBUTE_NAME = "hivemind-providers";
private List _providers = new ArrayList();
@@ -41,6 +45,10 @@
return _providers;
}
+ /**
+ * Process all manifest files found in the classpath
+ * @param resolver the ClassResolver to use for the search
+ */
private void processManifestFiles(ClassResolver resolver)
{
if (LOG.isDebugEnabled())
@@ -69,6 +77,12 @@
}
+ /**
+ * Process a single manifest file.
+ *
+ * @param resolver
+ * @param resource pointer to the manifest file
+ */
private void processManifestFile(ClassResolver resolver, URLResource resource)
{
URL url = resource.getResourceURL();
@@ -83,19 +97,37 @@
e);
}
// Search for an entry that defines a provider class
-// Attributes attributes = manifest.getAttributes(HIVEMIND_SECTION_NAME);
Attributes attributes = manifest.getMainAttributes();
if (attributes != null) {
- String providerClassName = attributes.getValue(PROVIDER_ATTRIBUTE_NAME);
- if (providerClassName != null) {
+ String providers = attributes.getValue(PROVIDER_ATTRIBUTE_NAME);
+ if (providers != null) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Found provider '" + providerClassName + "' defined in manifest file '" + url.toString() + "'");
+ LOG.debug("Found providers '" + providers + "' defined in manifest file '" + url.toString() + "'");
}
- loadProvider(resolver, providerClassName);
+ handleProviderAttribute(resolver, providers);
}
}
}
+ /**
+ * Parse the provider list in an attribute and load all classes.
+ */
+ private void handleProviderAttribute(ClassResolver resolver, String providers)
+ {
+ StringTokenizer tokenizer = new StringTokenizer(providers, ",");
+ while (tokenizer.hasMoreTokens())
+ {
+ String providerClassName = tokenizer.nextToken();
+ loadProvider(resolver, providerClassName);
+ }
+ }
+
+ /**
+ * Load a provider class and create an instance.
+ *
+ * @param resolver
+ * @param providerClassName
+ */
private void loadProvider(ClassResolver resolver, String providerClassName)
{
if (LOG.isDebugEnabled())