openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bergm...@apache.org
Subject svn commit: r903002 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/decorator/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/newtests/decorators/multiple/ test/java/org/apache/webbeans/newtests/decorat...
Date Mon, 25 Jan 2010 22:31:57 GMT
Author: bergmark
Date: Mon Jan 25 22:31:56 2010
New Revision: 903002

URL: http://svn.apache.org/viewvc?rev=903002&view=rev
Log:
[OWB-252] Implementation and simple test for treating the Decorator invocation as a stack.

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/RequestStringBuilder.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStackTests.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStack.xml
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,135 @@
+/*
+ * 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.decorator;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.logger.WebBeansLogger;
+
+import javassist.util.proxy.MethodHandler;
+
+public class DelegateHandler implements MethodHandler
+{
+    private transient static WebBeansLogger logger = WebBeansLogger.getLogger(DelegateHandler.class);
+
+    private transient List<Object> decorators;
+    private transient int position = 0;
+
+    private transient Object actualBean = null;
+
+    @Override
+    public Object invoke(Object instance, Method method, Method proceed, Object[] arguments)
throws Exception
+    {
+        // Tuck away a reference to the bean being Decorated
+        if (actualBean == null)
+        {
+            actualBean = instance;
+        }
+
+        while (position < decorators.size())
+        {
+
+            Object decorator = decorators.get(position++);
+
+            try
+            {
+                Method decMethod = decorator.getClass().getMethod(method.getName(), method.getParameterTypes());
+                boolean methodInInterface = checkForMethodInInterfaces(decorator.getClass(),
method);
+
+                if (decMethod != null && methodInInterface)
+                {
+                    if (!decMethod.isAccessible())
+                    {
+                        decMethod.setAccessible(true);
+                    }
+
+                    Object returnValue = decMethod.invoke(decorator, arguments);
+                    position--;
+                    return returnValue;
+                }
+
+            }
+            catch (SecurityException e)
+            {
+                logger.error(OWBLogConst.ERROR_0011, new Object[] { method.getName(), decorator.getClass().getName()
});
+                throw new WebBeansException(e);
+
+            }
+            catch (NoSuchMethodException e)
+            {
+                continue;
+            }
+            catch (InvocationTargetException e)
+            {
+                logger.error(OWBLogConst.ERROR_0012, new Object[] { method.getName(), decorator.getClass().getName()
}, e.getTargetException());
+
+                throw new WebBeansException(e);
+            }
+            catch (IllegalAccessException e)
+            {
+                logger.error(OWBLogConst.ERROR_0014, new Object[] { method.getName(), decorator.getClass().getName()
});
+                throw new WebBeansException(e);
+            }
+
+        }
+
+        if (!method.isAccessible())
+        {
+            method.setAccessible(true);
+        }
+
+        Object result = method.invoke(actualBean, arguments);
+        return result;
+
+    }
+
+    /**
+     * Helper method to locate method in any of the interfaces of the Decorator.
+     * 
+     * @param Class whose interfaces we want to check
+     * @param Method to check for in Interfaces
+     * @return True if the method exists in any of the interfaces of the
+     *         Decorator
+     */
+    private boolean checkForMethodInInterfaces(Class<? extends Object> class1, Method
m)
+    {
+        Class<?>[] interfaces = class1.getInterfaces();
+        for (int i = 0; i < interfaces.length; i++)
+        {
+            try
+            {
+                if (interfaces[i].getMethod(m.getName(), m.getParameterTypes()) != null)
+                {
+                    return true;
+                }
+            }
+            catch (NoSuchMethodException exception)
+            {
+                // no-op, we didn't find the method
+            }
+        }
+        //
+        return false;
+    }
+
+    public void setDecorators(List<Object> dec)
+    {
+        this.decorators = dec;
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/DelegateHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java?rev=903002&r1=903001&r2=903002&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java
Mon Jan 25 22:31:56 2010
@@ -79,7 +79,7 @@
         }
     }
     
-    public static List<Object> getDecoratorStack(AbstractBean<?> component, Object
instance)
+    public static List<Object> getDecoratorStack(AbstractBean<?> component, Object
instance, Object delegate)
     {
         List<Object> decoratorStack = new ArrayList<Object>();
         List<Decorator<?>> decoratorList = component.getDecorators();       

@@ -90,10 +90,8 @@
             WebBeansDecorator<?> decorator = (WebBeansDecorator<?>) itList.next();
             
             Object decoratorInstance = BeanManagerImpl.getManager().getInstance(decorator,null);
-
             decorator.setInjections(decoratorInstance);
-            decorator.setDelegate(decoratorInstance, instance);
-            
+            decorator.setDelegate(decoratorInstance, delegate);
             decoratorStack.add(decoratorInstance);
         }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=903002&r1=903001&r2=903002&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
