knut 2004/11/11 02:16:06
Modified: framework/src/java/org/apache/hivemind/service/impl
BuilderFacet.java BuilderFactoryLogic.java
BuilderMessagesFacet.java BuilderErrorLogFacet.java
BuilderErrorHandlerFacet.java
BuilderClassResolverFacet.java
BuilderParameter.java BuilderLogFacet.java
framework/src/java/org/apache/hivemind/internal Module.java
RegistryInfrastructure.java
framework/src/java/org/apache/hivemind/impl ModuleImpl.java
RegistryInfrastructureImpl.java
framework/src/test/hivemind/test/services
TestBuilderFactory.java
Log:
refactored constructor autowiring in BuilderFactory to reuse BuilderFacets
Revision Changes Path
1.10 +6 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java
Index: BuilderFacet.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFacet.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- BuilderFacet.java 2 Nov 2004 17:46:09 -0000 1.9
+++ BuilderFacet.java 11 Nov 2004 10:16:06 -0000 1.10
@@ -116,6 +116,12 @@
return null;
}
+ /** @since 1.1 */
+ public boolean canAutowireConstructorParameter()
+ {
+ return false;
+ }
+
/**
* Returns the type of property assigned by this facet, if known.
Returns null otherwise. This
* implementation returns null. Used by [EMAIL PROTECTED]
#autowire(Object, String, Module)}.
1.9 +9 -21
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java
Index: BuilderFactoryLogic.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderFactoryLogic.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BuilderFactoryLogic.java 10 Nov 2004 20:51:23 -0000 1.8
+++ BuilderFactoryLogic.java 11 Nov 2004 10:16:06 -0000 1.9
@@ -31,10 +31,8 @@
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.HiveMind;
import org.apache.hivemind.Location;
-import org.apache.hivemind.Messages;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.service.EventLinker;
@@ -157,26 +155,16 @@
Object[] parameters = new Object[parameterTypes.length];
for (int i = 0; i < parameters.length; i++)
- if (parameterTypes[i] == ClassResolver.class)
- parameters[i] =
_factoryParameters.getInvokingModule().getClassResolver();
- else if (parameterTypes[i] == ErrorHandler.class)
- parameters[i] =
_factoryParameters.getInvokingModule().getErrorHandler();
- else if (parameterTypes[i] == ErrorLog.class)
- parameters[i] = _factoryParameters.getErrorLog();
- else if (parameterTypes[i] == Log.class)
- parameters[i] = _factoryParameters.getLog();
- else if (parameterTypes[i] == Messages.class)
- parameters[i] =
_factoryParameters.getInvokingModule().getMessages();
+ {
+ BuilderFacet facet =
_parameter.getPropertyByType(parameterTypes[i]);
+
+ if (facet != null && facet.canAutowireConstructorParameter())
+ parameters[i] = facet.getFacetValue(_factoryParameters,
parameterTypes[i]);
+ else if
(_contributingModule.containsService(parameterTypes[i]))
+ parameters[i] =
_contributingModule.getService(parameterTypes[i]);
else
- try
- {
- parameters[i] =
_factoryParameters.getInvokingModule().getService(
- parameterTypes[i]);
- }
- catch (ApplicationRuntimeException e)
- {
- continue outer;
- }
+ continue outer;
+ }
return ConstructorUtils.invoke(candidate, parameters);
}
1.7 +6 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java
Index: BuilderMessagesFacet.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderMessagesFacet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BuilderMessagesFacet.java 2 Nov 2004 17:46:09 -0000 1.6
+++ BuilderMessagesFacet.java 11 Nov 2004 10:16:06 -0000 1.7
@@ -16,7 +16,6 @@
import org.apache.hivemind.Messages;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
-import org.apache.hivemind.internal.Module;
/**
* [EMAIL PROTECTED] org.apache.hivemind.service.impl.BuilderFacet}whose
value is the
@@ -41,5 +40,11 @@
protected Class getFacetType()
{
return Messages.class;
+ }
+
+ /** @since 1.1 */
+ public boolean canAutowireConstructorParameter()
+ {
+ return true;
}
}
1.3 +5 -2
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorLogFacet.java
Index: BuilderErrorLogFacet.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorLogFacet.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BuilderErrorLogFacet.java 4 Nov 2004 14:32:33 -0000 1.2
+++ BuilderErrorLogFacet.java 11 Nov 2004 10:16:06 -0000 1.3
@@ -14,10 +14,8 @@
package org.apache.hivemind.service.impl;
-import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.ErrorLog;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
-import org.apache.hivemind.internal.Module;
/**
* Exposes the service's [EMAIL PROTECTED]
org.apache.hivemind.internal.ExtensionPoint#getErrorLog() error log}
@@ -45,4 +43,9 @@
return ErrorLog.class;
}
+ /** @since 1.1 */
+ public boolean canAutowireConstructorParameter()
+ {
+ return true;
+ }
}
1.4 +6 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java
Index: BuilderErrorHandlerFacet.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderErrorHandlerFacet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BuilderErrorHandlerFacet.java 2 Nov 2004 17:46:09 -0000 1.3
+++ BuilderErrorHandlerFacet.java 11 Nov 2004 10:16:06 -0000 1.4
@@ -16,7 +16,6 @@
import org.apache.hivemind.ErrorHandler;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
-import org.apache.hivemind.internal.Module;
/**
* Exposes the invoking module's [EMAIL PROTECTED]
org.apache.hivemind.ErrorHandler}to a service as a
@@ -41,5 +40,11 @@
protected Class getFacetType()
{
return ErrorHandler.class;
+ }
+
+ /** @since 1.1 */
+ public boolean canAutowireConstructorParameter()
+ {
+ return true;
}
}
1.4 +5 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java
Index: BuilderClassResolverFacet.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderClassResolverFacet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BuilderClassResolverFacet.java 2 Nov 2004 17:46:09 -0000 1.3
+++ BuilderClassResolverFacet.java 11 Nov 2004 10:16:06 -0000 1.4
@@ -16,7 +16,6 @@
import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
-import org.apache.hivemind.internal.Module;
/**
* [EMAIL PROTECTED] org.apache.hivemind.service.impl.BuilderFacet}whose
value is the
@@ -43,4 +42,9 @@
return ClassResolver.class;
}
+ /** @since 1.1 */
+ public boolean canAutowireConstructorParameter()
+ {
+ return true;
+ }
}
1.6 +22 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java
Index: BuilderParameter.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderParameter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- BuilderParameter.java 18 Jul 2004 14:43:12 -0000 1.5
+++ BuilderParameter.java 11 Nov 2004 10:16:06 -0000 1.6
@@ -15,7 +15,9 @@
package org.apache.hivemind.service.impl;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.hivemind.impl.BaseLocatable;
@@ -27,10 +29,18 @@
public class BuilderParameter extends BaseLocatable
{
private String _className;
+
private List _properties = new ArrayList();
+
private List _parameters = new ArrayList();
+
+ /** @since 1.1 */
+ private Map _typedProperties = new HashMap();
+
private List _events = new ArrayList();
+
private String _initializeMethod;
+
private boolean _autowireServices;
public String getClassName()
@@ -51,6 +61,11 @@
public void addProperty(BuilderFacet facet)
{
_properties.add(facet);
+
+ Class facetType = facet.getFacetType();
+
+ if (facetType != null)
+ _typedProperties.put(facetType, facet);
}
public List getProperties()
@@ -58,6 +73,12 @@
return _properties;
}
+ /** @since 1.1 */
+ public BuilderFacet getPropertyByType(Class propertyType)
+ {
+ return (BuilderFacet) _typedProperties.get(propertyType);
+ }
+
public void setClassName(String string)
{
_className = string;
@@ -93,4 +114,4 @@
_autowireServices = autowireServices;
}
-}
+}
\ No newline at end of file
1.7 +6 -2
jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java
Index: BuilderLogFacet.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/BuilderLogFacet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BuilderLogFacet.java 2 Nov 2004 17:46:09 -0000 1.6
+++ BuilderLogFacet.java 11 Nov 2004 10:16:06 -0000 1.7
@@ -15,9 +15,7 @@
package org.apache.hivemind.service.impl;
import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
-import org.apache.hivemind.internal.Module;
/**
* Facet whose value is the <code>Log</code> instance for the service (which
is based on the
@@ -41,5 +39,11 @@
protected Class getFacetType()
{
return Log.class;
+ }
+
+ /** @since 1.1 */
+ public boolean canAutowireConstructorParameter()
+ {
+ return true;
}
}
1.8 +54 -42
jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/Module.java
Index: Module.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/Module.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Module.java 1 Sep 2004 13:17:37 -0000 1.7
+++ Module.java 11 Nov 2004 10:16:06 -0000 1.8
@@ -26,18 +26,16 @@
import org.apache.hivemind.schema.Translator;
/**
- * The definition of a HiveMind Module. A Module is
- * a container of service extension points and
- * configuration extension points. It also acts as a "gateway" so that
services
- * and configurations in other modules may be accessed.
- *
+ * The definition of a HiveMind Module. A Module is a container of service
extension points and
+ * configuration extension points. It also acts as a "gateway" so that
services and configurations
+ * in other modules may be accessed.
* <p>
- * Why do we expose the Module rather than the [EMAIL PROTECTED]
org.apache.hivemind.internal.RegistryInfrastructure}?
- * It's more than just qualifying ids before passing them up to the RI.
- * At some future point, a concept of visibility will be added to HiveMind.
This will make many services
- * and configurations private to the module which defines them and the
necessary visibility filtering
- * logic will be here.
- *
+ * Why do we expose the Module rather than the
+ * [EMAIL PROTECTED] org.apache.hivemind.internal.RegistryInfrastructure}?
It's more than just qualifying ids
+ * before passing them up to the RI. At some future point, a concept of
visibility will be added to
+ * HiveMind. This will make many services and configurations private to the
module which defines
+ * them and the necessary visibility filtering logic will be here.
+ *
* @author Howard Lewis Ship
*/
public interface Module extends Locatable, SymbolSource
@@ -48,59 +46,74 @@
public String getModuleId();
/**
- * Looks up
- * the [EMAIL PROTECTED] ServicePoint} (throwing an exception if not
found)
- * and invokes [EMAIL PROTECTED] ServicePoint#getService(Class)}.
+ * Returns true if a single service exists which implements the
specified service interface and
+ * is visible to this module.
+ *
+ * @param serviceInterface
+ * @return true if a single visible service for the specified service
interface exists
+ * @since 1.1
+ */
+ public boolean containsService(Class serviceInterface);
+
+ /**
+ * Looks up the [EMAIL PROTECTED] ServicePoint}(throwing an exception if
not found) and invokes
+ * [EMAIL PROTECTED] ServicePoint#getService(Class)}.
*
- * @param serviceId an unqualified id for a service within this module,
or a fully qualified id for a service in this or any other module
- * @param serviceInterface type the result will be cast to
+ * @param serviceId
+ * an unqualified id for a service within this module, or a
fully qualified id for a
+ * service in this or any other module
+ * @param serviceInterface
+ * type the result will be cast to
*/
public Object getService(String serviceId, Class serviceInterface);
/**
- * Finds a service that implements the provided interface. Exactly one
such service may exist or an exception is thrown.
+ * Finds a service that implements the provided interface. Exactly one
such service may exist or
+ * an exception is thrown.
*
- * @param serviceInterface used to locate the service
+ * @param serviceInterface
+ * used to locate the service
*/
public Object getService(Class serviceInterface);
/**
* Returns the identified service extension point.
*
- * @param serviceId an unqualified id for a service within this module,
or a fully qualified id for a service in this or any other module
- * @throws org.apache.hivemind.ApplicationRuntimeException if no such
service extension point exists
+ * @param serviceId
+ * an unqualified id for a service within this module, or a
fully qualified id for a
+ * service in this or any other module
+ * @throws org.apache.hivemind.ApplicationRuntimeException
+ * if no such service extension point exists
*/
public ServicePoint getServicePoint(String serviceId);
/**
- * Returns the [EMAIL PROTECTED] java.util.List} of elements for the
- * specified configuration point. The returned List
- * is unmodifiable. It may be empty, but won't be null.
- *
- * <p>It is expressly the <em>caller's</em> job to sort the elements
- * into an appropriate order (a copy will have to be made since
- * the returned List is unmodifiable).
- *
- * @param configurationId an unqualified id for a configuration within
this module, or a fully qualified id for a configuration in this or any other
module
- * @throws ApplicationRuntimeException if this module does not
- * contain the specified configuration extension point.
- *
+ * Returns the [EMAIL PROTECTED] java.util.List}of elements for the
specified configuration point. The
+ * returned List is unmodifiable. It may be empty, but won't be null.
+ * <p>
+ * It is expressly the <em>caller's</em> job to sort the elements into
an appropriate order (a
+ * copy will have to be made since the returned List is unmodifiable).
+ *
+ * @param configurationId
+ * an unqualified id for a configuration within this module,
or a fully qualified id
+ * for a configuration in this or any other module
+ * @throws ApplicationRuntimeException
+ * if this module does not contain the specified
configuration extension point.
*/
public List getConfiguration(String configurationId);
/**
- * Returns the resource resolver for this module. The resource resolver
- * is used to locate classes by name (using the correct classloader).
+ * Returns the resource resolver for this module. The resource resolver
is used to locate
+ * classes by name (using the correct classloader).
*/
public ClassResolver getClassResolver();
/**
- * Returns an object that can provide and format localized messages for
this
- * module. The messages come from a properties file,
- * <code>hivemodule.properties</code> (localized)
- * stored with the HiveMind deployment descriptor in the META-INF folder.
+ * Returns an object that can provide and format localized messages for
this module. The
+ * messages come from a properties file,
<code>hivemodule.properties</code> (localized) stored
+ * with the HiveMind deployment descriptor in the META-INF folder.
*/
public Messages getMessages();
@@ -121,14 +134,13 @@
public Locale getLocale();
/**
- * @see
org.apache.hivemind.internal.RegistryInfrastructure#expandSymbols(String,
Location)
- *
+ * @see
org.apache.hivemind.internal.RegistryInfrastructure#expandSymbols(String,
Location)
*/
public String expandSymbols(String input, Location location);
/**
- * Returns the [EMAIL PROTECTED] org.apache.hivemind.ErrorHandler} for
this Registry.
+ * Returns the [EMAIL PROTECTED] org.apache.hivemind.ErrorHandler}for
this Registry.
*/
public ErrorHandler getErrorHandler();
-}
+}
\ No newline at end of file
1.8 +10 -5
jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java
Index: RegistryInfrastructure.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/RegistryInfrastructure.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RegistryInfrastructure.java 25 Sep 2004 17:08:35 -0000 1.7
+++ RegistryInfrastructure.java 11 Nov 2004 10:16:06 -0000 1.8
@@ -24,7 +24,7 @@
/**
* Extension of [EMAIL PROTECTED] org.apache.hivemind.Registry}provided by
some internals of HiveMind to
- * fasciliate the creation of services and configurations.
+ * faciliate the creation of services and configurations.
*
* @author Howard Lewis Ship
*/
@@ -169,22 +169,27 @@
public boolean containsConfiguration(String configurationId, Module
module);
/**
- * Returns true if a single public service for the specified service
interface class exists.
+ * Returns true if a single service exists which implements the
specified service interface and
+ * is visible to the given module.
*
* @param serviceInterface
* @param module
* the service must be visible to the module (or null for the
application's view)
- * @return true if a single service for the specified service interface
exists
+ * @return true if a single visible service for the specified service
interface exists
* @since 1.1
*/
public boolean containsService(Class serviceInterface, Module module);
/**
- * Returns true if a public service for the specified service id and
service interface exists.
+ * Returns true if a single service with the given id exists which
implements the specified
+ * service interface and is visible to the given module.
*
* @param serviceId
* @param serviceInterface
- * @return true if a service for the specified service id and service
interface exists
+ * @param module
+ * the service must be visible to the module (or null for the
application's view)
+ * @return true if a single visible service for the specified service id
and service interface
+ * exists
* @since 1.1
*/
public boolean containsService(String serviceId, Class serviceInterface,
Module module);
1.13 +5 -0
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java
Index: ModuleImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ModuleImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ModuleImpl.java 25 Sep 2004 17:08:34 -0000 1.12
+++ ModuleImpl.java 11 Nov 2004 10:16:06 -0000 1.13
@@ -53,6 +53,11 @@
return _moduleId;
}
+ public boolean containsService(Class serviceInterface)
+ {
+ return _registry.containsService(serviceInterface, this);
+ }
+
public Object getService(String serviceId, Class serviceInterface)
{
String qualifiedId = IdUtils.qualify(_moduleId, serviceId);
1.3 +2 -3
jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java
Index: RegistryInfrastructureImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryInfrastructureImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RegistryInfrastructureImpl.java 31 Oct 2004 14:44:25 -0000 1.2
+++ RegistryInfrastructureImpl.java 11 Nov 2004 10:16:06 -0000 1.3
@@ -27,7 +27,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ErrorHandler;
-import org.apache.hivemind.HiveMind;
import org.apache.hivemind.HiveMindMessages;
import org.apache.hivemind.Location;
import org.apache.hivemind.ShutdownCoordinator;
@@ -45,7 +44,7 @@
import org.apache.hivemind.util.ToStringBuilder;
/**
- * Implementation of [EMAIL PROTECTED] org.apache.hivemind.Registry}.
+ * Implementation of [EMAIL PROTECTED] RegistryInfrastructure}.
*
* @author Howard Lewis Ship
*/
@@ -416,7 +415,7 @@
List servicePoints = (List)
_servicePointsByInterface.get(serviceInterface);
if (servicePoints == null)
- servicePoints = Collections.EMPTY_LIST;
+ return false;
int count = 0;
1.21 +11 -7
jakarta-hivemind/framework/src/test/hivemind/test/services/TestBuilderFactory.java
Index: TestBuilderFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/TestBuilderFactory.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- TestBuilderFactory.java 9 Nov 2004 17:29:12 -0000 1.20
+++ TestBuilderFactory.java 11 Nov 2004 10:16:06 -0000 1.21
@@ -499,10 +499,13 @@
module.getClassResolver();
mc.setReturnValue(classResolver);
- StringHolder h = new StringHolderImpl();
+ module.containsService(Comparable.class);
+ mc.setReturnValue(false);
+
+ module.containsService(StringHolder.class);
+ mc.setReturnValue(true);
- module.getService(Comparable.class);
- mc.setThrowable(new ApplicationRuntimeException("Failure."));
+ StringHolder h = new StringHolderImpl();
module.getService(StringHolder.class);
mc.setReturnValue(h);
@@ -516,6 +519,7 @@
parameter.setClassName(ConstructorAutowireTarget.class.getName());
parameter.setAutowireServices(true);
+ parameter.addProperty(new BuilderClassResolverFacet());
ConstructorAutowireTarget service = (ConstructorAutowireTarget)
execute(fp, parameter);
@@ -554,11 +558,11 @@
module.getClassResolver();
mc.setReturnValue(classResolver);
- module.getService(Comparable.class);
- mc.setThrowable(new ApplicationRuntimeException("Failure."));
+ module.containsService(Comparable.class);
+ mc.setReturnValue(false);
- module.getService(StringHolder.class);
- mc.setThrowable(new ApplicationRuntimeException("Failure."), 2);
+ module.containsService(StringHolder.class);
+ mc.setReturnValue(false, 2);
fp.getErrorLog();
fpc.setReturnValue(el);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]