Return-Path: X-Original-To: apmail-openwebbeans-commits-archive@www.apache.org Delivered-To: apmail-openwebbeans-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3B59112AA for ; Sun, 15 Jun 2014 19:34:23 +0000 (UTC) Received: (qmail 55901 invoked by uid 500); 15 Jun 2014 19:34:23 -0000 Delivered-To: apmail-openwebbeans-commits-archive@openwebbeans.apache.org Received: (qmail 55873 invoked by uid 500); 15 Jun 2014 19:34:23 -0000 Mailing-List: contact commits-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwebbeans.apache.org Delivered-To: mailing list commits@openwebbeans.apache.org Received: (qmail 55862 invoked by uid 99); 15 Jun 2014 19:34:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Jun 2014 19:34:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Jun 2014 19:34:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D64A523889EA; Sun, 15 Jun 2014 19:34:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1602754 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/component/creation/ main/java/org/apache/webbeans/portable/ test/java/org/apache/webbeans/test/disposes/beans/broken... Date: Sun, 15 Jun 2014 19:34:00 -0000 To: commits@openwebbeans.apache.org From: struberg@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140615193400.D64A523889EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: struberg Date: Sun Jun 15 19:33:59 2014 New Revision: 1602754 URL: http://svn.apache.org/r1602754 Log: OWB-971 disposal and produces not allowed in interceptors and decorators hacked together with arne Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java Removed: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/broken/ Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java Sun Jun 15 19:33:59 2014 @@ -23,7 +23,7 @@ import java.lang.reflect.Method; import javax.enterprise.context.spi.CreationalContext; import org.apache.webbeans.component.creation.MethodProducerFactory; -import org.apache.webbeans.exception.WebBeansConfigurationException; + /** * Concrete implementation of the {@link AbstractOwbBean}. @@ -39,8 +39,6 @@ public class ProducerMethodBean exten /** Creator method of the parent component */ protected Method creatorMethod; - /** Disposal method */ - protected Method disposalMethod; /** * Creates a new instance. @@ -67,11 +65,6 @@ public class ProducerMethodBean exten } - public Method getDisposalMethod() - { - return disposalMethod; - } - /** * Sets the method. * @@ -82,22 +75,6 @@ public class ProducerMethodBean exten this.creatorMethod = creatorMethod; } - /** - * Sets the disposal method. - * - * @param disposalMethod disposal method of this producer method component - */ - public void setDisposalMethod(Method disposalMethod) - { - if (this.disposalMethod != null) - { - throw new WebBeansConfigurationException("There are multiple disposal method for producer method " + - "component with name : " + getName() + " with implementation class " + - getBeanClass().getName() + " with disposal method name : " + - disposalMethod.getName()); - } - this.disposalMethod = disposalMethod; - } @Override public String getId() Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,97 @@ +/* + * 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.component.creation; + +import javax.enterprise.inject.Disposes; +import javax.enterprise.inject.Produces; +import javax.enterprise.inject.spi.AnnotatedField; +import javax.enterprise.inject.spi.AnnotatedMethod; +import javax.enterprise.inject.spi.AnnotatedParameter; +import javax.enterprise.inject.spi.AnnotatedType; +import java.util.Set; + +import org.apache.webbeans.component.ProducerMethodBean; +import org.apache.webbeans.exception.WebBeansConfigurationException; +import org.apache.webbeans.util.GenericsUtil; + +/** + * Base class for all bean builders + */ +public abstract class AbstractBeanBuilder +{ + + /** + * Make sure there is no disposer method without a corresponding producer method. + * @param annotatedMethods of the given bean class + * @param producerBeans or an empty Set + */ + protected void validateNoDisposerWithoutProducer(Set> annotatedMethods, Set> producerBeans) + { + for (final AnnotatedMethod annotatedMethod : annotatedMethods) + { + for (final AnnotatedParameter param : annotatedMethod.getParameters()) + { + if (param.isAnnotationPresent(Disposes.class)) + { + boolean found = false; + for (final ProducerMethodBean producer : producerBeans) + { + if (GenericsUtil.satisfiesDependency(false, producer.getCreatorMethod().getGenericReturnType(), param.getBaseType())) + { + found = true; + break; + } + } + if (!found) + { + throw new WebBeansConfigurationException("@Disposes without @Produces " + annotatedMethod.getJavaMember()); + } + break; + } + } + } + } + + + /** + * Certain beans like CDI Interceptors and Decorators + * are not allowed to define producer methods. + */ + protected void validateNoProducerMethod(AnnotatedType annotatedType) + { + Set> annotatedMethods = annotatedType.getMethods(); + for (final AnnotatedMethod annotatedMethod : annotatedMethods) + { + if (annotatedMethod.isAnnotationPresent(Produces.class)) + { + throw new WebBeansConfigurationException("This class must not have a @Produces method" + annotatedMethod.getJavaMember()); + } + } + + Set> annotatedFields = annotatedType.getFields(); + for (final AnnotatedField annotatedField : annotatedFields) + { + if (annotatedField.isAnnotationPresent(Produces.class)) + { + throw new WebBeansConfigurationException("This class must not have a @Produces field" + annotatedField.getJavaMember()); + } + } + } + +} Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java Sun Jun 15 19:33:59 2014 @@ -20,6 +20,7 @@ package org.apache.webbeans.component.cr import javax.enterprise.inject.spi.AnnotatedMember; import javax.enterprise.inject.spi.AnnotatedType; +import javax.enterprise.inject.spi.DefinitionException; import org.apache.webbeans.component.AbstractProducerBean; import org.apache.webbeans.component.BeanAttributesImpl; @@ -53,6 +54,14 @@ public abstract class AbstractProducerBe return parent.getWebBeansContext().getAnnotatedElementFactory().getAnnotatedType(superclass); } + /** + * Check if the producer rules are met. + */ + public void validate() throws DefinitionException + { + + } + protected abstract P createBean(InjectionTargetBean parent, Class beanClass); protected P createBean(Class beanClass) Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java Sun Jun 15 19:33:59 2014 @@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.Inter import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.util.Collections; import java.util.Map; import java.util.Set; @@ -51,6 +52,12 @@ public class CdiInterceptorBeanBuilder +public class DecoratorBeanBuilder extends AbstractBeanBuilder { private static Logger logger = WebBeansLoggerFacade.getLogger(DecoratorBeanBuilder.class); @@ -145,6 +146,13 @@ public class DecoratorBeanBuilder } } } + + // make sure that CDI Decorators do not have any Producer methods + validateNoProducerMethod(annotatedType); + + // make sure that CDI Decorator do not have a Disposes method + validateNoDisposerWithoutProducer(annotatedType.getMethods(), Collections.EMPTY_SET); + } public void defineDecoratorRules() Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java Sun Jun 15 19:33:59 2014 @@ -52,7 +52,7 @@ import org.apache.webbeans.util.ClassUti /** * Bean builder for {@link org.apache.webbeans.component.InterceptorBean}s. */ -public abstract class InterceptorBeanBuilder> +public abstract class InterceptorBeanBuilder> extends AbstractBeanBuilder { protected final WebBeansContext webBeansContext; protected final AnnotatedType annotatedType; Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java Sun Jun 15 19:33:59 2014 @@ -42,9 +42,6 @@ import org.apache.webbeans.util.Annotati import org.apache.webbeans.util.Asserts; /** - * Abstract implementation of {@link AbstractBeanBuilder}. - * - * @version $Rev$ $Date$ * * @param bean class type */ Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java Sun Jun 15 19:33:59 2014 @@ -44,10 +44,6 @@ import org.apache.webbeans.util.ClassUti import org.apache.webbeans.util.WebBeansUtil; /** - * Abstract implementation of {@link AbstractBeanBuilder}. - * - * @version $Rev$ $Date$ - * * @param bean class type */ public class ProducerFieldBeansBuilder> Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java Sun Jun 15 19:33:59 2014 @@ -25,7 +25,6 @@ import org.apache.webbeans.config.WebBea import org.apache.webbeans.exception.WebBeansConfigurationException; import org.apache.webbeans.util.AnnotationUtil; import org.apache.webbeans.util.Asserts; -import org.apache.webbeans.util.GenericsUtil; import org.apache.webbeans.util.WebBeansUtil; import javax.enterprise.event.Observes; @@ -33,20 +32,15 @@ import javax.enterprise.inject.Disposes; import javax.enterprise.inject.Produces; import javax.enterprise.inject.Specializes; import javax.enterprise.inject.spi.AnnotatedMethod; -import javax.enterprise.inject.spi.AnnotatedParameter; import javax.enterprise.inject.spi.AnnotatedType; import javax.inject.Inject; import java.util.HashSet; import java.util.Set; /** - * Abstract implementation of {@link AbstractBeanBuilder}. - * - * @version $Rev$ $Date$ - * * @param bean class type */ -public class ProducerMethodBeansBuilder> +public class ProducerMethodBeansBuilder> extends AbstractBeanBuilder { protected final WebBeansContext webBeansContext; @@ -100,7 +94,6 @@ public class ProducerMethodBeansBuilder< { producerMethodBeanCreator.configureProducerSpecialization(producerMethodBean, (AnnotatedMethod) annotatedMethod); } - MethodProducerFactory producerFactory = new MethodProducerFactory(annotatedMethod, bean, webBeansContext); producerMethodBean.setCreatorMethod(annotatedMethod.getJavaMember()); webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean, @@ -114,30 +107,8 @@ public class ProducerMethodBeansBuilder< } // valid all @Disposes have a @Produces - for (final AnnotatedMethod annotatedMethod : annotatedMethods) - { - for (final AnnotatedParameter param : annotatedMethod.getParameters()) - { - if (param.isAnnotationPresent(Disposes.class)) - { - boolean found = false; - for (final ProducerMethodBean producer : producerBeans) - { - if (GenericsUtil.satisfiesDependency(false, producer.getCreatorMethod().getGenericReturnType(), param.getBaseType())) - { - found = true; - break; - } - } - if (!found) - { - throw new WebBeansConfigurationException("@Disposes without @Produces " + annotatedMethod.getJavaMember()); - } - break; - } - } - } - + validateNoDisposerWithoutProducer(annotatedMethods, producerBeans); + return producerBeans; } Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java?rev=1602754&r1=1602753&r2=1602754&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java Sun Jun 15 19:33:59 2014 @@ -85,11 +85,6 @@ public class ProducerMethodProducer bean) - { - owner = bean; - } - @Override protected T produce(Map, ?> interceptors, CreationalContextImpl creationalContext) { Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/BrokenDisposalTest.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,49 @@ +/* + * 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.test.disposes.beans.broken; + +import javax.enterprise.inject.spi.DefinitionException; + +import org.apache.webbeans.test.AbstractUnitTest; +import org.junit.Test; + +/** + * Test a few situations where disposal methods are not allowed + */ +public class BrokenDisposalTest extends AbstractUnitTest +{ + @Test(expected = DefinitionException.class) + public void testDisposalWithoutProducerMethod() throws Exception + { + startContainer(NonProducerBeanWithDisposes.class); + } + + @Test(expected = DefinitionException.class) + public void testDisposalOnDecorator() throws Exception + { + addDecorator(DecoratorWithDisposes.class); + startContainer(); + } + + @Test(expected = DefinitionException.class) + public void testDisposalOnInterceptor() throws Exception + { + addInterceptor(InterceptorWithDisposes.class); + startContainer(); + } +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/DecoratorWithDisposes.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,69 @@ +/* + * 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.test.disposes.beans.broken; + +import javax.decorator.Decorator; +import javax.decorator.Delegate; +import javax.enterprise.inject.Disposes; +import javax.inject.Inject; + +import org.apache.webbeans.test.decorators.multiple.IOutputProvider; + +/** + * This class is a standard CDI bean but has a method annotated with + * @Disposes which is illegal. + */ +@Decorator +public class DecoratorWithDisposes implements IOutputProvider +{ + @Inject + @Delegate + private IOutputProvider delegate; + + + public void disposerMethodOnDecorator_isBroken(@Disposes String val) + { + + } + + @Override + public String getOutput() + { + return null; + } + + @Override + public String trace() + { + return null; + } + + @Override + public String otherMethod() + { + return null; + } + + @Override + public String getDelayedOutput() throws InterruptedException + { + return null; + } + +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/InterceptorWithDisposes.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,49 @@ +/* + * 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.test.disposes.beans.broken; + + +import javax.enterprise.inject.Disposes; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +import java.io.Serializable; + +import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional; + +/** + * This class is a standard CDI bean but has a method annotated with + * @Disposes which is illegal. + */ +@Transactional +@Interceptor +public class InterceptorWithDisposes implements Serializable +{ + @AroundInvoke + public Object caller(InvocationContext context) throws Exception + { + return context.proceed(); + } + + public void disposerMethodWithoutProducer_isBroken(@Disposes String val) + { + + } +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/disposes/beans/broken/NonProducerBeanWithDisposes.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,33 @@ +/* + * 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.test.disposes.beans.broken; + +import javax.enterprise.inject.Disposes; + +/** + * This class is a standard CDI bean but has a method annotated with + * @Disposes which is illegal. + */ +public class NonProducerBeanWithDisposes +{ + public void disposerMethodWithoutProducer_isBroken(@Disposes String val) + { + + } +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/BrokenProducesTest.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,57 @@ +/* + * 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.test.producer.broken; + +import javax.enterprise.inject.spi.DefinitionException; + +import org.apache.webbeans.test.AbstractUnitTest; +import org.junit.Test; + +/** + * Test a few situations where producer methods are not allowed + */ +public class BrokenProducesTest extends AbstractUnitTest +{ + + @Test(expected = DefinitionException.class) + public void testProducerMethodInDecorator() throws Exception + { + addDecorator(DecoratorWithProducerMethod.class); + startContainer(); + } + + @Test(expected = DefinitionException.class) + public void testProducerMethodInInterceptor() throws Exception + { + addInterceptor(InterceptorWithProducerMethod.class); + startContainer(); + } + @Test(expected = DefinitionException.class) + public void testProducerFieldInDecorator() throws Exception + { + addDecorator(DecoratorWithProducerField.class); + startContainer(); + } + + @Test(expected = DefinitionException.class) + public void testProducerFieldInInterceptor() throws Exception + { + addInterceptor(InterceptorWithProducerField.class); + startContainer(); + } +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerField.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,67 @@ +/* + * 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.test.producer.broken; + +import javax.decorator.Decorator; +import javax.decorator.Delegate; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; + +import org.apache.webbeans.test.decorators.multiple.IOutputProvider; + +/** + * This class is a standard CDI bean but has a method annotated with + * @Disposes which is illegal. + */ +@Decorator +public class DecoratorWithProducerField implements IOutputProvider +{ + @Inject + @Delegate + private IOutputProvider delegate; + + @Produces + public String kaboom = "kaboom"; + + + @Override + public String getOutput() + { + return null; + } + + @Override + public String trace() + { + return null; + } + + @Override + public String otherMethod() + { + return null; + } + + @Override + public String getDelayedOutput() throws InterruptedException + { + return null; + } + +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/DecoratorWithProducerMethod.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,70 @@ +/* + * 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.test.producer.broken; + +import javax.decorator.Decorator; +import javax.decorator.Delegate; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; + +import org.apache.webbeans.test.decorators.multiple.IOutputProvider; + +/** + * This class is a standard CDI bean but has a method annotated with + * @Disposes which is illegal. + */ +@Decorator +public class DecoratorWithProducerMethod implements IOutputProvider +{ + @Inject + @Delegate + private IOutputProvider delegate; + + + @Produces + public String producerMethodOnDecorator_isBroken() + { + return "kaboom"; + } + + @Override + public String getOutput() + { + return null; + } + + @Override + public String trace() + { + return null; + } + + @Override + public String otherMethod() + { + return null; + } + + @Override + public String getDelayedOutput() throws InterruptedException + { + return null; + } + +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerField.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,47 @@ +/* + * 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.test.producer.broken; + + +import javax.enterprise.inject.Produces; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; +import java.io.Serializable; + +import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional; + +/** + * This class is a standard CDI bean but has a method annotated with + * @Disposes which is illegal. + */ +@Transactional +@Interceptor +public class InterceptorWithProducerField implements Serializable +{ + @Produces + public String kaboom = "kaboom"; + + @AroundInvoke + public Object caller(InvocationContext context) throws Exception + { + return context.proceed(); + } + +} Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java?rev=1602754&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java (added) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/broken/InterceptorWithProducerMethod.java Sun Jun 15 19:33:59 2014 @@ -0,0 +1,50 @@ +/* + * 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.test.producer.broken; + + +import javax.enterprise.inject.Produces; +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; +import java.io.Serializable; + +import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional; + +/** + * This class is a standard CDI bean but has a method annotated with + * @Disposes which is illegal. + */ +@Transactional +@Interceptor +public class InterceptorWithProducerMethod implements Serializable +{ + @AroundInvoke + public Object caller(InvocationContext context) throws Exception + { + return context.proceed(); + } + + @Produces + public String producerMethodOnDecorator_isBroken() + { + return "kaboom"; + } + +}