Return-Path: Delivered-To: apmail-incubator-openwebbeans-commits-archive@minotaur.apache.org Received: (qmail 27241 invoked from network); 10 Oct 2009 18:43:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Oct 2009 18:43:37 -0000 Received: (qmail 13404 invoked by uid 500); 10 Oct 2009 18:43:37 -0000 Delivered-To: apmail-incubator-openwebbeans-commits-archive@incubator.apache.org Received: (qmail 13384 invoked by uid 500); 10 Oct 2009 18:43:37 -0000 Mailing-List: contact openwebbeans-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: openwebbeans-dev@incubator.apache.org Delivered-To: mailing list openwebbeans-commits@incubator.apache.org Received: (qmail 13372 invoked by uid 99); 10 Oct 2009 18:43:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 10 Oct 2009 18:43:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Sat, 10 Oct 2009 18:43:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C1788238888A; Sat, 10 Oct 2009 18:43:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r823919 - in /incubator/openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/annotation/ main/java/org/apache/webbeans/container/ main/java/org/apache/webbeans/inject/impl/ main/java/org/apache/webbeans/util/ test/java/org/ap... Date: Sat, 10 Oct 2009 18:43:10 -0000 To: openwebbeans-commits@incubator.apache.org From: gerdogdu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091010184310.C1788238888A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gerdogdu Date: Sat Oct 10 18:43:09 2009 New Revision: 823919 URL: http://svn.apache.org/viewvc?rev=823919&view=rev Log: Adding @Named qualifier for injection points. Adding tests. Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/NamedLiteral.java (with props) incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithNamedValue.java (with props) incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithoutNamedValue.java (with props) incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithNamedValue.java (with props) incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithoutNamedValue.java (with props) incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/named/ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/named/NamedTests.java (with props) Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/NamedLiteral.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/NamedLiteral.java?rev=823919&view=auto ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/NamedLiteral.java (added) +++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/NamedLiteral.java Sat Oct 10 18:43:09 2009 @@ -0,0 +1,39 @@ +/* + * 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.annotation; + +import javax.enterprise.inject.AnnotationLiteral; +import javax.inject.Named; + +/** + * Named literal. + * + * @version $Rev$ $Date$ + * + */ +public class NamedLiteral extends AnnotationLiteral implements Named +{ + private String value; + + @Override + public String value() + { + return value; + } + + public void setValue(String value) + { + this.value = value; + } +} Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/NamedLiteral.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=823919&r1=823918&r2=823919&view=diff ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java (original) +++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java Sat Oct 10 18:43:09 2009 @@ -15,6 +15,8 @@ import java.io.InputStream; import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Member; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=823919&r1=823918&r2=823919&view=diff ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java (original) +++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java Sat Oct 10 18:43:09 2009 @@ -34,6 +34,7 @@ import org.apache.webbeans.util.AnnotationUtil; import org.apache.webbeans.util.Asserts; import org.apache.webbeans.util.ClassUtil; +import org.apache.webbeans.util.WebBeansUtil; /** * Injection point resolver class. @@ -105,9 +106,10 @@ * @throws If bean is not avialable in the current deployment for given injection */ public void checkInjectionPoints(InjectionPoint injectionPoint) - { - Type type = injectionPoint.getType(); + { + WebBeansUtil.checkInjectionPointNamedQualifier(injectionPoint); + Type type = injectionPoint.getType(); Class clazz = null; if (type instanceof ParameterizedType) @@ -145,7 +147,7 @@ } - + /** * Returns bean for injection point. * Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java?rev=823919&r1=823918&r2=823919&view=diff ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java (original) +++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java Sat Oct 10 18:43:09 2009 @@ -30,7 +30,9 @@ import javax.enterprise.inject.spi.AnnotatedParameter; import javax.enterprise.inject.spi.Bean; import javax.enterprise.inject.spi.InjectionPoint; +import javax.inject.Named; +import org.apache.webbeans.annotation.NamedLiteral; import org.apache.webbeans.inject.xml.XMLInjectionModelType; import org.apache.webbeans.inject.xml.XMLInjectionPointModel; import org.apache.webbeans.portable.AnnotatedElementFactory; @@ -111,14 +113,48 @@ return false; } + /** + * Gets injected point instance. + * @param owner owner of the injection point + * @param annots annotations of the injection point + * @param type type of the injection point + * @param member member of the injection point + * @param annotated annotated instance of injection point + * @return injection point instance + */ private static InjectionPoint getGenericInjectionPoint(Bean owner, Annotation[] annots, Type type, Member member,Annotated annotated) { InjectionPointImpl injectionPoint = null; - Annotation[] bindingAnnots = AnnotationUtil.getQualifierAnnotations(annots); + Annotation[] qualifierAnnots = AnnotationUtil.getQualifierAnnotations(annots); + + //@Named update for injection fields! + if(member instanceof Field) + { + for(int i=0;i qualifierset = injectionPoint.getQualifiers(); + Named namedQualifier = null; + for(Annotation qualifier : qualifierset) + { + if(qualifier.annotationType().equals(Named.class)) + { + namedQualifier = (Named)qualifier; + break; + } + } + + if(namedQualifier != null) + { + String value = namedQualifier.value(); + + if(value == null || value.equals("")) + { + Member member = injectionPoint.getMember(); + if(!(member instanceof Field)) + { + throw new WebBeansConfigurationException("Injection point type : " + injectionPoint + " can not define @Named qualifier without value!"); + } + } + } + + } + } \ No newline at end of file Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithNamedValue.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithNamedValue.java?rev=823919&view=auto ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithNamedValue.java (added) +++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithNamedValue.java Sat Oct 10 18:43:09 2009 @@ -0,0 +1,25 @@ +/* + * 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.component.inject.named; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.webbeans.test.component.IPayment; + +public class NamedFieldWithNamedValue +{ + private @Inject @Named("payment") IPayment paymentProcessor; + +} Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithNamedValue.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithoutNamedValue.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithoutNamedValue.java?rev=823919&view=auto ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithoutNamedValue.java (added) +++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithoutNamedValue.java Sat Oct 10 18:43:09 2009 @@ -0,0 +1,25 @@ +/* + * 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.component.inject.named; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.webbeans.test.component.IPayment; + +public class NamedFieldWithoutNamedValue +{ + private @Inject @Named IPayment paymentProcessor; + +} Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedFieldWithoutNamedValue.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithNamedValue.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithNamedValue.java?rev=823919&view=auto ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithNamedValue.java (added) +++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithNamedValue.java Sat Oct 10 18:43:09 2009 @@ -0,0 +1,28 @@ +/* + * 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.component.inject.named; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.webbeans.test.component.IPayment; + +public class NamedOtherWithNamedValue +{ + @Inject + public NamedOtherWithNamedValue(@Named("value") IPayment payment) + { + + } +} Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithNamedValue.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithoutNamedValue.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithoutNamedValue.java?rev=823919&view=auto ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithoutNamedValue.java (added) +++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithoutNamedValue.java Sat Oct 10 18:43:09 2009 @@ -0,0 +1,28 @@ +/* + * 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.component.inject.named; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.webbeans.test.component.IPayment; + +public class NamedOtherWithoutNamedValue +{ + @Inject + public NamedOtherWithoutNamedValue(@Named IPayment payment) + { + + } +} Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/named/NamedOtherWithoutNamedValue.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/named/NamedTests.java URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/named/NamedTests.java?rev=823919&view=auto ============================================================================== --- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/named/NamedTests.java (added) +++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/named/NamedTests.java Sat Oct 10 18:43:09 2009 @@ -0,0 +1,137 @@ +/* + * 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.unittests.inject.named; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.util.Set; + +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.inject.Named; + +import org.apache.webbeans.container.InjectionResolver; +import org.apache.webbeans.exception.WebBeansConfigurationException; +import org.apache.webbeans.inject.impl.InjectionPointFactory; +import org.apache.webbeans.test.component.IPayment; +import org.apache.webbeans.test.component.inject.named.NamedFieldWithNamedValue; +import org.apache.webbeans.test.component.inject.named.NamedFieldWithoutNamedValue; +import org.apache.webbeans.test.component.inject.named.NamedOtherWithNamedValue; +import org.apache.webbeans.test.component.inject.named.NamedOtherWithoutNamedValue; +import org.apache.webbeans.test.servlet.TestContext; +import org.apache.webbeans.util.WebBeansUtil; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class NamedTests extends TestContext +{ + public NamedTests() + { + super(NamedTests.class.getName()); + } + + @Before + public void init() + { + super.init(); + } + + + @Test + public void testFieldWithNamedValue() throws Exception + { + Bean bean = defineSimpleWebBean(NamedFieldWithNamedValue.class); + Field field = NamedFieldWithNamedValue.class.getDeclaredField("paymentProcessor"); + + InjectionPoint point =InjectionPointFactory.getFieldInjectionPointData(bean, field); + + WebBeansUtil.checkInjectionPointNamedQualifier(point); + + String value = qulifier(point); + + Assert.assertEquals("payment", value); + } + + @Test + public void testFieldWithoutNamedValue() throws Exception + { + Bean bean = defineSimpleWebBean(NamedFieldWithoutNamedValue.class); + Field field = NamedFieldWithoutNamedValue.class.getDeclaredField("paymentProcessor"); + + InjectionPoint point =InjectionPointFactory.getFieldInjectionPointData(bean, field); + + WebBeansUtil.checkInjectionPointNamedQualifier(point); + + String value = qulifier(point); + + Assert.assertEquals("paymentProcessor", value); + + } + + @Test + public void testOtherWithNamedValue() throws Exception + { + Bean bean = defineSimpleWebBean(NamedOtherWithNamedValue.class); + Constructor constructor = NamedOtherWithNamedValue.class.getDeclaredConstructor(new Class[]{IPayment.class}); + + InjectionPoint point =InjectionPointFactory.getConstructorInjectionPointData(bean, constructor).get(0); + + WebBeansUtil.checkInjectionPointNamedQualifier(point); + + String value = qulifier(point); + + Assert.assertEquals("value", value); + + } + + @Test(expected=WebBeansConfigurationException.class) + public void testOtherWithoutNamedValue() throws Exception + { + Bean bean = defineSimpleWebBean(NamedOtherWithoutNamedValue.class); + Constructor constructor = NamedOtherWithoutNamedValue.class.getDeclaredConstructor(new Class[]{IPayment.class}); + + InjectionPoint point =InjectionPointFactory.getConstructorInjectionPointData(bean, constructor).get(0); + + String value = qulifier(point); + + Assert.assertEquals("", value); + + WebBeansUtil.checkInjectionPointNamedQualifier(point); + + } + + + private String qulifier(InjectionPoint injectionPoint) + { + Set qualifierset = injectionPoint.getQualifiers(); + Named namedQualifier = null; + for(Annotation qualifier : qualifierset) + { + if(qualifier.annotationType().equals(Named.class)) + { + namedQualifier = (Named)qualifier; + break; + } + } + + if(namedQualifier != null) + { + return namedQualifier.value(); + } + + return null; + } +} Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/named/NamedTests.java ------------------------------------------------------------------------------ svn:eol-style = native