use of org.jboss.weld.interceptor.proxy.InterceptionContext in project Payara by payara.
the class JCDIServiceImpl method getAroundConstructInterceptorInstance.
private <T> T getAroundConstructInterceptorInstance(Interceptor<T> interceptor, CreationalContext<T> creationalContext) {
T instance = null;
if (creationalContext instanceof CreationalContextImpl<?>) {
CreationalContextImpl<T> weldContext = Reflections.cast(creationalContext);
@SuppressWarnings("unchecked") InterceptorImpl<T> interceptorImpl = (InterceptorImpl) interceptor;
InterceptorClassMetadata<T> interceptorClassMetadata = interceptorImpl.getInterceptorMetadata();
InterceptionContext interceptionContext = weldContext.getAroundConstructInterceptionContext();
instance = interceptionContext.getInterceptorInstance(interceptorClassMetadata);
}
return instance;
}
use of org.jboss.weld.interceptor.proxy.InterceptionContext in project core by weld.
the class InterceptorApplyingInstantiator method newInstance.
@Override
public T newInstance(CreationalContext<T> ctx, BeanManagerImpl manager) {
InterceptionContext interceptionContext = null;
if (ctx instanceof CreationalContextImpl<?>) {
CreationalContextImpl<T> weldCtx = Reflections.cast(ctx);
interceptionContext = weldCtx.getAroundConstructInterceptionContext();
}
if (interceptionContext == null) {
// There is no interception context to reuse
interceptionContext = InterceptionContext.forNonConstructorInterception(interceptionModel, ctx, manager, annotatedType);
}
T instance = delegate().newInstance(ctx, manager);
applyInterceptors(instance, interceptionContext);
return instance;
}
use of org.jboss.weld.interceptor.proxy.InterceptionContext in project core by weld.
the class ConstructorInterceptionInstantiator method registerAroundConstructCallback.
private void registerAroundConstructCallback(CreationalContextImpl<T> ctx, BeanManagerImpl manager) {
final InterceptionContext interceptionContext = InterceptionContext.forConstructorInterception(model, ctx, manager, annotatedType);
AroundConstructCallback<T> callback = new AroundConstructCallback<T>() {
@Override
public T aroundConstruct(final ConstructionHandle<T> handle, AnnotatedConstructor<T> constructor, Object[] parameters, Map<String, Object> data) {
/*
* The AroundConstruct interceptor method can access the constructed instance using InvocationContext.getTarget
* method after the InvocationContext.proceed completes.
*/
final AtomicReference<T> target = new AtomicReference<T>();
List<InterceptorMethodInvocation> chain = interceptionContext.buildInterceptorMethodInvocationsForConstructorInterception();
InvocationContext invocationContext = new WeldInvocationContextImpl(constructor.getJavaMember(), parameters, data, chain, model.getMemberInterceptorBindings(getConstructor())) {
@Override
protected Object interceptorChainCompleted() throws Exception {
// all the interceptors were invoked, call the constructor now
T instance = handle.proceed(getParameters(), getContextData());
target.set(instance);
return null;
}
@Override
public Object getTarget() {
return target.get();
}
};
try {
invocationContext.proceed();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new WeldException(e);
}
T instance = target.get();
if (instance == null) {
// CDI-598
throw InterceptorLogger.LOG.targetInstanceNotCreated(constructor);
}
return instance;
}
};
ctx.registerAroundConstructCallback(callback);
ctx.setAroundConstructInterceptionContext(interceptionContext);
}
Aggregations