Mon Jan 25 22:31:56 2010
@@ -21,15 +21,17 @@
 import java.util.List;
 
 import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyFactory;
 
 import javax.interceptor.ExcludeClassInterceptors;
 import javax.interceptor.Interceptors;
 
 import org.apache.webbeans.component.AbstractBean;
-import org.apache.webbeans.config.DefinitionUtil;
 import org.apache.webbeans.config.BeansDeployer;
+import org.apache.webbeans.config.DefinitionUtil;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.decorator.DelegateHandler;
 import org.apache.webbeans.decorator.WebBeansDecorator;
 import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
@@ -37,6 +39,7 @@
 import org.apache.webbeans.intercept.ejb.EJBInterceptorConfig;
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
 import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -137,12 +140,6 @@
 
     protected AbstractBean<?> bean = null;
 
-    private transient Method calledMethod = null;
-
-    private transient boolean isSameDecMethod = false;
-    
-    private transient boolean isInDecoratorCall = false;
-
     protected InterceptorHandler(AbstractBean<?> bean)
     {
         this.bean = bean;
@@ -158,11 +155,23 @@
             //toString is supported but no other object method names!!!
             if ((!ClassUtil.isObjectMethod(method.getName()) || method.getName().equals("toString"))
&& InterceptorUtil.isWebBeansBusinessMethod(method))
             {
-                checkDecoratorStackForSameDecorator(method);
-
-                //Gets component decorator stack
-                List<Object> decorators = WebBeansDecoratorConfig.getDecoratorStack(bean,
instance);
-                            
+                
+                DelegateHandler delegateHandler = null;
+                List<Object> decorators = null;
+                
+                if(bean.getDecorators().size() > 0)
+                {
+                	ProxyFactory delegateFactory = JavassistProxyFactory.createProxyFactory(bean);
+                	delegateHandler = new DelegateHandler();
+                	delegateFactory.setHandler(delegateHandler);
+                	Object delegate = delegateFactory.createClass().newInstance();
+                		
+                    //Gets component decorator stack
+                    decorators = WebBeansDecoratorConfig.getDecoratorStack(bean, instance,
delegate);
+                    
+                    delegateHandler.setDecorators(decorators);
+                }
+           
                 // Run around invoke chain
                 List<InterceptorData> stack = bean.getInterceptorStack();
                 
@@ -178,9 +187,12 @@
                     interceptorRun = true;
                 }
                 
-                //Call decarators
-                callDecorators(decorators, method, arguments);            
-                
+                //If there are Decorators, allow the delegate handler to manage the stack
+                if(decorators != null)
+                {
+                	return delegateHandler.invoke(instance, method, proceed, arguments);
+                }
+               
             }
 
             if(interceptorRun)
@@ -209,93 +221,6 @@
         }
         
     }
