You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ar...@apache.org on 2013/01/03 23:25:30 UTC
svn commit: r1428644 - in
/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept:
AbstractInvocationContext.java DefaultInterceptorHandler.java
InterceptorInvocationContext.java
Author: arne
Date: Thu Jan 3 22:25:29 2013
New Revision: 1428644
URL: http://svn.apache.org/viewvc?rev=1428644&view=rev
Log:
OWB-344: Implemented DefaultInterceptorHandler
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java?rev=1428644&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java Thu Jan 3 22:25:29 2013
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.intercept;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.interceptor.InvocationContext;
+
+public abstract class AbstractInvocationContext<T> implements InvocationContext
+{
+
+ private T target;
+ private Method method;
+ private Object[] parameters;
+ private Map<String, Object> contextData;
+ private Object timer;
+
+ public AbstractInvocationContext(T target, Method method, Object[] parameters)
+ {
+ this.target = target;
+ this.method = method;
+ this.parameters = parameters;
+ }
+
+ public AbstractInvocationContext(T target, Method method, Object[] parameters, Object timer)
+ {
+ this(target, method, parameters);
+ this.timer = timer;
+ }
+
+ @Override
+ public T getTarget()
+ {
+ return target;
+ }
+
+ @Override
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ @Override
+ public Object[] getParameters()
+ {
+ return parameters;
+ }
+
+ @Override
+ public void setParameters(Object[] parameters)
+ {
+ this.parameters = parameters;
+ }
+
+ @Override
+ public Map<String, Object> getContextData()
+ {
+ if (contextData == null)
+ {
+ contextData = new HashMap<String, Object>();
+ }
+ return contextData;
+ }
+
+ @Override
+ public Object getTimer()
+ {
+ return timer;
+ }
+
+ @Override
+ public Object proceed() throws Exception
+ {
+ return method.invoke(target, parameters);
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java?rev=1428644&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DefaultInterceptorHandler.java Thu Jan 3 22:25:29 2013
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.intercept;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
+
+import org.apache.webbeans.proxy.InterceptorHandler;
+
+public class DefaultInterceptorHandler<T> implements InterceptorHandler
+{
+
+ private T target;
+ private List<Method> methods;
+ private Map<Method, List<Interceptor<T>>> interceptors;
+ private Map<Interceptor<T>, T> instances;
+
+ public DefaultInterceptorHandler(T target,
+ List<Method> methods,
+ Map<Method, List<Interceptor<T>>> interceptors,
+ Map<Interceptor<T>, T> instances)
+ {
+ this.target = target;
+ this.methods = methods;
+ this.instances = instances;
+ this.interceptors = interceptors;
+ }
+
+ public Object invoke(int index, Object[] parameters)
+ {
+ try
+ {
+ Method method = methods.get(index);
+ List<Interceptor<T>> interceptors = this.interceptors.get(method);
+ InterceptorInvocationContext<T> ctx
+ = new InterceptorInvocationContext<T>(target, InterceptionType.AROUND_INVOKE, interceptors, instances, method, parameters);
+ return ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java?rev=1428644&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorInvocationContext.java Thu Jan 3 22:25:29 2013
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.intercept;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
+
+public class InterceptorInvocationContext<T> extends AbstractInvocationContext<T>
+{
+
+ private InterceptionType type;
+ private List<Interceptor<T>> interceptors;
+ private Map<Interceptor<T>, T> instances;
+ private int index = 0;
+
+ public InterceptorInvocationContext(T target, InterceptionType type, List<Interceptor<T>> interceptors, Map<Interceptor<T>, T> instances, Method method, Object[] parameters)
+ {
+ super(target, method, parameters);
+ this.interceptors = interceptors;
+ this.instances = instances;
+ }
+
+ @Override
+ public Object proceed() throws Exception
+ {
+ if (index < interceptors.size())
+ {
+ Interceptor<T> interceptor = interceptors.get(index++);
+ return interceptor.intercept(type, instances.get(interceptor), this);
+ }
+ else
+ {
+ return super.proceed();
+ }
+ }
+}