Skip to content
Browse files

Improve code readability

  • Loading branch information...
1 parent 3a58943 commit 7a1f2ee842fdc1cf6e54279a607459505944e86f @luksa luksa committed with alesj Apr 18, 2012
View
8 impl/src/main/java/org/jboss/weld/bean/SessionBean.java
@@ -291,7 +291,7 @@ public T create(final CreationalContext<T> creationalContext) {
try {
T instance = SecureReflections.newInstance(proxyClass);
creationalContext.push(instance);
- ProxyFactory.setBeanInstance(instance, new EnterpriseTargetBeanInstance(getWeldAnnotated().getJavaClass(), new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, creationalContext)), this);
+ ProxyFactory.setBeanInstance(instance, createEnterpriseTargetBeanInstance(creationalContext), this);
if (hasDecorators()) {
instance = applyDecorators(instance, creationalContext, null);
}
@@ -306,6 +306,12 @@ public T create(final CreationalContext<T> creationalContext) {
}
+ private EnterpriseTargetBeanInstance createEnterpriseTargetBeanInstance(CreationalContext<T> creationalContext) {
+ return new EnterpriseTargetBeanInstance(
+ getWeldAnnotated().getJavaClass(),
+ new EnterpriseBeanProxyMethodHandler<T>(this, creationalContext));
+ }
+
@Override
protected T applyDecorators(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint) {
//for EJBs, we apply decorators through a proxy
View
12 impl/src/main/java/org/jboss/weld/bean/proxy/DecorationHelper.java
@@ -90,12 +90,6 @@ public static void pop() {
}
}
- public DecoratorProxyMethodHandler createMethodHandler(InjectionPoint injectionPoint, CreationalContext<?> creationalContext, Decorator<Object> decorator) {
- Object decoratorInstance = beanManager.getReference(injectionPoint, decorator, creationalContext);
- SerializableContextualInstanceImpl<Decorator<Object>, Object> serializableContextualInstance = new SerializableContextualInstanceImpl<Decorator<Object>, Object>(decorator, decoratorInstance, null, contextualStore);
- return new DecoratorProxyMethodHandler(serializableContextualInstance, previousDelegate);
- }
-
public T getNextDelegate(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) {
if (counter == decorators.size()) {
previousDelegate = originalInstance;
@@ -123,4 +117,10 @@ private T createProxy(InjectionPoint injectionPoint, CreationalContext<?> creati
}
}
+ public DecoratorProxyMethodHandler createMethodHandler(InjectionPoint injectionPoint, CreationalContext<?> creationalContext, Decorator<Object> decorator) {
+ Object decoratorInstance = beanManager.getReference(injectionPoint, decorator, creationalContext);
+ SerializableContextualInstanceImpl<Decorator<Object>, Object> serializableContextualInstance = new SerializableContextualInstanceImpl<Decorator<Object>, Object>(decorator, decoratorInstance, null, contextualStore);
+ return new DecoratorProxyMethodHandler(serializableContextualInstance, previousDelegate);
+ }
+
}
View
37 impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyMethodHandler.java
@@ -41,12 +41,6 @@
private final SerializableContextualInstance<Decorator<Object>, Object> decoratorInstance;
- /**
- * Constructor
- *
- * @param removeMethods
- * @param proxy The generic proxy
- */
public DecoratorProxyMethodHandler(SerializableContextualInstance<Decorator<Object>, Object> decoratorInstance, Object delegateInstance) {
super(delegateInstance, delegateInstance.getClass());
this.decoratorInstance = decoratorInstance;
@@ -68,23 +62,26 @@ public DecoratorProxyMethodHandler(SerializableContextualInstance<Decorator<Obje
*/
@Override
protected Object doInvoke(Object self, Method method, Method proceed, Object[] args) throws Throwable {
- SerializableContextualInstance<Decorator<Object>, Object> beanInstance = decoratorInstance;
- if (beanInstance.getContextual().get() instanceof WeldDecorator<?>) {
- WeldDecorator<?> decorator = (WeldDecorator<?>) beanInstance.getContextual().get();
- if (!method.isAnnotationPresent(Inject.class)) {
- WeldMethod<?, ?> decoratorMethod = decorator.getDecoratorMethod(method);
- if (decoratorMethod != null) {
- try {
- return decoratorMethod.invokeOnInstance(beanInstance.getInstance(), args);
- } catch (InvocationTargetException e) {
- throw e.getCause();
- }
- }
- }
+ Decorator<Object> decorator = decoratorInstance.getContextual().get();
+ if (decorator instanceof WeldDecorator<?>) {
+ WeldDecorator<?> weldDecorator = (WeldDecorator<?>) decorator;
+ return doInvoke(weldDecorator, decoratorInstance.getInstance(), method, args);
} else {
- throw new IllegalStateException(UNEXPECTED_UNWRAPPED_CUSTOM_DECORATOR, beanInstance.getContextual().get());
+ throw new IllegalStateException(UNEXPECTED_UNWRAPPED_CUSTOM_DECORATOR, decorator);
}
+ }
+ private Object doInvoke(WeldDecorator<?> weldDecorator, Object decoratorInstance, Method method, Object[] args) throws Throwable {
+ if (!method.isAnnotationPresent(Inject.class)) {
+ WeldMethod<?, ?> decoratorMethod = weldDecorator.getDecoratorMethod(method);
+ if (decoratorMethod != null) {
+ try {
+ return decoratorMethod.invokeOnInstance(decoratorInstance, args);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+ }
return SecureReflections.invoke(getTargetInstance(), method, args);
}
}
View
6 impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
@@ -710,11 +710,11 @@ public Object getReference(InjectionPoint injectionPoint, Bean<?> resolvedBean,
}
public Object getInjectableReference(InjectionPoint injectionPoint, CreationalContext<?> creationalContext) {
- if (!injectionPoint.isDelegate()) {
+ if (injectionPoint.isDelegate()) {
+ return DecorationHelper.peek().getNextDelegate(injectionPoint, creationalContext);
+ } else {
Bean<?> resolvedBean = getBean(new ResolvableBuilder(injectionPoint, this).create());
return getReference(injectionPoint, resolvedBean, creationalContext);
- } else {
- return DecorationHelper.peek().getNextDelegate(injectionPoint, creationalContext);
}
}

0 comments on commit 7a1f2ee

Please sign in to comment.
Something went wrong with that request. Please try again.