You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/03/30 22:13:00 UTC
svn commit: r929248 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/component/creation/
test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/
Author: gerdogdu
Date: Tue Mar 30 20:13:00 2010
New Revision: 929248
URL: http://svn.apache.org/viewvc?rev=929248&view=rev
Log:
[OWB-340] BeanManagerImpl.createInjectionTarget() Throws Exception When No Constructor Found
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTarget.java (with props)
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTargetNoConstructorTest.java (with props)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AnnotatedTypeBeanCreatorImpl.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AnnotatedTypeBeanCreatorImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AnnotatedTypeBeanCreatorImpl.java?rev=929248&r1=929247&r2=929248&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AnnotatedTypeBeanCreatorImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AnnotatedTypeBeanCreatorImpl.java Tue Mar 30 20:13:00 2010
@@ -18,14 +18,44 @@
*/
package org.apache.webbeans.component.creation;
+import java.lang.reflect.Constructor;
+
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+
import org.apache.webbeans.component.ManagedBean;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
public class AnnotatedTypeBeanCreatorImpl<T> extends ManagedBeanCreatorImpl<T>
{
+ private static final WebBeansLogger logger = WebBeansLogger.getLogger(AnnotatedTypeBeanCreatorImpl.class);
public AnnotatedTypeBeanCreatorImpl(ManagedBean<T> managedBean)
{
super(managedBean);
setMetaDataProvider(MetaDataProvider.THIRDPARTY);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void defineConstructor()
+ {
+ Constructor<T> constructor = null;
+ try
+ {
+ AnnotatedConstructor<T> annotated = WebBeansAnnotatedTypeUtil.getBeanConstructor(getAnnotatedType());
+ constructor = annotated.getJavaMember();
+ WebBeansAnnotatedTypeUtil.addConstructorInjectionPointMetaData(getBean(), annotated);
+
+ getBean().setConstructor(constructor);
+
+ }catch(Exception e)
+ {
+ logger.warn("No suitable constructor found for injection target class : " + getAnnotatedType().getJavaClass()+" ." +
+ "produce() method does not work!");
+ }
+ }
+
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTarget.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTarget.java?rev=929248&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTarget.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTarget.java Tue Mar 30 20:13:00 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.portable.injectiontarget.customtarget;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+public class CustomTarget
+{
+ private @Inject BeanManager beanManager;
+
+ public CustomTarget(String noConstr)
+ {
+
+ }
+
+ public BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTarget.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTargetNoConstructorTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTargetNoConstructorTest.java?rev=929248&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTargetNoConstructorTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTargetNoConstructorTest.java Tue Mar 30 20:13:00 2010
@@ -0,0 +1,93 @@
+/*
+ * 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.portable.injectiontarget.customtarget;
+
+import java.util.Collections;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CustomTargetNoConstructorTest extends AbstractUnitTest
+{
+ @Test
+ public void testInjectionTargetWithNoConstructor()
+ {
+ Exception ex = null;
+ try
+ {
+ startContainer(Collections.<Class<?>> emptyList());
+ final BeanManagerImpl manager = BeanManagerImpl.getManager();
+ AnnotatedType<CustomTarget> annotatedType = manager.createAnnotatedType(CustomTarget.class);
+ InjectionTarget<CustomTarget> injectionTarget = manager.createInjectionTarget(annotatedType);
+ CreationalContext<CustomTarget> context = manager.createCreationalContext(null);
+ try
+ {
+ injectionTarget.produce(context);
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ }
+ }
+ finally
+ {
+ shutDownContainer();
+ }
+
+ Assert.assertNotNull(ex);
+ }
+
+ @Test
+ public void testInjecDependenciesTargetWithNoConstructor()
+ {
+ Exception ex = null;
+ final BeanManagerImpl manager;
+ CreationalContext<CustomTarget> context =null;
+ CustomTarget instance = null;
+ try
+ {
+ startContainer(Collections.<Class<?>> emptyList());
+ manager = BeanManagerImpl.getManager();
+ context = manager.createCreationalContext(null);
+ AnnotatedType<CustomTarget> annotatedType = manager.createAnnotatedType(CustomTarget.class);
+ InjectionTarget<CustomTarget> injectionTarget = manager.createInjectionTarget(annotatedType);
+ try
+ {
+ instance = new CustomTarget("Hiho");
+ injectionTarget.inject(instance, context);
+
+ Assert.assertNotNull(instance.getBeanManager());
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ }
+ }
+ finally
+ {
+ context.release();
+ shutDownContainer();
+ }
+
+ Assert.assertNull(ex);
+ }
+
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/injectiontarget/customtarget/CustomTargetNoConstructorTest.java
------------------------------------------------------------------------------
svn:eol-style = native