openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelap...@apache.org
Subject svn commit: r1244337 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/event/ main/java/org/apache/webbeans/inject/ test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ ...
Date Wed, 15 Feb 2012 03:58:27 GMT
Author: kelapure
Date: Wed Feb 15 03:58:26 2012
New Revision: 1244337

URL: http://svn.apache.org/viewvc?rev=1244337&view=rev
Log:
OWB-645  InjectionPoint is null when using @Produces.

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/DataTransformer.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MyContainer.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyEncryptor.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolder.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolderFactory.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyInjector.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/DependentProducerMethodMultipleInjectionPointTest.java
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/injectionpoint/
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/injectionpoint/tests/
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/injectionpoint/tests/PlaceHolder.properties
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java?rev=1244337&r1=1244336&r2=1244337&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
Wed Feb 15 03:58:26 2012
@@ -18,27 +18,58 @@
  */
 package org.apache.webbeans.component;
 
+import java.util.Stack;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.annotation.DependentScopeLiteral;
 import org.apache.webbeans.config.WebBeansContext;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.InjectionPoint;
+import org.apache.webbeans.logger.WebBeansLogger;
 
 
 public class InjectionPointBean extends AbstractOwbBean<InjectionPoint>
 {
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(InjectionPointBean.class);
+    
     //X TODO refactor. public static variables are utterly ugly
-    public static ThreadLocal<InjectionPoint> local = new ThreadLocal<InjectionPoint>();
+    private static ThreadLocal<Stack<InjectionPoint>> localThreadlocalStack =
new ThreadLocal<Stack<InjectionPoint>>();
 
+    private static Stack<InjectionPoint> getStackOfInjectionPoints()
+    {
+        Stack<InjectionPoint> stackIP = localThreadlocalStack.get();
+        if (null == stackIP)
+        {
+            stackIP = new Stack<InjectionPoint>();
+        }
+        return stackIP;
+    }
+
+    public static boolean setThreadLocal(InjectionPoint ip)
+    {
+        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
+        stackIP.push(ip);
+        localThreadlocalStack.set(stackIP);
+        logger.debug("PUSHED IP on stack {0}", stackIP);
+        return true;
+    }
+    
+    public static void unsetThreadLocal()
+    {
+        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
+        InjectionPoint ip = stackIP.pop();
+        logger.debug("POPPED IP on stack {0}", ip);
+    }
+    
     /**
      * Removes the ThreadLocal from the ThreadMap to prevent memory leaks.
      */
     public static void removeThreadLocal()
     {
-        local.remove();
+        logger.debug(" local.remove() ");
+        getStackOfInjectionPoints().clear();
+        localThreadlocalStack.remove();
     }
-
+    
     public InjectionPointBean(WebBeansContext webBeansContext)
     {
         super(WebBeansType.INJECTIONPOINT,InjectionPoint.class, webBeansContext);
@@ -52,22 +83,16 @@ public class InjectionPointBean extends 
     @Override
     protected InjectionPoint createInstance(CreationalContext<InjectionPoint> creationalContext)
     {
-        try
-        {
-            return local.get();
-            
-        }
-        finally
-        {
-            local.set(null);
-            local.remove();
-        }
+        logger.debug("ENTRY createInstance {0}", creationalContext);
+        InjectionPoint ip = getStackOfInjectionPoints().peek();
+        logger.debug("RETURN {0}", ip);
+        return ip;
     }
 
     @Override
     protected void destroyInstance(InjectionPoint instance, CreationalContext<InjectionPoint>
creationalContext)
     {
-        local.remove();
+        removeThreadLocal();
     }
     
     /* (non-Javadoc)
@@ -79,5 +104,4 @@ public class InjectionPointBean extends 
         return true;
     }
     
-    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1244337&r1=1244336&r2=1244337&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Wed Feb 15 03:58:26 2012
@@ -374,6 +374,8 @@ public class ObserverMethodImpl<T> imple
 
                 if (!observesAnnotation)
                 {
+                    boolean injectionPointBeanLocalSetOnStack = false;
+                    
                     //Get parameter annotations
                     Annotation[] bindingTypes = annotationManager.getQualifierAnnotations(annot);
                     
@@ -391,13 +393,17 @@ public class ObserverMethodImpl<T> imple
                     {
                         if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
                         {
-                            InjectionPointBean.local.set(point);   
+                            injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point);
                         }
                     }                           
                     
                     CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                     Object instance = manager.getInstance(injectedBean, creational); 
-                    
+                    if (injectionPointBeanLocalSetOnStack)
+                    {
+                        InjectionPointBean.unsetThreadLocal();
+                    }
+
                     param = new ObserverParams();
                     param.isBean = true;
                     param.creational = creational;
@@ -436,6 +442,8 @@ public class ObserverMethodImpl<T> imple
             }
             else
             {
+                boolean injectionPointBeanLocalSetOnStack = false;
+                
                 //Get parameter annotations
                 Annotation[] bindingTypes =
                     annotationManager.getQualifierAnnotations(AnnotationUtil.
@@ -453,12 +461,17 @@ public class ObserverMethodImpl<T> imple
                 {
                     if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
                     {
-                        InjectionPointBean.local.set(point);   
+                        injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point);
                     }
                 }                    
                 
                 CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                 Object instance = manager.getInstance(injectedBean, creational); 
+                
+                if (injectionPointBeanLocalSetOnStack)
+                {
+                    InjectionPointBean.unsetThreadLocal();
+                }
                                     
                 param = new ObserverParams();
                 param.isBean = true;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1244337&r1=1244336&r2=1244337&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
Wed Feb 15 03:58:26 2012
@@ -108,49 +108,60 @@ public abstract class AbstractInjectable
             EventBean.local.set(injectionPoint);
         }        
         
-        //Injection for dependent instance InjectionPoint fields
-        boolean dependentProducer = false;
-        if(WebBeansUtil.isDependent(injectedBean))
+        boolean injectionPointBeanLocalSetOnStack = false;
+        try 
         {
-            if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
+            //Injection for dependent instance InjectionPoint fields
+            boolean dependentProducer = false;
+            if(WebBeansUtil.isDependent(injectedBean))
             {
-                InjectionPointBean.local.set(injectionPoint);   
-            }
-            
-            if(!injectionPoint.isTransient())
-            {
-                if(injectedBean instanceof AbstractProducerBean)
+                if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
+                {
+                    injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(injectionPoint);
+                }
+
+                if(!injectionPoint.isTransient())
                 {
-                    if(injectionOwnerBean.isPassivationCapable())
+                    if(injectedBean instanceof AbstractProducerBean)
                     {
-                        dependentProducer = true;   
+                        if(injectionOwnerBean.isPassivationCapable())
+                        {
+                            dependentProducer = true;   
+                        }
                     }
                 }
-            }
-        }        
-        
-        //Gets injectable reference for injected bean
-        injected = beanManager.getInjectableReference(injectionPoint, injectionOwnerCreationalContext);
+            }        
 
-        /*X TODO see spec issue CDI-140 */
-        if(dependentProducer)
-        {
-            if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
+            //Gets injectable reference for injected bean
+            injected = beanManager.getInjectableReference(injectionPoint, injectionOwnerCreationalContext);
+
+            /*X TODO see spec issue CDI-140 */
+            if(dependentProducer)
             {
-                throw new IllegalProductException("If a producer method or field of scope
@Dependent returns an serializable object for injection " +
-                                                  "into an injection point "+ injectionPoint
+" that requires a passivation capable dependency");
+                if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
+                {
+                    throw new IllegalProductException("If a producer method or field of scope
@Dependent returns an serializable object for injection " +
+                                                    "into an injection point "+ injectionPoint
+" that requires a passivation capable dependency");
+                }
             }
-        }
 
-        
-        // add this dependent into bean dependent list
-        if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
+            // add this dependent into bean dependent list
+            if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
+            {
+                if(instanceUnderInjection.get() != null)
+                {
+                    ((CreationalContextImpl<?>) injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean,
injected);
+                }
+            }
+        } 
+        finally
         {
-            if(instanceUnderInjection.get() != null)
+            if (injectionPointBeanLocalSetOnStack)
             {
-                ((CreationalContextImpl<?>) injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean,
injected);
+                InjectionPointBean.unsetThreadLocal();
             }
         }
+        
 
         return injected;
     }

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=1244337&r1=1244336&r2=1244337&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
Wed Feb 15 03:58:26 2012
@@ -222,6 +222,7 @@ public final class OWBInjector implement
     private Object getInjectedObjectReference(InjectionPoint injectionPoint, BeanManagerImpl
beanManager)
     {
         Object object = null;
+        boolean injectionPointBeanLocalSetOnStack = false;
         
         //Injected contextual beam
         InjectionResolver injectionResolver = beanManager.getInjectionResolver();
@@ -242,11 +243,15 @@ public final class OWBInjector implement
         {
             if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
             {
-                InjectionPointBean.local.set(injectionPoint);   
+                injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(injectionPoint);
             }
         }
         
         object = beanManager.getInjectableReference(injectionPoint, ownerCreationalContext);
+        if (injectionPointBeanLocalSetOnStack )
+        {
+            InjectionPointBean.unsetThreadLocal();
+        }
         
         return object;
     }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/DataTransformer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/DataTransformer.java?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/DataTransformer.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/DataTransformer.java
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * Licensed 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.injection.injectionpoint.beans;
+
+import java.util.Iterator;
+import java.util.List;
+
+public class DataTransformer {
+
+    public String concatStrings(List<String> stringList) {
+
+        StringBuilder stringBuilder = new StringBuilder();
+        if (stringList != null && !stringList.isEmpty()) {
+            String string;
+            for (Iterator iterator = stringList.iterator(); iterator.hasNext(); stringBuilder.append(string))
{
+                string = (String) iterator.next();
+            }
+
+        }
+        return stringBuilder.toString();
+
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MyContainer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MyContainer.java?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MyContainer.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MyContainer.java
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,14 @@
+package org.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import javax.inject.Inject;
+
+public class MyContainer {
+
+    @Inject
+    @PropertyHolder
+    private String nestedProperty;
+
+    public String getNestedProperty() {
+        return nestedProperty;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyEncryptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyEncryptor.java?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyEncryptor.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyEncryptor.java
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * Licensed 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.injection.injectionpoint.beans;
+
+public class PropertyEncryptor {
+
+    public String decryptProperty(String decryptPropertyValue) {
+        return decryptPropertyValue;
+    }
+    
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolder.java?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolder.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolder.java
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,20 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import javax.enterprise.util.Nonbinding;
+import javax.inject.Qualifier;
+
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
+public @interface PropertyHolder {
+    
+    @Nonbinding public String value() default "";
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolderFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolderFactory.java?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolderFactory.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyHolderFactory.java
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,157 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+import org.apache.webbeans.config.PropertyLoader;
+import org.apache.webbeans.logger.WebBeansLogger;
+
+/**
+ * Factory class for PropertyHolder Annotation. 
+ * Defines @Produces methods for PropertyHolder.
+ */
+public class PropertyHolderFactory {
+
+    private static final WebBeansLogger logger = WebBeansLogger.getLogger(PropertyHolderFactory.class);
+    
+    //Properties
+    private static final String PROPERTY_FILE = 
+            "org/apache/webbeans/newtests/injection/injectionpoint/tests/PlaceHolder.properties";
+    private volatile static Properties placeHolderProperties;
+    
+    //Inject classes PropertyHolderFactory depends upon.
+    @Inject
+    private DataTransformer dataTransformer;
+    
+    @Inject
+    private PropertyEncryptor propertyEncryptor;
+
+    /**
+     * Defines retrieval of Properties from placeHolder.properties file in class
+     * path.
+     *
+     * @return Properties
+     */
+    public synchronized static Properties getProperties() {
+
+        if (placeHolderProperties == null) {
+            placeHolderProperties = PropertyLoader.getProperties(PROPERTY_FILE);
+            logger.info("loaded "+placeHolderProperties);
+        }
+        return placeHolderProperties;
+    }
+
+    /**
+     * Defines PropertyHolder value fetch, Producer method.
+     *
+     * @param injectionPoint
+     * @return String
+     */
+    @Produces
+    @PropertyHolder
+    public String getPlaceHolderValue(InjectionPoint injectionPoint) {
+
+        logger.info("getPlaceHolderValue {0}", injectionPoint);
+
+        //Get value attribute of the PlaceHolder Annotation
+        String keyName = injectionPoint.getAnnotated().getAnnotation(PropertyHolder.class).value();
+
+        //If PlaceHolder value annotation is not specified, Use field name as Key to Properties.
+        if (isBlank(keyName)) {
+            keyName = injectionPoint.getMember().getName();
+        }
+
+        //Consturct list for appending
+        List<String> stringList = new ArrayList<String>();
+        stringList.add(injectionPoint.getMember().getDeclaringClass().getName());
+        stringList.add(".");
+        stringList.add(keyName);
+
+        //Constuct KeyName string.
+        keyName = dataTransformer.concatStrings(stringList);
+        logger.info("Fetching value for key: " + keyName);
+
+        //Check System Property, if its not available check in Properties file.
+        String keyValue = System.getProperty(keyName);
+        if (isBlank(keyValue)) {
+            Properties properties = PropertyHolderFactory.getProperties();
+            keyValue = properties.getProperty(keyName);
+        }
+
+        //Check for Encrypted property value
+        keyValue = this.decryptProperty(keyValue);
+
+        logger.info("Produced property : Key->{" + keyName + "}, Value->{" + keyValue
+ "}");
+
+        
+        return keyValue;
+    }//End Method.
+
+    /**
+     * Checks if given property value is encrypted. If encrypted, returns the
+     * decrypted value.
+     *
+     * @param propertyValue
+     * @return String
+     */
+    private String decryptProperty(String propertyValue) {
+        logger.info("Checking if decrypting of value is needed for " + propertyValue);
+
+        if (!isEmpty(propertyValue)
+                && propertyValue.matches("ENC(\\S+)")) {
+
+            String decryptPropertyValue = substringBetween(propertyValue, "ENC(", ")");
+            propertyValue = propertyEncryptor.decryptProperty(decryptPropertyValue);
+        }
+
+        return propertyValue;
+    }
+
+    public static boolean isBlank(String str) {
+        int strLen;
+        if (str == null || (strLen = str.length()) == 0) {
+            return true;
+        }
+        for (int i = 0; i < strLen; i++) {
+            if ((Character.isWhitespace(str.charAt(i)) == false)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean isEmpty(String str) {
+        return str == null || str.length() == 0;
+    }
+
+    /**
+     * Sets DataTransformer instance.
+     *
+     * @param dataTransformer
+     */
+    public void setDataTransformer(DataTransformer dataTransformer) {
+        this.dataTransformer = dataTransformer;
+    }
+    public static final int INDEX_NOT_FOUND = -1;
+
+    public static String substringBetween(String str, String open, String close) {
+        if (str == null || open == null || close == null) {
+            return null;
+        }
+        int start = str.indexOf(open);
+        if (start != INDEX_NOT_FOUND) {
+            int end = str.indexOf(close, start + open.length());
+            if (end != INDEX_NOT_FOUND) {
+                return str.substring(start + open.length(), end);
+            }
+        }
+        return null;
+    }
+}
\ No newline at end of file

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyInjector.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyInjector.java?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyInjector.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/PropertyInjector.java
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * Licensed 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.injection.injectionpoint.beans;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@Named("org.apache.webbeans.newtests.injection.injectionpoint.beans.PropertyInjector")
+public class PropertyInjector {
+
+    @Inject
+    private DataTransformer dataTransformer;
+    
+    @Inject
+    @PropertyHolder
+    private String anotherVarName;
+    
+    @Inject
+    @PropertyHolder
+    private String ldapHost;
+    
+    @Inject
+    private MyContainer nested;
+    
+    public String getAnotherVarName() {
+        return anotherVarName;
+    }
+
+    public DataTransformer getDataTransformer() {
+        return dataTransformer;
+    }
+
+
+    public String getLdapHost() {
+        return ldapHost;
+    }
+
+
+    public MyContainer getNested() {
+        return nested;
+    }
+}
\ No newline at end of file

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/DependentProducerMethodMultipleInjectionPointTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/DependentProducerMethodMultipleInjectionPointTest.java?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/DependentProducerMethodMultipleInjectionPointTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/DependentProducerMethodMultipleInjectionPointTest.java
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,47 @@
+package org.apache.webbeans.newtests.injection.injectionpoint.tests;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import junit.framework.Assert;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.injection.injectionpoint.beans.*;
+import org.junit.Test;
+
+public class DependentProducerMethodMultipleInjectionPointTest extends AbstractUnitTest {
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testInjectionPointValidity() throws Exception {
+        
+        Collection<String> beanXmls = new ArrayList<String>();
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(DataTransformer.class);
+        beanClasses.add(PropertyEncryptor.class);
+        beanClasses.add(MyContainer.class);
+        beanClasses.add(PropertyHolder.class);
+        beanClasses.add(PropertyHolderFactory.class);
+        beanClasses.add(PropertyInjector.class);
+        
+        startContainer(beanClasses, beanXmls);  
+
+        Bean<PropertyInjector> bean = (Bean<PropertyInjector>) getBeanManager().getBeans(PropertyInjector.class.getName()).iterator().next();
+        CreationalContext<PropertyInjector> cc = getBeanManager().createCreationalContext(bean);
+        PropertyInjector propertyInjector = (PropertyInjector) getBeanManager().getReference(bean,
PropertyInjector.class, cc);
+
+        Assert.assertNotNull(propertyInjector.getDataTransformer());
+        
+        Assert.assertNotNull(propertyInjector.getAnotherVarName());
+        Assert.assertTrue(propertyInjector.getAnotherVarName().equals("Injection is working...Finally"));
+        
+        Assert.assertNotNull(propertyInjector.getLdapHost());
+        Assert.assertTrue(propertyInjector.getLdapHost().equals("Rohit Kelapure LDAP Host"));
+        
+        Assert.assertNotNull(propertyInjector.getNested().getNestedProperty());
+        Assert.assertTrue(propertyInjector.getNested().getNestedProperty().trim().equals("Rohit
Kelapure Nested Property"));
+        
+        shutDownContainer();
+        
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/injectionpoint/tests/PlaceHolder.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/injectionpoint/tests/PlaceHolder.properties?rev=1244337&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/injectionpoint/tests/PlaceHolder.properties
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/injection/injectionpoint/tests/PlaceHolder.properties
Wed Feb 15 03:58:26 2012
@@ -0,0 +1,17 @@
+# Copyright 2012 The Apache Software Foundation.
+#
+# Licensed 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.
+
+org.apache.webbeans.newtests.injection.injectionpoint.beans.PropertyInjector.anotherVarName
= Injection is working...Finally
+org.apache.webbeans.newtests.injection.injectionpoint.beans.PropertyInjector.ldapHost = Rohit
Kelapure LDAP Host
+org.apache.webbeans.newtests.injection.injectionpoint.beans.MyContainer.nestedProperty =
Rohit Kelapure Nested Property                            



Mime
View raw message