You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by hl...@apache.org on 2003/07/16 19:22:38 UTC
cvs commit: jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl EJBProxyFactory.java
hlship 2003/07/16 10:22:38
Modified: hivemind/src/java/org/apache/commons/hivemind
HiveMindMessages.properties
ServiceImplementationFactory.java
hivemind/xdocs descriptor.xml services.xml
hivemind/src/java/org/apache/commons/hivemind/parse
FactoryDescriptor.java HiveMind_1.0.xsd
ParametersDescriptor.java
hivemind/src/test/hivemind/test/parse
TestDescriptorParser.java
ContributeFactoryParameters.xml
hivemind/src/test/hivemind/test/services EJBProxy.xml
hivemind/src/java/org/apache/commons/hivemind/service/impl
EJBProxyFactory.java
Log:
Change the <parameters> element to configure a parameters object provided by the service implementation factory.
Revision Changes Path
1.12 +5 -2 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMindMessages.properties
Index: HiveMindMessages.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/HiveMindMessages.properties,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- HiveMindMessages.properties 15 Jul 2003 17:36:20 -0000 1.11
+++ HiveMindMessages.properties 16 Jul 2003 17:22:37 -0000 1.12
@@ -5,10 +5,13 @@
no-such-service-extension-id=Service extension point {0} does not exist.
no-such-configuration-extension-id=Configuration extension point {0} does not exist.
no-such-service=Service {0} (implementing interface {1}) does not exist.
-service-wrong-parameter-count=Service factory {0} expects {1,choice,0#no parameters,1#one parameter, 1>#{1} parameters} , but was passed {2,choice,0#no parameters,1#one parameter, 1>#{2} parameters} parameters.
+
+missing-factory-parameter=Core implementation factory parameter ''{0}'' is not specified for factory {1}.
+
HiveMind.default-registry-not-set=HiveMind.getDefault() invoked before default registry has been set.
HiveMind.elements-not-orderable=Elements of list {0} do not implement the Orderable interface and can not be sorted.
+
# impl package
BaseRegistry.no-such-module-id=Registry does not contain module ''{0}''.
1.2 +14 -2 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceImplementationFactory.java
Index: ServiceImplementationFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceImplementationFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServiceImplementationFactory.java 30 Jun 2003 23:04:30 -0000 1.1
+++ ServiceImplementationFactory.java 16 Jul 2003 17:22:37 -0000 1.2
@@ -65,6 +65,18 @@
*/
public interface ServiceImplementationFactory
{
+ /**
+ * Called first, to create a object to hold parameters. The <parameters>
+ * element will configure the empty object that is returned; the configured
+ * parameters object is passed back to
+ * {@link #createCoreServiceImplementation(ServiceExtensionPoint, Object)}.
+ *
+ * @returns the object, or null if the factory does not use any
+ * parameters.
+ */
+
+ public Object createNewParameters();
+
/**
* Creates a core implementation object for a particular service extension point.
* Typically, the factory creates an instance and modifies it to implement
@@ -76,5 +88,5 @@
* @param parameters any additional parameters that are needed by the factory.
* parameters may be empty, but won't be null.
*/
- public Object createCoreServiceImplementation(ServiceExtensionPoint point, Object[] parameters);
+ public Object createCoreServiceImplementation(ServiceExtensionPoint point, Object parameters);
}
1.13 +8 -5 jakarta-commons-sandbox/hivemind/xdocs/descriptor.xml
Index: descriptor.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/descriptor.xml,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- descriptor.xml 2 Jul 2003 21:41:12 -0000 1.12
+++ descriptor.xml 16 Jul 2003 17:22:37 -0000 1.13
@@ -682,13 +682,14 @@
<td>0..1</td>
- <td>A list of parameters passed to the factory, used when it constructs the implmentation.</td>
+ <td>Used to configure the specific parameters used by the factory to create the instance.</td>
</tr>
<tr>
<td colspan="4">
The remaining elements are the same
- as for &create-instance;
+ as for &create-instance; (and are used to configure properties of the instance
+ created by the factory).
</td>
</tr>
@@ -699,13 +700,15 @@
<section name="parameters">
- <p>&_parameters; is used to pass a list of values to an implementation factory.
+ <p>&_parameters; is used to configure a
+ <a href="apidocs/org/apache/commons/hivemind/ServiceImplementationFactory.html">service implementation factory</a>'s
+ parameters.
</p>
<p>
- &_parameters; accepts the same elements as &configuration;
+ &_parameters; accepts the same elements as &create-instance;
</p>
</section>
1.10 +58 -16 jakarta-commons-sandbox/hivemind/xdocs/services.xml
Index: services.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/services.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- services.xml 15 Jul 2003 17:36:20 -0000 1.9
+++ services.xml 16 Jul 2003 17:22:37 -0000 1.10
@@ -35,31 +35,62 @@
and the client, and add functionality to the core implementation such as
logging, security, transaction demarkation or performance monitoring.</p>
</section>
+
<section name="Contributing to Services">
<p>Any module may contribute to any service extension point. A <
contribute-service> element contains these contributions.
- Contributions take three forms: <ul> <li>Instance Creators</li> <li>
- Instance Factories</li> <li>Interceptors</li> </ul> </p>
- <subsection name="Factory Contributions">
- <p>A factory contribution is used to instantiate a Java class as the
+ Contributions take three forms:
+
+ <ul>
+ <li>Implementations
+ <ul>
+ <li>by creating an instance</li>
+ <li>by invoking an implementation factory</li>
+ </ul>
+ </li>
+ <li>Interceptors</li>
+ </ul>
+
+ </p>
+
+ <subsection name="Implementation Contributions">
+ <p>An implementation contribution is used to instantiate a Java class as the
core implementation instance for the service. This instance may be
- configured as well (by setting properties of the instance).</p>
- <p>There are two forms of service constructors: instance creators and
- instance factories.</p>
+ configured as well (by setting properties of the instance).</p>
+ <p>There are two forms of implementation contributions:
+ instance creators and
+ implementation factories.</p>
<p>An instance creator is represented by a &create-instance; element. It
includes a class attribute, the Java class to instantiate.</p>
- <p>An instance factory is represented by a &service-factory; element. It
+ <p>An implementation factory is represented by a &service-factory; element. It
includes a service-id attribute. This is the fully qualfied id of a
service implementation factory service, a service which implements the
<a href="apidocs/org/apache/commons/hivemind/ServiceImplementationFactory.html">ServiceImplementationFactory</a>
interface.</p>
+
<p>In both cases, the properties of the core instance may be configured
- using enclosed &set;, &set-expression;, &set-create;, &set-factory;
- &set-service-ref; and &set-xml;
- elements.</p>
+ using enclosed &set;, &set-expression;, etc. elements</p>
+ </subsection>
+
+ <subsection name="Implementation Factories">
+
+ <p>
+ An implementation factory is used to create a core implementation for a
+ service at runtime. This may be accomplished using JDK Proxies or
+ bytecode enhancement.
+ </p>
+
+ <p>
+ Often, the factory will need some additional configuration information.
+ For example, the
+ <a href="apidocs/org/apache/commons/hivemind/service/impl/EJBProxyFactory.html">org.apache.commons.hivemind.EJBProxyFactory</a>
+ uses its parameters to identify the JNDI name of the EJB's home interface.
+ </p>
+
</subsection>
+
<subsection name="Interceptor Contributions">
<p>An interceptor contribution is represented by a &interceptor;
element. The service-id attribute identifies a service interceptor factory
@@ -68,15 +99,25 @@
<a href="apidocs/org/apache/commons/hivemind/ServiceInterceptorFactory.html">ServiceInterceptorFactory</a>
interface.</p>
+
<p>An interceptor factory knows how to create an object that implements
- an arbitrary interface, adding the functionality of that interface.
- For example, a logging interceptor factory would create an object
- instance that logged entry and exit to each method. The factory
+ an arbitrary interface (the interface being defined by the
+ service extension point), adding the functionality of that interface.
+ For example, the
+
+<a href="apidocs/org/apache/commons/hivemind/service/impl/LoggingInterceptorFactory.html">org.apache.commons.hivemind.LoggingInterceptor</a>
+ factory creates an
+ instance that logs entry and exit to each method.
+ </p>
+
+ <p>The factory
shouldn't care what the interface itself is ... it should adapt to
whatever interface is defined by the service extension point it will
create an instance for.</p>
+
<p>Interceptor factories can be implemented using dynamic proxies (a
feature introduced in JDK 1.3), or by dynamic bytecode enhancement.</p>
+
<p>A service extension point may have any number of interceptor
contributions. If the order in which interceptors are applied is
important, then the optional order attribute can be specified; it is
@@ -90,7 +131,8 @@
the core implementation. Then comes "Performance" and last "Logging". When a client
invokes a method, it is really invoking it on the "Logging" interceptor, which then re-invokes the method
on the "Performance" interceptor, and so in, down to the core implementation. Each interceptor
- can perform work before and/or after re-invoking the method on the next layer. In this example,
+ can perform work before and/or after re-invoking the method on the next layer
+ (as well as catch exceptions thrown by the more inner objects). In this example,
"Logging" was given a high order so that it wouldn't affect the "Performance" interceptor. Security
was given a lower order than "Performance" so that the time for security checks would be included in the
"Performance" analysis.
1.7 +14 -13 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/FactoryDescriptor.java
Index: FactoryDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/FactoryDescriptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FactoryDescriptor.java 30 Jun 2003 23:04:54 -0000 1.6
+++ FactoryDescriptor.java 16 Jul 2003 17:22:37 -0000 1.7
@@ -79,7 +79,7 @@
public class FactoryDescriptor extends AbstractInstanceBuilderDescriptor
{
private String _factoryServiceId;
- private ParametersDescriptor _parameters;
+ private ParametersDescriptor _parameters;
public String getFactoryServiceId()
{
@@ -91,7 +91,6 @@
_factoryServiceId = string;
}
-
/**
* Obtains the factory service (using the service id) and uses
* it to create a new instance, which is configured
@@ -101,7 +100,8 @@
public Object provideValue(Module module)
{
Registry registry = module.getRegistry();
- InstanceFactory factory = (InstanceFactory) registry.getService(_factoryServiceId, InstanceFactory.class);
+ InstanceFactory factory =
+ (InstanceFactory) registry.getService(_factoryServiceId, InstanceFactory.class);
if (factory == null)
throw new ApplicationRuntimeException(
@@ -123,6 +123,7 @@
public Object createCoreServiceImplementation(ServiceExtensionPoint point, Module module)
{
Registry registry = module.getRegistry();
+
ServiceImplementationFactory factory =
(ServiceImplementationFactory) registry.getService(
_factoryServiceId,
@@ -134,11 +135,12 @@
getLocation(),
null);
- Object[] parameters =
- _parameters == null ? new Object[0] : _parameters.extractParameterValues(module);
-
+ Object factoryParameters = factory.createNewParameters();
+
+ if (_parameters != null)
+ _parameters.configureFactoryParameter(factoryParameters, module);
- Object result = factory.createCoreServiceImplementation(point, parameters);
+ Object result = factory.createCoreServiceImplementation(point, factoryParameters);
configureNewInstance(result, module);
@@ -158,11 +160,10 @@
return _parameters;
}
-
- /**
- * Sets the parameters for the factory, which is only used
- * for service factories.
- */
+ /**
+ * Sets the parameters for the factory, which is only used
+ * for service factories.
+ */
public void setParameters(ParametersDescriptor descriptor)
{
_parameters = descriptor;
1.13 +3 -3 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/HiveMind_1.0.xsd
Index: HiveMind_1.0.xsd
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/HiveMind_1.0.xsd,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- HiveMind_1.0.xsd 2 Jul 2003 21:41:12 -0000 1.12
+++ HiveMind_1.0.xsd 16 Jul 2003 17:22:37 -0000 1.13
@@ -464,10 +464,10 @@
<xs:sequence minOccurs="0" maxOccurs="1">
<xs:element name="parameters" minOccurs="0" maxOccurs="1">
<xs:annotation>
- <xs:documentation>Specifies parameters passed to a service factory.</xs:documentation>
+ <xs:documentation>Used to configure the parameters object passed to the core instance factory.</xs:documentation>
</xs:annotation>
<xs:complexType>
- <xs:group ref="value-providers-group" minOccurs="1"
+ <xs:group ref="configure-instance-group" minOccurs="1"
maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
1.4 +33 -35 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ParametersDescriptor.java
Index: ParametersDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/ParametersDescriptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParametersDescriptor.java 16 Jul 2003 14:11:01 -0000 1.3
+++ ParametersDescriptor.java 16 Jul 2003 17:22:37 -0000 1.4
@@ -73,38 +73,36 @@
*/
public class ParametersDescriptor extends BaseLocatable
{
- private List _providers = new ArrayList();
-
- public void addProvider(ValueProvider provider)
- {
- _providers.add(provider);
- }
-
- public List getProviders()
- {
- return _providers;
- }
-
- public Object[] extractParameterValues(Module module)
- {
- int count = _providers.size();
- Object[] result = new Object[count];
-
- for (int i = 0; i < count; i++)
- {
- ValueProvider provider = (ValueProvider)_providers.get(i);
- result[i] = provider.provideValue(module);
- }
-
- return result;
- }
-
- public String toString()
- {
- ToStringBuilder builder = new ToStringBuilder(this);
-
- builder.append("providers", _providers);
-
- return builder.toString();
- }
+ private List _configurators = new ArrayList();
+
+ public void addConfigurator(Configurator c)
+ {
+ _configurators.add(c);
+ }
+
+ public List getConfigurators()
+ {
+ return _configurators;
+ }
+
+ public void configureFactoryParameter(Object factoryParameters, Module module)
+ {
+ int count = _configurators.size();
+
+ for (int i = 0; i < count; i++)
+ {
+ Configurator c = (Configurator) _configurators.get(i);
+
+ c.configure(factoryParameters, module);
+ }
+ }
+
+ public String toString()
+ {
+ ToStringBuilder builder = new ToStringBuilder(this);
+
+ builder.append("configuratiors", _configurators);
+
+ return builder.toString();
+ }
}
1.13 +4 -3 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java
Index: TestDescriptorParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/TestDescriptorParser.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TestDescriptorParser.java 2 Jul 2003 21:41:13 -0000 1.12
+++ TestDescriptorParser.java 16 Jul 2003 17:22:37 -0000 1.13
@@ -565,11 +565,12 @@
assertEquals("package.blat.BlatFactory", fd.getFactoryServiceId());
ParametersDescriptor pd = fd.getParameters();
- List l = pd.getProviders();
+ List l = pd.getConfigurators();
assertEquals(1, l.size());
ValueDescriptor vd = (ValueDescriptor) l.get(0);
- assertEquals("foo", vd.getValue());
+ assertEquals("foo", vd.getPropertyName());
+ assertEquals("baz", vd.getValue());
l = fd.getConfigurators();
assertEquals(1, l.size());
1.2 +2 -2 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/ContributeFactoryParameters.xml
Index: ContributeFactoryParameters.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/parse/ContributeFactoryParameters.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContributeFactoryParameters.xml 26 Jun 2003 20:31:30 -0000 1.1
+++ ContributeFactoryParameters.xml 16 Jul 2003 17:22:37 -0000 1.2
@@ -7,7 +7,7 @@
<contribute-service service-id="package.bar.Bar">
<service-factory service-id="package.blat.BlatFactory">
<parameters>
- <value>foo</value>
+ <set property="foo" value="baz"/>
</parameters>
<set property="bar" value="blat"/>
</service-factory>
1.3 +2 -2 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/EJBProxy.xml
Index: EJBProxy.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/EJBProxy.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EJBProxy.xml 30 Jun 2003 23:04:45 -0000 1.2
+++ EJBProxy.xml 16 Jul 2003 17:22:38 -0000 1.3
@@ -11,7 +11,7 @@
<service-factory service-id="org.apache.commons.hivemind.EJBProxyFactory">
<parameters>
- <value>hivemind.test.services.Simple</value>
+ <set property="jndiName" value="hivemind.test.services.Simple"/>
</parameters>
</service-factory>
</service>
1.4 +45 -13 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/EJBProxyFactory.java
Index: EJBProxyFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/EJBProxyFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EJBProxyFactory.java 15 Jul 2003 17:36:19 -0000 1.3
+++ EJBProxyFactory.java 16 Jul 2003 17:22:38 -0000 1.4
@@ -65,35 +65,62 @@
import org.apache.commons.hivemind.Registry;
import org.apache.commons.hivemind.ServiceExtensionPoint;
import org.apache.commons.hivemind.ServiceImplementationFactory;
+import org.apache.commons.lang.StringUtils;
import org.apache.tapestry.ApplicationRuntimeException;
+import org.apache.tapestry.spec.BaseLocatable;
/**
* An implementation of {@link org.apache.commons.hivemind.ServiceImplementationFactory}
* that can create a proxy to a stateless session EJB. Using this factory, it is
* easy to create a HiveMind service wrapper around the actual EJB.
*
+ * <p>
+ * The parameters for the factory are used to identify the JNDI name of the
+ * session EJB's home interface.
+ *
+ *
*
* @author Howard Lewis Ship
* @version $Id$
*/
-public class EJBProxyFactory implements ServiceImplementationFactory, Initializable
+public class EJBProxyFactory
+ extends BaseLocatable
+ implements ServiceImplementationFactory, Initializable
{
private String _serviceId;
- public Object createCoreServiceImplementation(
- ServiceExtensionPoint point,
- Object[] parameters)
+ /**
+ * Parameters object for {@link EJBProxyFactory}. Used to
+ * specify the JNDI name of the session EJB's home interface.
+ */
+ public static class Parameters
{
- if (parameters.length != 1)
- throw new ApplicationRuntimeException(
- HiveMind.format(
- "service-wrong-parameter-count",
- _serviceId,
- "1",
- Integer.toString(parameters.length)));
+ private String _jndiName;
+
+ public String getJndiName()
+ {
+ return _jndiName;
+ }
+
+ public void setJndiName(String string)
+ {
+ _jndiName = string;
+ }
+ }
+
+ public Object createCoreServiceImplementation(ServiceExtensionPoint point, Object parameters)
+ {
Class serviceInterface = point.getServiceInterface();
- String jndiName = (String) parameters[0];
+ Parameters p = (Parameters) parameters;
+
+ String jndiName = p.getJndiName();
+
+ if (StringUtils.isEmpty(jndiName))
+ throw new ApplicationRuntimeException(
+ HiveMind.format("missing-factory-parameter", "jndiName", _serviceId),
+ getLocation(),
+ null);
Registry registry = point.getModule().getRegistry();
@@ -109,6 +136,11 @@
public void initializeService(ServiceExtensionPoint point, Object service)
{
_serviceId = point.getExtensionPointId();
+ }
+
+ public Object createNewParameters()
+ {
+ return new Parameters();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org