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=1434919&r1=1434918&r2=1434919&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 Thu Jan 17 21:20:09 2013 @@ -59,6 +59,8 @@ import org.apache.webbeans.exception.Web import org.apache.webbeans.inject.impl.InjectionPointFactory; import org.apache.webbeans.logger.WebBeansLoggerFacade; import org.apache.webbeans.portable.AnnotatedElementFactory; +import org.apache.webbeans.portable.EventProducer; +import org.apache.webbeans.portable.InjectionPointProducer; import org.apache.webbeans.util.AnnotationUtil; import org.apache.webbeans.util.ClassUtil; import org.apache.webbeans.util.WebBeansUtil; @@ -395,20 +397,20 @@ public class ObserverMethodImpl<T> imple { if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType()))) { - injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point); + injectionPointBeanLocalSetOnStack = InjectionPointProducer.setThreadLocal(point); } } if (isEventProviderInjection(point)) { - EventBean.local.set(point); + EventProducer.local.set(point); } CreationalContext<Object> creational = manager.createCreationalContext(injectedBean); Object instance = manager.getReference(injectedBean, null, creational); if (injectionPointBeanLocalSetOnStack) { - InjectionPointBean.unsetThreadLocal(); + InjectionPointProducer.unsetThreadLocal(); } param = new ObserverParams(); @@ -468,13 +470,13 @@ public class ObserverMethodImpl<T> imple { if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType()))) { - injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point); + injectionPointBeanLocalSetOnStack = InjectionPointProducer.setThreadLocal(point); } } if (isEventProviderInjection(point)) { - EventBean.local.set(point); + EventProducer.local.set(point); } CreationalContext<Object> creational = manager.createCreationalContext(injectedBean); @@ -482,7 +484,7 @@ public class ObserverMethodImpl<T> imple if (injectionPointBeanLocalSetOnStack) { - InjectionPointBean.unsetThreadLocal(); + InjectionPointProducer.unsetThreadLocal(); } param = new ObserverParams();
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=1434919&r1=1434918&r2=1434919&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 Thu Jan 17 21:20:09 2013 @@ -42,6 +42,9 @@ import org.apache.webbeans.config.WebBea import org.apache.webbeans.container.BeanManagerImpl; import org.apache.webbeans.container.InjectionResolver; import org.apache.webbeans.context.creational.CreationalContextImpl; +import org.apache.webbeans.portable.EventProducer; +import org.apache.webbeans.portable.InjectionPointProducer; +import org.apache.webbeans.portable.InstanceProducer; import org.apache.webbeans.util.ClassUtil; import org.apache.webbeans.util.WebBeansUtil; @@ -90,12 +93,12 @@ public abstract class AbstractInjectable Bean<?> injectedBean = instance.getInjectionPointBean(injectionPoint); if(isInstanceProviderInjection(injectionPoint)) { - InstanceBean.local.set(injectionPoint); + InstanceProducer.local.set(injectionPoint); } else if(isEventProviderInjection(injectionPoint)) { - EventBean.local.set(injectionPoint); + EventProducer.local.set(injectionPoint); } boolean injectionPointBeanLocalSetOnStack = false; @@ -107,7 +110,7 @@ public abstract class AbstractInjectable { if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType()))) { - injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(injectionPoint); + injectionPointBeanLocalSetOnStack = InjectionPointProducer.setThreadLocal(injectionPoint); } if(!injectionPoint.isTransient()) @@ -148,7 +151,7 @@ public abstract class AbstractInjectable { if (injectionPointBeanLocalSetOnStack) { - InjectionPointBean.unsetThreadLocal(); + InjectionPointProducer.unsetThreadLocal(); } } Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java Thu Jan 17 21:20:09 2013 @@ -39,6 +39,7 @@ import org.apache.webbeans.config.WebBea import org.apache.webbeans.container.BeanManagerImpl; import org.apache.webbeans.container.InjectionResolver; import org.apache.webbeans.context.creational.CreationalContextImpl; +import org.apache.webbeans.portable.InjectionPointProducer; import org.apache.webbeans.util.ClassUtil; import org.apache.webbeans.util.InjectionExceptionUtil; import org.apache.webbeans.util.OwbCustomObjectInputStream; @@ -49,7 +50,7 @@ import org.apache.webbeans.util.WebBeans * * @param <T> specific instance type */ -class InstanceImpl<T> implements Instance<T>, Serializable +public class InstanceImpl<T> implements Instance<T>, Serializable { private static final long serialVersionUID = -8401944412490389024L; @@ -80,7 +81,7 @@ class InstanceImpl<T> implements Instanc * @param ownerInstance the object the current Instance got injected into * @param annotations qualifier annotations */ - InstanceImpl(Type injectionClazz, InjectionPoint injectionPoint, WebBeansContext webBeansContext, + public InstanceImpl(Type injectionClazz, InjectionPoint injectionPoint, WebBeansContext webBeansContext, CreationalContext<?> creationalContext, Object ownerInstance, Annotation... annotations) { this.injectionClazz = injectionClazz; @@ -105,7 +106,7 @@ class InstanceImpl<T> implements Instanc { T instance; - InjectionPointBean.setThreadLocal(injectionPoint); + InjectionPointProducer.setThreadLocal(injectionPoint); try { Annotation[] anns = new Annotation[qualifierAnnotations.size()]; @@ -142,7 +143,7 @@ class InstanceImpl<T> implements Instanc } finally { - InjectionPointBean.removeThreadLocal(); + InjectionPointProducer.removeThreadLocal(); } return instance; @@ -273,7 +274,7 @@ class InstanceImpl<T> implements Instanc { Set<Bean<?>> beans = resolveBeans(); Set<T> instances = new HashSet<T>(); - InjectionPointBean.setThreadLocal(injectionPoint); + InjectionPointProducer.setThreadLocal(injectionPoint); try { for(Bean<?> bean : beans) @@ -284,7 +285,7 @@ class InstanceImpl<T> implements Instanc } finally { - InjectionPointBean.removeThreadLocal(); + InjectionPointProducer.removeThreadLocal(); } return instances.iterator(); Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java Thu Jan 17 21:20:09 2013 @@ -76,7 +76,7 @@ public final class WebBeansInterceptorCo */ public void defineBeanInterceptorStack(InjectionTargetBean<?> bean) { - if (bean instanceof InterceptedMarker) + if (bean instanceof InterceptedMarker && bean.getInjectionTarget() instanceof InjectionTargetImpl) { InjectionTargetImpl<?> injectionTarget = (InjectionTargetImpl<?>) bean.getInjectionTarget(); BeanInterceptorInfo interceptorInfo = webBeansContext.getInterceptorResolutionService(). Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractProducer.java Thu Jan 17 21:20:09 2013 @@ -18,8 +18,10 @@ */ package org.apache.webbeans.portable; +import java.util.Collections; import java.util.Set; +import javax.enterprise.inject.Instance; import javax.enterprise.inject.spi.InjectionPoint; import javax.enterprise.inject.spi.Producer; @@ -28,6 +30,11 @@ public abstract class AbstractProducer<T private Set<InjectionPoint> injectionPoints; + public AbstractProducer() + { + this(Collections.<InjectionPoint>emptySet()); + } + public AbstractProducer(Set<InjectionPoint> points) { // this shares the InjectionPoints with the owning component for now @@ -39,4 +46,8 @@ public abstract class AbstractProducer<T { return injectionPoints; } + + @Override + public void dispose(T instance) { + } } Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java?rev=1434919&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/BeanManagerProducer.java Thu Jan 17 21:20:09 2013 @@ -0,0 +1,51 @@ +/* + * 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.portable; + +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.BeanManager; + +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.container.InjectableBeanManager; + +public class BeanManagerProducer extends AbstractProducer<BeanManager> { + + private WebBeansContext context; + private BeanManager manager; + + public BeanManagerProducer(WebBeansContext webBeansContext) + { + context = webBeansContext; + } + + @Override + public BeanManager produce(CreationalContext<BeanManager> creationalContext) { + if (manager == null) + { + manager = new InjectableBeanManager(context.getBeanManagerImpl()); + } + + return manager; + } + + @Override + public void dispose(BeanManager instance) { + manager = null; + } +} Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java?rev=1434919&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java Thu Jan 17 21:20:09 2013 @@ -0,0 +1,88 @@ +/* + * 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.portable; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.event.Event; +import javax.enterprise.inject.spi.InjectionPoint; + +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.event.EventImpl; +import org.apache.webbeans.exception.WebBeansException; + +public class EventProducer<T> extends AbstractProducer<Event<T>> { + + //X TODO refactor. public static variables are utterly ugly + public static ThreadLocal<InjectionPoint> local = new ThreadLocal<InjectionPoint>(); + private WebBeansContext webBeansContext; + + public EventProducer(WebBeansContext webBeansContext) + { + this.webBeansContext = webBeansContext; + } + + /** + * {@inheritDoc} + */ + @Override + public Event<T> produce(CreationalContext<Event<T>> creationalContext) { + Event<T> instance = null; + + InjectionPoint injectionPoint = local.get(); + Type eventType; + + if(injectionPoint != null) + { + Type[] eventActualTypeArgs; + Type type = injectionPoint.getType(); + ParameterizedType pt = (ParameterizedType) type; + eventActualTypeArgs = pt.getActualTypeArguments(); + + //First argument and sole argument is actual Event type + //Example : Event<MyEvent> + eventType = eventActualTypeArgs[0]; + + //Event qualifiers + Annotation[] qualifiers = new Annotation[injectionPoint.getQualifiers().size()]; + qualifiers = injectionPoint.getQualifiers().toArray(qualifiers); + + try + { + instance = new EventImpl<T>(qualifiers, eventType, injectionPoint, webBeansContext); + } + catch (Exception e) + { + throw new WebBeansException("Exception in creating Event implicit component for event type : " + + eventType); + } + finally + { + local.set(null); + local.remove(); + } + + } + + return instance; + } +} Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java?rev=1434919&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java Thu Jan 17 21:20:09 2013 @@ -0,0 +1,81 @@ +/* + * 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.portable; + +import java.util.Stack; + +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.InjectionPoint; + +public class InjectionPointProducer extends AbstractProducer<InjectionPoint> { + + //X TODO refactor. public static variables are utterly ugly + private static ThreadLocal<Stack<InjectionPoint>> localThreadlocalStack = new ThreadLocal<Stack<InjectionPoint>>(); + + /** + * {@inheritDoc} + */ + @Override + public InjectionPoint produce(CreationalContext<InjectionPoint> creationalContext) { + return getStackOfInjectionPoints().peek(); + } + + @Override + public void dispose(InjectionPoint ip) { + removeThreadLocal(); + } + + 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); + return true; + } + + public static void unsetThreadLocal() + { + Stack<InjectionPoint> stackIP = getStackOfInjectionPoints(); + stackIP.pop(); + } + + /** + * Removes the ThreadLocal from the ThreadMap to prevent memory leaks. + */ + public static void removeThreadLocal() + { + getStackOfInjectionPoints().clear(); + localThreadlocalStack.remove(); + } + + public static boolean isStackEmpty() + { + return getStackOfInjectionPoints().isEmpty(); + } +} Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java?rev=1434919&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java Thu Jan 17 21:20:09 2013 @@ -0,0 +1,88 @@ +/* + * 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.portable; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.Set; + +import javax.enterprise.context.Dependent; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.Instance; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.util.TypeLiteral; +import javax.inject.Provider; + +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.inject.AbstractInjectable; +import org.apache.webbeans.inject.instance.InstanceImpl; +import org.apache.webbeans.util.AnnotationUtil; +import org.apache.webbeans.util.CollectionUtil; + +public class InstanceProducer<T> extends AbstractProducer<Instance<T>> +{ + // TODO refactor. public static variables are uterly ugly + public static ThreadLocal<InjectionPoint> local = new ThreadLocal<InjectionPoint>(); + private Class<Instance<T>> returnType; + private Set<Annotation> qualifiers; + private WebBeansContext webBeansContext; + + public InstanceProducer(Class<Instance<T>> returnType, Set<Annotation> qualifiers, WebBeansContext webBeansContext) + { + this.returnType = returnType; + this.qualifiers = qualifiers; + this.webBeansContext = webBeansContext; + } + + @Override + public Instance<T> produce(CreationalContext<Instance<T>> creationalContext) + { + try + { + InjectionPoint injectionPoint = local.get(); + Set<Annotation> qualifiers; + Type type; + + if (injectionPoint != null) + { + ParameterizedType injectedType = (ParameterizedType)injectionPoint.getType(); + qualifiers = injectionPoint.getQualifiers(); + type = injectedType.getActualTypeArguments()[0]; + } + else + { + qualifiers = this.qualifiers; + type = this.returnType; + } + + Object ownerInstance = AbstractInjectable.instanceUnderInjection.get(); + + Instance<T> instance = new InstanceImpl<T>(type, injectionPoint, webBeansContext, creationalContext, ownerInstance, qualifiers.toArray(new Annotation[qualifiers.size()])); + + return instance; + } + finally + { + local.set(null); + local.remove(); + } + } +} Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java?rev=1434919&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerFieldProducer.java Thu Jan 17 21:20:09 2013 @@ -0,0 +1,117 @@ +/* + * 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.portable; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Set; + +import javax.enterprise.context.Dependent; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.AnnotatedField; +import javax.enterprise.inject.spi.AnnotatedMethod; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.InjectionPoint; + +import org.apache.webbeans.component.AbstractOwbBean; +import org.apache.webbeans.component.OwbBean; +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.context.creational.CreationalContextImpl; +import org.apache.webbeans.exception.WebBeansException; +import org.apache.webbeans.inject.InjectableMethod; +import org.apache.webbeans.util.WebBeansUtil; + +public class ProducerFieldProducer<T, P> extends AbstractProducer<T> { + + private Bean<P> owner; + private WebBeansContext webBeansContext; + private AnnotatedField<P> producerField; + + public ProducerFieldProducer(OwbBean<P> owner, AnnotatedField<P> producerField, Set<InjectionPoint> points) + { + super(points); + this.owner = owner; + this.webBeansContext = owner.getWebBeansContext(); + this.producerField = producerField; + } + + @Override + public T produce(CreationalContext<T> creationalContext) { + T instance = null; + P parentInstance = null; + CreationalContext<P> parentCreational = null; + try + { + parentCreational = webBeansContext.getBeanManagerImpl().createCreationalContext(owner); + + Field field = producerField.getJavaMember(); + if (!field.isAccessible()) + { + webBeansContext.getSecurityService().doPrivilegedSetAccessible(field, true); + } + + if (Modifier.isStatic(field.getModifiers())) + { + instance = (T) field.get(null); + } + else + { + parentInstance = getParentInstanceFromContext(parentCreational); + + instance = (T) field.get(parentInstance); + } + } + catch(Exception e) + { + throw new WebBeansException(e); + } + finally + { + if (owner.getScope().equals(Dependent.class)) + { + owner.destroy(parentInstance, parentCreational); + } + } + + return instance; + + } + + @SuppressWarnings("unchecked") + protected P getParentInstanceFromContext(CreationalContext<?> creationalContext) + { + P parentInstance; + + Bean<?> specialize = WebBeansUtil.getMostSpecializedBean(webBeansContext.getBeanManagerImpl(), (AbstractOwbBean<T>) owner); + + if (specialize != null) + { + parentInstance = (P) webBeansContext.getBeanManagerImpl().getContext(specialize.getScope()). + get((Bean<Object>)specialize,(CreationalContext<Object>) creationalContext); + } + else + { + parentInstance = (P) webBeansContext.getBeanManagerImpl().getContext( + owner.getScope()).get((Bean<Object>)owner, (CreationalContext<Object>) creationalContext); + } + + return parentInstance; + + } +} Added: 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=1434919&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java Thu Jan 17 21:20:09 2013 @@ -0,0 +1,111 @@ +/* + * 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.portable; + +import java.lang.reflect.Modifier; +import java.util.Map; +import java.util.Set; + +import javax.enterprise.context.Dependent; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.AnnotatedMethod; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.InjectionPoint; +import javax.enterprise.inject.spi.InjectionTarget; + +import org.apache.webbeans.component.OwbBean; +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.context.creational.CreationalContextImpl; +import org.apache.webbeans.inject.InjectableMethod; +import org.apache.webbeans.util.Asserts; + +public class ProducerMethodProducer<T, P> extends AbstractProducer<T> { + + private Bean<P> owner; + private WebBeansContext webBeansContext; + private AnnotatedMethod<P> producerMethod; + private AnnotatedMethod<P> disposalMethod; + + public ProducerMethodProducer(OwbBean<P> owner, AnnotatedMethod<P> producerMethod, AnnotatedMethod<P> disposerMethod, Set<InjectionPoint> points) + { + super(points); + Asserts.assertNotNull(producerMethod); + this.owner = owner; + this.webBeansContext = owner.getWebBeansContext(); + this.producerMethod = producerMethod; + this.disposalMethod = disposerMethod; + } + + public void setDisposalMethod(AnnotatedMethod<P> disposalMethod) + { + this.disposalMethod = disposalMethod; + } + + @Override + public T produce(CreationalContext<T> creationalContext) { + CreationalContextImpl<T> context = (CreationalContextImpl<T>)creationalContext; + P ownerInstance = (P)webBeansContext.getBeanManagerImpl().getReference(owner, owner.getBeanClass(), creationalContext); + return new InjectableMethod<T>(producerMethod.getJavaMember(), ownerInstance, this, context).doInjection(); + } + + @Override + public void dispose(T instance) { + if (disposalMethod != null) + { + P parentInstance = null; + CreationalContext<P> parentCreational = null; + InjectableMethod<T> m = null; + try + { + parentCreational = webBeansContext.getBeanManagerImpl().createCreationalContext(owner); + + if (!Modifier.isStatic(disposalMethod.getJavaMember().getModifiers())) + { + parentInstance = (P)webBeansContext.getBeanManagerImpl().getReference(owner, owner.getBeanClass(), parentCreational); + } + + m = new InjectableMethod<T>(disposalMethod.getJavaMember(), parentInstance, this, (CreationalContextImpl<T>) parentCreational); + m.setDisposable(true); + m.setProducerMethodInstance(instance); + + m.doInjection(); + + } + finally + { + if (owner.getScope().equals(Dependent.class)) + { + owner.destroy(parentInstance, parentCreational); + } + + //Destroy dependent parameters + Map<Bean<?>, Object> dependents = m.getDependentBeanParameters(); + if(dependents != null) + { + Set<Bean<?>> beans = dependents.keySet(); + for(Bean<?> bean : beans) + { + Bean<Object> beanTt = (Bean<Object>)bean; + beanTt.destroy(dependents.get(beanTt), (CreationalContext<Object>) parentCreational); + } + } + } + } + } +} Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProxyProducer.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProxyProducer.java?rev=1434919&view=auto ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProxyProducer.java (added) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProviderBasedProxyProducer.java Thu Jan 17 21:20:09 2013 @@ -0,0 +1,51 @@ +/* + * 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.portable; + +import javax.enterprise.context.spi.CreationalContext; +import javax.inject.Provider; + +import org.apache.webbeans.config.WebBeansContext; +import org.apache.webbeans.proxy.NormalScopeProxyFactory; + +public class ProviderBasedProxyProducer<T> extends AbstractProducer<T> { + + private WebBeansContext webBeansContext; + private Class<T> returnType; + private Provider<T> provider; + private T proxyInstance; + + public ProviderBasedProxyProducer(WebBeansContext webBeansContext, Class<T> returnType, Provider<T> provider) + { + this.webBeansContext = webBeansContext; + this.returnType = returnType; + this.provider = provider; + } + + @Override + public T produce(CreationalContext<T> creationalContext) { + if (proxyInstance == null) + { + NormalScopeProxyFactory proxyFactory = webBeansContext.getNormalScopeProxyFactory(); + Class<T> proxyClass = proxyFactory.createProxyClass(getClass().getClassLoader(), returnType); + proxyInstance = proxyFactory.createProxyInstance(proxyClass, provider); + } + return proxyInstance; + } +} Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original) +++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Thu Jan 17 21:20:09 2013 @@ -125,7 +125,8 @@ import org.apache.webbeans.intercept.Int import org.apache.webbeans.logger.WebBeansLoggerFacade; import org.apache.webbeans.plugins.OpenWebBeansEjbLCAPlugin; import org.apache.webbeans.plugins.PluginLoader; -import org.apache.webbeans.portable.creation.ProducerBeansProducerRemove; +import org.apache.webbeans.portable.ProducerFieldProducer; +import org.apache.webbeans.portable.ProducerMethodProducer; import org.apache.webbeans.portable.events.discovery.ErrorStack; import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType; import org.apache.webbeans.portable.events.generics.GProcessBean; @@ -1882,7 +1883,7 @@ public final class WebBeansUtil public GProcessProducer fireProcessProducerEventForMethod(ProducerMethodBean<?> producerMethod, AnnotatedMethod<?> method) { - GProcessProducer producerEvent = new GProcessProducer(new ProducerBeansProducerRemove(producerMethod),method); + GProcessProducer producerEvent = new GProcessProducer(new ProducerMethodProducer(producerMethod.getParent(), method, null, producerMethod.getInjectionPoints()),method); //Fires ProcessProducer for methods webBeansContext.getBeanManagerImpl().fireEvent(producerEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY); @@ -1892,7 +1893,7 @@ public final class WebBeansUtil public GProcessProducer fireProcessProducerEventForField(ProducerFieldBean<?> producerField, AnnotatedField<?> field) { - GProcessProducer producerEvent = new GProcessProducer(new ProducerBeansProducerRemove(producerField),field); + GProcessProducer producerEvent = new GProcessProducer(new ProducerFieldProducer(producerField.getParent(), field, producerField.getInjectionPoints()), field); //Fires ProcessProducer for fields webBeansContext.getBeanManagerImpl().fireEvent(producerEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY); Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java (original) +++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java Thu Jan 17 21:20:09 2013 @@ -57,7 +57,8 @@ import org.apache.webbeans.exception.Web import org.apache.webbeans.logger.WebBeansLoggerFacade; import org.apache.webbeans.newtests.AbstractUnitTest; import org.apache.webbeans.portable.InjectionTargetImpl; -import org.apache.webbeans.portable.creation.ProducerBeansProducerRemove; +import org.apache.webbeans.portable.ProducerFieldProducer; +import org.apache.webbeans.portable.ProducerMethodProducer; import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType; import org.apache.webbeans.test.component.decorator.broken.DelegateAttributeIsnotInterface; import org.apache.webbeans.test.component.decorator.broken.DelegateAttributeMustImplementAllDecoratedTypes; @@ -554,7 +555,6 @@ public abstract class TestContext implem { // add them one after the other to enable serialization handling et al manager.addBean(producerMethod); - producerMethod.setProducer(new ProducerBeansProducerRemove(producerMethod)); } Set<ProducerFieldBean<?>> producerFields = managedBeanCreator.defineProducerFields(component); @@ -562,7 +562,6 @@ public abstract class TestContext implem { // add them one after the other to enable serialization handling et al manager.addBean(producerField); - producerField.setProducer(new ProducerBeansProducerRemove(producerField)); } managedBeanCreator.validateDisposalMethods(component); Modified: openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsBean.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsBean.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsBean.java (original) +++ openwebbeans/trunk/webbeans-jms/src/main/java/org/apache/webbeans/jms/component/JmsBean.java Thu Jan 17 21:20:09 2013 @@ -49,12 +49,6 @@ public class JmsBean<T> extends Abstract } @Override - protected T createInstance(CreationalContext<T> creationalContext) - { - return null; - } - - @Override protected void destroyInstance(T instance,CreationalContext<T> creationalContext) { try Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationFilter.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationFilter.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationFilter.java (original) +++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationFilter.java Thu Jan 17 21:20:09 2013 @@ -24,6 +24,7 @@ import org.apache.webbeans.config.OWBLog import org.apache.webbeans.config.WebBeansContext; import org.apache.webbeans.el.ELContextStore; import org.apache.webbeans.logger.WebBeansLoggerFacade; +import org.apache.webbeans.portable.InjectionPointProducer; import org.apache.webbeans.spi.ContainerLifecycle; import org.apache.webbeans.spi.FailOverService; import org.apache.webbeans.util.WebBeansUtil; @@ -224,7 +225,7 @@ public class WebBeansConfigurationFilter { // TODO maybe there are more to cleanup - InjectionPointBean.removeThreadLocal(); + InjectionPointProducer.removeThreadLocal(); WebContextsService.removeThreadLocals(); } } Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java (original) +++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java Thu Jan 17 21:20:09 2013 @@ -24,6 +24,7 @@ import org.apache.webbeans.config.WebBea import org.apache.webbeans.conversation.ConversationManager; import org.apache.webbeans.el.ELContextStore; import org.apache.webbeans.logger.WebBeansLoggerFacade; +import org.apache.webbeans.portable.InjectionPointProducer; import org.apache.webbeans.spi.ContainerLifecycle; import org.apache.webbeans.spi.FailOverService; import org.apache.webbeans.util.WebBeansUtil; @@ -135,7 +136,7 @@ public class WebBeansConfigurationListen */ private void cleanupRequestThreadLocals() { - InjectionPointBean.removeThreadLocal(); + InjectionPointProducer.removeThreadLocal(); WebContextsService.removeThreadLocals(); } Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1434919&r1=1434918&r2=1434919&view=diff ============================================================================== --- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java (original) +++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java Thu Jan 17 21:20:09 2013 @@ -25,6 +25,7 @@ import org.apache.webbeans.config.WebBea import org.apache.webbeans.exception.WebBeansException; import org.apache.webbeans.lifecycle.AbstractLifeCycle; import org.apache.webbeans.logger.WebBeansLoggerFacade; +import org.apache.webbeans.portable.InjectionPointProducer; import org.apache.webbeans.spi.ResourceInjectionService; import org.apache.webbeans.spi.adaptor.ELAdaptor; import org.apache.webbeans.web.context.WebContextsService; @@ -202,7 +203,7 @@ public final class WebContainerLifecycle */ private void cleanupShutdownThreadLocals() { - InjectionPointBean.removeThreadLocal(); + InjectionPointProducer.removeThreadLocal(); WebContextsService.removeThreadLocals(); }
