openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r964703 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/inject/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/portable/javaee/
Date Fri, 16 Jul 2010 07:46:49 GMT
Author: gerdogdu
Date: Fri Jul 16 07:46:48 2010
New Revision: 964703

URL: http://svn.apache.org/viewvc?rev=964703&view=rev
Log:
Simplify the Java EE instance injection points injections.

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/JavaEeInjectionTest.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/MockInstance.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/SampleBean.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java?rev=964703&r1=964702&r2=964703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
Fri Jul 16 07:46:48 2010
@@ -29,7 +29,6 @@ import javax.enterprise.inject.Default;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
 import javax.inject.Inject;
 
 import org.apache.webbeans.component.InjectionPointBean;
@@ -42,6 +41,7 @@ import org.apache.webbeans.util.Annotati
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.SecurityUtil;
+import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
 /**
@@ -106,8 +106,7 @@ public final class OWBInjector implement
             }
 
             Class<Object> injectableComponentClass = (Class<Object>)javaEeComponentInstance.getClass();
-            InjectionTarget<Object> injectionTarget = null;
-            
+
             //Look for custom InjectionTarget
             InjectionTargetWrapper<Object> wrapper = beanManager.getInjectionTargetWrapper(injectableComponentClass);
             if(wrapper != null)
@@ -117,8 +116,7 @@ public final class OWBInjector implement
             }
             
             AnnotatedType<Object> annotated = (AnnotatedType<Object>) beanManager.createAnnotatedType(injectableComponentClass);
-            injectionTarget = beanManager.createInjectionTarget(annotated);
-            Set<InjectionPoint> injectionPoints = injectionTarget.getInjectionPoints();
+            Set<InjectionPoint> injectionPoints = WebBeansAnnotatedTypeUtil.getJavaEeComponentInstanceInjectionPoints(annotated);
             if(injectionPoints != null && injectionPoints.size() > 0)
             {
                 for(InjectionPoint injectionPoint : injectionPoints)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java?rev=964703&r1=964702&r2=964703&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
Fri Jul 16 07:46:48 2010
@@ -27,6 +27,7 @@ import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -768,6 +769,7 @@ public final class WebBeansAnnotatedType
         }
     }
     
+    @SuppressWarnings("unchecked")
     public static <T> ManagedBean<T> defineAbstractDecorator(AnnotatedType<T>
type)
     {
         
@@ -777,6 +779,48 @@ public final class WebBeansAnnotatedType
         return bean;
     }
     
+    /**
+     * Gets injection points for the given javaee component annotated type.
+     * @param <T> component class type
+     * @param type annotated type for the class
+     * @return injection points of the java ee component class
+     * @throws IllegalArgumentException if any exception occurs
+     */
+    public static <T> Set<InjectionPoint> getJavaEeComponentInstanceInjectionPoints(AnnotatedType<T>
type) throws IllegalArgumentException
+    {
+        try
+        {
+            if(type == null)
+            {
+                return Collections.emptySet();
+            }
+            else
+            {
+                //Class of the component
+                Class<T> clazz = type.getJavaClass();
+                
+                //Just creating temporary for getting injected fields
+                ManagedBean<T> managedBean = new ManagedBean<T>(clazz,WebBeansType.MANAGED);
   
+                managedBean.setAnnotatedType(type);
+                            
+                AnnotatedTypeBeanCreatorImpl<T> managedBeanCreator = new AnnotatedTypeBeanCreatorImpl<T>(managedBean);
           
+                managedBeanCreator.setAnnotatedType(type);
+                
+                //Just define injections
+                managedBeanCreator.defineInjectedFields();
+                managedBeanCreator.defineInjectedMethods();
+                
+                return managedBean.getInjectionPoints();
+                
+            }            
+        }catch(Exception e)
+        {
+            String message = "Error is occured while getting injection points for the Java
EE component instance class, " + type.getJavaClass(); 
+            logger.error(message,e);
+            throw new IllegalArgumentException(message, e);
+        }
+    }
+    
     public static <T> ManagedBean<T>  defineManagedBean(AnnotatedType<T>
type)
     {
         Class<T> clazz = type.getJavaClass();

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/JavaEeInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/JavaEeInjectionTest.java?rev=964703&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/JavaEeInjectionTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/JavaEeInjectionTest.java
Fri Jul 16 07:46:48 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.javaee;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.apache.webbeans.inject.OWBInjector;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Test;
+
+public class JavaEeInjectionTest extends AbstractUnitTest
+{
+    @Test
+    public void testInjectionTarget() throws Exception
+    {
+        Collection<Class<?>> classes = new ArrayList<Class<?>>();
+        classes.add(SampleBean.class);
+        startContainer(classes);
+        
+        MockInstance instance = new MockInstance();
+        OWBInjector injector = new OWBInjector();
+        injector.inject(instance);
+        
+        Assert.assertNotNull(instance.getBeanManager());
+        Assert.assertNotNull(instance.getSample());
+        Assert.assertNotNull(instance.getViaMethod());
+        
+        injector.destroy();
+        
+        shutDownContainer();
+        
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/JavaEeInjectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/MockInstance.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/MockInstance.java?rev=964703&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/MockInstance.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/MockInstance.java
Fri Jul 16 07:46:48 2010
@@ -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.newtests.portable.javaee;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+public class MockInstance
+{
+    private @Inject SampleBean sample;
+    
+    private SampleBean viaMethod;
+    
+    private @Inject BeanManager beanManager;
+    
+    @Inject
+    public void init(SampleBean sample)
+    {
+        this.viaMethod = sample;
+    }
+
+    public SampleBean getSample()
+    {
+        return sample;
+    }
+
+    public void setSample(SampleBean sample)
+    {
+        this.sample = sample;
+    }
+
+    public SampleBean getViaMethod()
+    {
+        return viaMethod;
+    }
+
+    public void setViaMethod(SampleBean viaMethod)
+    {
+        this.viaMethod = viaMethod;
+    }
+
+    public BeanManager getBeanManager()
+    {
+        return beanManager;
+    }
+
+    public void setBeanManager(BeanManager beanManager)
+    {
+        this.beanManager = beanManager;
+    }
+    
+    
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/MockInstance.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/SampleBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/SampleBean.java?rev=964703&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/SampleBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/SampleBean.java
Fri Jul 16 07:46:48 2010
@@ -0,0 +1,24 @@
+/*
+ * 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.javaee;
+
+public class SampleBean
+{
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/javaee/SampleBean.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message