Weld SVN: r5202 - in core/trunk/impl/src/main: java/org/jboss/weld/bean and 10 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2009-12-03 08:31:01 -0500 (Thu, 03 Dec 2009)
New Revision: 5202
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/Validator.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractDecoratorMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
core/trunk/impl/src/main/java/org/jboss/weld/jsf/JsfHelper.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BootstrapMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MergedStereotypes.java
core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/StereotypeModel.java
core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/bootstrap_en.properties
Log:
Unwrapping of ITE in EJB Methodhandler
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
Modified: core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -237,8 +237,8 @@
* 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;
@@ -402,8 +402,8 @@
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(),
@@ -429,8 +429,8 @@
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,
@@ -447,8 +447,8 @@
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;
@@ -687,25 +687,25 @@
}
/**
- * 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());
}
/**
@@ -724,14 +724,14 @@
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)
@@ -1167,7 +1167,7 @@
{
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");
@@ -1517,8 +1517,8 @@
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();
Modified: core/trunk/impl/src/main/java/org/jboss/weld/Validator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/Validator.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/Validator.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -268,7 +268,7 @@
validateBeans(manager.getBeans(), new ArrayList<RIBean<?>>(), manager);
validateEnabledDecoratorClasses(manager);
validateEnabledInterceptorClasses(manager);
- validateEnabledPolicies(manager);
+ validateEnabledAlternatives(manager);
validateDisposalMethods(environment);
validateBeanNames(manager);
}
@@ -371,32 +371,32 @@
}
- 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);
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractReceiverBean.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -115,7 +115,7 @@
{
this.policy = true;
}
- else if (getMergedStereotypes().isPolicy())
+ else if (getMergedStereotypes().isAlternative())
{
this.policy = true;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -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
@@ -75,7 +77,7 @@
}
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;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractDecoratorMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractDecoratorMethodHandler.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractDecoratorMethodHandler.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -74,7 +74,7 @@
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);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -110,7 +110,8 @@
}
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;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -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;
@@ -53,7 +54,7 @@
// 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;
@@ -75,7 +76,7 @@
this.stateful = bean.getEjbDescriptor().isStateful();
log.trace(CREATED_SESSION_BEAN_PROXY, bean);
}
-
+
/**
* Lookups the EJB in the container and executes the method on it
*
@@ -107,24 +108,38 @@
}
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();
@@ -137,5 +152,5 @@
return businessInterface;
}
}
-
+
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -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;
@@ -106,13 +106,13 @@
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)
{
@@ -122,7 +122,7 @@
{
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());
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/jsf/JsfHelper.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/jsf/JsfHelper.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/jsf/JsfHelper.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -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;
@@ -58,7 +60,15 @@
{
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
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BootstrapMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BootstrapMessage.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/BootstrapMessage.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -21,7 +21,7 @@
@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,
Modified: core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MergedStereotypes.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MergedStereotypes.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/MergedStereotypes.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -36,8 +36,8 @@
private final Set<Annotation> possibleScopeTypes;
// Is the bean name defaulted?
private boolean beanNameDefaulted;
- // Are any of the sterotypes policies
- private boolean policy;
+ // Are any of the sterotypes alternatives
+ private boolean alternative;
private Set<Class<? extends Annotation>> stereotypes;
@@ -71,9 +71,9 @@
{
throw new ForbiddenStateException(STEREOTYPE_NOT_REGISTERED, stereotypeAnnotation);
}
- if (stereotype.isPolicy())
+ if (stereotype.isAlternative())
{
- policy = true;
+ alternative = true;
}
if (stereotype.getDefaultScopeType() != null)
{
@@ -89,9 +89,9 @@
}
}
- public boolean isPolicy()
+ public boolean isAlternative()
{
- return policy;
+ return alternative;
}
/**
@@ -130,8 +130,8 @@
@Override
public String toString()
{
- return "Merged stereotype model; Any of the sterotypes is a policy: " +
- policy + "; possible scopes " + possibleScopeTypes;
+ return "Merged stereotype model; Any of the sterotypes is an alternative: " +
+ alternative + "; possible scopes " + possibleScopeTypes;
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/StereotypeModel.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/StereotypeModel.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/metadata/cache/StereotypeModel.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -57,8 +57,8 @@
private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = Arrays2.<Class<? extends Annotation>>asSet(Stereotype.class);
private static final LocLogger log = loggerFactory().getLogger(REFLECTION);
- // Is the stereotype a policy
- private boolean policy;
+ // Is the stereotype an alternative
+ private boolean alternative;
// The default scope type
private Annotation defaultScopeType;
// Is the bean name defaulted
@@ -78,7 +78,7 @@
public StereotypeModel(Class<T> sterotype, ClassTransformer transformer)
{
super(sterotype, transformer);
- initPolicy();
+ initAlternative();
initDefaultScopeType();
initBeanNameDefaulted();
initInterceptorBindings();
@@ -154,11 +154,11 @@
/**
* Initializes the default deployment type
*/
- private void initPolicy()
+ private void initAlternative()
{
if (getAnnotatedAnnotation().isAnnotationPresent(Alternative.class))
{
- this.policy = true;
+ this.alternative = true;
}
}
@@ -230,9 +230,9 @@
/**
* @return
*/
- public boolean isPolicy()
+ public boolean isAlternative()
{
- return policy;
+ return alternative;
}
public Set<Annotation> getInheritedSterotypes()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/resolution/NameBasedResolver.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -83,7 +83,7 @@
matchedBeans.add(bean);
}
}
- return Beans.retainEnabledPolicies(matchedBeans, manager.getEnabledPolicyClasses(), manager.getEnabledPolicyStereotypes());
+ return Beans.retainEnabledAlternatives(matchedBeans, manager.getEnabledAlternativeClasses(), manager.getEnabledAlternativeStereotypes());
}
});
Modified: core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeBeanResolver.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -75,7 +75,7 @@
@Override
protected Set<T> filterResult(Set<T> matched)
{
- return Beans.retainEnabledPolicies(matched, manager.getEnabledPolicyClasses(), manager.getEnabledPolicyStereotypes());
+ return Beans.retainEnabledAlternatives(matched, manager.getEnabledAlternativeClasses(), manager.getEnabledAlternativeStereotypes());
}
@Override
@@ -100,12 +100,12 @@
Set<Bean<? extends X>> disambiguatedBeans = beans;
if (disambiguatedBeans.size() > 1)
{
- boolean policyPresent = Beans.isPolicyPresent(disambiguatedBeans);
+ boolean alternativePresent = Beans.isAlternativePresent(disambiguatedBeans);
disambiguatedBeans = new HashSet<Bean<? extends X>>();
for (Bean<? extends X> bean : beans)
{
- if (policyPresent ? bean.isAlternative() : true && !Beans.isSpecialized(bean, beans, manager.getSpecializedBeans()))
+ if (alternativePresent ? bean.isAlternative() : true && !Beans.isSpecialized(bean, beans, manager.getSpecializedBeans()))
{
disambiguatedBeans.add(bean);
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -535,7 +535,7 @@
* @param enabledDeploymentTypes The enabled deployment types
* @return The filtered beans
*/
- public static <T extends Bean<?>> Set<T> retainEnabledPolicies(Set<T> beans, Collection<Class<?>> enabledPolicyClasses, Collection<Class<? extends Annotation>> enabledPolicySterotypes)
+ public static <T extends Bean<?>> Set<T> retainEnabledAlternatives(Set<T> beans, Collection<Class<?>> enabledAlternativeClasses, Collection<Class<? extends Annotation>> enabledAlternativeSterotypes)
{
if (beans.size() == 0)
{
@@ -546,7 +546,7 @@
Set<T> enabledBeans = new HashSet<T>();
for (T bean : beans)
{
- if (isBeanEnabled(bean, enabledPolicyClasses, enabledPolicySterotypes))
+ if (isBeanEnabled(bean, enabledAlternativeClasses, enabledAlternativeSterotypes))
{
enabledBeans.add(bean);
}
@@ -555,11 +555,11 @@
}
}
- public static boolean isBeanEnabled(Bean<?> bean, Collection<Class<?>> enabledPolicyClasses, Collection<Class<? extends Annotation>> enabledPolicySterotypes)
+ public static boolean isBeanEnabled(Bean<?> bean, Collection<Class<?>> enabledAlternativeClasses, Collection<Class<? extends Annotation>> enabledAlternativeSterotypes)
{
if (bean.isAlternative())
{
- if (enabledPolicyClasses.contains(bean.getBeanClass()))
+ if (enabledAlternativeClasses.contains(bean.getBeanClass()))
{
return true;
}
@@ -567,7 +567,7 @@
{
for (Class<? extends Annotation> stereotype : bean.getStereotypes())
{
- if (enabledPolicySterotypes.contains(stereotype))
+ if (enabledAlternativeSterotypes.contains(stereotype))
{
return true;
}
@@ -582,12 +582,12 @@
}
/**
- * Check if any of the beans is a policy
+ * Check if any of the beans is an alternative
*
* @param beans
* @return
*/
- public static <X> boolean isPolicyPresent(Set<Bean<? extends X>> beans)
+ public static <X> boolean isAlternativePresent(Set<Bean<? extends X>> beans)
{
for (Bean<?> bean : beans)
{
@@ -607,7 +607,7 @@
}
else
{
- return mergedStereotypes.isPolicy();
+ return mergedStereotypes.isAlternative();
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -21,7 +21,6 @@
import static org.jboss.weld.logging.messages.UtilMessage.ACCESS_ERROR_ON_CONSTRUCTOR;
import static org.jboss.weld.logging.messages.UtilMessage.ACCESS_ERROR_ON_FIELD;
import static org.jboss.weld.logging.messages.UtilMessage.ANNOTATION_VALUES_INACCESSIBLE;
-import static org.jboss.weld.logging.messages.UtilMessage.ERROR_INVOKING_METHOD;
import static org.jboss.weld.logging.messages.UtilMessage.NO_SUCH_METHOD;
import static org.jboss.weld.logging.messages.UtilMessage.SECURITY_EXCEPTION_SCANNING;
@@ -524,61 +523,24 @@
return false;
}
- /**
- * Invokes a method and wraps exceptions
- *
- * @param method The method to invoke
- * @param instance The instance to invoke on
- * @param parameters The parameters
- * @return The return value
- */
- public static Object invokeAndWrap(Method method, Object instance, Object... parameters)
- {
- try
- {
- return invoke(method, instance, parameters);
- }
- catch (IllegalArgumentException e)
- {
- throw new WeldException(ERROR_INVOKING_METHOD, e, method.getName(), method.getDeclaringClass());
- }
- catch (IllegalAccessException e)
- {
- throw new WeldException(ERROR_INVOKING_METHOD, e, method.getName(), method.getDeclaringClass());
- }
- catch (InvocationTargetException e)
- {
- throw new WeldException(ERROR_INVOKING_METHOD, e, method.getName(), method.getDeclaringClass());
- }
- }
-
public static Object invoke(Method method, Object instance, Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
ensureAccessible(method);
return method.invoke(instance, parameters);
}
- public static Object invokeAndWrap(String methodName, Object instance, Object... parameters)
+ public static Object invoke(String methodName, Object instance, Object... parameters) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
Class<?>[] parameterTypes = new Class<?>[parameters.length];
for (int i = 0; i < parameters.length; i++)
{
parameterTypes[i] = parameters[i].getClass();
}
- try
- {
- return invokeAndWrap(instance.getClass().getMethod(methodName, parameterTypes), instance, parameters);
- }
- catch (SecurityException e)
- {
- throw new WeldException(ERROR_INVOKING_METHOD, e, methodName, instance.getClass());
- }
- catch (java.lang.NoSuchMethodException e)
- {
- throw new WeldException(ERROR_INVOKING_METHOD, e, methodName, instance.getClass());
- }
+ Method method = instance.getClass().getMethod(methodName, parameterTypes);
+ return invoke(method, instance, parameters);
}
+
/**
* Gets value of a field and wraps exceptions
*
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -47,14 +47,14 @@
private final ResourceLoader resourceLoader;
private EnabledClasses enabledClasses = null;
- public List<Class<?>> getEnabledPolicyClasses()
+ public List<Class<?>> getEnabledAlternativeClasses()
{
- return enabledClasses.getEnabledPolicyClasses();
+ return enabledClasses.getEnabledAlternativeClasses();
}
- public List<Class<? extends Annotation>> getEnabledPolicyStereotypes()
+ public List<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
{
- return enabledClasses.getEnabledPolicyStereotypes();
+ return enabledClasses.getEnabledAlternativeStereotypes();
}
public List<Class<?>> getEnabledDecoratorClasses()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -31,16 +31,16 @@
*/
public class EnabledClasses
{
- private List<Class<? extends Annotation>> enabledPolicyStereotypes;
- private List<Class<?>> enabledPolicyClasses;
+ private List<Class<? extends Annotation>> enabledAlternativeStereotypes;
+ private List<Class<?>> enabledAlternativeClasses;
private List<Class<?>> enabledDecoratorClasses;
private List<Class<?>> enabledInterceptorClasses;
private ResourceLoader resourceLoader;
private EnabledClasses(MergedElements beanXmlElements, ResourceLoader resourceLoader)
{
- enabledPolicyStereotypes = new ArrayList<Class<? extends Annotation>>();
- enabledPolicyClasses = new ArrayList<Class<?>>();
+ enabledAlternativeStereotypes = new ArrayList<Class<? extends Annotation>>();
+ enabledAlternativeClasses = new ArrayList<Class<?>>();
enabledDecoratorClasses = new ArrayList<Class<?>>();
enabledInterceptorClasses = new ArrayList<Class<?>>();
this.resourceLoader = resourceLoader;
@@ -54,19 +54,19 @@
private void process(MergedElements beanXmlElements)
{
- processPolicies(beanXmlElements.getPoliciesElements());
+ processAlternatives(beanXmlElements.getAlternativesElements());
enabledDecoratorClasses.addAll(getClassesInElements(beanXmlElements.getDecoratorsElements()));
enabledInterceptorClasses.addAll(getClassesInElements(beanXmlElements.getInterceptorsElements()));
}
- private void processPolicies(List<BeansXmlElement> policyElements)
+ private void processAlternatives(List<BeansXmlElement> alternativesElements)
{
- Collection<Class<?>> classes = getClassesInElements(policyElements);
+ Collection<Class<?>> classes = getClassesInElements(alternativesElements);
for (Class<?> clazz : classes) {
if (clazz.isAnnotation()) {
- enabledPolicyStereotypes.add(clazz.asSubclass(Annotation.class));
+ enabledAlternativeStereotypes.add(clazz.asSubclass(Annotation.class));
} else {
- enabledPolicyClasses.add(clazz);
+ enabledAlternativeClasses.add(clazz);
}
}
}
@@ -81,14 +81,14 @@
return classes;
}
- public List<Class<? extends Annotation>> getEnabledPolicyStereotypes()
+ public List<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
{
- return enabledPolicyStereotypes;
+ return enabledAlternativeStereotypes;
}
- public List<Class<?>> getEnabledPolicyClasses()
+ public List<Class<?>> getEnabledAlternativeClasses()
{
- return enabledPolicyClasses;
+ return enabledAlternativeClasses;
}
public List<Class<?>> getEnabledDecoratorClasses()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java 2009-12-03 13:31:01 UTC (rev 5202)
@@ -37,7 +37,7 @@
*/
public class MergedElements
{
- private List<BeansXmlElement> policiesElements = new ArrayList<BeansXmlElement>();
+ private List<BeansXmlElement> alternativesElements = new ArrayList<BeansXmlElement>();
private List<BeansXmlElement> decoratorsElements = new ArrayList<BeansXmlElement>();
private List<BeansXmlElement> interceptorsElements = new ArrayList<BeansXmlElement>();
@@ -45,7 +45,7 @@
public void merge(URL url, Document beansXmlDocument)
{
Element documentElement = beansXmlDocument.getDocumentElement();
- policiesElements.addAll(getNamedElement(url, documentElement, "alternatives", MULTIPLE_ALTERNATIVES));
+ alternativesElements.addAll(getNamedElement(url, documentElement, "alternatives", MULTIPLE_ALTERNATIVES));
interceptorsElements.addAll(getNamedElement(url, documentElement, "interceptors", MULTIPLE_INTERCEPTORS));
decoratorsElements.addAll(getNamedElement(url, documentElement, "decorators", MULTIPLE_DECORATORS));
}
@@ -69,9 +69,9 @@
}
- public List<BeansXmlElement> getPoliciesElements()
+ public List<BeansXmlElement> getAlternativesElements()
{
- return policiesElements;
+ return alternativesElements;
}
public List<BeansXmlElement> getDecoratorsElements()
Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/bootstrap_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/bootstrap_en.properties 2009-12-03 12:39:54 UTC (rev 5201)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/bootstrap_en.properties 2009-12-03 13:31:01 UTC (rev 5202)
@@ -1,6 +1,6 @@
VALIDATING_BEANS=Weld initialized. Validating beans
JTA_UNAVAILABLE=Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
-ENABLED_POLICIES=Enabled policies for {0}: {1} {2}
+ENABLED_ALTERNATIVES=Enabled alternatives for {0}: {1} {2}
ENABLED_DECORATORS=Enabled decorator types for {0}: {1}
ENABLED_INTERCEPTORS=Enabled interceptor types for {0}: {1}
FOUND_BEAN=Bean: {0}
15 years
Weld SVN: r5201 - core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-12-03 07:39:54 -0500 (Thu, 03 Dec 2009)
New Revision: 5201
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/Quality.java
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/AnnotationTest.java
Log:
WELDX-56
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/AnnotationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/AnnotationTest.java 2009-12-03 07:18:13 UTC (rev 5200)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/AnnotationTest.java 2009-12-03 12:39:54 UTC (rev 5201)
@@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.lang.reflect.Method;
import org.testng.annotations.Test;
@@ -18,6 +19,14 @@
Synchronous synchronous = AnnotationTest.class.getAnnotation(Synchronous.class);
deserialize(serialize(synchronous));
}
+
+ @Test
+ public void testGetAnnotationDefaults() throws Throwable
+ {
+ Method method = Quality.class.getMethod("value");
+ Object value = method.getDefaultValue();
+ assert value.equals("very");
+ }
protected byte[] serialize(Object instance) throws IOException
{
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/Quality.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/Quality.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/Quality.java 2009-12-03 12:39:54 UTC (rev 5201)
@@ -0,0 +1,23 @@
+package org.jboss.weld.tests.unit.reflection.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Target( { TYPE, METHOD, PARAMETER })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+@interface Quality
+{
+
+ String value() default "very";
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/reflection/annotation/Quality.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
15 years
Weld SVN: r5200 - in core/trunk/impl/src/main/java/org/jboss/weld: util and 1 other directory.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2009-12-03 02:18:13 -0500 (Thu, 03 Dec 2009)
New Revision: 5200
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java
Log:
Don't swallow exceptions in EJB proxy method handler
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-12-02 22:07:31 UTC (rev 5199)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-12-03 07:18:13 UTC (rev 5200)
@@ -120,7 +120,7 @@
Class<?> businessInterface = getBusinessInterface(method);
Object proxiedInstance = reference.getBusinessObject(businessInterface);
Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
- Object returnValue = Reflections.invokeAndWrap(proxiedMethod, proxiedInstance, args);
+ Object returnValue = Reflections.invoke(proxiedMethod, proxiedInstance, args);
log.trace(CALL_PROXIED_METHOD, method, proxiedInstance, args, returnValue);
return returnValue;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java 2009-12-02 22:07:31 UTC (rev 5199)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Reflections.java 2009-12-03 07:18:13 UTC (rev 5200)
@@ -536,8 +536,7 @@
{
try
{
- method.setAccessible(true);
- return method.invoke(instance, parameters);
+ return invoke(method, instance, parameters);
}
catch (IllegalArgumentException e)
{
@@ -553,6 +552,12 @@
}
}
+ public static Object invoke(Method method, Object instance, Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
+ {
+ ensureAccessible(method);
+ return method.invoke(instance, parameters);
+ }
+
public static Object invokeAndWrap(String methodName, Object instance, Object... parameters)
{
Class<?>[] parameterTypes = new Class<?>[parameters.length];
15 years
Weld SVN: r5199 - in core/trunk/impl/src/main/java/org/jboss/weld: bean/builtin and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-12-02 17:07:31 -0500 (Wed, 02 Dec 2009)
New Revision: 5199
Added:
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ProxyCleaner.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/Container.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/LoggerFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/MessageConveyorFactory.java
Log:
Some more explicit cleanup
Modified: core/trunk/impl/src/main/java/org/jboss/weld/Container.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/Container.java 2009-12-02 22:04:00 UTC (rev 5198)
+++ core/trunk/impl/src/main/java/org/jboss/weld/Container.java 2009-12-02 22:07:31 UTC (rev 5199)
@@ -25,6 +25,8 @@
import org.jboss.weld.bootstrap.api.Singleton;
import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.logging.LoggerFactory;
+import org.jboss.weld.logging.MessageConveyorFactory;
/**
* A Weld application container
@@ -102,7 +104,6 @@
{
return instance.isSet() && instance() != null && instance().getStatus().isAvailable();
}
-
/**
* Initialize the container for the current application deployment
@@ -155,6 +156,9 @@
deploymentServices.cleanup();
deploymentManager.cleanup();
+ LoggerFactory.cleanup();
+ MessageConveyorFactory.cleanup();
+ instance.clear();
}
/**
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java 2009-12-02 22:04:00 UTC (rev 5198)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/CallableMethodHandler.java 2009-12-02 22:07:31 UTC (rev 5199)
@@ -8,25 +8,57 @@
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.concurrent.Callable;
import javassist.util.proxy.MethodHandler;
+import org.jboss.weld.Container;
import org.jboss.weld.NullInstanceException;
+import org.jboss.weld.bootstrap.api.Service;
import org.slf4j.cal10n.LocLogger;
public class CallableMethodHandler implements MethodHandler, Serializable
{
+ public static class CallableMethodHandlerCleaner implements Service
+ {
+
+ private final Collection<CallableMethodHandler> callableMethodHandlers;
+
+ public CallableMethodHandlerCleaner()
+ {
+ this.callableMethodHandlers = new HashSet<CallableMethodHandler>();
+ }
+
+ private void add(CallableMethodHandler callableMethodHandler)
+ {
+ this.callableMethodHandlers.add(callableMethodHandler);
+ }
+
+ public void cleanup()
+ {
+ for (CallableMethodHandler callableMethodHandler : callableMethodHandlers)
+ {
+ callableMethodHandler.cleanup();
+ }
+ callableMethodHandlers.clear();
+ }
+
+ }
+
private static final long serialVersionUID = -1348302663981663427L;
private static final LocLogger log = loggerFactory().getLogger(BEAN);
- private final Callable<?> callable;
+ // Can't make this final, need to deallocate on shutdown
+ private Callable<?> callable;
public CallableMethodHandler(Callable<?> callable)
{
super();
this.callable = callable;
+ Container.instance().deploymentServices().get(CallableMethodHandlerCleaner.class).add(this);
}
public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[] args) throws Throwable
@@ -60,5 +92,10 @@
}
}
}
+
+ private void cleanup()
+ {
+ this.callable = null;
+ }
}
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ProxyCleaner.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ProxyCleaner.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ProxyCleaner.java 2009-12-02 22:07:31 UTC (rev 5199)
@@ -0,0 +1 @@
+
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ProxyCleaner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2009-12-02 22:04:00 UTC (rev 5198)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2009-12-02 22:07:31 UTC (rev 5199)
@@ -46,6 +46,7 @@
import org.jboss.weld.Validator;
import org.jboss.weld.Container.Status;
import org.jboss.weld.bean.builtin.BeanManagerBean;
+import org.jboss.weld.bean.builtin.CallableMethodHandler.CallableMethodHandlerCleaner;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.bootstrap.api.Environment;
import org.jboss.weld.bootstrap.api.Lifecycle;
@@ -320,6 +321,7 @@
services.add(MetaAnnotationStore.class, new MetaAnnotationStore(services.get(ClassTransformer.class)));
services.add(ContextualStore.class, new ContextualStoreImpl());
services.add(ServiceLoaderFactory.class, new DefaultServiceLoaderFactory());
+ services.add(CallableMethodHandlerCleaner.class, new CallableMethodHandlerCleaner());
return services;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/logging/LoggerFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/logging/LoggerFactory.java 2009-12-02 22:04:00 UTC (rev 5198)
+++ core/trunk/impl/src/main/java/org/jboss/weld/logging/LoggerFactory.java 2009-12-02 22:07:31 UTC (rev 5199)
@@ -10,8 +10,13 @@
public class LoggerFactory
{
- private static LoggerFactory INSTANCE = new LoggerFactory("WELD");
+ private static LoggerFactory INSTANCE;
+ public static void cleanup()
+ {
+ INSTANCE = null;
+ }
+
private final LocLoggerFactory locLoggerFactory;
private final IMessageConveyor messageConveyor;
@@ -33,6 +38,10 @@
public static LoggerFactory loggerFactory()
{
+ if (INSTANCE == null)
+ {
+ INSTANCE = new LoggerFactory("WELD");
+ }
return INSTANCE;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/logging/MessageConveyorFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/logging/MessageConveyorFactory.java 2009-12-02 22:04:00 UTC (rev 5198)
+++ core/trunk/impl/src/main/java/org/jboss/weld/logging/MessageConveyorFactory.java 2009-12-02 22:07:31 UTC (rev 5199)
@@ -9,7 +9,7 @@
public abstract class MessageConveyorFactory
{
- private static MessageConveyorFactory INSTANCE = load();
+ private static MessageConveyorFactory INSTANCE;
private static MessageConveyorFactory load()
{
@@ -29,9 +29,18 @@
public static MessageConveyorFactory messageConveyerFactory()
{
+ if (INSTANCE == null)
+ {
+ INSTANCE = load();
+ }
return INSTANCE;
}
+ public static void cleanup()
+ {
+ INSTANCE = null;
+ }
+
public static IMessageConveyor defaultMessageConveyer(String subsystem)
{
return messageConveyerFactory().getDefaultMessageConveyer(subsystem);
15 years
Weld SVN: r5198 - core/trunk/impl/src/main/java/org/jboss/weld/util.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-12-02 17:04:00 -0500 (Wed, 02 Dec 2009)
New Revision: 5198
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java
Log:
More intelligent version printer
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java 2009-12-02 21:57:37 UTC (rev 5197)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Names.java 2009-12-02 22:04:00 UTC (rev 5198)
@@ -332,22 +332,40 @@
public static String version(Package pkg)
{
- if (pkg != null)
+ if (pkg == null)
{
- String version = pkg.getImplementationVersion();
- if (version != null)
+ throw new IllegalArgumentException("Package can not be null");
+ }
+ else
+ {
+ return version(pkg.getImplementationVersion());
+ }
+ }
+
+ public static String version(String version)
+ {
+ if (version != null)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(version.substring(0, version.indexOf("."))).append(".");
+ version = version.substring(version.indexOf(".") + 1);
+ builder.append(version.substring(0, version.indexOf("."))).append(".");
+ version = version.substring(version.indexOf(".") + 1);
+ if (version.indexOf("-") > 0)
{
- String separator = null;
- if (version.indexOf("-") > 0)
- {
- separator = "-";
- }
- else
- {
- separator = ".";
- }
- return new StringBuilder().append(version.substring(0, version.lastIndexOf(separator))).append(" (").append(version.substring(version.lastIndexOf(separator) + 1)).append(")").toString();
+ builder.append(version.substring(0, version.indexOf("-"))).append(" (");
+ builder.append(version.substring(version.indexOf("-") + 1)).append(")");
}
+ else if (version.indexOf(".") > 0)
+ {
+ builder.append(version.substring(0, version.indexOf("."))).append(" (");
+ builder.append(version.substring(version.indexOf(".") + 1)).append(")");
+ }
+ else
+ {
+ builder.append(version);
+ }
+ return builder.toString();
}
return "SNAPSHOT";
}
15 years
Weld SVN: r5197 - api/trunk/cdi/src/main/resources.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-12-02 16:57:37 -0500 (Wed, 02 Dec 2009)
New Revision: 5197
Modified:
api/trunk/cdi/src/main/resources/beans.xsd
Log:
use javaee not cdi
Modified: api/trunk/cdi/src/main/resources/beans.xsd
===================================================================
--- api/trunk/cdi/src/main/resources/beans.xsd 2009-12-02 21:56:18 UTC (rev 5196)
+++ api/trunk/cdi/src/main/resources/beans.xsd 2009-12-02 21:57:37 UTC (rev 5197)
@@ -16,8 +16,8 @@
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified" targetNamespace="http://seamframework.org/ns/CDI"
- xmlns:cdi="http://seamframework.org/ns/CDI" version="1.0">
+ elementFormDefault="qualified" targetNamespace="http://java.sun.com/xml/ns/javaee"
+ xmlns:javaee="http://java.sun.com/xml/ns/javaee" version="1.0">
<xs:annotation>
<xs:documentation>
@@ -25,7 +25,7 @@
a set of complementary services that help improve the structure
of application code. beans.xml is used to enable CDI services
for the current bean archive as well as to enable named
- interceptors, decorators and altenatives for the current bean
+ interceptors, decorators and alternatives for the current bean
archive.
</xs:documentation>
</xs:annotation>
@@ -45,9 +45,9 @@
</xs:annotation>
<xs:complexType>
<xs:all>
- <xs:element ref="cdi:interceptors" />
- <xs:element ref="cdi:decorators" />
- <xs:element ref="cdi:alternatives" />
+ <xs:element ref="javaee:interceptors" />
+ <xs:element ref="javaee:decorators" />
+ <xs:element ref="javaee:alternatives" />
</xs:all>
</xs:complexType>
</xs:element>
15 years
Weld SVN: r5196 - core/trunk/porting-package/src/main/java/org/jboss/weld/tck.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-12-02 16:56:18 -0500 (Wed, 02 Dec 2009)
New Revision: 5196
Modified:
core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java
Log:
Trivial to check for a proxy without refering to core (make Porting package less dependent on core code)
Modified: core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java
===================================================================
--- core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java 2009-12-02 21:55:41 UTC (rev 5195)
+++ core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java 2009-12-02 21:56:18 UTC (rev 5196)
@@ -1,7 +1,6 @@
package org.jboss.weld.tck;
import org.jboss.jsr299.tck.spi.Beans;
-import org.jboss.weld.util.Proxies;
/**
* Implements the Beans SPI for the TCK specifically for the JBoss RI.
@@ -16,7 +15,7 @@
public boolean isProxy(Object instance)
{
- return Proxies.isProxy(instance);
+ return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
}
}
15 years
Weld SVN: r5195 - core/trunk/jboss-as.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-12-02 16:55:41 -0500 (Wed, 02 Dec 2009)
New Revision: 5195
Modified:
core/trunk/jboss-as/build.properties
Log:
JBoss AS 6.0.0.M1
Modified: core/trunk/jboss-as/build.properties
===================================================================
--- core/trunk/jboss-as/build.properties 2009-12-02 21:54:51 UTC (rev 5194)
+++ core/trunk/jboss-as/build.properties 2009-12-02 21:55:41 UTC (rev 5195)
@@ -1,5 +1,5 @@
# Container a number of properties associated with installing Weld into JBoss AS and running the TCK in JBoss AS
-jboss.home=/Applications/jboss-5.2.0.Beta
+jboss.home=/Applications/jboss-6.0.0.M1
org.jboss.testharness.container.javaOpts=-Xms128m -Xmx512m -XX:MaxPermSize=192m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000
# time to allow before attempting to restart JBoss AS
15 years
Weld SVN: r5194 - core/trunk/jboss-tck-runner/src/test/resources.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-12-02 16:54:51 -0500 (Wed, 02 Dec 2009)
New Revision: 5194
Modified:
core/trunk/jboss-tck-runner/src/test/resources/tck-tests.xml
Log:
update exclude list
Modified: core/trunk/jboss-tck-runner/src/test/resources/tck-tests.xml
===================================================================
--- core/trunk/jboss-tck-runner/src/test/resources/tck-tests.xml 2009-12-02 20:04:29 UTC (rev 5193)
+++ core/trunk/jboss-tck-runner/src/test/resources/tck-tests.xml 2009-12-02 21:54:51 UTC (rev 5194)
@@ -21,22 +21,12 @@
<package name="org.jboss.jsr299.tck.interceptors.tests.*" />
</packages>
<classes>
- <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.interceptorWithNonPassivatingInjectedField.PassivationCapableBeanWithNonPassivatingInterceptorTest">
+ <!-- JBoss AS 6.0.0.M1 is still using EJB 3.0 Interceptor API - JBAS-7421 -->
+ <class name="org.jboss.jsr299.tck.interceptors.tests.invocationContext.InvocationContextTest">
<methods>
- <exclude name="testPassivationCapableBeanWithNonPassivatingInterceptorFails" />
- </methods>
- </class>
- <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.managedBeanWithNonSerializableInterceptorClass.ManagedBeanWithNonSerializableInterceptorClassTest">
- <methods>
- <exclude name="testManagedBeanWithNonSerializableInterceptorClassNotOK" />
+ <exclude name="testGetTimerMethod" />
</methods>
</class>
- <class name="org.jboss.jsr299.tck.tests.policy.PolicyAvailabilityTest">
- <methods>
- <exclude name="testProducerPoliciesOnClass" />
- <exclude name="testProducerPoliciesOnMethodAndField" />
- </methods>
- </class>
</classes>
</test>
15 years
Weld SVN: r5193 - core/trunk/impl/src/main/java/org/jboss/weld/xml.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2009-12-02 15:04:29 -0500 (Wed, 02 Dec 2009)
New Revision: 5193
Added:
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
Log:
Tidied up beans.xml parsing while looking at WELD-319
Added: core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java 2009-12-02 20:04:29 UTC (rev 5193)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.xml;
+
+import static org.jboss.weld.logging.messages.XmlMessage.CANNOT_LOAD_CLASS;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.weld.DeploymentException;
+import org.jboss.weld.logging.messages.XmlMessage;
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.jboss.weld.resources.spi.ResourceLoadingException;
+import org.jboss.weld.util.dom.NodeListIterable;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class BeansXmlElement
+{
+ private URL file;
+ private Element element;
+ private List<String> classNames;
+
+ private BeansXmlElement(URL file, Element element)
+ {
+ super();
+ this.file = file;
+ this.element = element;
+ classNames = new ArrayList<String>();
+ }
+
+ public BeansXmlElement validateWithMessage(XmlMessage multipleViolationMessage)
+ {
+ for (Node child : new NodeListIterable(element.getChildNodes()))
+ {
+ String className = getClassNameFromNode(child);
+ if (className == null)
+ {
+ continue;
+ }
+ if (classNames.contains(className))
+ {
+ throw new DeploymentException(multipleViolationMessage);
+ }
+ classNames.add(className);
+ }
+ return this;
+ }
+
+ private String getClassNameFromNode(Node node)
+ {
+ if (node instanceof Element)
+ {
+ if (node.getChildNodes().getLength() == 1 && node.getChildNodes().item(0) instanceof Text)
+ {
+ String className = ((Text) node.getChildNodes().item(0)).getData();
+ return className;
+ }
+ }
+ return null;
+ }
+
+ public static BeansXmlElement of(URL file, Node element)
+ {
+ return new BeansXmlElement(file, (Element) element);
+ }
+
+ public List<Class<?>> getClasses(ResourceLoader resourceLoader)
+ {
+ List<Class<?>> classes = new ArrayList<Class<?>>();
+ for (String className : classNames)
+ {
+ try
+ {
+ classes.add(resourceLoader.classForName(className));
+ }
+ catch (ResourceLoadingException e)
+ {
+ throw new DeploymentException(CANNOT_LOAD_CLASS, className, file);
+ }
+ }
+ return classes;
+ }
+
+ public URL getFile()
+ {
+ return file;
+ }
+
+ public Element getElement()
+ {
+ return element;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "File: " + getFile() + "; Node: " + getElement();
+ }
+
+}
\ No newline at end of file
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2009-12-02 14:59:26 UTC (rev 5192)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2009-12-02 20:04:29 UTC (rev 5193)
@@ -16,19 +16,14 @@
*/
package org.jboss.weld.xml;
-import static org.jboss.weld.logging.messages.XmlMessage.CANNOT_LOAD_CLASS;
import static org.jboss.weld.logging.messages.XmlMessage.CONFIGURATION_ERROR;
import static org.jboss.weld.logging.messages.XmlMessage.LOAD_ERROR;
-import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_ALTERNATIVES;
-import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_DECORATORS;
-import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_INTERCEPTORS;
import static org.jboss.weld.logging.messages.XmlMessage.PARSING_ERROR;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.net.URL;
-import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
@@ -37,266 +32,133 @@
import org.jboss.weld.DeploymentException;
import org.jboss.weld.resources.spi.ResourceLoader;
-import org.jboss.weld.resources.spi.ResourceLoadingException;
-import org.jboss.weld.util.dom.NodeListIterable;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.Text;
import org.xml.sax.SAXException;
/**
* Simple parser for beans.xml
*
* @author Pete Muir
- *
+ * @author Nicklas Karlsson
*/
public class BeansXmlParser
{
-
- private static class XmlElement
- {
- private URL file;
- private Element element;
-
- public XmlElement(URL file, Element element)
- {
- super();
- this.file = file;
- this.element = element;
- }
-
- public URL getFile()
- {
- return file;
- }
-
- public Element getElement()
- {
- return element;
- }
-
- @Override
- public String toString()
- {
- return "File: " + getFile() + "; Node: " + getElement();
- }
-
- }
-
- private final Iterable<URL> beansXml;
+ private final Iterable<URL> beansXmls;
private final ResourceLoader resourceLoader;
-
- private List<Class<? extends Annotation>> enabledPolicyStereotypes;
- private List<Class<?>> enabledPolicyClasses;
- private List<Class<?>> enabledDecoratorClasses;
- private List<Class<?>> enabledInterceptorClasses;
-
+ private EnabledClasses enabledClasses = null;
+
public List<Class<?>> getEnabledPolicyClasses()
{
- return enabledPolicyClasses;
+ return enabledClasses.getEnabledPolicyClasses();
}
-
+
public List<Class<? extends Annotation>> getEnabledPolicyStereotypes()
{
- return enabledPolicyStereotypes;
+ return enabledClasses.getEnabledPolicyStereotypes();
}
-
+
public List<Class<?>> getEnabledDecoratorClasses()
{
- return enabledDecoratorClasses;
+ return enabledClasses.getEnabledDecoratorClasses();
}
-
+
public List<Class<?>> getEnabledInterceptorClasses()
{
- return enabledInterceptorClasses;
+ return enabledClasses.getEnabledInterceptorClasses();
}
-
+
public BeansXmlParser(ResourceLoader resourceLoader, Iterable<URL> beansXml)
{
- this.beansXml = beansXml;
+ this.beansXmls = beansXml;
this.resourceLoader = resourceLoader;
}
-
+
public void parse()
{
- DocumentBuilder documentBuilder;
- try
+ DocumentBuilder documentBuilder = getDocumentBuilder();
+ MergedElements mergedElements = new MergedElements();
+ for (URL beansXml : beansXmls)
{
- documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- }
- catch (ParserConfigurationException e)
- {
- throw new WeldXmlException(CONFIGURATION_ERROR, e);
- }
- List<XmlElement> policiesElements = new ArrayList<XmlElement>();
- List<XmlElement> decoratorsElements = new ArrayList<XmlElement>();
- List<XmlElement> interceptorsElements = new ArrayList<XmlElement>();
- for (URL url : beansXml)
- {
- InputStream is;
- boolean fileHasContents;
- try
+ // TODO: Do we really need to check if there is content?
+ if (!isBeansXmlOK(beansXml))
{
- is = url.openStream();
- fileHasContents = is.available() > 0;
+ continue;
}
- catch (IOException e)
- {
- throw new WeldXmlException(LOAD_ERROR, e, url.toString());
- }
- if (fileHasContents)
- {
- Document document;
- try
- {
- document = documentBuilder.parse(is);
- document.normalize();
- }
- catch (SAXException e)
- {
- throw new DeploymentException(PARSING_ERROR, e, url.toString());
- }
- catch (IOException e)
- {
- throw new DeploymentException(LOAD_ERROR, e, url.toString());
- }
- Element beans = document.getDocumentElement();
- for (Node child : new NodeListIterable(beans.getChildNodes()))
- {
- if (child instanceof Element && "alternatives".equals(child.getNodeName()))
- {
- policiesElements.add(new XmlElement(url, (Element) child));
- }
- if (child instanceof Element && "interceptors".equals(child.getNodeName()))
- {
- interceptorsElements.add(new XmlElement(url, (Element) child));
- }
+ Document document = getDocument(documentBuilder, beansXml);
+ mergedElements.merge(beansXml, document);
+ }
+ enabledClasses = EnabledClasses.of(mergedElements, resourceLoader);
+ }
- if (child instanceof Element && "decorators".equals(child.getNodeName()))
- {
- decoratorsElements.add(new XmlElement(url, (Element) child));
- }
- }
- }
+ private Document getDocument(DocumentBuilder documentBuilder, URL beansXml)
+ {
+ Document document;
+ InputStream in = null;
+ try
+ {
+ in = beansXml.openStream();
+ document = documentBuilder.parse(in);
+ document.normalize();
}
-
- if (policiesElements.size() > 1)
+ catch (SAXException e)
{
- throw new DeploymentException(MULTIPLE_ALTERNATIVES, policiesElements);
+ throw new DeploymentException(PARSING_ERROR, e, beansXml.toString());
}
- else if (policiesElements.size() == 1)
+ catch (IOException e)
{
- enabledPolicyStereotypes = new ArrayList<Class<? extends Annotation>>();
- enabledPolicyClasses = new ArrayList<Class<?>>();
- processPolicyElement(resourceLoader, policiesElements.get(0), enabledPolicyClasses, enabledPolicyStereotypes);
+ throw new DeploymentException(LOAD_ERROR, e, beansXml.toString());
}
-
- if (decoratorsElements.size() > 1)
+ finally
{
- throw new DeploymentException(MULTIPLE_DECORATORS, decoratorsElements);
+ closeStream(in);
}
- else if (decoratorsElements.size() == 1)
+ return document;
+ }
+
+ private void closeStream(InputStream in)
+ {
+ if (in == null)
{
- enabledDecoratorClasses = new ArrayList<Class<?>>();
- enabledDecoratorClasses.addAll(processElement(resourceLoader, decoratorsElements.get(0)));
+ return;
}
-
- if (interceptorsElements.size() > 1)
+ try
{
- throw new DeploymentException(MULTIPLE_INTERCEPTORS, interceptorsElements);
+ in.close();
}
- else if (interceptorsElements.size() == 1)
+ catch (IOException e)
{
- enabledInterceptorClasses = new ArrayList<Class<?>>();
- enabledInterceptorClasses.addAll(processInterceptorElement(resourceLoader, interceptorsElements.get(0)));
+ e.printStackTrace();
}
-
}
-
- private static void processPolicyElement(ResourceLoader resourceLoader, XmlElement element, List<Class<?>> enabledPolicyClasses, List<Class<? extends Annotation>> enabledPolicyStereotypes)
+
+ private boolean isBeansXmlOK(URL beansXml)
{
- for (Node child : new NodeListIterable(element.getElement().getChildNodes()))
+ InputStream in = null;
+ try
{
- String className = processNode(child);
- if (className != null)
- {
- try
- {
- Class<?> clazz = resourceLoader.classForName(className);
- if (clazz.isAnnotation())
- {
- enabledPolicyStereotypes.add(clazz.asSubclass(Annotation.class));
- }
- else
- {
- enabledPolicyClasses.add(clazz);
- }
- }
- catch (ResourceLoadingException e)
- {
- throw new DeploymentException(CANNOT_LOAD_CLASS, className, element.getFile());
- }
- }
+ in = beansXml.openStream();
+ return in.available() > 0;
}
- }
-
- private static String processNode(Node node)
- {
- if (node instanceof Element)
+ catch (IOException e)
{
- if (node.getChildNodes().getLength() == 1 && node.getChildNodes().item(0) instanceof Text)
- {
- String className = ((Text) node.getChildNodes().item(0)).getData();
- return className;
- }
+ throw new WeldXmlException(LOAD_ERROR, e, beansXml.toString());
}
- return null;
- }
-
- private static List<Class<?>> processElement(ResourceLoader resourceLoader, XmlElement element)
- {
- List<Class<?>> list = new ArrayList<Class<?>>();
- for (Node child : new NodeListIterable(element.getElement().getChildNodes()))
+ finally
{
- String className = processNode(child);
- if (className != null)
- {
- try
- {
- list.add(resourceLoader.classForName(className));
- }
- catch (ResourceLoadingException e)
- {
- throw new DeploymentException(CANNOT_LOAD_CLASS, className, element.getFile());
- }
- }
+ closeStream(in);
}
- return list;
}
-
- //TODO - move validation to Validator
- private static List<Class<?>> processInterceptorElement(ResourceLoader resourceLoader, XmlElement element)
+ private DocumentBuilder getDocumentBuilder()
{
- List<Class<?>> list = new ArrayList<Class<?>>();
- for (Node child : new NodeListIterable(element.getElement().getChildNodes()))
+ try
{
- String className = processNode(child);
- if (className != null)
- {
- try
- {
- Class<?> clazz = resourceLoader.classForName(className);
- list.add(clazz);
- }
- catch (ResourceLoadingException e)
- {
- throw new DeploymentException(CANNOT_LOAD_CLASS, className, element.getFile());
- }
- }
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder();
}
- return list;
+ catch (ParserConfigurationException e)
+ {
+ throw new WeldXmlException(CONFIGURATION_ERROR, e);
+ }
}
-
+
}
Added: core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2009-12-02 20:04:29 UTC (rev 5193)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.xml;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import org.jboss.weld.resources.spi.ResourceLoader;
+
+/**
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class EnabledClasses
+{
+ private List<Class<? extends Annotation>> enabledPolicyStereotypes;
+ private List<Class<?>> enabledPolicyClasses;
+ private List<Class<?>> enabledDecoratorClasses;
+ private List<Class<?>> enabledInterceptorClasses;
+ private ResourceLoader resourceLoader;
+
+ private EnabledClasses(MergedElements beanXmlElements, ResourceLoader resourceLoader)
+ {
+ enabledPolicyStereotypes = new ArrayList<Class<? extends Annotation>>();
+ enabledPolicyClasses = new ArrayList<Class<?>>();
+ enabledDecoratorClasses = new ArrayList<Class<?>>();
+ enabledInterceptorClasses = new ArrayList<Class<?>>();
+ this.resourceLoader = resourceLoader;
+ process(beanXmlElements);
+ }
+
+ public static EnabledClasses of(MergedElements beanXmlElements, ResourceLoader resourceLoader)
+ {
+ return new EnabledClasses(beanXmlElements, resourceLoader);
+ }
+
+ private void process(MergedElements beanXmlElements)
+ {
+ processPolicies(beanXmlElements.getPoliciesElements());
+ enabledDecoratorClasses.addAll(getClassesInElements(beanXmlElements.getDecoratorsElements()));
+ enabledInterceptorClasses.addAll(getClassesInElements(beanXmlElements.getInterceptorsElements()));
+ }
+
+ private void processPolicies(List<BeansXmlElement> policyElements)
+ {
+ Collection<Class<?>> classes = getClassesInElements(policyElements);
+ for (Class<?> clazz : classes) {
+ if (clazz.isAnnotation()) {
+ enabledPolicyStereotypes.add(clazz.asSubclass(Annotation.class));
+ } else {
+ enabledPolicyClasses.add(clazz);
+ }
+ }
+ }
+
+ private Collection<Class<?>> getClassesInElements(List<BeansXmlElement> elements)
+ {
+ LinkedHashSet<Class<?>> classes = new LinkedHashSet<Class<?>>();
+ for (BeansXmlElement element : elements)
+ {
+ classes.addAll(element.getClasses(resourceLoader));
+ }
+ return classes;
+ }
+
+ public List<Class<? extends Annotation>> getEnabledPolicyStereotypes()
+ {
+ return enabledPolicyStereotypes;
+ }
+
+ public List<Class<?>> getEnabledPolicyClasses()
+ {
+ return enabledPolicyClasses;
+ }
+
+ public List<Class<?>> getEnabledDecoratorClasses()
+ {
+ return enabledDecoratorClasses;
+ }
+
+ public List<Class<?>> getEnabledInterceptorClasses()
+ {
+ return enabledInterceptorClasses;
+ }
+}
Added: core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java 2009-12-02 20:04:29 UTC (rev 5193)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.xml;
+
+import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_ALTERNATIVES;
+import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_DECORATORS;
+import static org.jboss.weld.logging.messages.XmlMessage.MULTIPLE_INTERCEPTORS;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.weld.DeploymentException;
+import org.jboss.weld.logging.messages.XmlMessage;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class MergedElements
+{
+ private List<BeansXmlElement> policiesElements = new ArrayList<BeansXmlElement>();
+ private List<BeansXmlElement> decoratorsElements = new ArrayList<BeansXmlElement>();
+ private List<BeansXmlElement> interceptorsElements = new ArrayList<BeansXmlElement>();
+
+
+ public void merge(URL url, Document beansXmlDocument)
+ {
+ Element documentElement = beansXmlDocument.getDocumentElement();
+ policiesElements.addAll(getNamedElement(url, documentElement, "alternatives", MULTIPLE_ALTERNATIVES));
+ interceptorsElements.addAll(getNamedElement(url, documentElement, "interceptors", MULTIPLE_INTERCEPTORS));
+ decoratorsElements.addAll(getNamedElement(url, documentElement, "decorators", MULTIPLE_DECORATORS));
+ }
+
+ // TODO: look over exception message when multiple blocks or multiple
+ // classes. Now they're the same.
+ private List<BeansXmlElement> getNamedElement(URL url, Element beans, String name, XmlMessage multipleViolationMessage)
+ {
+ List<BeansXmlElement> elements = new ArrayList<BeansXmlElement>();
+ NodeList nodeList = beans.getElementsByTagName(name);
+ if (nodeList.getLength() > 1)
+ {
+ throw new DeploymentException(multipleViolationMessage);
+ }
+ else if (nodeList.getLength() == 1)
+ {
+ BeansXmlElement element = BeansXmlElement.of(url, nodeList.item(0)).validateWithMessage(multipleViolationMessage);
+ elements.add(element);
+ }
+ return elements;
+ }
+
+
+ public List<BeansXmlElement> getPoliciesElements()
+ {
+ return policiesElements;
+ }
+
+ public List<BeansXmlElement> getDecoratorsElements()
+ {
+ return decoratorsElements;
+ }
+
+ public List<BeansXmlElement> getInterceptorsElements()
+ {
+ return interceptorsElements;
+ }
+
+}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java 2009-12-02 14:59:26 UTC (rev 5192)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java 2009-12-02 20:04:29 UTC (rev 5193)
@@ -28,7 +28,7 @@
* support.
*
* @author David Allen
- *
+ *
*/
public class WeldXmlException extends InjectionException
{
15 years