You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/12/04 22:07:51 UTC

svn commit: r1417182 [14/22] - in /openejb/trunk/openejb: container/openejb-core/ deps/ deps/webbeans-impl/ deps/webbeans-impl/src/ deps/webbeans-impl/src/main/ deps/webbeans-impl/src/main/java/ deps/webbeans-impl/src/main/java/org/ deps/webbeans-impl/...

Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java Tue Dec  4 21:07:25 2012
@@ -0,0 +1,103 @@
+/*
+ * 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.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.interceptor.Interceptor;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.Asserts;
+
+public class InterceptorsManager
+{
+    private List<Class<?>> enabledInterceptors = new CopyOnWriteArrayList<Class<?>>();
+    private final WebBeansContext webBeansContext;
+
+    private final BeanManagerImpl manager;
+
+    public InterceptorsManager(WebBeansContext webBeansContext)
+    {
+        this.webBeansContext = webBeansContext;
+        manager = webBeansContext.getBeanManagerImpl();
+    }
+
+    public void addNewInterceptor(Class<?> interceptorClazz)
+    {
+        Asserts.nullCheckForClass(interceptorClazz, "interceptorClazz can not be null");
+
+        if (!enabledInterceptors.contains(interceptorClazz))
+        {
+            enabledInterceptors.add(interceptorClazz);
+        }
+    }
+
+    public int compare(Class<?> src, Class<?> target)
+    {
+        Asserts.assertNotNull(src, "src parameter can not be  null");
+        Asserts.assertNotNull(target, "target parameter can not be null");
+
+        int srcIndex = enabledInterceptors.indexOf(src);
+        int targetIndex = enabledInterceptors.indexOf(target);
+
+        if (srcIndex == -1 || targetIndex == -1)
+        {
+            throw new IllegalArgumentException("One of the compare class of the list : [" + src.getName() + "," + target.getName() + "]"
+                                               + " is not contained in the enabled interceptors list!");
+        }
+
+        if (srcIndex == targetIndex)
+        {
+            return 0;
+        }
+        else if (srcIndex < targetIndex)
+        {
+            return -1;
+        }
+        else
+        {
+            return 1;
+        }
+    }
+
+    public boolean isInterceptorEnabled(Class<?> interceptorClazz)
+    {
+        Asserts.nullCheckForClass(interceptorClazz, "interceptorClazz can not be null");
+
+        return enabledInterceptors.contains(interceptorClazz);
+    }
+    
+    public void validateInterceptorClasses()
+    {
+        for(Class<?> interceptorClass : enabledInterceptors)
+        {
+            AnnotatedType<?> annotatedType = webBeansContext.getAnnotatedElementFactory().getAnnotatedType(interceptorClass);
+
+            //Validate decorator classes
+            if(!annotatedType.isAnnotationPresent(Interceptor.class) && !manager.containsCustomInterceptorClass(interceptorClass))
+            {
+                throw new WebBeansConfigurationException("Given class : " + interceptorClass + " is not a interceptor class");
+            }   
+        }                
+    }    
+}

Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java Tue Dec  4 21:07:25 2012
@@ -0,0 +1,486 @@
+/*
+ * 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.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.interceptor.InvocationContext;
+
+import org.apache.webbeans.component.EnterpriseBeanMarker;
+import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.util.ClassUtil;
+
+/**
+ * Implementation of the {@link InvocationContext} interface.
+ */
+public class InvocationContextImpl implements InvocationContext
+{
+    /** Context data for passing between interceptors */
+    private Map<String, Object> contextData = new HashMap<String, Object>();
+
+    /** Invoked method */
+    private Method method;
+
+    /** Method parameters */
+    private Object[] parameters;
+
+    /** Interceptor stack */
+    private List<InterceptorData> interceptorDatas;
+
+    /** Target object */
+    private Object target;
+
+    /** Interceptor type */
+    private InterceptionType type;
+
+    /** Used for numbering interceptors */
+    private int currentMethod = 1;
+    
+    /**Bean creational context*/
+    private CreationalContext<?> creationalContext;
+    
+    private OwbBean<?> owbBean;
+    private InvocationContext ejbInvocationContext;
+    private WebBeansContext webBeansContext;
+
+    
+    /** alternate key to be used for dependent creational contexts */
+    private Object ccKey;
+    
+    /**
+     * Initializes the invocation context.
+     *
+     * @param bean the Bean meta info
+     * @param instance target object
+     * @param method method
+     * @param parameters method parameters
+     * @param datas interceptor stack
+     * @param type interceptor type
+     */
+    public InvocationContextImpl(WebBeansContext webBeansContext, OwbBean<?> bean, Object instance, Method method,
+                                 Object[] parameters, List<InterceptorData> datas, InterceptionType type)
+    {
+        this.webBeansContext = webBeansContext;
+        owbBean = bean;
+        this.method = method;
+        this.parameters = parameters;
+        interceptorDatas = datas;
+        this.type = type;
+        
+        if(instance == null)
+        {
+            configureTarget(bean);    
+        }
+        else
+        {
+            target = instance;
+        }
+    }
+    
+    /**
+     * Sets owner bean creational context.
+     * @param ownerCreationalContext owner creational context
+     */
+    public void setCreationalContext(CreationalContext<?> ownerCreationalContext)
+    {
+        creationalContext = ownerCreationalContext;
+    }
+
+    /**
+     * Sets EJB invocation context
+     * @param c EJB containers invocation context
+     */
+    public void setEJBInvocationContext(InvocationContext c)
+    {
+        ejbInvocationContext = c;
+    }
+
+    
+    /**
+     * Gets target instance for given bean.
+     * @param bean bean instance
+     */
+    @SuppressWarnings("unchecked")
+    private void configureTarget(OwbBean<?> bean)
+    {
+        Context webbeansContext = bean.getWebBeansContext().getBeanManagerImpl().getContext(bean.getScope());
+
+        target = webbeansContext.get((Contextual<Object>)bean, (CreationalContext<Object>) creationalContext);
+        
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public Map<String, Object> getContextData()
+    {
+        return contextData;
+    }
+
+    /**
+    * {@inheritDoc}
+    */
+    public Method getMethod()
+    {
+        return method;
+    }
+
+    /**
+    * {@inheritDoc}
+    */
+    public Object[] getParameters()
+    {
+        return parameters;
+    }
+
+    /**
+    * {@inheritDoc}
+    */
+    public Object getTarget()
+    {
+        return target;
+    }
+
+    /**
+    * {@inheritDoc}
+    */
+    public Object proceed() throws Exception
+    {
+        try
+        {
+            if (type.equals(InterceptionType.AROUND_INVOKE))
+            {
+                return proceedAroundInvokes(interceptorDatas);
+            }
+            else if (type.equals(InterceptionType.AROUND_TIMEOUT))
+            {
+                return proceedAroundTimeouts(interceptorDatas);
+            }
+            return proceedCommonAnnots(interceptorDatas, type);
+
+        }
+        catch (InvocationTargetException ite)
+        {
+            target = null; // destroy target instance
+            
+            // Try to provide the original exception to the interceptor stack, 
+            // not the InvocationTargetException from Method.invoke
+            Throwable t = ite.getCause();
+            if (t instanceof Exception)
+            {
+                throw (Exception) t;
+            }
+            throw ite;
+        }
+        catch (Exception e)
+        {
+            target = null; // destroy target instance
+
+            throw e;
+        }
+    }
+    
+    /**
+     * AroundInvoke operations on stack.
+     * @param datas interceptor stack
+     * @return final result
+     * @throws Exception for exceptions
+     */
+    private Object proceedAroundInvokes(List<InterceptorData> datas) throws Exception
+    {
+        Object result = null;
+
+        if (currentMethod <= datas.size())
+        {
+            InterceptorData intc = datas.get(currentMethod - 1);
+
+            Method aroundInvokeMethod = intc.getAroundInvoke();
+
+            if (!aroundInvokeMethod.isAccessible())
+            {
+                owbBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(aroundInvokeMethod, true);
+            }
+            
+            Object t = intc.createNewInstance(ccKey != null ? ccKey : target,
+                    (CreationalContextImpl<?>) creationalContext);
+
+            if (t == null)
+            {
+                t = target;
+            }
+
+            currentMethod++;
+            
+            result = aroundInvokeMethod.invoke(t, new Object[] { this });
+            
+        }
+        else
+        {
+            if(!(owbBean instanceof EnterpriseBeanMarker))
+            {
+                if(!method.isAccessible())
+                {                
+                    owbBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(method, true);
+                }
+                
+                result = method.invoke(target, parameters);
+            }
+            else 
+            { 
+                if (ejbInvocationContext != null)
+                {
+                    result = ejbInvocationContext.proceed();
+                }
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * AroundTimeout operations on stack.
+     * @param datas interceptor stack
+     * @return final result
+     * @throws Exception for exceptions
+     */
+    private Object proceedAroundTimeouts(List<InterceptorData> datas) throws Exception
+    {
+        Object result = null;
+
+        if (currentMethod <= datas.size())
+        {
+            InterceptorData intc = datas.get(currentMethod - 1);
+
+            Method aroundTimeoutMethod = intc.getAroundTimeout();
+
+            if (!aroundTimeoutMethod.isAccessible())
+            {
+                owbBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(aroundTimeoutMethod, true);
+            }
+            
+            Object t = intc.createNewInstance(ccKey != null ? ccKey : target,
+                    (CreationalContextImpl<?>) creationalContext);
+
+            if (t == null)
+            {
+                t = target;
+            }
+
+            currentMethod++;
+            
+            result = aroundTimeoutMethod.invoke(t, new Object[] { this });
+        }
+        else
+        {
+            if(!(owbBean instanceof EnterpriseBeanMarker))
+            {
+                if(!method.isAccessible())
+                {                
+                    owbBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(method, true);
+                }
+                
+                result = method.invoke(target, parameters);
+            } 
+            else
+            { 
+                if (ejbInvocationContext != null)
+                {
+                    result = ejbInvocationContext.proceed();
+                }
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * Post construct and predestroy 
+     * callback operations.
+     * @param datas interceptor stack
+     * @param type interceptor type
+     * @return final result
+     * @throws Exception for any exception
+     */
+    private Object proceedCommonAnnots(List<InterceptorData> datas, InterceptionType type) throws Exception
+    {
+        Object result = null;
+
+        if (currentMethod <= datas.size())
+        {
+            InterceptorData intc = datas.get(currentMethod - 1);
+            Method commonAnnMethod = null;
+
+            if (type.equals(InterceptionType.POST_CONSTRUCT))
+            {
+                commonAnnMethod = intc.getPostConstruct();
+            }
+            else if (type.equals(InterceptionType.POST_ACTIVATE))
+            {
+                commonAnnMethod = intc.getPostActivate();
+            }
+            else if (type.equals(InterceptionType.PRE_PASSIVATE))
+            {
+                commonAnnMethod = intc.getPrePassivate();
+            }
+            else if (type.equals(InterceptionType.PRE_DESTROY))
+            {
+                commonAnnMethod = intc.getPreDestroy();
+            }
+            else
+            {
+                throw new IllegalArgumentException("Unsupportet InterceptionType: " + type);
+            }
+
+            if (commonAnnMethod == null)
+            {
+                throw new IllegalArgumentException("Could not find intercepted Method!");
+            }
+
+            if (!commonAnnMethod.isAccessible())
+            {
+                webBeansContext.getSecurityService().doPrivilegedSetAccessible(commonAnnMethod, true);
+            }
+
+            currentMethod++;
+
+            Object t = intc.createNewInstance(ccKey != null ? ccKey : target,
+                    (CreationalContextImpl<?>) creationalContext);
+
+            //In bean class
+            if (t == null)
+            {
+                if(!(owbBean instanceof EnterpriseBeanMarker))
+                {
+                    t = target;                
+                    result = commonAnnMethod.invoke(t, new Object[] {});
+                    
+                    //Continue to call others
+                    proceedCommonAnnots(datas, type);                                    
+                }                
+            }
+            //In interceptor class
+            else
+            {
+                result = commonAnnMethod.invoke(t, new Object[] { this });
+            }
+
+        }
+        else 
+        {
+            /* For EJB's, we do not call the "in bean class" interceptors --the container does, and only if
+             * our last 299 interceptor called proceed (which takes us here).
+             */
+            if ((owbBean instanceof EnterpriseBeanMarker) && (ejbInvocationContext != null))
+            {
+                result = ejbInvocationContext.proceed();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setParameters(Object[] params)
+    {
+        if (getMethod() != null)
+        {
+            if (params == null)
+            {
+                if (parameters.length >= 0)
+                {
+                    throw new IllegalArgumentException("Gvien parameters is null but expected not null parameters");
+                }
+            }
+            else
+            {
+                if (params.length != parameters.length)
+                {
+                    throw new IllegalArgumentException("Expected " + parameters.length + " " +
+                            "parameters, but only got " + params.length + " parameters");
+                }
+
+                Class<?>[] methodParameters = method.getParameterTypes();
+                int i = 0;
+                for (Object obj : params)
+                {
+                    Class<?> parameterType = methodParameters[i++];
+                    if (obj == null)
+                    {
+                        if (parameterType.isPrimitive())
+                        {
+                            throw new IllegalArgumentException("Expected parameter " + i + " to be primitive type " + parameterType.getName() +
+                                    ", but got a parameter that is null");
+                        }
+                    }
+                    else
+                    {
+                        //Primitive check
+                        if(parameterType.isPrimitive())
+                        {
+                            //First change to wrapper for comparision
+                            parameterType = ClassUtil.getPrimitiveWrapper(parameterType);
+                        }
+
+                        //Actual check
+                        if (!parameterType.isInstance(obj))
+                        {
+                            throw new IllegalArgumentException("Expected parameter " + i + " to be of type " + parameterType.getName() +
+                                    ", but got a parameter of type " + obj.getClass().getName());
+                        }
+                    }
+                }
+
+                System.arraycopy(params, 0, parameters, 0, params.length);
+
+            }
+
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object getTimer()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }    
+    
+    /**
+     * Sets the alternate key (alternate owner instance) to be used within 
+     * the passed CreationalContext for dependent interceptors.
+     * 
+     * @param ccKey a unique key used to index dependent interceptors
+     */
+    public void setCcKey(Object ccKey)
+    {
+        this.ccKey = ccKey;
+    }
+}

Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java Tue Dec  4 21:07:25 2012
@@ -0,0 +1,200 @@
+/*
+ * 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.concurrent.CopyOnWriteArrayList;
+
+import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.UnproxyableResolutionException;
+import javax.enterprise.inject.spi.InterceptionType;
+
+import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.context.AbstractContext;
+import org.apache.webbeans.context.creational.CreationalContextFactory;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+
+
+/**
+ * Normal scoped beans interceptor handler.
+ * @version $Rev: 1384120 $ $Date: 2012-09-12 22:52:57 +0200 (mer., 12 sept. 2012) $
+ *
+ */
+@SuppressWarnings("unchecked")
+public class NormalScopedBeanInterceptorHandler extends InterceptorHandler 
+{
+    /**Serial id*/
+    private static final long serialVersionUID = 1L;
+
+    /** this stores the {@link java.lang.reflect.Method#hashCode()} of intercepted methods */
+    private CopyOnWriteArrayList<Integer> cachedInterceptedMethods = new CopyOnWriteArrayList<Integer>();
+
+    /**
+     * Creates a new bean instance
+     * @param bean bean 
+     * @param creationalContext creational context
+     */
+    public NormalScopedBeanInterceptorHandler(OwbBean<?> bean, CreationalContext<?> creationalContext)
+    {
+        super(bean);    
+        
+        //Initiate bean for saving creational context instance
+        initiateBeanBag((OwbBean<Object>)bean, (CreationalContext<Object>)creationalContext);
+    }
+    
+    private void initiateBeanBag(OwbBean<Object> bean, CreationalContext<Object> creationalContext)
+    {
+        try
+        {
+            Context webbeansContext = getBeanManager().getContext(bean.getScope());
+            if (webbeansContext instanceof AbstractContext)
+            {
+                AbstractContext owbContext = (AbstractContext)webbeansContext;
+                owbContext.initContextualBag(bean, creationalContext);
+            }            
+        }
+        catch(ContextNotActiveException e)
+        {
+            //Nothing
+        }
+    }
+
+    @Override
+    protected boolean isNotInterceptedOrDecoratedMethod(Method method)
+    {
+        int currentHash = method.hashCode();
+        if (cachedInterceptedMethods.contains(currentHash))
+        {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    protected void setNotInterceptedOrDecoratedMethod(Method method)
+    {
+        Integer hashCode = method.hashCode();
+        if (!cachedInterceptedMethods.contains(hashCode))
+        {
+            cachedInterceptedMethods.add(hashCode);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object invoke(Object instance, Method method, Method proceed, Object[] arguments) throws Throwable
+    {
+        return invoke(instance, method, arguments);
+    }
+
+    public Object invoke(Object instance, Method method, Object[] arguments) throws Throwable
+    {
+        //Get instance from context
+        Object webbeansInstance = getContextualInstance();
+        
+        //Call super
+        return super.invoke(webbeansInstance, method, arguments, (CreationalContextImpl<?>) getContextualCreationalContext());
+    }
+        
+    /**
+     * {@inheritDoc}
+     */
+    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData> stack) throws Exception
+    {
+        InvocationContextImpl impl = new InvocationContextImpl(webBeansContext, bean, getContextualInstance(),
+                                                               proceed, arguments, stack, InterceptionType.AROUND_INVOKE);
+        impl.setCreationalContext(getContextualCreationalContext());
+
+        return impl.proceed();
+
+    }
+    
+    
+    /**
+     * Gets instance from context.
+     * @return the underlying contextual instance, either cached or resolved from the context 
+     */
+    protected Object getContextualInstance()
+    {
+        Object webbeansInstance;
+
+        //Context of the bean
+        Context webbeansContext = getBeanManager().getContext(bean.getScope());
+        
+        //Already saved in context?
+        webbeansInstance = webbeansContext.get(bean);
+        if (webbeansInstance != null)
+        {
+            // voila, we are finished if we found an existing contextual instance
+            return webbeansInstance;
+        }
+
+        // finally, we create a new contextual instance
+        webbeansInstance = webbeansContext.get((Contextual<Object>) bean, getContextualCreationalContext());
+
+        if (webbeansInstance == null)
+        {
+            throw new UnproxyableResolutionException("Cannot find a contextual instance of bean " + bean.toString());
+        }
+        return webbeansInstance;
+    }
+    
+    protected CreationalContext<Object> getContextualCreationalContext()
+    {
+        CreationalContext<Object> creationalContext = null;
+        
+        OwbBean<Object> contextual = (OwbBean<Object>) bean;
+        //Context of the bean
+        Context webbeansContext = getBeanManager().getContext(bean.getScope());
+        CreationalContextFactory contextFactory = bean.getWebBeansContext().getCreationalContextFactory();
+        if (webbeansContext instanceof AbstractContext)
+        {
+            AbstractContext owbContext = (AbstractContext)webbeansContext;
+            creationalContext = owbContext.getCreationalContext(contextual);
+
+            //No creational context means that no BeanInstanceBag
+            //Actually this can be occurs like scenarions
+            //@SessionScoped bean injected into @ApplicationScopedBean
+            //And session is destroyed and restarted but proxy still
+            //contained in @ApplicationScopedBean
+            if(creationalContext == null)
+            {
+                creationalContext = contextFactory.getCreationalContext(contextual);
+                owbContext.initContextualBag((OwbBean<Object>) bean, creationalContext);
+            }
+        }
+
+        // for 3rd party contexts (actually all contexts provided via portable extensions)
+        // we don't have all the stuff of AbstractContext available
+        // In this case we may safely simply create a fresh CreationalContext, because
+        // if an 'old' contextual instance exists, it would have been found by the
+        // preceding call to Context.get(Contextual) (without any CreationalContext)
+        if(creationalContext == null)
+        {
+            creationalContext = contextFactory.getCreationalContext(contextual);
+        }
+
+        return creationalContext;
+    }
+}

Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/OwbInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/OwbInterceptor.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/OwbInterceptor.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/OwbInterceptor.java Tue Dec  4 21:07:25 2012
@@ -0,0 +1,46 @@
+/*
+ * 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.annotation.Annotation;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Interceptor;
+
+import org.apache.webbeans.component.AbstractOwbBean;
+
+public interface OwbInterceptor<T> extends Interceptor<T>
+{
+    public AbstractOwbBean<T> getDelegate();
+    
+    public AnnotatedType<T> getAnnotatedType();
+    
+    public void addInterceptorBinding(Class<? extends Annotation> binding, Annotation annot);
+    
+    public boolean hasBinding(List<Class<? extends Annotation>> bindingTypes, List<Annotation> annots);
+    
+    public Class<?> getClazz();
+    
+    public Set<Interceptor<?>> getMetaInceptors();
+    
+    public void setInjections(Object proxy, CreationalContext<?> creationalContext);
+}

Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java Tue Dec  4 21:07:25 2012
@@ -0,0 +1,634 @@
+/*
+ * 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 org.apache.webbeans.annotation.AnnotationManager;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.config.inheritance.IBeanInheritedMetaData;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.plugins.OpenWebBeansEjbLCAPlugin;
+import org.apache.webbeans.spi.BDABeansXmlScanner;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.webbeans.util.AnnotationUtil;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.interceptor.AroundInvoke;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Configures the Web Beans related interceptors.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @version $Rev$ $Date$
+ * @see WebBeansInterceptor
+ */
+public final class WebBeansInterceptorConfig
+{
+    /** Logger instance */
+    private static Logger logger = WebBeansLoggerFacade.getLogger(WebBeansInterceptorConfig.class);
+
+    private WebBeansContext webBeansContext;
+
+    public WebBeansInterceptorConfig(WebBeansContext webBeansContext)
+    {
+        this.webBeansContext = webBeansContext;
+    }
+
+    /**
+     * Configures WebBeans specific interceptor class.
+     *
+     * @param interceptorBindingTypes interceptor class
+     */
+    public <T> void configureInterceptorClass(AbstractInjectionTargetBean<T> delegate, Annotation[] interceptorBindingTypes)
+    {
+        if(delegate.getScope() != Dependent.class)
+        {
+            if(logger.isLoggable(Level.WARNING))
+            {
+                logger.log(Level.WARNING, OWBLogConst.WARN_0005_1, delegate.getBeanClass().getName());
+            }
+        }
+
+        if(delegate.getName() != null)
+        {
+            if(logger.isLoggable(Level.WARNING))
+            {
+                logger.log(Level.WARNING, OWBLogConst.WARN_0005_2, delegate.getBeanClass().getName());
+            }
+        }
+
+        if(delegate.isAlternative())
+        {
+            if(logger.isLoggable(Level.WARNING))
+            {
+                logger.log(Level.WARNING, OWBLogConst.WARN_0005_3, delegate.getBeanClass().getName());
+            }
+        }
+
+        if (logger.isLoggable(Level.FINE))
+        {
+            logger.log(Level.FINE, "Configuring interceptor class : [{0}]", delegate.getReturnType());
+        }
+        WebBeansInterceptor<T> interceptor = new WebBeansInterceptor<T>(delegate);
+
+        List<Annotation> anns = Arrays.asList(interceptorBindingTypes);
+
+        for (Annotation ann : interceptorBindingTypes)
+        {
+            checkAnns(anns, ann, delegate);
+            interceptor.addInterceptorBinding(ann.annotationType(), ann);
+        }
+
+
+        delegate.getWebBeansContext().getBeanManagerImpl().addInterceptor(interceptor);
+
+    }
+
+    private void checkAnns(List<Annotation> list, Annotation ann, Bean<?> bean)
+    {
+        for(Annotation old : list)
+        {
+            if(old.annotationType().equals(ann.annotationType()))
+            {
+                if(!AnnotationUtil.isQualifierEqual(ann, old))
+                {
+                    throw new WebBeansConfigurationException("Interceptor Binding types must be equal for interceptor : " + bean);
+                }
+            }
+        }
+    }
+
+    /**
+     * Configures the given class for applicable interceptors.
+     *
+     */
+    public void configure(AbstractInjectionTargetBean<?> component, List<InterceptorData> stack)
+    {
+        Class<?> clazz = ((AbstractOwbBean<?>)component).getReturnType();
+        AnnotatedType<?> annotatedType = component.getAnnotatedType();
+        Set<Annotation> annotations = null;
+
+        if(annotatedType != null)
+        {
+            annotations = annotatedType.getAnnotations();
+        }
+
+        Set<Interceptor<?>> componentInterceptors = null;
+
+        Set<Annotation> bindingTypeSet = new HashSet<Annotation>();
+        Annotation[] anns;
+        Annotation[] typeAnns = null;
+        if(annotations != null)
+        {
+            typeAnns = annotations.toArray(new Annotation[annotations.size()]);
+        }
+        else
+        {
+            typeAnns = clazz.getDeclaredAnnotations();
+        }
+        AnnotationManager annotationManager = component.getWebBeansContext().getAnnotationManager();
+        if (annotationManager.hasInterceptorBindingMetaAnnotation(typeAnns))
+        {
+            anns = annotationManager.getInterceptorBindingMetaAnnotations(typeAnns);
+
+            for (Annotation ann : anns)
+            {
+                bindingTypeSet.add(ann);
+            }
+        }
+
+        // check for stereotypes _explicitly_ declared on the bean class (not
+        // inherited)
+        Annotation[] stereoTypes =
+            annotationManager.getStereotypeMetaAnnotations(typeAnns);
+        for (Annotation stero : stereoTypes)
+        {
+            if (annotationManager.hasInterceptorBindingMetaAnnotation(stero.annotationType().getDeclaredAnnotations()))
+            {
+                Annotation[] steroInterceptorBindings = annotationManager.getInterceptorBindingMetaAnnotations(
+                        stero.annotationType().getDeclaredAnnotations());
+
+                for (Annotation ann : steroInterceptorBindings)
+                {
+                    bindingTypeSet.add(ann);
+                }
+            }
+        }
+
+        // Look for inherited binding types, keeping in mind that
+        // IBeanInheritedMetaData knows nothing of the transitive
+        // relationships of Interceptor Bindings or Stereotypes. We must resolve
+        // these here.
+        IBeanInheritedMetaData metadata = component.getInheritedMetaData();
+        if (metadata != null)
+        {
+            Set<Annotation> inheritedBindingTypes = metadata.getInheritedInterceptorBindings();
+            if (!inheritedBindingTypes.isEmpty())
+            {
+                Annotation[] inheritedAnns = new Annotation[inheritedBindingTypes.size()];
+                inheritedAnns = inheritedBindingTypes.toArray(inheritedAnns);
+                anns = annotationManager.getInterceptorBindingMetaAnnotations(inheritedAnns);
+                bindingTypeSet.addAll(Arrays.asList(anns));
+            }
+
+            // Retrieve inherited stereotypes, check for meta-annotations, and
+            // find the ultimate set of bindings
+            Set<Annotation> inheritedStereotypes = metadata.getInheritedStereoTypes();
+
+            if (!inheritedStereotypes.isEmpty())
+            {
+                // We need AnnotationUtil to resolve the transitive relationship
+                // of stereotypes we've found
+                Annotation[] inherited = new Annotation[inheritedStereotypes.size()];
+                inherited = inheritedStereotypes.toArray(inherited);
+                Annotation[] transitiveStereotypes = annotationManager.getStereotypeMetaAnnotations(inherited);
+
+                for (Annotation stereo : transitiveStereotypes)
+                {
+                    if (annotationManager.hasInterceptorBindingMetaAnnotation(stereo.annotationType().getDeclaredAnnotations()))
+                    {
+                        Annotation[] steroInterceptorBindings =
+                            annotationManager.getInterceptorBindingMetaAnnotations(stereo.annotationType().getDeclaredAnnotations());
+                        for (Annotation ann : steroInterceptorBindings)
+                        {
+                            bindingTypeSet.add(ann);
+                        }
+                    }
+                }
+            }
+        }
+
+        anns = new Annotation[bindingTypeSet.size()];
+        anns = bindingTypeSet.toArray(anns);
+
+        //Spec Section 9.5.2
+        List<Annotation> beanAnnots = Arrays.asList(anns);
+        for(Annotation checkAnn : anns)
+        {
+            checkAnns(beanAnnots, checkAnn, component);
+        }
+
+        if (anns.length > 0)
+        {
+            componentInterceptors = findDeployedWebBeansInterceptor(anns, component.getWebBeansContext());
+
+            // Adding class interceptors
+            addComponentInterceptors(componentInterceptors, stack);
+        }
+
+        // Method level interceptors.
+        if(annotatedType == null)
+        {
+            addMethodInterceptors(component, clazz, stack, componentInterceptors, bindingTypeSet);
+        }
+        else
+        {
+            addMethodInterceptors(annotatedType, stack, componentInterceptors);
+        }
+        filterInterceptorsPerBDA(component,stack);
+
+        Collections.sort(stack, new InterceptorDataComparator(component.getWebBeansContext()));
+
+    }
+
+    private void filterInterceptorsPerBDA(AbstractInjectionTargetBean<?> component, List<InterceptorData> stack)
+    {
+
+        ScannerService scannerService = component.getWebBeansContext().getScannerService();
+        if (!scannerService.isBDABeansXmlScanningEnabled())
+        {
+            return;
+        }
+        BDABeansXmlScanner beansXMLScanner = scannerService.getBDABeansXmlScanner();
+        String beanBDABeansXML = beansXMLScanner.getBeansXml(component.getBeanClass());
+        Set<Class<?>> definedInterceptors = beansXMLScanner.getInterceptors(beanBDABeansXML);
+
+        InterceptorData interceptorData;
+
+        if (stack != null && stack.size() > 0)
+        {
+            Iterator<InterceptorData> it = stack.iterator();
+            while (it.hasNext())
+            {
+                interceptorData = (InterceptorData) it.next();
+                if (!definedInterceptors.contains(interceptorData.getInterceptorClass()))
+                {
+                    it.remove();
+                }
+            }
+        }
+
+    }
+
+    public void addComponentInterceptors(Set<Interceptor<?>> set, List<InterceptorData> stack)
+    {
+        Iterator<Interceptor<?>> it = set.iterator();
+        while (it.hasNext())
+        {
+            WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) it.next();
+            AnnotatedType<?> annotatedType = interceptor.getAnnotatedType();
+
+            OpenWebBeansEjbLCAPlugin ejbPlugin = webBeansContext.getPluginLoader().getEjbLCAPlugin();
+            Class <? extends Annotation> prePassivateClass = null;
+            Class <? extends Annotation> postActivateClass = null;
+            if (null != ejbPlugin)
+            {
+                prePassivateClass = ejbPlugin.getPrePassivateClass();
+                postActivateClass = ejbPlugin.getPostActivateClass();
+            }
+
+            if(annotatedType != null)
+            {
+                // interceptor binding
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor, annotatedType,
+                                                                             AroundInvoke.class, true,
+                                                                             false, stack, null);
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor, annotatedType,
+                                                                             PostConstruct.class, true,
+                                                                             false, stack, null);
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor, annotatedType,
+                                                                             PreDestroy.class, true,
+                                                                             false, stack, null);
+
+                if (null != ejbPlugin)
+                {
+                    webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                 annotatedType,
+                                                                                 prePassivateClass,
+                                                                                 true, false, stack,
+                                                                                 null);
+                    webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                 annotatedType,
+                                                                                 postActivateClass,
+                                                                                 true, false, stack,
+                                                                                 null);
+
+                }
+            }
+            else
+            {
+                // interceptor binding
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                             interceptor.getClazz(),
+                                                                             AroundInvoke.class, true,
+                                                                             false, stack, null, true);
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                             interceptor.getClazz(),
+                                                                             PostConstruct.class, true,
+                                                                             false, stack, null, true);
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                             interceptor.getClazz(),
+                                                                             PreDestroy.class, true,
+                                                                             false, stack, null, true);
+
+                if (null != ejbPlugin)
+                {
+                    webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                 interceptor.getClazz(),
+                                                                                 prePassivateClass,
+                                                                                 true, false, stack,
+                                                                                 null, true);
+                    webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                 interceptor.getClazz(),
+                                                                                 postActivateClass,
+                                                                                 true, false, stack,
+                                                                                 null, true);
+
+                }
+
+            }
+        }
+
+    }
+
+    /**
+     * Add configured interceptors, combining the bindings at the component-level with annotations on methods
+     * @param component
+     * @param clazz the bean class
+     * @param stack the current interceptor stack for the bean
+     * @param componentInterceptors the configured interceptors from the component level
+     * @param resolvedComponentInterceptorBindings complete (including transitive) set of component-level interceptor bindings
+     */
+    private void addMethodInterceptors(AbstractInjectionTargetBean<?> component, Class<?> clazz, List<InterceptorData> stack, Set<Interceptor<?>> componentInterceptors,
+                                              Set<Annotation> resolvedComponentInterceptorBindings)
+    {
+        AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
+
+        // All methods, not just those declared
+        Method[] methods = clazz.getMethods();
+        Set<Method> set = new HashSet<Method>();
+        for(Method m : methods)
+        {
+            set.add(m);
+        }
+
+        //GE : I added for private, protected etc. methods.
+        //Not just for public methods.
+        methods = webBeansContext.getSecurityService().doPrivilegedGetDeclaredMethods(clazz);
+        for(Method m : methods)
+        {
+            set.add(m);
+        }
+
+        methods = set.toArray(new Method[set.size()]);
+
+        for (Method method : methods)
+        {
+            Set<Annotation> interceptorAnns = new HashSet<Annotation>();
+            if (annotationManager.hasInterceptorBindingMetaAnnotation(
+                method.getDeclaredAnnotations()))
+            {
+                Annotation[] anns =
+                    annotationManager.getInterceptorBindingMetaAnnotations(
+                        method.getAnnotations());
+                for (Annotation ann : anns)
+                {
+                    interceptorAnns.add(ann);
+                }
+            }
+
+            // To find the right interceptors, we need to consider method and
+            // class-level combined
+            interceptorAnns.addAll(resolvedComponentInterceptorBindings);
+
+            if (!interceptorAnns.isEmpty())
+            {
+                Annotation[] result = new Annotation[interceptorAnns.size()];
+                result = interceptorAnns.toArray(result);
+
+                Set<Interceptor<?>> setInterceptors = findDeployedWebBeansInterceptor(result, webBeansContext);
+
+                if (componentInterceptors != null)
+                {
+                    setInterceptors.removeAll(componentInterceptors);
+                }
+
+                Iterator<Interceptor<?>> it = setInterceptors.iterator();
+
+                while (it.hasNext())
+                {
+                    WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) it.next();
+
+                    webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                 interceptor.getClazz(),
+                                                                                 AroundInvoke.class,
+                                                                                 true, true, stack,
+                                                                                 method, true);
+                    webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                 interceptor.getClazz(),
+                                                                                 PostConstruct.class,
+                                                                                 true, true, stack,
+                                                                                 method, true);
+                    webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                 interceptor.getClazz(),
+                                                                                 PreDestroy.class, true,
+                                                                                 true, stack, method,
+                                                                                 true);
+
+                    OpenWebBeansEjbLCAPlugin ejbPlugin = webBeansContext.getPluginLoader().getEjbLCAPlugin();
+                    if (null != ejbPlugin)
+                    {
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interceptor.getClazz(),
+                                                                                     ejbPlugin.getPrePassivateClass(),
+                                                                                     true, true, stack,
+                                                                                     method, true);
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interceptor.getClazz(),
+                                                                                     ejbPlugin.getPostActivateClass(),
+                                                                                     true, true, stack,
+                                                                                     method, true);
+                    }
+
+
+                }
+            }
+        }
+
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> void addMethodInterceptors(AnnotatedType<T> annotatedType,
+                                           List<InterceptorData> stack,
+                                           Set<Interceptor<?>> componentInterceptors)
+    {
+
+        AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
+        Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods();
+        for(AnnotatedMethod<? super T> methodA : methods)
+        {
+            AnnotatedMethod<T> methodB = (AnnotatedMethod<T>)methodA;
+            Method method = methodB.getJavaMember();
+            Set<Annotation> interceptorAnns = new HashSet<Annotation>();
+
+            Annotation[] methodAnns = AnnotationUtil.getAnnotationsFromSet(methodB.getAnnotations());
+            if (annotationManager.hasInterceptorBindingMetaAnnotation(methodAnns))
+            {
+                Annotation[] anns =
+                    annotationManager.getInterceptorBindingMetaAnnotations(
+                        methodAnns);
+                Annotation[] annsClazz =
+                    annotationManager.getInterceptorBindingMetaAnnotations(
+                        AnnotationUtil.getAnnotationsFromSet(annotatedType.getAnnotations()));
+
+                for (Annotation ann : anns)
+                {
+                    interceptorAnns.add(ann);
+                }
+
+                for (Annotation ann : annsClazz)
+                {
+                    interceptorAnns.add(ann);
+                }
+            }
+
+            Annotation[] stereoTypes =
+                annotationManager.getStereotypeMetaAnnotations(
+                    AnnotationUtil.getAnnotationsFromSet(annotatedType.getAnnotations()));
+            for (Annotation stero : stereoTypes)
+            {
+                if (annotationManager.hasInterceptorBindingMetaAnnotation(
+                    stero.annotationType().getDeclaredAnnotations()))
+                {
+                    Annotation[] steroInterceptorBindings =
+                        annotationManager.getInterceptorBindingMetaAnnotations(
+                            stero.annotationType().getDeclaredAnnotations());
+
+                    for (Annotation ann : steroInterceptorBindings)
+                    {
+                        interceptorAnns.add(ann);
+                    }
+                }
+            }
+
+            if (!interceptorAnns.isEmpty())
+            {
+                Annotation[] result = new Annotation[interceptorAnns.size()];
+                result = interceptorAnns.toArray(result);
+
+                Set<Interceptor<?>> setInterceptors = findDeployedWebBeansInterceptor(result, webBeansContext);
+
+                if(componentInterceptors != null)
+                {
+                    setInterceptors.removeAll(componentInterceptors);
+                }
+
+                Iterator<Interceptor<?>> it = setInterceptors.iterator();
+
+                while (it.hasNext())
+                {
+                    WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) it.next();
+
+                    AnnotatedType<?> interAnnoType = interceptor.getAnnotatedType();
+
+                    if(interAnnoType == null)
+                    {
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interceptor.getClazz(),
+                                                                                     AroundInvoke.class,
+                                                                                     true, true, stack,
+                                                                                     method, true);
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interceptor.getClazz(),
+                                                                                     PostConstruct.class,
+                                                                                     true, true, stack,
+                                                                                     method, true);
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interceptor.getClazz(),
+                                                                                     PreDestroy.class,
+                                                                                     true, true, stack,
+                                                                                     method, true);
+                    }
+                    else
+                    {
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interAnnoType,
+                                                                                     AroundInvoke.class,
+                                                                                     true, true, stack,
+                                                                                     method);
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interAnnoType,
+                                                                                     PostConstruct.class,
+                                                                                     true, true, stack,
+                                                                                     method);
+                        webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
+                                                                                     interAnnoType,
+                                                                                     PreDestroy.class,
+                                                                                     true, true, stack,
+                                                                                     method);
+                    }
+                }
+            }
+        }
+
+    }
+
+    /*
+     * Find the deployed interceptors with given interceptor binding types.
+     */
+    public Set<Interceptor<?>> findDeployedWebBeansInterceptor(Annotation[] anns, WebBeansContext webBeansContext)
+    {
+        Set<Interceptor<?>> set = new HashSet<Interceptor<?>>();
+
+        Iterator<Interceptor<?>> it = webBeansContext.getBeanManagerImpl().getInterceptors().iterator();
+        WebBeansInterceptor<?> interceptor;
+
+        List<Class<? extends Annotation>> bindingTypes = new ArrayList<Class<? extends Annotation>>();
+        List<Annotation> listAnnot = new ArrayList<Annotation>();
+        for (Annotation ann : anns)
+        {
+            bindingTypes.add(ann.annotationType());
+            listAnnot.add(ann);
+        }
+
+        while (it.hasNext())
+        {
+            interceptor = (WebBeansInterceptor<?>) it.next();
+
+            if (interceptor.hasBinding(bindingTypes, listAnnot))
+            {
+                set.add(interceptor);
+                set.addAll(interceptor.getMetaInceptors());
+            }
+        }
+
+        return set;
+    }
+}

Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/custom/CustomInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/custom/CustomInterceptor.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/custom/CustomInterceptor.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/custom/CustomInterceptor.java Tue Dec  4 21:07:25 2012
@@ -0,0 +1,179 @@
+/*
+ * 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.custom;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.interceptor.InvocationContext;
+
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
+
+public class CustomInterceptor<T> extends WebBeansInterceptor<T> implements Interceptor<T>
+{
+    private Interceptor<T> actualInterceptor;
+
+    public CustomInterceptor(AbstractInjectionTargetBean<T> delegateBean, Interceptor<T> actualInterceptor)
+    {
+        super(delegateBean);
+        this.actualInterceptor = actualInterceptor;
+    }
+
+    @Override
+    public Set<Annotation> getInterceptorBindings()
+    {        
+        return actualInterceptor.getInterceptorBindings();
+    }
+
+    @Override
+    public Object intercept(InterceptionType type, T instance, InvocationContext ctx)
+    {
+        
+        return actualInterceptor.intercept(type, instance, ctx);
+    }
+
+    @Override
+    public boolean intercepts(InterceptionType type)
+    {
+        
+        return actualInterceptor.intercepts(type);
+    }
+
+    @Override
+    public Class<?> getBeanClass()
+    {
+        
+        return actualInterceptor.getBeanClass();
+    }
+
+    @Override
+    public Set<InjectionPoint> getInjectionPoints()
+    {
+        
+        return actualInterceptor.getInjectionPoints();
+    }
+
+    @Override
+    public String getName()
+    {
+        
+        return actualInterceptor.getName();
+    }
+
+    @Override
+    public Set<Annotation> getQualifiers()
+    {
+        
+        return actualInterceptor.getQualifiers();
+    }
+
+    @Override
+    public Class<? extends Annotation> getScope()
+    {
+        
+        return actualInterceptor.getScope();
+    }
+
+    @Override
+    public Set<Class<? extends Annotation>> getStereotypes()
+    {
+        
+        return actualInterceptor.getStereotypes();
+    }
+
+    @Override
+    public Set<Type> getTypes()
+    {
+        
+        return actualInterceptor.getTypes();
+    }
+
+    @Override
+    public boolean isAlternative()
+    {
+        
+        return actualInterceptor.isAlternative();
+    }
+
+    @Override
+    public boolean isNullable()
+    {
+        
+        return actualInterceptor.isNullable();
+    }
+
+    @Override
+    public T create(CreationalContext<T> context)
+    {
+        
+        return actualInterceptor.create(context);
+    }
+
+    @Override
+    public void destroy(T instance, CreationalContext<T> context)
+    {
+        actualInterceptor.destroy(instance, context);
+        
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((actualInterceptor == null) ? 0 : actualInterceptor.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (!super.equals(obj))
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        CustomInterceptor other = (CustomInterceptor) obj;
+        if (actualInterceptor == null)
+        {
+            if (other.actualInterceptor != null)
+            {
+                return false;
+            }
+        }
+        else if (!actualInterceptor.equals(other.actualInterceptor))
+        {
+            return false;
+        }
+        return true;
+    }
+}

Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ejb/EJBInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ejb/EJBInterceptorConfig.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ejb/EJBInterceptorConfig.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ejb/EJBInterceptorConfig.java Tue Dec  4 21:07:25 2012
@@ -0,0 +1,188 @@
+/*
+ * 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.ejb;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.AroundTimeout;
+import javax.interceptor.Interceptors;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.intercept.InterceptorData;
+import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.ClassUtil;
+
+/**
+ * Configures the EJB related interceptors.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public final class EJBInterceptorConfig
+{
+
+    private final WebBeansContext webBeansContext;
+
+    public EJBInterceptorConfig(WebBeansContext webBeansContext)
+    {
+        this.webBeansContext = webBeansContext;
+    }
+
+    /**
+     * Configures the given class for applicable interceptors.
+     *
+     * @param annotatedType to configure interceptors for
+     * @param interceptorStack to fill
+     */
+    public void configure(AnnotatedType<?> annotatedType, List<InterceptorData> interceptorStack)
+    {
+        Asserts.assertNotNull(annotatedType);
+
+
+        Interceptors incs = annotatedType.getAnnotation(Interceptors.class);
+        if (incs != null)
+        {
+            Class<?>[] interceptorClasses = incs.value();
+
+            for (Class<?> intClass : interceptorClasses)
+            {
+                configureInterceptorAnnots(intClass, interceptorStack, false, null);
+            }
+
+        }
+        configureBeanAnnots(annotatedType, interceptorStack);
+
+        Class clazz = annotatedType.getJavaClass();
+        webBeansContext.getInterceptorUtil().filterOverridenLifecycleInterceptor(clazz, interceptorStack);
+    }
+
+    /**
+     * Configure {@link Interceptors} on bean class.
+     * @param clazz bean class
+     * @param stack interceptor stack of bean
+     * @param isMethod if interceptor definition is on the bean
+     * @param m if isMethod true, then it is intercepted method
+     */
+    private void configureInterceptorAnnots(Class<?> clazz, List<InterceptorData> stack, boolean isMethod, Method m)
+    {
+        // 1- Look interceptor class super class
+        // 2- Look interceptor class
+        Class<?> superClass = clazz.getSuperclass();
+        if (superClass != null && !superClass.equals(Object.class))
+        {
+            configureInterceptorAnnots(superClass, stack, false, null);
+        }
+
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, AroundInvoke.class,
+                                                                      true, isMethod, stack, m, false);
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, AroundTimeout.class,
+                                                                      true, isMethod, stack, m, false);
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, PostConstruct.class,
+                                                                      true, isMethod, stack, m, false);
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, PreDestroy.class,
+                                                                      true, isMethod, stack, m, false);
+
+    }
+
+    /**
+     * Configure bean class defined interceptors.
+     * @param annotatedType bean class
+     * @param stack interceptor stack
+     */
+    private void configureBeanAnnots(AnnotatedType annotatedType, List<InterceptorData> stack)
+    {
+        // 1- Look method intercepor class annotations
+        // 2- Look super class around invoke
+        // 3- Look bean around invoke
+
+        // 1-
+        Set<AnnotatedMethod<?>> annotatedMethods = annotatedType.getMethods();
+
+        for (AnnotatedMethod<?> annotatedMethod : annotatedMethods)
+        {
+            Interceptors incs = annotatedMethod.getAnnotation(Interceptors.class);
+            if (incs != null)
+            {
+                Method method = annotatedMethod.getJavaMember();
+                Class<?>[] intClasses = incs.value();
+
+                for (Class<?> intClass : intClasses)
+                {
+                    configureInterceptorAnnots(intClass, stack, true, method);
+                }
+
+            }
+        }
+
+        Class clazz = annotatedType.getJavaClass();
+        // 2- Super clazz
+        List<Class<?>> listSuperClazz = ClassUtil.getSuperClasses(clazz, new ArrayList<Class<?>>());
+        configureBeanSuperClassAnnots(listSuperClazz, stack);
+
+        // 3- Bean itself
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, AroundInvoke.class,
+                                                                      false, false, stack, null, false);
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, AroundTimeout.class,
+                                                                      false, false, stack, null, false);
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, PostConstruct.class,
+                                                                      false, false, stack, null, false);
+        webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz, PreDestroy.class,
+                                                                      false, false, stack, null, false);
+
+    }
+
+    /**
+     * Configures super classes interceptors.
+     * @param list super classes
+     * @param stack interceptor stack
+     */
+    private void configureBeanSuperClassAnnots(List<Class<?>> list, List<InterceptorData> stack)
+    {
+        int i = list.size();
+
+        for (int j = i - 1; j >= 0; j--)
+        {
+            Class<?> clazz = list.get(j);
+            if (!clazz.equals(Object.class))
+            {
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz,
+                                                                              AroundInvoke.class, false,
+                                                                              false, stack, null, false);
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz,
+                                                                              AroundTimeout.class, false,
+                                                                              false, stack, null, false);
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz,
+                                                                              PostConstruct.class, false,
+                                                                              false, stack, null, false);
+                webBeansContext.getWebBeansUtil().configureInterceptorMethods(null, clazz,
+                                                                              PreDestroy.class, false,
+                                                                              false, stack, null, false);
+            }
+        }
+    }
+
+}