Skip to content

Commit

Permalink
Unwrapping of ITE in EJB Methodhandler
Browse files Browse the repository at this point in the history
Removal of invokeAndWrap
Using Reflections.invoke instad of method.invoke in some method handlers
Removal of duplication checks in beans.xml parser (should be in validator)
policy -> alternative with the exception of the inheritance naming problem in beans package

Sorry for the mixed commit
  • Loading branch information
nickarls committed Dec 3, 2009
1 parent 03002f4 commit 476a2e7
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 147 deletions.
44 changes: 22 additions & 22 deletions impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
Expand Up @@ -237,8 +237,8 @@ public Annotated getAnnotated()
* archive accessibility, and the configuration for this bean deployment
* archive
*/
private transient Collection<Class<?>> enabledPolicyClasses;
private transient Collection<Class<? extends Annotation>> enabledPolicyStereotypes;
private transient Collection<Class<?>> enabledAlternativeClasses;
private transient Collection<Class<? extends Annotation>> enabledAlternativeStereotypes;
private transient List<Class<?>> enabledDecoratorClasses;
private transient List<Class<?>> enabledInterceptorClasses;
private transient final Set<CurrentActivity> currentActivities;
Expand Down Expand Up @@ -402,8 +402,8 @@ public static BeanManagerImpl newChildActivityManager(BeanManagerImpl parentMana
parentManager.getContexts(),
parentManager.getCurrentActivities(),
parentManager.getSpecializedBeans(),
parentManager.getEnabledPolicyClasses(),
parentManager.getEnabledPolicyStereotypes(),
parentManager.getEnabledAlternativeClasses(),
parentManager.getEnabledAlternativeStereotypes(),
parentManager.getEnabledDecoratorClasses(),
parentManager.getEnabledInterceptorClasses(),
new StringBuilder().append(parentManager.getChildIds().incrementAndGet()).toString(),
Expand All @@ -429,8 +429,8 @@ private BeanManagerImpl(
ListMultimap<Class<? extends Annotation>, Context> contexts,
Set<CurrentActivity> currentActivities,
Map<Contextual<?>, Contextual<?>> specializedBeans,
Collection<Class<?>> enabledPolicyClasses,
Collection<Class<? extends Annotation>> enabledPolicyStereotypes,
Collection<Class<?>> enabledAlternativeClasses,
Collection<Class<? extends Annotation>> enabledAlternativeStereotypes,
List<Class<?>> enabledDecoratorClasses,
List<Class<?>> enabledInterceptorClasses,
String id,
Expand All @@ -447,8 +447,8 @@ private BeanManagerImpl(
this.currentActivities = currentActivities;
this.specializedBeans = specializedBeans;
this.observers = observers;
this.enabledPolicyClasses = enabledPolicyClasses;
this.enabledPolicyStereotypes = enabledPolicyStereotypes;
this.enabledAlternativeClasses = enabledAlternativeClasses;
this.enabledAlternativeStereotypes = enabledAlternativeStereotypes;
setEnabledDecoratorClasses(enabledDecoratorClasses);
setEnabledInterceptorClasses(enabledInterceptorClasses);
this.namespaces = namespaces;
Expand Down Expand Up @@ -687,25 +687,25 @@ private void checkBindingTypes(Collection<Annotation> bindings)
}

/**
* A collection of enabled policy classes
* A collection of enabled alternative classes
*
*/
public Collection<Class<?>> getEnabledPolicyClasses()
public Collection<Class<?>> getEnabledAlternativeClasses()
{
return Collections.unmodifiableCollection(enabledPolicyClasses);
return Collections.unmodifiableCollection(enabledAlternativeClasses);
}

/**
* @return the enabledPolicySterotypes
* @return the enabled alternative stereotypes
*/
public Collection<Class<? extends Annotation>> getEnabledPolicyStereotypes()
public Collection<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
{
return Collections.unmodifiableCollection(enabledPolicyStereotypes);
return Collections.unmodifiableCollection(enabledAlternativeStereotypes);
}

public boolean isBeanEnabled(Bean<?> bean)
{
return Beans.isBeanEnabled(bean, getEnabledPolicyClasses(), getEnabledPolicyStereotypes());
return Beans.isBeanEnabled(bean, getEnabledAlternativeClasses(), getEnabledAlternativeStereotypes());
}

/**
Expand All @@ -724,14 +724,14 @@ public List<Class<?>> getEnabledInterceptorClasses()
return Collections.unmodifiableList(enabledInterceptorClasses);
}

public void setEnabledPolicyClasses(Collection<Class<?>> enabledPolicyClasses)
public void setEnabledAlternativeClasses(Collection<Class<?>> enabledAlternativeClasses)
{
this.enabledPolicyClasses = enabledPolicyClasses;
this.enabledAlternativeClasses = enabledAlternativeClasses;
}

public void setEnabledPolicyStereotypes(Collection<Class<? extends Annotation>> enabledPolicySterotypes)
public void setEnabledAlternativeStereotypes(Collection<Class<? extends Annotation>> enabledAlternativeSterotypes)
{
this.enabledPolicyStereotypes = enabledPolicySterotypes;
this.enabledAlternativeStereotypes = enabledAlternativeSterotypes;
}

public void setEnabledDecoratorClasses(List<Class<?>> enabledDecoratorClasses)
Expand Down Expand Up @@ -1167,7 +1167,7 @@ public String toString()
{
StringBuilder buffer = new StringBuilder();
buffer.append("Manager\n");
buffer.append("Enabled policies: " + getEnabledPolicyClasses() + " " + getEnabledPolicyStereotypes() + "\n");
buffer.append("Enabled alternatives: " + getEnabledAlternativeClasses() + " " + getEnabledAlternativeStereotypes() + "\n");
buffer.append("Registered contexts: " + contexts.keySet() + "\n");
buffer.append("Registered beans: " + getBeans().size() + "\n");
buffer.append("Specialized beans: " + specializedBeans.size() + "\n");
Expand Down Expand Up @@ -1517,8 +1517,8 @@ public void cleanup()
this.decorators.clear();
this.enabledDecoratorClasses.clear();
this.enabledInterceptorClasses.clear();
this.enabledPolicyClasses.clear();
this.enabledPolicyStereotypes.clear();
this.enabledAlternativeClasses.clear();
this.enabledAlternativeStereotypes.clear();
this.enterpriseBeans.clear();
this.interceptorResolver.clear();
this.interceptors.clear();
Expand Down
26 changes: 13 additions & 13 deletions impl/src/main/java/org/jboss/weld/Validator.java
Expand Up @@ -268,7 +268,7 @@ public void validateDeployment(BeanManagerImpl manager, BeanDeployerEnvironment
validateBeans(manager.getBeans(), new ArrayList<RIBean<?>>(), manager);
validateEnabledDecoratorClasses(manager);
validateEnabledInterceptorClasses(manager);
validateEnabledPolicies(manager);
validateEnabledAlternatives(manager);
validateDisposalMethods(environment);
validateBeanNames(manager);
}
Expand Down Expand Up @@ -371,32 +371,32 @@ private void validateEnabledDecoratorClasses(BeanManagerImpl beanManager)
}


private void validateEnabledPolicies(BeanManagerImpl beanManager)
private void validateEnabledAlternatives(BeanManagerImpl beanManager)
{
List<Class<?>> seenPolicies = new ArrayList<Class<?>>();
for (Class<? extends Annotation> stereotype : beanManager.getEnabledPolicyStereotypes())
List<Class<?>> seenAlternatives = new ArrayList<Class<?>>();
for (Class<? extends Annotation> stereotype : beanManager.getEnabledAlternativeStereotypes())
{
if (!stereotype.isAnnotationPresent(Alternative.class))
{
throw new DeploymentException("Enabled policy sterotype " + stereotype + " is not annotated @Policy");
throw new DeploymentException("Enabled alternative sterotype " + stereotype + " is not annotated @Alternative");
}
if (seenPolicies.contains(stereotype))
if (seenAlternatives.contains(stereotype))
{
throw new DeploymentException("Cannot enable the same policy sterotype " + stereotype + " in beans.xml");
throw new DeploymentException("Cannot enable the same alternative sterotype " + stereotype + " in beans.xml");
}
seenPolicies.add(stereotype);
seenAlternatives.add(stereotype);
}
for (Class<?> clazz : beanManager.getEnabledPolicyClasses())
for (Class<?> clazz : beanManager.getEnabledAlternativeClasses())
{
if (!clazz.isAnnotationPresent(Alternative.class))
{
throw new DeploymentException("Enabled policy bean class " + clazz + " is not annotated @Policy");
throw new DeploymentException("Enabled alternative bean class " + clazz + " is not annotated @Alternative");
}
if (seenPolicies.contains(clazz))
if (seenAlternatives.contains(clazz))
{
throw new DeploymentException("Cannot enable the same policy bean class " + clazz + " in beans.xml");
throw new DeploymentException("Cannot enable the same alternative bean class " + clazz + " in beans.xml");
}
seenPolicies.add(clazz);
seenAlternatives.add(clazz);
}
}

Expand Down
Expand Up @@ -115,7 +115,7 @@ else if (getAnnotatedItem().isAnnotationPresent(Alternative.class))
{
this.policy = true;
}
else if (getMergedStereotypes().isPolicy())
else if (getMergedStereotypes().isAlternative())
{
this.policy = true;
}
Expand Down
Expand Up @@ -12,11 +12,13 @@
import java.util.HashSet;
import java.util.concurrent.Callable;

import javassist.tools.reflect.Reflection;
import javassist.util.proxy.MethodHandler;

import org.jboss.weld.Container;
import org.jboss.weld.NullInstanceException;
import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.util.Reflections;
import org.slf4j.cal10n.LocLogger;

public class CallableMethodHandler implements MethodHandler, Serializable
Expand Down Expand Up @@ -75,7 +77,7 @@ public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[]
}
try
{
Object returnValue = proxiedMethod.invoke(instance, args);
Object returnValue = Reflections.invoke(proxiedMethod, instance, args);
log.trace(CALL_PROXIED_METHOD, proxiedMethod, instance, args, returnValue == null ? null : returnValue);
return returnValue;
}
Expand Down
Expand Up @@ -74,7 +74,7 @@ public Object invoke(Object self, Method thisMethod, Method proceed, Object[] ar
if (Reflections.isAbstract(thisMethod))
{
Method method = ((AnnotatedMethod<?>) delegateClass.getWeldMethod(new MethodSignatureImpl(thisMethod))).getJavaMember();
return method.invoke(delegate, args);
return Reflections.invoke(method, delegate, args);
}

return proceed.invoke(self, args);
Expand Down
Expand Up @@ -110,7 +110,8 @@ public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[]
}
try
{
Object returnValue = Reflections.lookupMethod(proxiedMethod, proxiedInstance).invoke(proxiedInstance, args);
Method method = Reflections.lookupMethod(proxiedMethod, proxiedInstance);
Object returnValue = Reflections.invoke(method, proxiedInstance, args);
log.trace(CALL_PROXIED_METHOD, proxiedMethod, proxiedInstance, args, returnValue == null ? null : returnValue);
return returnValue;
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import static org.jboss.weld.logging.messages.BeanMessage.INVALID_REMOVE_METHOD_INVOCATION;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;

Expand Down Expand Up @@ -53,7 +54,7 @@ public class EnterpriseBeanProxyMethodHandler<T> implements MethodHandler, Seria
// The log provider
private static final LocLogger log = loggerFactory().getLogger(BEAN);

private final SessionObjectReference reference;
private final SessionObjectReference reference;
private final Class<?> objectInterface;
private final Collection<MethodSignature> removeMethodSignatures;
private final boolean clientCanCallRemoveMethods;
Expand All @@ -75,7 +76,7 @@ public EnterpriseBeanProxyMethodHandler(SessionBean<T> bean, CreationalContext<T
this.stateful = bean.getEjbDescriptor().isStateful();
log.trace(CREATED_SESSION_BEAN_PROXY, bean);
}

/**
* Lookups the EJB in the container and executes the method on it
*
Expand Down Expand Up @@ -107,24 +108,38 @@ public Object invoke(Object self, Method method, Method proceed, Object[] args)
}
return null;
}

if (!clientCanCallRemoveMethods)
{
// TODO we can certainly optimize this search algorithm!
MethodSignature methodSignature = new MethodSignatureImpl(method);
if (removeMethodSignatures.contains(methodSignature))
{
throw new InvalidOperationException(INVALID_REMOVE_METHOD_INVOCATION, method );
throw new InvalidOperationException(INVALID_REMOVE_METHOD_INVOCATION, method);
}
}
Class<?> businessInterface = getBusinessInterface(method);
Object proxiedInstance = reference.getBusinessObject(businessInterface);
Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
Object returnValue = Reflections.invoke(proxiedMethod, proxiedInstance, args);
log.trace(CALL_PROXIED_METHOD, method, proxiedInstance, args, returnValue);
return returnValue;
try
{
Object returnValue = Reflections.invoke(proxiedMethod, proxiedInstance, args);
log.trace(CALL_PROXIED_METHOD, method, proxiedInstance, args, returnValue);
return returnValue;
}
catch (InvocationTargetException e)
{
if (e.getCause() != null)
{
throw e.getCause();
}
else
{
throw e;
}
}
}

private Class<?> getBusinessInterface(Method method)
{
Class<?> businessInterface = method.getDeclaringClass();
Expand All @@ -137,5 +152,5 @@ private Class<?> getBusinessInterface(Method method)
return businessInterface;
}
}

}
12 changes: 6 additions & 6 deletions impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
Expand Up @@ -20,7 +20,7 @@
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.BootstrapMessage.ENABLED_DECORATORS;
import static org.jboss.weld.logging.messages.BootstrapMessage.ENABLED_INTERCEPTORS;
import static org.jboss.weld.logging.messages.BootstrapMessage.ENABLED_POLICIES;
import static org.jboss.weld.logging.messages.BootstrapMessage.ENABLED_ALTERNATIVES;

import java.util.List;

Expand Down Expand Up @@ -106,13 +106,13 @@ private void parseBeansXml()
BeansXmlParser parser = new BeansXmlParser(beanManager.getServices().get(ResourceLoader.class), getBeanDeploymentArchive().getBeansXml());
parser.parse();

if (parser.getEnabledPolicyClasses() != null)
if (parser.getEnabledAlternativeClasses() != null)
{
beanManager.setEnabledPolicyClasses(parser.getEnabledPolicyClasses());
beanManager.setEnabledAlternativeClasses(parser.getEnabledAlternativeClasses());
}
if (parser.getEnabledPolicyStereotypes() != null)
if (parser.getEnabledAlternativeStereotypes() != null)
{
beanManager.setEnabledPolicyStereotypes(parser.getEnabledPolicyStereotypes());
beanManager.setEnabledAlternativeStereotypes(parser.getEnabledAlternativeStereotypes());
}
if (parser.getEnabledDecoratorClasses() != null)
{
Expand All @@ -122,7 +122,7 @@ private void parseBeansXml()
{
beanManager.setEnabledInterceptorClasses(parser.getEnabledInterceptorClasses());
}
log.debug(ENABLED_POLICIES, this.beanManager, beanManager.getEnabledPolicyClasses(), beanManager.getEnabledPolicyStereotypes());
log.debug(ENABLED_ALTERNATIVES, this.beanManager, beanManager.getEnabledAlternativeClasses(), beanManager.getEnabledAlternativeStereotypes());
log.debug(ENABLED_DECORATORS, this.beanManager, beanManager.getEnabledDecoratorClasses());
log.debug(ENABLED_INTERCEPTORS, this.beanManager, beanManager.getEnabledInterceptorClasses());
}
Expand Down
12 changes: 11 additions & 1 deletion impl/src/main/java/org/jboss/weld/jsf/JsfHelper.java
Expand Up @@ -22,6 +22,8 @@
import static org.jboss.weld.logging.messages.JsfMessage.IMPROPER_ENVIRONMENT;
import static org.jboss.weld.logging.messages.JsfMessage.RESUMING_CONVERSATION;

import java.lang.reflect.InvocationTargetException;

import javax.enterprise.util.AnnotationLiteral;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
Expand Down Expand Up @@ -58,7 +60,15 @@ public static boolean isPostback(FacesContext facesContext)
{
if (Container.instance().deploymentServices().get(JsfApiAbstraction.class).isApiVersionCompatibleWith(2.0))
{
return (Boolean) Reflections.invokeAndWrap("isPostback", facesContext);
try
{
return (Boolean) Reflections.invoke("isPostback", facesContext);
}
catch (Exception e)
{
// Sorry, guys ;-) --NIK
return false;
}
}
else
{
Expand Down
Expand Up @@ -21,7 +21,7 @@ public enum BootstrapMessage

@MessageId("000100") VALIDATING_BEANS,
@MessageId("000101") JTA_UNAVAILABLE,
@MessageId("000103") ENABLED_POLICIES,
@MessageId("000103") ENABLED_ALTERNATIVES,
@MessageId("000104") ENABLED_DECORATORS,
@MessageId("000105") ENABLED_INTERCEPTORS,
@MessageId("000106") FOUND_BEAN,
Expand Down

0 comments on commit 476a2e7

Please sign in to comment.