@Override public <T> WeldCreationalContext<T> createCreationalContext(Contextual<T> contextual) { return new CreationalContextImpl<T>(contextual); }
private Bean<?> findNormalScopedDependant(CreationalContextImpl<?> weldCreationalContext) { CreationalContextImpl<?> parent = weldCreationalContext.getParentCreationalContext(); if (parent != null) { if (parent.getContextual() instanceof Bean) { Bean<?> bean = (Bean<?>) parent.getContextual(); if (isNormalScope(bean.getScope())) { return bean; } else { return findNormalScopedDependant(parent); } } } return null; }
ctx.registerAroundConstructCallback(callback); ctx.setAroundConstructInterceptionContext(interceptionContext);
/** * Destroys dependent instance * * @param instance * @return true if the instance was destroyed, false otherwise */ public boolean destroyDependentInstance(T instance) { synchronized (dependentInstances) { for (Iterator<ContextualInstance<?>> iterator = dependentInstances.iterator(); iterator.hasNext();) { ContextualInstance<?> contextualInstance = iterator.next(); if (contextualInstance.getInstance() == instance) { iterator.remove(); destroy(contextualInstance); return true; } } } return false; }
protected Object getReceiver(CreationalContext<X> creationalContext) { if (creationalContext != null) { if (creationalContext instanceof CreationalContextImpl<?>) { // Create child creational context so that a dependent observer may be destroyed after the observer method completes creationalContext = ((CreationalContextImpl<?>) creationalContext).getCreationalContext(declaringBean); } return ContextualInstance.get(declaringBean, beanManager, creationalContext); } // Conditional observer - no creational context is required return ContextualInstance.getIfExists(declaringBean, beanManager); }
@Override public T newInstance(CreationalContext<T> ctx, BeanManagerImpl manager) { if (ctx instanceof CreationalContextImpl<?>) { CreationalContextImpl<T> weldCtx = Reflections.cast(ctx); if (!weldCtx.isConstructorInterceptionSuppressed()) { registerAroundConstructCallback(weldCtx, manager); } } return delegate().newInstance(ctx, manager); }
@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; }
private T invokeAroundConstructCallbacks(Object[] parameters, CreationalContextImpl<T> ctx) { final List<AroundConstructCallback<T>> callbacks = ctx.getAroundConstructCallbacks(); if (callbacks.isEmpty()) { return newInstance(parameters); } final Iterator<AroundConstructCallback<T>> iterator = callbacks.iterator(); return invokeAroundConstructCallback(iterator.next(), new ConstructionHandle<T>() { @Override public T proceed(Object[] parameters, Map<String, Object> data) { if (iterator.hasNext()) { return invokeAroundConstructCallback(iterator.next(), this, getComponentConstructor(), parameters, data); } else { return newInstance(parameters); } } }, getComponentConstructor(), parameters, new HashMap<String, Object>()); }
final Object incompleteInstance = weldCreationalContext.getIncompleteInstance(resolvedBean); if (incompleteInstance != null) { return incompleteInstance;
/** * Destroys dependent instance * * @param instance * @return true if the instance was destroyed, false otherwise */ public boolean destroyDependentInstance(T instance) { synchronized (dependentInstances) { for (Iterator<ContextualInstance<?>> iterator = dependentInstances.iterator(); iterator.hasNext();) { ContextualInstance<?> contextualInstance = iterator.next(); if (contextualInstance.getInstance() == instance) { iterator.remove(); destroy(contextualInstance); return true; } } } return false; }
protected Object getReceiver(CreationalContext<X> creationalContext) { if (creationalContext != null) { if (creationalContext instanceof CreationalContextImpl<?>) { // Create child creational context so that a dependent observer may be destroyed after the observer method completes creationalContext = ((CreationalContextImpl<?>) creationalContext).getCreationalContext(declaringBean); } return ContextualInstance.get(declaringBean, beanManager, creationalContext); } // Conditional observer - no creational context is required return ContextualInstance.getIfExists(declaringBean, beanManager); }
@Override public T newInstance(CreationalContext<T> ctx, BeanManagerImpl manager) { if (ctx instanceof CreationalContextImpl<?>) { CreationalContextImpl<T> weldCtx = Reflections.cast(ctx); if (!weldCtx.isConstructorInterceptionSuppressed()) { registerAroundConstructCallback(weldCtx, manager); } } return delegate().newInstance(ctx, manager); }
@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; }
private T invokeAroundConstructCallbacks(Object[] parameters, CreationalContextImpl<T> ctx) { final List<AroundConstructCallback<T>> callbacks = ctx.getAroundConstructCallbacks(); if (callbacks.isEmpty()) { return newInstance(parameters); } final Iterator<AroundConstructCallback<T>> iterator = callbacks.iterator(); return invokeAroundConstructCallback(iterator.next(), new ConstructionHandle<T>() { @Override public T proceed(Object[] parameters, Map<String, Object> data) { if (iterator.hasNext()) { return invokeAroundConstructCallback(iterator.next(), this, getComponentConstructor(), parameters, data); } else { return newInstance(parameters); } } }, getComponentConstructor(), parameters, new HashMap<String, Object>()); }
final Object incompleteInstance = weldCreationalContext.getIncompleteInstance(resolvedBean); if (incompleteInstance != null) { return incompleteInstance;
@SuppressWarnings("rawtypes") private Object readResolve() throws ObjectStreamException { return new CreationalContextImpl(); }
private Bean<?> findNormalScopedDependant(CreationalContextImpl<?> weldCreationalContext) { CreationalContextImpl<?> parent = weldCreationalContext.getParentCreationalContext(); if (parent != null) { if (parent.getContextual() instanceof Bean) { Bean<?> bean = (Bean<?>) parent.getContextual(); if (isNormalScope(bean.getScope())) { return bean; } else { return findNormalScopedDependant(parent); } } } return null; }
ctx.registerAroundConstructCallback(callback); ctx.setAroundConstructInterceptionContext(interceptionContext);
/** * Destroys dependent instance * * @param instance * @return true if the instance was destroyed, false otherwise */ public boolean destroyDependentInstance(T instance) { synchronized (dependentInstances) { for (Iterator<ContextualInstance<?>> iterator = dependentInstances.iterator(); iterator.hasNext();) { ContextualInstance<?> contextualInstance = iterator.next(); if (contextualInstance.getInstance() == instance) { iterator.remove(); destroy(contextualInstance); return true; } } } return false; }
protected Object getReceiver(CreationalContext<X> creationalContext) { if (creationalContext != null) { if (creationalContext instanceof CreationalContextImpl<?>) { // Create child creational context so that a dependent observer may be destroyed after the observer method completes creationalContext = ((CreationalContextImpl<?>) creationalContext).getCreationalContext(declaringBean); } return ContextualInstance.get(declaringBean, beanManager, creationalContext); } // Conditional observer - no creational context is required return ContextualInstance.getIfExists(declaringBean, beanManager); }