You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/04/13 23:28:54 UTC
svn commit: r528674 - in
/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core:
./ interceptor/
Author: dain
Date: Fri Apr 13 14:28:53 2007
New Revision: 528674
URL: http://svn.apache.org/viewvc?view=rev&rev=528674
Log:
get/setParameters on InvocationContext is not allowed for Callback methods
We now pass initial parameters via constructor since setParameters is a restricted method
Use Operation enumeration to determine if an invocation is for a callback method
Modified:
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/Operation.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxRpcInvocationContext.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxWsInvocationContext.java
incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/Operation.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/Operation.java?view=diff&rev=528674&r1=528673&r2=528674
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/Operation.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/Operation.java Fri Apr 13 14:28:53 2007
@@ -17,24 +17,36 @@
package org.apache.openejb.core;
public enum Operation {
- INJECTION,
- POST_CONSTRUCT,
- BUSINESS,
- BUSINESS_WS,
- TIMEOUT,
- AFTER_BEGIN,
- AFTER_COMPLETION,
- BEFORE_COMPLETION,
- PRE_DESTROY,
- REMOVE,
- SET_CONTEXT,
- UNSET_CONTEXT,
- CREATE,
- POST_CREATE,
- ACTIVATE,
- PASSIVATE,
- FIND,
- HOME,
- LOAD,
- STORE
+ INJECTION(true),
+ POST_CONSTRUCT(true),
+ BUSINESS(false),
+ BUSINESS_WS(false),
+ TIMEOUT(true),
+ AFTER_BEGIN(true),
+ AFTER_COMPLETION(true),
+ BEFORE_COMPLETION(true),
+ PRE_DESTROY(true),
+ REMOVE(true),
+ SET_CONTEXT(true),
+ UNSET_CONTEXT(true),
+ CREATE(true),
+ POST_CREATE(true),
+ ACTIVATE(true),
+ PASSIVATE(true),
+ FIND(true),
+ HOME(true),
+ LOAD(true),
+ STORE(true);
+
+ private boolean callback;
+
+
+ Operation(boolean callback) {
+ this.callback = callback;
+ }
+
+
+ public boolean isCallback() {
+ return callback;
+ }
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java?view=diff&rev=528674&r1=528673&r2=528674
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java Fri Apr 13 14:28:53 2007
@@ -32,12 +32,14 @@
private final Object beanInstance;
private final List<Interceptor> interceptors;
private final Method targetMethod;
+ private final Operation operation;
public InterceptorStack(Object beanInstance, Method targetMethod, Operation operation, List<InterceptorData> interceptorDatas, Map<String, Object> interceptorInstances) {
if (interceptorDatas == null) throw new NullPointerException("interceptorDatas is null");
if (interceptorInstances == null) throw new NullPointerException("interceptorInstances is null");
this.beanInstance = beanInstance;
this.targetMethod = targetMethod;
+ this.operation = operation;
interceptors = new ArrayList<Interceptor>(interceptorDatas.size());
for (InterceptorData interceptorData : interceptorDatas) {
@@ -55,32 +57,25 @@
}
}
- public InterceptorStack(Object beanInstance, Method method, List<Interceptor> interceptors) {
- this.beanInstance = beanInstance;
- this.targetMethod = method;
- this.interceptors = interceptors;
- }
-
- public InvocationContext createInvocationContext() {
- InvocationContext invocationContext = new ReflectionInvocationContext(interceptors, beanInstance, targetMethod);
+ public InvocationContext createInvocationContext(Object... parameters) {
+ InvocationContext invocationContext = new ReflectionInvocationContext(operation, interceptors, beanInstance, targetMethod, parameters);
return invocationContext;
}
public Object invoke(Object... parameters) throws Exception {
- InvocationContext invocationContext = createInvocationContext();
- invocationContext.setParameters(parameters);
+ InvocationContext invocationContext = createInvocationContext(parameters);
Object value = invocationContext.proceed();
return value;
}
public Object invoke(javax.xml.ws.handler.MessageContext messageContext) throws Exception {
- InvocationContext invocationContext = new JaxWsInvocationContext(interceptors, beanInstance, targetMethod, messageContext);
+ InvocationContext invocationContext = new JaxWsInvocationContext(operation, interceptors, beanInstance, targetMethod, messageContext);
Object value = invocationContext.proceed();
return value;
}
public Object invoke(javax.xml.rpc.handler.MessageContext messageContext) throws Exception {
- InvocationContext invocationContext = new JaxRpcInvocationContext(interceptors, beanInstance, targetMethod, messageContext);
+ InvocationContext invocationContext = new JaxRpcInvocationContext(operation, interceptors, beanInstance, targetMethod, messageContext);
Object value = invocationContext.proceed();
return value;
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxRpcInvocationContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxRpcInvocationContext.java?view=diff&rev=528674&r1=528673&r2=528674
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxRpcInvocationContext.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxRpcInvocationContext.java Fri Apr 13 14:28:53 2007
@@ -16,6 +16,8 @@
*/
package org.apache.openejb.core.interceptor;
+import org.apache.openejb.core.Operation;
+
import javax.xml.rpc.handler.MessageContext;
import java.util.List;
import java.lang.reflect.Method;
@@ -29,8 +31,8 @@
*/
public class JaxRpcInvocationContext extends ReflectionInvocationContext {
- public JaxRpcInvocationContext(List<Interceptor> interceptors, Object target, Method method, MessageContext messageContext) {
- super(interceptors, target, method);
+ public JaxRpcInvocationContext(Operation operation, List<Interceptor> interceptors, Object target, Method method, MessageContext messageContext) {
+ super(operation, interceptors, target, method);
getContextData().put(MessageContext.class.getName(), messageContext);
}
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxWsInvocationContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxWsInvocationContext.java?view=diff&rev=528674&r1=528673&r2=528674
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxWsInvocationContext.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/JaxWsInvocationContext.java Fri Apr 13 14:28:53 2007
@@ -16,6 +16,8 @@
*/
package org.apache.openejb.core.interceptor;
+import org.apache.openejb.core.Operation;
+
import javax.xml.ws.handler.MessageContext;
import java.util.List;
import java.util.Map;
@@ -27,8 +29,8 @@
public class JaxWsInvocationContext extends ReflectionInvocationContext {
private final javax.xml.ws.handler.MessageContext messageContext;
- public JaxWsInvocationContext(List<Interceptor> interceptors, Object target, Method method, MessageContext messageContext) {
- super(interceptors, target, method);
+ public JaxWsInvocationContext(Operation operation, List<Interceptor> interceptors, Object target, Method method, MessageContext messageContext) {
+ super(operation, interceptors, target, method);
this.messageContext = messageContext;
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java?view=diff&rev=528674&r1=528673&r2=528674
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/ReflectionInvocationContext.java Fri Apr 13 14:28:53 2007
@@ -17,8 +17,9 @@
*/
package org.apache.openejb.core.interceptor;
+import org.apache.openejb.core.Operation;
+
import javax.interceptor.InvocationContext;
-import javax.xml.ws.handler.MessageContext;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
@@ -37,19 +38,24 @@
private final Map<String, Object> contextData = new TreeMap<String, Object>();
private final Class<?>[] parameterTypes;
- private boolean parametersSet;
+ private final Operation operation;
- public ReflectionInvocationContext(List<Interceptor> interceptors, Object target, Method method) {
+ public ReflectionInvocationContext(Operation operation, List<Interceptor> interceptors, Object target, Method method, Object... parameters) {
+ if (operation == null) throw new NullPointerException("operation is null");
if (interceptors == null) throw new NullPointerException("interceptors is null");
if (target == null) throw new NullPointerException("target is null");
+ this.operation = operation;
this.interceptors = interceptors.iterator();
this.target = target;
this.method = method;
- parameterTypes = (method == null)? new Class[]{}: method.getParameterTypes();
- parameters = new Object[parameterTypes.length];
+ this.parameters = parameters;
- parametersSet = parameters.length == 0;
+ if (method == null) {
+ parameterTypes = new Class[0];
+ } else {
+ parameterTypes = method.getParameterTypes();
+ }
}
public Object getTarget() {
@@ -61,21 +67,24 @@
}
public Object[] getParameters() {
- if (method == null) {
+ if (operation.isCallback()) {
throw new IllegalStateException("Callback methods can not access parameters");
}
return parameters.clone();
}
public void setParameters(Object[] parameters) {
+ if (operation.isCallback()) {
+ throw new IllegalStateException("Callback methods can not access parameters");
+ }
if (parameters == null) throw new NullPointerException("parameters is null");
if (parameters.length != this.parameters.length) {
throw new IllegalArgumentException("Expected " + this.parameters.length + " parameters, but only got " + parameters.length + " parameters");
}
- for (int i = 0; i < parameters.length; i++) {
- Object parameter = parameters[i];
- Class<?> parameterType = parameterTypes[i];
-
+// for (int i = 0; i < parameters.length; i++) {
+// Object parameter = parameters[i];
+// Class<?> parameterType = parameterTypes[i];
+//
// if (parameter == null) {
// if (parameterType.isPrimitive()) {
// throw new IllegalArgumentException("Expected parameter " + i + " to be primitive type " + parameterType.getName() +
@@ -85,9 +94,8 @@
// throw new IllegalArgumentException("Expected parameter " + i + " to be of type " + parameterType.getName() +
// ", but got a parameter of type " + parameter.getClass().getName());
// }
- }
+// }
System.arraycopy(parameters, 0, this.parameters, 0, parameters.length);
- parametersSet = true;
}
public Map<String, Object> getContextData() {
@@ -113,7 +121,6 @@
}
public Object proceed() throws Exception {
- if (!parametersSet) throw new IllegalStateException("Parameters have not been set");
// The bulk of the logic of this method has intentionally been moved
// out so stepping through a large stack in a debugger can be done quickly.
// Simply put one break point on 'next.invoke()' or one inside that method.
@@ -180,6 +187,6 @@
public String toString() {
String methodName = (method != null)? method.getName(): null;
- return "InvocationContext(target="+target.getClass().getName()+", method="+methodName+")";
+ return "InvocationContext(operation=" + operation + ", target="+target.getClass().getName()+", method="+methodName+")";
}
}