jyang 2004/03/18 16:12:24
Modified: cornerstone/src/java/org/apache/cornerstone/framework/init
Cornerstone.java
Log:
added getRegistry()
added support for factory.className in mini implementation manager
PR:
Obtained from:
Submitted by:
Reviewed by:
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.4 +79 -17
jakarta-jetspeed-2/cornerstone/src/java/org/apache/cornerstone/framework/init/Cornerstone.java
Index: Cornerstone.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/cornerstone/src/java/org/apache/cornerstone/framework/init/Cornerstone.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Cornerstone.java 16 Mar 2004 02:01:35 -0000 1.3
+++ Cornerstone.java 19 Mar 2004 00:12:24 -0000 1.4
@@ -24,6 +24,9 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+
+import org.apache.cornerstone.framework.api.factory.IFactory;
+import org.apache.cornerstone.framework.api.registry.IRegistry;
import org.apache.cornerstone.framework.constant.Constant;
import org.apache.cornerstone.framework.util.Util;
import org.apache.log4j.Logger;
@@ -78,20 +81,46 @@
* @param iface Interface of implementation to create
* @return Implementation of the interface
*/
- public static Object getImplementation(Class iface)
+ public static Object getImplementation(Class implementationInterface)
{
- Object implementation = _ImplementationMap.get(iface);
+ Object implementation = _ImplementationMap.get(implementationInterface);
if (implementation == null)
{
- Boolean implementationLoaded = (Boolean)
_ImplementationLoadedMap.get(iface);
+ Boolean implementationLoaded = (Boolean)
_ImplementationLoadedMap.get(implementationInterface);
if (implementationLoaded == null)
{
- implementation = loadImplementation(iface);
+ implementation = loadImplementation(implementationInterface);
}
}
return implementation;
}
+ public static IRegistry getRegistry()
+ {
+ String registryFactoryClassName =
getImplementationFactoryClassName(IRegistry.class);
+ if (registryFactoryClassName != null)
+ {
+ try
+ {
+ IFactory factory = (IFactory)
Util.createInstance(registryFactoryClassName);
+ IRegistry registry = (IRegistry)
factory.createInstance(_RuntimeHomeDir);
+ _ImplementationMap.put(IRegistry.class, registry);
+ _ImplementationLoadedMap.put(IRegistry.class, Boolean.TRUE);
+ return registry;
+ }
+ catch (Exception e)
+ {
+ _Logger.error("failed to create registry; factoryClassName=" +
registryFactoryClassName);
+ return null;
+ }
+ }
+ else
+ {
+ _Logger.error("failed to create registry; factoryClassName=" +
registryFactoryClassName);
+ return null;
+ }
+ }
+
protected static void readBootStrapProperties() throws InitException
{
try
@@ -145,30 +174,63 @@
}
}
- protected static Object loadImplementation(Class implementationInterface)
- {
+ protected static String getImplementationInstanceClassName(Class
implementationInterface)
+ {
String implementationClassNameConfigName = Constant.IMPLEMENTATION +
Constant.SLASH + implementationInterface.getName() + Constant.SLASH +
Constant.INSTANCE_CLASS_NAME;
String implementationClassName =
_BootStrapProperties.getProperty(implementationClassNameConfigName);
- _ImplementationLoadedMap.put(implementationInterface, Boolean.TRUE);
- if (implementationClassName == null)
+ return implementationClassName;
+ }
+
+ protected static String getImplementationFactoryClassName(Class
implementationInterface)
+ {
+ String implementationFactoryClassNameConfigName = Constant.IMPLEMENTATION +
Constant.SLASH + implementationInterface.getName() + Constant.SLASH +
Constant.FACTORY_CLASS_NAME;
+ String implementationFactoryClassName =
_BootStrapProperties.getProperty(implementationFactoryClassNameConfigName);
+ return implementationFactoryClassName;
+ }
+
+ protected static Object loadImplementation(Class implementationInterface)
+ {
+ String implementationClassName =
getImplementationInstanceClassName(implementationInterface);
+ if (implementationClassName != null)
{
- return null;
- }
- else
- {
+ // instance.className provided
try
{
_Logger.info("loadImplementation(): implementationClassName="
+ implementationClassName);
- Object manager =
Util.createInstance(implementationClassName);
- _ImplementationMap.put(implementationInterface,
manager);
- return manager;
+ Object implementation =
Util.createInstance(implementationClassName);
+ _ImplementationMap.put(implementationInterface,
implementation);
+ _ImplementationLoadedMap.put(implementationInterface,
Boolean.TRUE);
+ return implementation;
}
catch (Exception e)
{
- _Logger.error("failed to create manager of " +
implementationInterface.getName(), e);
+ _Logger.error("failed to create implementation of " +
implementationInterface.getName(), e);
return null;
}
}
+
+ String implementationFactoryClassName =
getImplementationFactoryClassName(implementationInterface);
+ if (implementationFactoryClassName != null)
+ {
+ // factory.className provided
+ try
+ {
+ _Logger.info("loadImplementation():
implementationFactoryClassName=" + implementationFactoryClassName);
+ IFactory factory = (IFactory)
Util.createInstance(implementationFactoryClassName);
+ Object implementation = factory.createInstance();
+ _ImplementationMap.put(implementationInterface,
implementation);
+ _ImplementationLoadedMap.put(implementationInterface,
Boolean.TRUE);
+ return implementation;
+ }
+ catch (Exception e)
+ {
+ _Logger.error("failed to create implementation of " +
implementationInterface.getName(), e);
+ return null;
+ }
+ }
+
+ _Logger.error("no instance or factory class name specified for " +
implementationInterface.getName());
+ return null;
}
private static Logger _Logger = Logger.getLogger(Cornerstone.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]