hlship 2003/09/18 13:08:59
Modified: hivemind/xdocs bootstrap.xml
hivemind/framework/src/java/org/apache/commons/hivemind
HiveMind.java
hivemind/framework/src/java/org/apache/commons/hivemind/impl
RegistryBuilder.java
hivemind/framework/src/test/hivemind/test
TestRegistryBuilder.java
Log:
Move constructDefaultRegistry() from HiveMind to RegistryBuilder.
Add a test for constructDefaultRegistry().
Revision Changes Path
1.5 +2 -2 jakarta-commons-sandbox/hivemind/xdocs/bootstrap.xml
Index: bootstrap.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/bootstrap.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- bootstrap.xml 18 Sep 2003 19:00:57 -0000 1.4
+++ bootstrap.xml 18 Sep 2003 20:08:59 -0000 1.5
@@ -157,7 +157,7 @@
<p>
Alternately, the static method
-<a
href="&apiroot;/HiveMind.html#constructDefaultRegistry()">constructDefaultRegistry()</a>
can be invoked. It's just those same four lines of code.
+<a
href="&apiroot;/impl/RegistryBuilder.html#constructDefaultRegistry()">constructDefaultRegistry()</a>
can be invoked. It's just those same four lines of code.
</p>
1.3 +1 -21
jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/HiveMind.java
Index: HiveMind.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/HiveMind.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HiveMind.java 18 Sep 2003 19:00:59 -0000 1.2
+++ HiveMind.java 18 Sep 2003 20:08:59 -0000 1.3
@@ -62,12 +62,9 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
-import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import org.apache.commons.hivemind.impl.DefaultClassResolver;
-import org.apache.commons.hivemind.impl.RegistryBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -255,21 +252,4 @@
return null;
}
- /**
- * 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 have
different
- * error handling needs, or wish to pick up HiveMind module deployment
- * descriptors for non-standard locations, then you can
- * use [EMAIL PROTECTED] RegistryBuilder} instead.
- */
- public static Registry constructDefaultRegistry()
- {
- ClassResolver resolver = new DefaultClassResolver();
- RegistryBuilder builder = new RegistryBuilder();
-
- builder.processModules(resolver);
-
- return builder.constructRegistry(Locale.getDefault());
- }
}
1.3 +19 -1
jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/impl/RegistryBuilder.java
Index: RegistryBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/framework/src/java/org/apache/commons/hivemind/impl/RegistryBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RegistryBuilder.java 18 Sep 2003 19:00:58 -0000 1.2
+++ RegistryBuilder.java 18 Sep 2003 20:08:59 -0000 1.3
@@ -735,4 +735,22 @@
return c == null ? 0 : c.size();
}
+ /**
+ * 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 have
different
+ * error handling needs, or wish to pick up HiveMind module deployment
+ * descriptors for non-standard locations, you must create
+ * a RegistryBuilder instance yourself.
+ */
+ public static Registry constructDefaultRegistry()
+ {
+ ClassResolver resolver = new DefaultClassResolver();
+ RegistryBuilder builder = new RegistryBuilder();
+
+ builder.processModules(resolver);
+
+ return builder.constructRegistry(Locale.getDefault());
+ }
+
}
1.3 +34 -5
jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java
Index: TestRegistryBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestRegistryBuilder.java 18 Sep 2003 19:00:59 -0000 1.2
+++ TestRegistryBuilder.java 18 Sep 2003 20:08:59 -0000 1.3
@@ -70,6 +70,7 @@
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.impl.DefaultClassResolver;
import org.apache.commons.hivemind.impl.RegistryBuilder;
+import org.apache.commons.hivemind.service.ClassFactory;
/**
* Tests the [EMAIL PROTECTED] org.apache.commons.hivemind.impl.RegistryBuilder}
class.
@@ -127,11 +128,39 @@
Registry r = b.constructRegistry(Locale.getDefault());
List l = r.getConfiguration("hivemind.test.config.Symbols");
- assertEquals(1, l.size());
+ assertEquals(1, l.size());
- Datum d = (Datum) l.get(0);
+ Datum d = (Datum) l.get(0);
- assertEquals("wife", d.getKey());
- assertEquals("wilma", d.getValue());
+ assertEquals("wife", d.getKey());
+ assertEquals("wilma", d.getValue());
+ }
+
+ public void testConstructDefaultRegistry() throws Exception
+ {
+ ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
+
+ try
+ {
+ // Add src to the classpath, so that META-INF will be picked up
properly.
+
+ File file = new File("src");
+
+ URLClassLoader testLoader =
+ new URLClassLoader(new URL[] { file.toURL()}, originalLoader);
+
+ Thread.currentThread().setContextClassLoader(testLoader);
+
+ Registry r = RegistryBuilder.constructDefaultRegistry();
+
+ ClassFactory factory =
+ (ClassFactory) r.getService("hivemind.ClassFactory",
ClassFactory.class);
+
+ assertNotNull(factory);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(originalLoader);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]