-    
-    private void checkDecoratorStackForSameDecorator(Method method)
-    {
-        if(this.isInDecoratorCall)
-        {
-            if (this.calledMethod == null)
-            {
-                this.calledMethod = method;
-            }
-            
-            else if (this.calledMethod.equals(method))
-            {
-                this.isSameDecMethod = true;
-            }
-            
-            else
-            {
-                this.calledMethod = method;
-                this.isSameDecMethod = false;
-            }            
-        }
-        else
-        {
-            this.calledMethod = null;
-        }
-    }
-
-    private void callDecorators(List<Object> decorators, Method method, Object[] arguments)
-    {
-
-        Iterator<Object> itDec = decorators.iterator();
-        
-        while (itDec.hasNext())
-        {
-            if(!this.isInDecoratorCall)
-            {
-                this.isInDecoratorCall = true;
-            }
-            
-            Object decorator = itDec.next();
-            
-            try
-            {
-                Method decMethod = decorator.getClass().getMethod(method.getName(), method.getParameterTypes());
-
-                if (decMethod != null)
-                {
-                    if (!this.isSameDecMethod)
-                    {
-                        if (!decMethod.isAccessible())
-                        {
-                            decMethod.setAccessible(true);
-                        }
-
-                        decMethod.invoke(decorator, arguments);
-                    }
-                }
-
-            }
-            catch (SecurityException e)
-            {
-                logger.error(OWBLogConst.ERROR_0011, new Object[]{method.getName(), decorator.getClass().getName()});
-                throw new WebBeansException(e);
-
-            }
-            catch (NoSuchMethodException e)
-            {
-                continue;
-            }
-            catch (InvocationTargetException e)
-            {
-                logger.error(OWBLogConst.ERROR_0012, new Object[]{method.getName(), decorator.getClass().getName()},
e.getTargetException());
-
-                throw new WebBeansException(e);
-            }
-            catch (IllegalAccessException e)
-            {
-                logger.error(OWBLogConst.ERROR_0014, new Object[]{method.getName(), decorator.getClass().getName()});
-                throw new WebBeansException(e);
-            }
-            finally
-            {
-                this.isInDecoratorCall = false;
-            }
-
-        }
-    }
 
     protected abstract <T> Object callAroundInvokes(Method proceed, Object[] arguments,
List<InterceptorData> stack) throws Exception;
 

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.newtests.decorators.multiple;
+
+import java.util.LinkedList;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+
+@Decorator
+public class Decorator1 implements IOutputProvider
+{
+
+    @Inject
+    @Delegate
+    @Any
+    IOutputProvider op;
+    @Inject
+    RequestStringBuilder rsb;
+
+    public String getOutput()
+    {
+        rsb.addOutput("Decorator1\n");
+        return op.getOutput();
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.newtests.decorators.multiple;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@Decorator
+public class Decorator2 implements IOutputProvider
+{
+
+    @Inject
+    @Delegate
+    @Default
+    @Any
+    @Named
+    IOutputProvider op;
+    @Inject
+    @Default
+    RequestStringBuilder rsb;
+
+    public String getOutput()
+    {
+        rsb.addOutput("Decorator2\n");
+        return op.getOutput();
+    }
+
+}
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,21 @@
+/*
+ * 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.newtests.decorators.multiple;
+
+public interface IOutputProvider
+{
+
+    public String getOutput();
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.newtests.decorators.multiple;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@RequestScoped
+@Named
+public class OutputProvider implements IOutputProvider
+{
+
+    @Inject
+    RequestStringBuilder rsb = null;
+
+    public String getOutput()
+    {
+
+        rsb.addOutput("OutputProvider\n");
+        return rsb.toString();
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/RequestStringBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/RequestStringBuilder.java?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/RequestStringBuilder.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/RequestStringBuilder.java
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.newtests.decorators.multiple;
+
+import javax.enterprise.inject.Model;
+
+@Model
+public class RequestStringBuilder
+{
+
+    private StringBuilder sb = new StringBuilder();
+
+    public void addOutput(String s)
+    {
+        sb.append(s);
+    }
+
+    public String toString()
+    {
+        return sb.toString();
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/RequestStringBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStackTests.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStackTests.java?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStackTests.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStackTests.java
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.newtests.decorators.tests;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.AnnotationLiteral;
+
+import junit.framework.Assert;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.decorators.multiple.Decorator1;
+import org.apache.webbeans.newtests.decorators.multiple.Decorator2;
+import org.apache.webbeans.newtests.decorators.multiple.IOutputProvider;
+import org.apache.webbeans.newtests.decorators.multiple.OutputProvider;
+import org.apache.webbeans.newtests.decorators.multiple.RequestStringBuilder;
+import org.junit.Test;
+
+public class MultipleDecoratorStackTests extends AbstractUnitTest
+{
+
+    public static final String PACKAGE_NAME = MultipleDecoratorStackTests.class.getPackage().getName();
+
+    @Test
+    public void testDecoratorStack()
+    {
+        Collection<Class<?>> classes = new ArrayList<Class<?>>();
+        classes.add(Decorator1.class);
+        classes.add(Decorator2.class);
+        classes.add(IOutputProvider.class);
+        classes.add(OutputProvider.class);
+        classes.add(RequestStringBuilder.class);
+
+        Collection<URL> xmls = new ArrayList<URL>();
+        xmls.add(getXMLUrl(PACKAGE_NAME, "MultipleDecoratorStack"));
+
+        startContainer(classes, xmls);
+
+        Bean<?> bean = getBeanManager().getBeans(OutputProvider.class, new AnnotationLiteral<Default>()
+        {
+        }).iterator().next();
+        Object instance = getBeanManager().getReference(bean, OutputProvider.class, getBeanManager().createCreationalContext(bean));
+
+        OutputProvider outputProvider = (OutputProvider) instance;
+
+        Assert.assertTrue(outputProvider != null);
+
+        String result = outputProvider.getOutput();
+        System.out.println(result);
+        // Verify that the Decorators were called in order, and in a stack.
+        Assert.assertTrue(result.equalsIgnoreCase("Decorator1\nDecorator2\nOutputProvider\n"));
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStackTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStack.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStack.xml?rev=903002&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStack.xml
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStack.xml
Mon Jan 25 22:31:56 2010
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<beans>
+   <decorators>
+      <class>org.apache.webbeans.newtests.decorators.multiple.Decorator1</class>
+      <class>org.apache.webbeans.newtests.decorators.multiple.Decorator2</class>
+   </decorators>
+</beans>
\ No newline at end of file

Propchange: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/decorators/tests/MultipleDecoratorStack.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message