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/09/06 00:32:38 UTC
cvs commit: jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl AbstractServiceInterceptorFactory.java
hlship 2003/09/05 15:32:38
Modified: hivemind/src/java/org/apache/commons/hivemind/impl
InterceptorStackImpl.java
ServiceInterceptorContributionImpl.java
InvokeFactoryServiceConstructor.java
hivemind/xdocs descriptor.xml
hivemind/src/java/org/apache/commons/hivemind/parse
DescriptorParser.java InvokeFactoryDescriptor.java
InterceptorDescriptor.java
hivemind/src/test/hivemind/test/services/impl
TrackerFactory.java
hivemind/src/test/hivemind/test/services TestServices.java
hivemind/src/java/org/apache/commons/hivemind
ServiceInterceptorFactory.java
ServiceInterceptorContribution.java
hivemind/src/xsl hivemind.xsl
hivemind/src/java/org/apache/commons/hivemind/service/impl
AbstractServiceInterceptorFactory.java
Added: hivemind/src/java/org/apache/commons/hivemind/parse
AbstractServiceInvocationDescriptor.java
hivemind/src/test/hivemind/test/services/impl
MethodFilter.java FilterLoggingInterceptor.java
BedrockImpl.java
hivemind/src/test/hivemind/test/services
InterceptorParameters.xml Bedrock.java
Log:
Allow interceptor factories to have parameters (like service implementation factories)
Allow <interceptor> element to enclose parameters to an interceptor factory
Revision Changes Path
1.6 +6 -11 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InterceptorStackImpl.java
Index: InterceptorStackImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InterceptorStackImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InterceptorStackImpl.java 5 Sep 2003 15:04:41 -0000 1.5
+++ InterceptorStackImpl.java 5 Sep 2003 22:32:37 -0000 1.6
@@ -139,7 +139,7 @@
throw new ApplicationRuntimeException(
HiveMind.format(
"InterceptorStack.null-interceptor",
- _contribution.getFactoryId(),
+ _contribution.getFactoryServiceId(),
_sep.getExtensionPointId()),
_contribution.getLocation(),
null);
@@ -150,7 +150,7 @@
"InterceptorStack.interceptor-does-not-implement-interface",
new Object[] {
interceptor,
- _contribution.getFactoryId(),
+ _contribution.getFactoryServiceId(),
_sep.getExtensionPointId(),
_interfaceClass.getName()}),
_contribution.getLocation(),
@@ -167,24 +167,19 @@
public void process(ServiceInterceptorContribution contribution)
{
- String factoryId = contribution.getFactoryId();
+ String factoryId = contribution.getFactoryServiceId();
if (LOG.isDebugEnabled())
LOG.debug("Applying interceptor factory " + factoryId + " to " + _top);
- ServiceInterceptorFactory factory =
- (ServiceInterceptorFactory) _registry.getService(
- factoryId,
- ServiceInterceptorFactory.class);
-
// And now we can finally do this!
try
{
_contribution = contribution;
- factory.createInterceptor(this);
- }
+ contribution.createInterceptor(this);
+ }
finally
{
_contribution = null;
1.5 +70 -9 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ServiceInterceptorContributionImpl.java
Index: ServiceInterceptorContributionImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/ServiceInterceptorContributionImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServiceInterceptorContributionImpl.java 30 Aug 2003 14:29:51 -0000 1.4
+++ ServiceInterceptorContributionImpl.java 5 Sep 2003 22:32:37 -0000 1.5
@@ -57,7 +57,17 @@
package org.apache.commons.hivemind.impl;
+import java.util.List;
+
+import org.apache.commons.hivemind.HiveMind;
+import org.apache.commons.hivemind.InterceptorStack;
+import org.apache.commons.hivemind.Module;
+import org.apache.commons.hivemind.Registry;
+import org.apache.commons.hivemind.ServiceExtensionPoint;
+import org.apache.commons.hivemind.ServiceImplementationFactory;
import org.apache.commons.hivemind.ServiceInterceptorContribution;
+import org.apache.commons.hivemind.ServiceInterceptorFactory;
+import org.apache.commons.hivemind.schema.Schema;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
@@ -67,23 +77,30 @@
* @version $Id$
*/
-public class ServiceInterceptorContributionImpl extends BaseLocatable implements ServiceInterceptorContribution
+public class ServiceInterceptorContributionImpl
+ extends BaseLocatable
+ implements ServiceInterceptorContribution
{
- private String _factoryId;
+ private String _factoryServiceId;
private int _order;
-
+ private Module _contributingModule;
+ private List _parameters;
+ private List _convertedParameters;
+ private ServiceInterceptorFactory _factory;
+
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
- builder.append("factoryId", _factoryId);
+ builder.append("factoryServiceId", _factoryServiceId);
builder.append("order", _order);
+ builder.append("parameters", _parameters);
return builder.toString();
}
- public String getFactoryId()
+ public String getFactoryServiceId()
{
- return _factoryId;
+ return _factoryServiceId;
}
public int getOrder()
@@ -91,14 +108,58 @@
return _order;
}
- public void setFactoryId(String string)
+ public void setFactoryServiceId(String string)
{
- _factoryId = string;
+ _factoryServiceId = string;
}
public void setOrder(int i)
{
_order = i;
+ }
+
+ public void createInterceptor(InterceptorStack stack)
+ {
+ setup();
+
+ _factory.createInterceptor(stack, _contributingModule, _convertedParameters);
+ }
+
+ private synchronized void setup()
+ {
+ if (_factory == null)
+ {
+ Registry registry = _contributingModule.getRegistry();
+
+ String qualifiedFactoryId = HiveMind.qualify(_contributingModule, _factoryServiceId);
+
+ String factoryModuleId = RegistryImpl.split(qualifiedFactoryId);
+ Module factoryModule = registry.getModule(factoryModuleId);
+ ServiceExtensionPoint factoryPoint =
+ factoryModule.getServiceExtensionPoint(qualifiedFactoryId);
+
+ _factory =
+ (ServiceInterceptorFactory) factoryPoint.getService(
+ ServiceInterceptorFactory.class);
+
+ Schema schema = factoryPoint.getParametersSchema();
+
+ SchemaProcessorImpl processor = new SchemaProcessorImpl(schema);
+
+ processor.process(_parameters, _contributingModule);
+
+ _convertedParameters = processor.getElements();
+ }
+ }
+
+ public void setContributingModule(Module module)
+ {
+ _contributingModule = module;
+ }
+
+ public void setParameters(List list)
+ {
+ _parameters = list;
}
}
1.6 +1 -2 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InvokeFactoryServiceConstructor.java
Index: InvokeFactoryServiceConstructor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/impl/InvokeFactoryServiceConstructor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InvokeFactoryServiceConstructor.java 5 Sep 2003 15:04:41 -0000 1.5
+++ InvokeFactoryServiceConstructor.java 5 Sep 2003 22:32:37 -0000 1.6
@@ -59,7 +59,6 @@
import java.util.List;
-import org.apache.commons.hivemind.ApplicationRuntimeException;
import org.apache.commons.hivemind.HiveMind;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.Registry;
1.23 +9 -1 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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- descriptor.xml 24 Aug 2003 03:28:29 -0000 1.22
+++ descriptor.xml 5 Sep 2003 22:32:38 -0000 1.23
@@ -249,6 +249,14 @@
applied. Lowest orders go first; the default value is 0.</td>
</tr>
</table>
+
+<p>
+Like a service implementation factory, a service interceptor factory may need parameters.
+As with &invoke-factory;, parameters to the interceptor factory are enclosed by
+the &_interceptor; element. The service interceptor factory will decode the
+parameters using its ¶meters-schema; schema definition.
+</p>
+
</section>
<section name="invoke-factory">
1.30 +17 -12 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java
Index: DescriptorParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/DescriptorParser.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- DescriptorParser.java 30 Aug 2003 14:29:51 -0000 1.29
+++ DescriptorParser.java 5 Sep 2003 22:32:38 -0000 1.30
@@ -154,7 +154,6 @@
private static final int STATE_EXTENSION = 4;
private static final int STATE_SERVICE = 5;
private static final int STATE_CREATE_INSTANCE = 6;
- private static final int STATE_INTERCEPTOR = 7;
private static final int STATE_EXTEND_SERVICE = 8;
/**
@@ -165,7 +164,13 @@
private static final int STATE_SCHEMA = 9;
private static final int STATE_ELEMENT = 10;
private static final int STATE_RULES = 11;
- private static final int STATE_INVOKE_FACTORY = 12;
+
+ /**
+ * Used with <invoke-factory> and <interceptor> to
+ * collect parameters that will be passed to the implementation or
+ * interceptor factory service.
+ */
+ private static final int STATE_COLLECT_SERVICE_PARAMETERS = 12;
/**
* Represents building Element hierarchy as a light-wieght DOM.
@@ -778,9 +783,9 @@
beginRules(qName);
break;
- case STATE_INVOKE_FACTORY :
+ case STATE_COLLECT_SERVICE_PARAMETERS :
- beginInvokeFactory(qName);
+ beginCollectServiceParameters(qName);
break;
default :
@@ -1016,17 +1021,17 @@
/**
* Very similar to {@link #beginExtension(String)}, in that it creates an
* {@link ElementImpl}, adds it as a parameter to the
- * {@link InvokeFactoryDescriptor}, then enters STATE_LWDOM to fill in its
+ * {@link AbstractServiceInvocationDescriptor}, then enters STATE_LWDOM to fill in its
* attributes and content.
*/
- private void beginInvokeFactory(String elementName)
+ private void beginCollectServiceParameters(String elementName)
{
ElementImpl element = buildLWDomElement(elementName);
- InvokeFactoryDescriptor ifd = (InvokeFactoryDescriptor) peekObject();
+ AbstractServiceInvocationDescriptor sid = (AbstractServiceInvocationDescriptor) peekObject();
- ifd.addParameter(element);
+ sid.addParameter(element);
push(elementName, element, STATE_LWDOM);
}
@@ -1087,7 +1092,7 @@
{
InvokeFactoryDescriptor ifd = new InvokeFactoryDescriptor();
- push(elementName, ifd, STATE_INVOKE_FACTORY);
+ push(elementName, ifd, STATE_COLLECT_SERVICE_PARAMETERS);
checkAttributes(INVOKE_FACTORY_ATTRIBUTES);
@@ -1104,11 +1109,11 @@
{
InterceptorDescriptor id = new InterceptorDescriptor();
- push(elementName, id, STATE_INTERCEPTOR);
+ push(elementName, id, STATE_COLLECT_SERVICE_PARAMETERS);
checkAttributes(INTERCEPTOR_ATTRIBUTES);
- id.setServiceId(getAttribute("service-id"));
+ id.setFactoryServiceId(getAttribute("service-id"));
if (isAttribute("order"))
id.setOrder(getIntAttribute("order"));
1.5 +6 -41 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InvokeFactoryDescriptor.java
Index: InvokeFactoryDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InvokeFactoryDescriptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- InvokeFactoryDescriptor.java 30 Aug 2003 14:29:51 -0000 1.4
+++ InvokeFactoryDescriptor.java 5 Sep 2003 22:32:38 -0000 1.5
@@ -64,7 +64,6 @@
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.ServiceExtensionPoint;
import org.apache.commons.hivemind.ServiceImplementationConstructor;
-import org.apache.commons.hivemind.impl.BaseLocatable;
import org.apache.commons.hivemind.impl.InvokeFactoryServiceConstructor;
import org.apache.commons.lang.builder.ToStringBuilder;
@@ -74,34 +73,10 @@
* @author Howard Lewis Ship
* @version $Id$
*/
-public class InvokeFactoryDescriptor extends BaseLocatable implements InstanceBuilder
+public class InvokeFactoryDescriptor
+ extends AbstractServiceInvocationDescriptor
+ implements InstanceBuilder
{
- private String _factoryServiceId;
- private List _parameters;
-
- public void addParameter(Element parameter)
- {
- if (_parameters == null)
- _parameters = new ArrayList();
-
- _parameters.add(parameter);
- }
-
- public List getParameters()
- {
- return _parameters;
- }
-
- public String getFactoryServiceId()
- {
- return _factoryServiceId;
- }
-
- public void setFactoryServiceId(String string)
- {
- _factoryServiceId = string;
- }
-
public ServiceImplementationConstructor createConstructor(
ServiceExtensionPoint point,
Module contributingModule)
@@ -111,20 +86,10 @@
result.setLocation(getLocation());
result.setContributingModule(contributingModule);
result.setParameters(getParameters());
- result.setFactoryServiceId(_factoryServiceId);
- result.setServiceExtensionPoint(point);
+ result.setFactoryServiceId(getFactoryServiceId());
+ result.setServiceExtensionPoint(point);
return result;
- }
-
- public String toString()
- {
- ToStringBuilder builder = new ToStringBuilder(this);
-
- builder.append("factoryServiceId", _factoryServiceId);
- builder.append("parameters", _parameters);
-
- return builder.toString();
}
}
1.9 +4 -27 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InterceptorDescriptor.java
Index: InterceptorDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/InterceptorDescriptor.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- InterceptorDescriptor.java 30 Aug 2003 14:29:51 -0000 1.8
+++ InterceptorDescriptor.java 5 Sep 2003 22:32:38 -0000 1.9
@@ -58,8 +58,6 @@
package org.apache.commons.hivemind.parse;
import org.apache.commons.hivemind.Orderable;
-import org.apache.commons.hivemind.impl.BaseLocatable;
-import org.apache.commons.lang.builder.ToStringBuilder;
/**
* Descriptor for the <interceptor> element.
@@ -67,40 +65,19 @@
* @author Howard Lewis Ship
* @version $Id$
*/
-public class InterceptorDescriptor extends BaseLocatable
-implements Orderable
+public class InterceptorDescriptor extends AbstractServiceInvocationDescriptor
{
private int _order;
- private String _serviceId;
-
- public String toString()
- {
- ToStringBuilder builder = new ToStringBuilder(this);
-
- builder.append("serviceId", _serviceId);
- builder.append("order", _order);
-
- return builder.toString();
- }
public int getOrder()
{
return _order;
}
- public String getServiceId()
- {
- return _serviceId;
- }
-
public void setOrder(int i)
{
_order = i;
}
-
- public void setServiceId(String string)
- {
- _serviceId = string;
- }
-
+
+ // TODO: get the order property into toString()
}
1.1 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/parse/AbstractServiceInvocationDescriptor.java
Index: AbstractServiceInvocationDescriptor.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.hivemind.parse;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.hivemind.Element;
import org.apache.commons.hivemind.impl.BaseLocatable;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* Base class for descriptors that represent invocating a service with parameters.
* This is used for the <interceptor> and <invoke-factory> elements.
*
* @author Howard Lewis Ship
* @version $Id: AbstractServiceInvocationDescriptor.java,v 1.1 2003/09/05 22:32:38 hlship Exp $
*/
public abstract class AbstractServiceInvocationDescriptor extends BaseLocatable
{
private String _factoryServiceId;
private List _parameters;
public void addParameter(Element parameter)
{
if (_parameters == null)
_parameters = new ArrayList();
_parameters.add(parameter);
}
public List getParameters()
{
return _parameters;
}
public String getFactoryServiceId()
{
return _factoryServiceId;
}
public void setFactoryServiceId(String string)
{
_factoryServiceId = string;
}
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
builder.append("factoryServiceId", _factoryServiceId);
builder.append("parameters", _parameters);
return builder.toString();
}
}
1.8 +12 -3 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/TrackerFactory.java
Index: TrackerFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/TrackerFactory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TrackerFactory.java 30 Aug 2003 14:29:54 -0000 1.7
+++ TrackerFactory.java 5 Sep 2003 22:32:38 -0000 1.8
@@ -63,9 +63,16 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.ServiceInterceptorFactory;
import org.apache.commons.hivemind.InterceptorStack;
+/**
+ * Used with the unit tests.
+ *
+ * @author Howard Lewis Ship
+ * @version $Id$
+ */
public class TrackerFactory implements ServiceInterceptorFactory
{
private static final List _list = new ArrayList();
@@ -100,11 +107,13 @@
return _list;
}
- public void createInterceptor(InterceptorStack stack)
+ public void createInterceptor(
+ InterceptorStack stack,
+ Module contributingModule,
+ List parameters)
{
Class interfaceClass = stack.getServiceInterface();
- ClassLoader loader =
- stack.getClassResolver().getClassLoader();
+ ClassLoader loader = stack.getClassResolver().getClassLoader();
Object top = stack.peek();
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/MethodFilter.java
Index: MethodFilter.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package hivemind.test.services.impl;
/**
* Used by {@link hivemind.test.services.impl.FilterLoggingInterceptor} to
* identify which methods are logged.
*
* @author Howard Lewis Ship
* @version $Id: MethodFilter.java,v 1.1 2003/09/05 22:32:38 hlship Exp $
*/
public class MethodFilter
{
private String _name;
public String getName()
{
return _name;
}
public void setName(String string)
{
_name = string;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/FilterLoggingInterceptor.java
Index: FilterLoggingInterceptor.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package hivemind.test.services.impl;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.hivemind.ApplicationRuntimeException;
import org.apache.commons.hivemind.InterceptorStack;
import org.apache.commons.hivemind.Module;
import org.apache.commons.hivemind.ServiceInterceptorFactory;
import org.apache.commons.hivemind.service.BodyBuilder;
import org.apache.commons.hivemind.service.ClassFab;
import org.apache.commons.hivemind.service.ClassFabUtils;
import org.apache.commons.hivemind.service.ClassFactory;
import org.apache.commons.hivemind.service.impl.AbstractLoggingInterceptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Much like {@link org.apache.commons.hivemind.service.impl.LoggingInterceptorFactory},
* but uses parameters to limit the methods that will be logged.
*
* @author Howard Lewis Ship
* @version $Id: FilterLoggingInterceptor.java,v 1.1 2003/09/05 22:32:38 hlship Exp $
*/
public class FilterLoggingInterceptor implements ServiceInterceptorFactory
{
private ClassFactory _classFactory;
public void createInterceptor(InterceptorStack stack, Module invokingModule, List parameters)
{
Set names = new HashSet();
Iterator i = parameters.iterator();
while (i.hasNext())
{
MethodFilter filter = (MethodFilter) i.next();
names.add(filter.getName());
}
Class serviceInterfaceClass = stack.getServiceInterface();
String name = ClassFabUtils.generateClassName("Interceptor");
ClassFab classFab =
_classFactory.newClass(
name,
AbstractLoggingInterceptor.class,
stack.getServiceExtensionPoint().getModule());
classFab.addInterface(serviceInterfaceClass);
classFab.addField("_inner", serviceInterfaceClass);
classFab.addConstructor(
new Class[] { Log.class, serviceInterfaceClass },
null,
"{ super($1); _inner = $2; }");
Method[] methods = serviceInterfaceClass.getMethods();
BodyBuilder builder = new BodyBuilder();
for (int j = 0; j < methods.length; j++)
{
Method m = methods[j];
String methodName = m.getName();
builder.clear();
builder.begin();
if (names.contains(methodName))
{
builder.add("_logEntry(");
builder.addQuoted(methodName);
builder.addln(", $args);");
}
builder.add("return ($r) ");
builder.add("_inner.");
builder.add(methodName);
builder.addln("($$);");
builder.end();
classFab.addMethod(
Modifier.PUBLIC,
methodName,
m.getReturnType(),
m.getParameterTypes(),
m.getExceptionTypes(),
builder.toString());
}
Class interceptorClass = classFab.createClass();
Log log = LogFactory.getLog(stack.getServiceExtensionPoint().getExtensionPointId());
Object interceptor = null;
try
{
Constructor c =
interceptorClass.getConstructor(new Class[] { Log.class, serviceInterfaceClass });
interceptor = c.newInstance(new Object[] { log, stack.peek()});
}
catch (Exception ex)
{
throw new ApplicationRuntimeException(ex);
}
stack.push(interceptor);
}
public void setClassFactory(ClassFactory factory)
{
_classFactory = factory;
}
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/impl/BedrockImpl.java
Index: BedrockImpl.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package hivemind.test.services.impl;
import hivemind.test.services.Bedrock;
/**
* Implementation of {@link hivemind.test.services.Bedrock}.
*
* @author Howard Lewis Ship
* @version $Id: BedrockImpl.java,v 1.1 2003/09/05 22:32:38 hlship Exp $
*/
public class BedrockImpl implements Bedrock
{
public void fred()
{
}
public void barney()
{
}
public void wilma()
{
}
}
1.26 +23 -1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/TestServices.java
Index: TestServices.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/TestServices.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- TestServices.java 30 Aug 2003 14:29:54 -0000 1.25
+++ TestServices.java 5 Sep 2003 22:32:38 -0000 1.26
@@ -447,4 +447,26 @@
checkLoggingEvent(null, "END returnArrayType() [(java.lang.String[]){alpha, beta}]", true);
}
+ public void testInterceptorParameters() throws Exception
+ {
+ Registry r = buildRegistry("InterceptorParameters.xml");
+
+ interceptLogging("hivemind.test.services.Bedrock");
+
+ Bedrock b = (Bedrock)r.getService("hivemind.test.services.Bedrock", Bedrock.class);
+
+ b.fred();
+ b.barney();
+ b.wilma();
+
+ // Only fred and wilma should be logged.
+
+ List events = getInterceptedLogEvents();
+
+ assertEquals(2, events.size());
+ checkLoggingEvent(null, "BEGIN fred()", events, 0);
+ checkLoggingEvent(null, "BEGIN wilma()", events, 1);
+
+ }
+
}
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/InterceptorParameters.xml
Index: InterceptorParameters.xml
===================================================================
<?xml version="1.0"?>
<!-- $Id: InterceptorParameters.xml,v 1.1 2003/09/05 22:32:38 hlship Exp $ -->
<module id="hivemind.test.services" version="1.0.0">
<service id="FilterLoggingInterceptor" interface="org.apache.commons.hivemind.ServiceInterceptorFactory">
<parameters-schema>
<element name="method">
<attribute name="name" required="true"/>
<rules>
<create-object class="hivemind.test.services.impl.MethodFilter"/>
<read-attribute attribute="name" property="name"/>
<invoke-parent method="addElement"/>
</rules>
</element>
</parameters-schema>
<invoke-factory service-id="hivemind.BuilderFactory">
<construct class="hivemind.test.services.impl.FilterLoggingInterceptor">
<set-service property="classFactory" service-id="hivemind.ClassFactory"/>
</construct>
</invoke-factory>
</service>
<service id="Bedrock" interface="hivemind.test.services.Bedrock">
<create-instance class="hivemind.test.services.impl.BedrockImpl"/>
<interceptor service-id="FilterLoggingInterceptor">
<method name="fred"/>
<method name="wilma"/>
</interceptor>
</service>
</module>
1.1 jakarta-commons-sandbox/hivemind/src/test/hivemind/test/services/Bedrock.java
Index: Bedrock.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package hivemind.test.services;
/**
* Interface used to test {@link hivemind.test.services.impl.FilterLoggingInterceptor},
* which itself tests the ability to pass parameters to a interceptor factory.
*
* @author Howard Lewis Ship
* @version $Id: Bedrock.java,v 1.1 2003/09/05 22:32:38 hlship Exp $
*/
public interface Bedrock
{
public void fred();
public void barney();
public void wilma();
}
1.3 +7 -5 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceInterceptorFactory.java
Index: ServiceInterceptorFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceInterceptorFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServiceInterceptorFactory.java 30 Aug 2003 14:29:52 -0000 1.2
+++ ServiceInterceptorFactory.java 5 Sep 2003 22:32:38 -0000 1.3
@@ -57,6 +57,8 @@
package org.apache.commons.hivemind;
+import java.util.List;
+
/**
* Interface defining an interceptor factory, an object that can create
* an interceptor. Interceptors are objects that implement a particular
@@ -68,8 +70,8 @@
*/
public interface ServiceInterceptorFactory
{
- /**
- * Creates an interceptor and pushes it onto the interceptor stack.
- */
- public void createInterceptor(InterceptorStack stack);
+ /**
+ * Creates an interceptor and pushes it onto the interceptor stack.
+ */
+ public void createInterceptor(InterceptorStack stack, Module invokingModule, List parameters);
}
1.6 +7 -2 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceInterceptorContribution.java
Index: ServiceInterceptorContribution.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/ServiceInterceptorContribution.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServiceInterceptorContribution.java 30 Aug 2003 14:29:52 -0000 1.5
+++ ServiceInterceptorContribution.java 5 Sep 2003 22:32:38 -0000 1.6
@@ -71,5 +71,10 @@
* Interceptor factories are simply another HiveMind service,
* one that implements {@link ServiceInterceptorFactory}.
*/
- public String getFactoryId();
+ public String getFactoryServiceId();
+
+ /**
+ * Invoked to actually create the interceptor and push it onto the stack.
+ */
+ public void createInterceptor(InterceptorStack stack);
}
1.18 +21 -2 jakarta-commons-sandbox/hivemind/src/xsl/hivemind.xsl
Index: hivemind.xsl
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/xsl/hivemind.xsl,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- hivemind.xsl 24 Aug 2003 03:28:30 -0000 1.17
+++ hivemind.xsl 5 Sep 2003 22:32:38 -0000 1.18
@@ -463,7 +463,26 @@
<xsl:if test="@order">
<span class="attribute"> order</span>="<xsl:value-of select="@order"/>"
</xsl:if>
- <span class="tag">/></span> </li>
+
+ <xsl:choose>
+ <xsl:when test="*">
+ <span class="tag">></span>
+ <ul>
+ <xsl:apply-templates mode="raw"/>
+ </ul>
+ <span class="tag"></interceptor></span>
+ </xsl:when>
+ <xsl:when test="normalize-space()">
+ <span class="tag">></span>
+ <xsl:value-of select="."/>
+ <span class="tag"></interceptor></span>
+ </xsl:when>
+ <xsl:otherwise>
+ <span class="tag">/></span>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </li>
</xsl:template>
1.15 +17 -3 jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/AbstractServiceInterceptorFactory.java
Index: AbstractServiceInterceptorFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/service/impl/AbstractServiceInterceptorFactory.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- AbstractServiceInterceptorFactory.java 2 Sep 2003 21:13:04 -0000 1.14
+++ AbstractServiceInterceptorFactory.java 5 Sep 2003 22:32:38 -0000 1.15
@@ -61,6 +61,7 @@
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.commons.hivemind.ApplicationRuntimeException;
@@ -76,6 +77,7 @@
* Base class for creating new service interceptors. Most implementations
* merely have to implement
* {@link #addServiceMethodImplementation(ClassFab, String, Class, Class[], Class[])}.
+ * This is only suitable for interceptors which do not use parameters.
*
* <p>
* Implementations of this service must be configured with:
@@ -97,7 +99,17 @@
_cachedClasses = Collections.synchronizedMap(new HashMap());
}
- public void createInterceptor(InterceptorStack stack)
+ /**
+ * Creates the interceptor. Expects that the parameters list is empty.
+ * The class that is created is cached; if an interceptor is requested
+ * for the same extension point, then the previously constructed class
+ * is reused (this can happen with the threaded service model, for example,
+ * when a thread-local service implementation is created for different threads).
+ */
+ public void createInterceptor(
+ InterceptorStack stack,
+ Module contributingModule,
+ List parameters)
{
Class serviceInterfaceClass = stack.getServiceInterface();
Class interceptorClass = getInterceptorClass(stack);
@@ -198,7 +210,9 @@
/**
* Used to instantiate the interceptor. This implementation passes the top object
- * on the interceptor stack to the interceptorClass' constructor.
+ * on the interceptor stack to the interceptorClass' constructor. Subclasses that
+ * defined a different constructor (in {@link #createInfrastructure(Class, ClassFab)})
+ * will need to override this method as well.
*
* @param stack the interceptor stack on which the returned interceptor will be placed.
* @param serviceInterfaceClass the class for the interface