use of org.jboss.weld.bean.proxy.ProxyMethodHandler in project core by weld.
the class InstanceImpl method destroy.
@Override
public void destroy(T instance) {
checkNotNull(instance);
// Attempt to destroy instance which is either a client proxy or a dependent session bean proxy
if (instance instanceof ProxyObject) {
ProxyObject proxy = (ProxyObject) instance;
if (proxy.getHandler() instanceof ProxyMethodHandler) {
ProxyMethodHandler handler = (ProxyMethodHandler) proxy.getHandler();
Bean<?> bean = handler.getBean();
if (isSessionBeanProxy(instance) && Dependent.class.equals(bean.getScope())) {
// Destroy internal reference to a dependent session bean
destroyDependentInstance(instance);
return;
} else {
// Destroy contextual instance of a normal-scoped bean
Context context = getBeanManager().getContext(bean.getScope());
if (context instanceof AlterableContext) {
AlterableContext alterableContext = (AlterableContext) context;
alterableContext.destroy(bean);
return;
} else {
throw BeanLogger.LOG.destroyUnsupported(context);
}
}
}
}
// Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy
destroyDependentInstance(instance);
}
use of org.jboss.weld.bean.proxy.ProxyMethodHandler in project core by weld.
the class DecoratorInjectionTarget method inject.
@Override
public void inject(T instance, CreationalContext<T> ctx) {
super.inject(instance, ctx);
if (accessibleField != null && instance instanceof DecoratorProxy) {
// this code is only applicable if the delegate is injected into a field
// as the proxy can't intercept the delegate when setting the field
// we need to now read the delegate from the field
// this is only needed for fields, as constructor and method injection are handed
// at injection time
Object delegate;
try {
delegate = accessibleField.get(instance);
} catch (IllegalAccessException e) {
throw UtilLogger.LOG.accessErrorOnField(accessibleField.getName(), accessibleField.getDeclaringClass(), e);
}
final ProxyMethodHandler handler = new ProxyMethodHandler(beanManager.getContextId(), new TargetBeanInstance(delegate), getBean());
((ProxyObject) instance).setHandler(handler);
}
}
Aggregations