Created
May 9, 2013 18:00
-
-
Save rmannibucau/5549271 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java | |
=================================================================== | |
--- webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java (revision 1480620) | |
+++ webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java (working copy) | |
@@ -71,6 +71,7 @@ | |
import org.apache.webbeans.component.NewBean; | |
import org.apache.webbeans.component.OwbBean; | |
import org.apache.webbeans.component.third.ThirdpartyBeanImpl; | |
+import org.apache.webbeans.component.third.ThirdpartyBeanPassivationCapableImpl; | |
import org.apache.webbeans.config.WebBeansContext; | |
import org.apache.webbeans.context.creational.CreationalContextImpl; | |
import org.apache.webbeans.decorator.DecoratorComparator; | |
@@ -356,7 +357,7 @@ | |
* @param newBean | |
* @return | |
*/ | |
- public BeanManager addInternalBean(Bean<?> newBean) | |
+ public <T> BeanManager addInternalBean(Bean<T> newBean) | |
{ | |
if(newBean instanceof AbstractOwbBean) | |
{ | |
@@ -365,7 +366,15 @@ | |
} | |
else | |
{ | |
- ThirdpartyBeanImpl<?> bean = new ThirdpartyBeanImpl(webBeansContext, newBean); | |
+ ThirdpartyBeanImpl<?> bean; | |
+ if (!PassivationCapable.class.isInstance(newBean)) | |
+ { | |
+ bean = new ThirdpartyBeanImpl<T>(webBeansContext, newBean); | |
+ } | |
+ else | |
+ { | |
+ bean = new ThirdpartyBeanPassivationCapableImpl<T>(webBeansContext, newBean); | |
+ } | |
addPassivationInfo(bean); | |
deploymentBeans.add(bean); | |
} | |
Index: webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanPassivationCapableImpl.java | |
=================================================================== | |
--- webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanPassivationCapableImpl.java (working copy) | |
+++ webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanPassivationCapableImpl.java (working copy) | |
@@ -18,160 +18,30 @@ | |
*/ | |
package org.apache.webbeans.component.third; | |
-import java.lang.annotation.Annotation; | |
-import java.util.Set; | |
+import org.apache.webbeans.config.WebBeansContext; | |
-import javax.enterprise.context.spi.CreationalContext; | |
import javax.enterprise.inject.spi.Bean; | |
-import javax.enterprise.inject.spi.InjectionPoint; | |
import javax.enterprise.inject.spi.PassivationCapable; | |
-import javax.enterprise.inject.spi.Producer; | |
-import org.apache.webbeans.component.AbstractOwbBean; | |
-import org.apache.webbeans.component.BeanAttributesImpl; | |
-import org.apache.webbeans.component.WebBeansType; | |
-import org.apache.webbeans.config.WebBeansContext; | |
-import org.apache.webbeans.inject.AlternativesManager; | |
- | |
-public class ThirdpartyBeanImpl<T> extends AbstractOwbBean<T> implements Bean<T> | |
+public class ThirdpartyBeanPassivationCapableImpl<T> extends ThirdpartyBeanImpl<T> implements PassivationCapable | |
{ | |
- private Bean<T> bean = null; | |
- | |
- public ThirdpartyBeanImpl(WebBeansContext webBeansContext, Bean<T> bean) | |
- { | |
- super(webBeansContext, | |
- WebBeansType.THIRDPARTY, | |
- new BeanAttributesImpl<T>(bean), | |
- bean.getBeanClass(), | |
- bean.isNullable()); | |
- | |
- this.bean = bean; | |
- | |
- } | |
+ private final String id; | |
- @Override | |
- public Producer<T> getProducer() | |
+ public ThirdpartyBeanPassivationCapableImpl(final WebBeansContext webBeansContext, final Bean<T> bean) | |
{ | |
- return new Producer<T>() | |
- { | |
- @Override | |
- public T produce(CreationalContext<T> creationalContext) | |
- { | |
- return bean.create(creationalContext); | |
- } | |
- | |
- @Override | |
- public void dispose(T instance) | |
- { | |
- bean.destroy(instance, null); | |
- } | |
- | |
- @Override | |
- public Set<InjectionPoint> getInjectionPoints() | |
- { | |
- return bean.getInjectionPoints(); | |
- } | |
- }; | |
+ super(webBeansContext, bean); | |
+ id = PassivationCapable.class.cast(bean).getId(); | |
} | |
@Override | |
- public Set<InjectionPoint> getInjectionPoints() | |
- { | |
- return bean.getInjectionPoints(); | |
- } | |
- | |
- @Override | |
- public T create(CreationalContext<T> context) | |
- { | |
- | |
- return bean.create(context); | |
- } | |
- | |
- @Override | |
- public void destroy(T instance, CreationalContext<T> context) | |
- { | |
- bean.destroy(instance,context); | |
- | |
- } | |
- | |
- /* (non-Javadoc) | |
- * @see org.apache.webbeans.component.AbstractBean#getId() | |
- */ | |
- @Override | |
public String getId() | |
{ | |
- if(bean instanceof PassivationCapable) | |
- { | |
- PassivationCapable pc = (PassivationCapable) bean; | |
- return pc.getId(); | |
- } | |
- | |
- return null; | |
+ return id; | |
} | |
- | |
- | |
@Override | |
public boolean isPassivationCapable() | |
{ | |
- return bean instanceof PassivationCapable; | |
+ return true; | |
} | |
- | |
- @Override | |
- public Class<?> getBeanClass() | |
- { | |
- return bean.getBeanClass(); | |
- } | |
- | |
- @Override | |
- public boolean isAlternative() | |
- { | |
- boolean alternative = super.isAlternative(); | |
- if(alternative) | |
- { | |
- AlternativesManager manager = getWebBeansContext().getAlternativesManager(); | |
- //Class alternative | |
- if(manager.isClassAlternative(getBeanClass())) | |
- { | |
- return true; | |
- } | |
- | |
- Set<Class<? extends Annotation>> stereoTypes = bean.getStereotypes(); | |
- if(stereoTypes != null) | |
- { | |
- for(Class<? extends Annotation> stereo : stereoTypes) | |
- { | |
- if(manager.isStereoAlternative(stereo)) | |
- { | |
- return true; | |
- } | |
- } | |
- } | |
- } | |
- | |
- return false; | |
- } | |
- | |
- /** | |
- * We need to override the hash code from the AbstractOwbBean | |
- * and delegate to the shaded instance. | |
- * | |
- * @return the hash mixed with the shadowed bean. | |
- */ | |
- @Override | |
- public int hashCode() | |
- { | |
- return 29 * bean.hashCode(); | |
- } | |
- | |
- @Override | |
- public boolean equals(Object other) | |
- { | |
- if (other instanceof ThirdpartyBeanImpl) | |
- { | |
- return ((ThirdpartyBeanImpl) other).bean.equals(bean); | |
- } | |
- | |
- return bean.equals(other); | |
- } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment