Weld SVN: r6413 - in extensions/trunk/src: main/java/org/jboss/weld/extensions/managedproducer and 3 other directories.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-06-08 07:15:20 -0400 (Tue, 08 Jun 2010)
New Revision: 6413
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducer.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java
extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/
extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/BeanProducer.java
extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/MPType.java
extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedProducerTest.java
extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedReciever.java
extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedBean.java
extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedInterface.java
Modified:
extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Log:
bring back @ManagedProducer
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducer.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducer.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducer.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,13 @@
+package org.jboss.weld.extensions.managedproducer;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.METHOD)
+public @interface ManagedProducer
+{
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerBean.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,216 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.managedproducer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Named;
+
+/**
+ * Bean implementation that produces a JDK proxy
+ *
+ * when a method is invoked on the proxy it calls the managed producer method
+ * and invokes the method on the returned object
+ *
+ * @author stuart
+ *
+ * @param <M>
+ */
+public class ManagedProducerBean<M> implements Bean<M>
+{
+
+ final Class<?> beanClass;
+
+ final String name;
+
+ final Set<Annotation> qualifiers;
+
+ final Set<Type> types;
+
+ final Class<?> proxyClass;
+
+ final BeanManager manager;
+
+ final Constructor<?> proxyConstructor;
+
+
+ final AnnotatedMethod<?> method;
+
+ public ManagedProducerBean(AnnotatedMethod<?> method, BeanManager manager)
+ {
+ this.method = method;
+ beanClass = method.getDeclaringType().getJavaClass();
+ // get the name
+ if (method.isAnnotationPresent(Named.class))
+ {
+ name = method.getAnnotation(Named.class).value();
+ }
+ else
+ {
+ name = null;
+ }
+ // get the qualifiers
+ qualifiers = new HashSet<Annotation>();
+ for (Annotation a : method.getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ }
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(new AnnotationLiteral<Default>()
+ {
+ });
+ }
+ // get the bean types
+ types = new HashSet<Type>();
+ Set<Class<?>> interfaces = new HashSet<Class<?>>();
+ for (Type t : method.getTypeClosure())
+ {
+ if (t instanceof Class<?>)
+ {
+ Class<?> c = (Class<?>) t;
+ if (c.isInterface())
+ {
+ types.add(c);
+ interfaces.add(c);
+ }
+ }
+ else if (t instanceof ParameterizedType)
+ {
+ ParameterizedType p = (ParameterizedType) t;
+ Class<?> c = (Class<?>) p.getRawType();
+ if (c.isInterface())
+ {
+ types.add(t);
+ }
+ }
+ }
+ // build the properties
+ Class<?>[] iarray = new Class[interfaces.size()];
+ int count = 0;
+ this.manager = manager;
+ for (Class<?> c : interfaces)
+ {
+ iarray[count++] = c;
+ }
+ proxyClass = Proxy.getProxyClass(beanClass.getClassLoader(), iarray);
+ try
+ {
+ proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return beanClass;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return Collections.emptySet();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ /**
+ * the proxies that are injected all have Dependant scope
+ */
+ public Class<? extends Annotation> getScope()
+ {
+ return Dependent.class;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return Collections.emptySet();
+ }
+
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+ public boolean isAlternative()
+ {
+ return false;
+ }
+
+ public boolean isNullable()
+ {
+ return false;
+ }
+
+ public M create(CreationalContext<M> creationalContext)
+ {
+ Annotation[] quals = { new AnnotationLiteral<Default>()
+ {
+ } };
+ Set<Bean<?>> beans = manager.getBeans(InjectionPoint.class, quals);
+ Bean injectionPointBean = (Bean) beans.iterator().next();
+ InjectionPoint injectionPoint = (InjectionPoint) manager.getReference(injectionPointBean, InjectionPoint.class, creationalContext);
+ ManagedProducerInvocationHandler<?> hdl = new ManagedProducerInvocationHandler(manager, this.method, this, injectionPoint);
+ try
+ {
+ M obj = (M) proxyConstructor.newInstance(new Object[] { hdl });
+ creationalContext.push(obj);
+ return obj;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void destroy(M instance, CreationalContext<M> creationalContext)
+ {
+ creationalContext.release();
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerExtension.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.managedproducer;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+/**
+ * An extension that allows the use of @ManagedProducer methods
+ *
+ * these methods work in a similar manner to @Unwrap methods in seam 2
+ *
+ * @author stuart
+ *
+ */
+public class ManagedProducerExtension implements Extension
+{
+
+ Set<ManagedProducerBean<?>> beans = new HashSet<ManagedProducerBean<?>>();
+
+ public void processAnnotatedType(@Observes ProcessAnnotatedType<?> type, BeanManager manager)
+ {
+ for (AnnotatedMethod<?> m : type.getAnnotatedType().getMethods())
+ {
+ if (m.isAnnotationPresent(ManagedProducer.class))
+ {
+ // we have a managed producer
+ // lets make a not of it and register it later
+
+ beans.add(new ManagedProducerBean(m, manager));
+ }
+ }
+ }
+
+ public void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBean)
+ {
+ for (ManagedProducerBean<?> b : beans)
+ {
+ afterBean.addBean(b);
+ }
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/managedproducer/ManagedProducerInvocationHandler.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.managedproducer;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.AmbiguousResolutionException;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.weld.extensions.bean.InjectionPointImpl;
+
+public class ManagedProducerInvocationHandler<T> implements InvocationHandler
+{
+
+ final BeanManager manager;
+ final AnnotatedMethod<?> annotatedMethod;
+ final Method method;
+ final Bean<?> bean;
+ final InjectionPoint[] injectionPoints;
+ final Map<Method, Method> methods = Collections.synchronizedMap(new HashMap<Method, Method>());
+ final Bean<?> mainClassBean;
+ final InjectionPoint injectionPoint;
+
+
+ public ManagedProducerInvocationHandler(BeanManager manager, AnnotatedMethod<?> method, Bean<?> bean, InjectionPoint injectionPoint)
+ {
+ this.manager = manager;
+ this.method = method.getJavaMember();
+ this.annotatedMethod = method;
+ this.bean = bean;
+ injectionPoints = new InjectionPoint[this.method.getTypeParameters().length];
+ for (int i = 0; i < injectionPoints.length; ++i)
+ {
+ injectionPoints[i] = new InjectionPointImpl(method.getParameters().get(i), manager, bean, false, false);
+ }
+ Type mainType = method.getDeclaringType().getBaseType();
+ HashSet<Annotation> mainClassQualifiers = new HashSet<Annotation>();
+ for (Annotation a : method.getDeclaringType().getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ mainClassQualifiers.add(a);
+ }
+ }
+ Set<Bean<?>> beans = manager.getBeans(mainType, mainClassQualifiers.toArray(new Annotation[0]));
+ if (beans.isEmpty())
+ {
+ throw new UnsatisfiedResolutionException("could not find declaring bean for managed producer method " + method.getDeclaringType().getJavaClass() + "." + this.method.getName());
+ }
+ else if (beans.size() > 1)
+ {
+ throw new AmbiguousResolutionException("could not find declaring bean for managed producer method " + method.getDeclaringType().getJavaClass() + "." + this.method.getName());
+ }
+ mainClassBean = beans.iterator().next();
+ this.injectionPoint = injectionPoint;
+ }
+
+ public Object invoke(Object proxy, Method m, Object[] args) throws Throwable
+ {
+ CreationalContext<?> ctx = manager.createCreationalContext(bean);
+ Object[] params = new Object[method.getParameterTypes().length];
+ for (int i = 0; i < this.method.getParameterTypes().length; ++i)
+ {
+ if (InjectionPoint.class.isAssignableFrom(this.method.getParameterTypes()[i]))
+ {
+ params[i] = injectionPoint;
+ }
+ else
+ {
+ params[i] = manager.getInjectableReference(injectionPoints[i], ctx);
+ }
+ }
+ Object base = manager.getReference(mainClassBean, annotatedMethod.getDeclaringType().getJavaClass(), ctx);
+
+ Object result = method.invoke(base, params);
+ Object ret = m.invoke(result, args);
+ ctx.release();
+ return ret;
+ }
+
+}
Modified: extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-06-08 06:15:09 UTC (rev 6412)
+++ extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-06-08 11:15:20 UTC (rev 6413)
@@ -2,4 +2,5 @@
org.jboss.weld.extensions.resourceLoader.servlet.ServletResourceExtension
org.jboss.weld.extensions.bean.lookup.IdentifiableBeanExtension
org.jboss.weld.extensions.core.CoreExtension
-org.jboss.weld.extensions.interceptor.InterceptorExtension
\ No newline at end of file
+org.jboss.weld.extensions.interceptor.InterceptorExtension
+org.jboss.weld.extensions.managedproducer.ManagedProducerExtension
\ No newline at end of file
Added: extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/BeanProducer.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/BeanProducer.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/BeanProducer.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.test.managedproducer;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.weld.extensions.managedproducer.ManagedProducer;
+
+public class BeanProducer
+{
+ @ManagedProducer
+ public ProducedInterface produce(InjectionPoint injectionPoint)
+ {
+ ProducedBean b = new ProducedBean();
+ b.setValue(injectionPoint.getAnnotated().getAnnotation(MPType.class).value());
+ return b;
+ }
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/MPType.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/MPType.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/MPType.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.test.managedproducer;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface MPType
+{
+ String value();
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedProducerTest.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedProducerTest.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedProducerTest.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.test.managedproducer;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+@Artifact
+public class ManagedProducerTest extends AbstractWeldTest
+{
+ @Test
+ public void testManagedProducers()
+ {
+ ManagedReciever bean = getReference(ManagedReciever.class);
+ assert bean.bean1.getValue().equals("bean1") : " value: " + bean.bean1.getValue();
+ assert bean.bean2.getValue().equals("bean2") : " value: " + bean.bean1.getValue();
+ }
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedReciever.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedReciever.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ManagedReciever.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.test.managedproducer;
+
+import javax.inject.Inject;
+
+public class ManagedReciever
+{
+ @MPType("bean1")
+ @Inject
+ ProducedInterface bean1;
+
+ @MPType("bean2")
+ @Inject
+ ProducedInterface bean2;
+
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedBean.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedBean.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedBean.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.test.managedproducer;
+
+import org.jboss.weld.extensions.core.Veto;
+
+@Veto
+public class ProducedBean implements ProducedInterface
+{
+ String value = "wrong";
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+}
Added: extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedInterface.java
===================================================================
--- extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedInterface.java (rev 0)
+++ extensions/trunk/src/test/java/org/jboss/weld/extensions/test/managedproducer/ProducedInterface.java 2010-06-08 11:15:20 UTC (rev 6413)
@@ -0,0 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.extensions.test.managedproducer;
+
+public interface ProducedInterface
+{
+
+ public abstract String getValue();
+
+}
\ No newline at end of file
14 years, 7 months
Weld SVN: r6412 - in core/trunk/tests/src/test/java/org/jboss/weld/tests/producer: method and 1 other directory.
by weld-commits@lists.jboss.org
Author: marius.bogoevici
Date: 2010-06-08 02:15:09 -0400 (Tue, 08 Jun 2010)
New Revision: 6412
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java
Log:
Mark WELD-546 tests as broken. They currently fail both locally and in Hudson.
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java 2010-06-07 21:15:51 UTC (rev 6411)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java 2010-06-08 06:15:09 UTC (rev 6412)
@@ -34,7 +34,7 @@
@Artifact
public class ProducerBeanInvocationTest extends AbstractWeldTest
{
- @Test
+ @Test(groups = "broken")
// WELD-546
public void test()
{
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java 2010-06-07 21:15:51 UTC (rev 6411)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java 2010-06-08 06:15:09 UTC (rev 6412)
@@ -34,7 +34,7 @@
@Artifact
public class ProducerBeanInvocationTest extends AbstractWeldTest
{
- @Test
+ @Test(groups = "broken")
// WELD-546
public void test()
{
14 years, 7 months
Weld SVN: r6411 - api/trunk/cdi and 5 other directories.
by weld-commits@lists.jboss.org
Author: marius.bogoevici
Date: 2010-06-07 17:15:51 -0400 (Mon, 07 Jun 2010)
New Revision: 6411
Modified:
api/trunk/bom/pom.xml
api/trunk/cdi/pom.xml
api/trunk/weld-spi/pom.xml
cdi-tck/trunk/impl/pom.xml
cdi-tck/trunk/pom.xml
core/trunk/impl/pom.xml
core/trunk/tests/pom.xml
Log:
replace jboss-interceptor-api with org.jboss.spec.javax.interceptor
Modified: api/trunk/bom/pom.xml
===================================================================
--- api/trunk/bom/pom.xml 2010-06-07 11:35:19 UTC (rev 6410)
+++ api/trunk/bom/pom.xml 2010-06-07 21:15:51 UTC (rev 6411)
@@ -86,7 +86,7 @@
<!-- Stick with JSF API 1.2 to preserve backwards compatibility with JSF 1.2 - we don't need any JSF 2 features -->
<jsf.api.version>1.2_13</jsf.api.version>
<jaxws.api.version>2.1</jaxws.api.version>
- <interceptor.api.version>1.1</interceptor.api.version>
+ <interceptor.api.version>1.0.0.Beta1</interceptor.api.version>
</properties>
<dependencyManagement>
@@ -187,8 +187,8 @@
the JCP/Sun publish this
-->
<dependency>
- <groupId>org.jboss.interceptor</groupId>
- <artifactId>jboss-interceptor-api</artifactId>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
<version>${interceptor.api.version}</version>
</dependency>
Modified: api/trunk/cdi/pom.xml
===================================================================
--- api/trunk/cdi/pom.xml 2010-06-07 11:35:19 UTC (rev 6410)
+++ api/trunk/cdi/pom.xml 2010-06-07 21:15:51 UTC (rev 6411)
@@ -40,8 +40,8 @@
</dependency>
<dependency>
- <groupId>org.jboss.interceptor</groupId>
- <artifactId>jboss-interceptor-api</artifactId>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
</dependency>
<dependency>
Modified: api/trunk/weld-spi/pom.xml
===================================================================
--- api/trunk/weld-spi/pom.xml 2010-06-07 11:35:19 UTC (rev 6410)
+++ api/trunk/weld-spi/pom.xml 2010-06-07 21:15:51 UTC (rev 6411)
@@ -81,8 +81,8 @@
</dependency>
<dependency>
- <groupId>org.jboss.interceptor</groupId>
- <artifactId>jboss-interceptor-api</artifactId>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
<optional>true</optional>
</dependency>
Modified: cdi-tck/trunk/impl/pom.xml
===================================================================
--- cdi-tck/trunk/impl/pom.xml 2010-06-07 11:35:19 UTC (rev 6410)
+++ cdi-tck/trunk/impl/pom.xml 2010-06-07 21:15:51 UTC (rev 6411)
@@ -66,8 +66,8 @@
</dependency>
<dependency>
- <groupId>org.jboss.interceptor</groupId>
- <artifactId>jboss-interceptor-api</artifactId>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
</dependency>
<dependency>
Modified: cdi-tck/trunk/pom.xml
===================================================================
--- cdi-tck/trunk/pom.xml 2010-06-07 11:35:19 UTC (rev 6410)
+++ cdi-tck/trunk/pom.xml 2010-06-07 21:15:51 UTC (rev 6411)
@@ -92,7 +92,7 @@
<uel.api.version>2.1.2-b04</uel.api.version>
<jsf.api.version>1.2_13</jsf.api.version>
<jaxws.api.version>2.1</jaxws.api.version>
- <interceptor.api.version>1.1</interceptor.api.version>
+ <interceptor.api.version>1.0.0.Beta1</interceptor.api.version>
<jws.api.version>1.0-MR1</jws.api.version>
<apache.httpclient.version>3.1</apache.httpclient.version>
<htmlunit.version>2.4</htmlunit.version>
@@ -248,8 +248,8 @@
</dependency>
<dependency>
- <groupId>org.jboss.interceptor</groupId>
- <artifactId>jboss-interceptor-api</artifactId>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
<version>${interceptor.api.version}</version>
</dependency>
Modified: core/trunk/impl/pom.xml
===================================================================
--- core/trunk/impl/pom.xml 2010-06-07 11:35:19 UTC (rev 6410)
+++ core/trunk/impl/pom.xml 2010-06-07 21:15:51 UTC (rev 6411)
@@ -103,8 +103,8 @@
</dependency>
<dependency>
- <groupId>org.jboss.interceptor</groupId>
- <artifactId>jboss-interceptor-api</artifactId>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
</dependency>
<dependency>
Modified: core/trunk/tests/pom.xml
===================================================================
--- core/trunk/tests/pom.xml 2010-06-07 11:35:19 UTC (rev 6410)
+++ core/trunk/tests/pom.xml 2010-06-07 21:15:51 UTC (rev 6411)
@@ -78,8 +78,8 @@
</dependency>
<dependency>
- <groupId>org.jboss.interceptor</groupId>
- <artifactId>jboss-interceptor-api</artifactId>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
</dependency>
<dependency>
14 years, 7 months
Weld SVN: r6410 - in core/trunk/tests/src/test/java/org/jboss/weld/tests/producer: field/named and 1 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-07 07:35:19 -0400 (Mon, 07 Jun 2010)
New Revision: 6410
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Baz.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Qux.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/QuxProducer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Baz.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Qux.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/QuxProducer.java
Removed:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java
Log:
alter tests to reproduce issue
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Baz.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Baz.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Baz.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -0,0 +1,13 @@
+package org.jboss.weld.tests.producer.field;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface Baz
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Baz.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.tests.producer.field;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+/**
+ * Simple test which invokes a method directly on a normal scoped producer
+ * bean to ensure that it's proxy is for that bean and not the product
+ * of a producer method.
+ *
+ * @author David Allen
+ *
+ */
+@Artifact
+public class ProducerBeanInvocationTest extends AbstractWeldTest
+{
+ @Test
+ // WELD-546
+ public void test()
+ {
+ Qux bar = getReference(Qux.class);
+ assert bar.getBar().equals("qux");
+ QuxProducer producer = getReference(QuxProducer.class);
+ assert producer.ping();
+ Qux bazBar = getReference(Qux.class, new AnnotationLiteral<Baz>(){});
+ assert bazBar.getBar().equals("baz");
+ }
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/ProducerBeanInvocationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Qux.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Qux.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Qux.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -0,0 +1,26 @@
+package org.jboss.weld.tests.producer.field;
+
+import javax.enterprise.context.RequestScoped;
+
+@RequestScoped
+public class Qux
+{
+
+ private final String name;
+
+ public Qux(String name)
+ {
+ this.name = name;
+ }
+
+ public Qux()
+ {
+ this("qux");
+ }
+
+ public String getBar()
+ {
+ return name;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/Qux.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/QuxProducer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/QuxProducer.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/QuxProducer.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -0,0 +1,18 @@
+package org.jboss.weld.tests.producer.field;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+
+@RequestScoped
+public class QuxProducer
+{
+
+ @Produces @Baz @RequestScoped
+ private Qux bar = new Qux("baz");
+
+ public boolean ping()
+ {
+ return true;
+ };
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/QuxProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java 2010-06-06 20:24:34 UTC (rev 6409)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -33,6 +33,4 @@
{
System.out.println("new user's name: " + newUser.getName());
}
-
- public boolean ping() { return true; }
}
\ No newline at end of file
Deleted: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java 2010-06-06 20:24:34 UTC (rev 6409)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.tests.producer.field.named;
-
-import org.jboss.testharness.impl.packaging.Artifact;
-import org.jboss.weld.test.AbstractWeldTest;
-import org.testng.annotations.Test;
-
-/**
- * Simple test which invokes a method directly on a normal scoped producer
- * bean to ensure that it's proxy is for that bean and not the product
- * of a producer method.
- *
- * @author David Allen
- *
- */
-@Artifact
-public class ProducerBeanInvocationTest extends AbstractWeldTest
-{
- @Test
- // WELD-546
- public void test()
- {
- NewUserAction userAction = this.getReference(NewUserAction.class);
- assert userAction.ping();
- }
-}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Baz.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Baz.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Baz.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -0,0 +1,13 @@
+package org.jboss.weld.tests.producer.method;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface Baz
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Baz.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java 2010-06-06 20:24:34 UTC (rev 6409)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -17,14 +17,12 @@
package org.jboss.weld.tests.producer.method;
import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
/**
* @author pmuir
*
*/
-@Model
public class FooProducer
{
@@ -53,6 +51,4 @@
return disposed;
}
- public boolean ping() { return true; }
-
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java 2010-06-06 20:24:34 UTC (rev 6409)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -17,6 +17,8 @@
package org.jboss.weld.tests.producer.method;
+import javax.enterprise.util.AnnotationLiteral;
+
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;
@@ -36,7 +38,11 @@
// WELD-546
public void test()
{
- FooProducer fooProducer = this.getReference(FooProducer.class);
- assert fooProducer.ping();
+ Qux bar = getReference(Qux.class);
+ assert bar.getBar().equals("qux");
+ QuxProducer producer = getReference(QuxProducer.class);
+ assert producer.ping();
+ Qux bazBar = getReference(Qux.class, new AnnotationLiteral<Baz>(){});
+ assert bazBar.getBar().equals("baz");
}
}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Qux.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Qux.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Qux.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -0,0 +1,26 @@
+package org.jboss.weld.tests.producer.method;
+
+import javax.enterprise.context.RequestScoped;
+
+@RequestScoped
+public class Qux
+{
+
+ private final String name;
+
+ public Qux(String name)
+ {
+ this.name = name;
+ }
+
+ public Qux()
+ {
+ this("qux");
+ }
+
+ public String getBar()
+ {
+ return name;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/Qux.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/QuxProducer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/QuxProducer.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/QuxProducer.java 2010-06-07 11:35:19 UTC (rev 6410)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.producer.method;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+
+@RequestScoped
+public class QuxProducer
+{
+
+ @Produces @Baz @RequestScoped
+ public Qux getQux()
+ {
+ return new Qux("baz");
+ }
+
+ public boolean ping()
+ {
+ return true;
+ };
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/QuxProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
14 years, 7 months
Weld SVN: r6409 - in core/trunk/tests/src/test/java/org/jboss/weld/tests/producer: method and 1 other directory.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-06-06 16:24:34 -0400 (Sun, 06 Jun 2010)
New Revision: 6409
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java
Log:
WELD-546 Tests
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java 2010-06-05 20:33:48 UTC (rev 6408)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/NewUserAction.java 2010-06-06 20:24:34 UTC (rev 6409)
@@ -33,4 +33,6 @@
{
System.out.println("new user's name: " + newUser.getName());
}
+
+ public boolean ping() { return true; }
}
\ No newline at end of file
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java 2010-06-06 20:24:34 UTC (rev 6409)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.tests.producer.field.named;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+/**
+ * Simple test which invokes a method directly on a normal scoped producer
+ * bean to ensure that it's proxy is for that bean and not the product
+ * of a producer method.
+ *
+ * @author David Allen
+ *
+ */
+@Artifact
+public class ProducerBeanInvocationTest extends AbstractWeldTest
+{
+ @Test
+ // WELD-546
+ public void test()
+ {
+ NewUserAction userAction = this.getReference(NewUserAction.class);
+ assert userAction.ping();
+ }
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/field/named/ProducerBeanInvocationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java 2010-06-05 20:33:48 UTC (rev 6408)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/FooProducer.java 2010-06-06 20:24:34 UTC (rev 6409)
@@ -17,12 +17,14 @@
package org.jboss.weld.tests.producer.method;
import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
/**
* @author pmuir
*
*/
+@Model
public class FooProducer
{
@@ -51,4 +53,6 @@
return disposed;
}
+ public boolean ping() { return true; }
+
}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java 2010-06-06 20:24:34 UTC (rev 6409)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.tests.producer.method;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+/**
+ * Simple test which invokes a method directly on a normal scoped producer
+ * bean to ensure that it's proxy is for that bean and not the product
+ * of a producer method.
+ *
+ * @author David Allen
+ *
+ */
+@Artifact
+public class ProducerBeanInvocationTest extends AbstractWeldTest
+{
+ @Test
+ // WELD-546
+ public void test()
+ {
+ FooProducer fooProducer = this.getReference(FooProducer.class);
+ assert fooProducer.ping();
+ }
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/producer/method/ProducerBeanInvocationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 7 months
Weld SVN: r6408 - in core/trunk: impl/src/main/java/org/jboss/weld/manager and 6 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-05 16:33:48 -0400 (Sat, 05 Jun 2010)
New Revision: 6408
Added:
core/trunk/impl/src/main/java/org/jboss/weld/manager/EnabledClasses.java
Removed:
core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java
core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeInterceptorResolver.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java
Log:
use EnabledClasses throughout Weld to simplify BeanManagerImpl
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 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -71,9 +71,9 @@
services.addAll(deploymentServices.entrySet());
services.addAll(beanDeploymentArchive.getServices().entrySet());
this.beanManager = BeanManagerImpl.newManager(deploymentManager, beanDeploymentArchive.getId(), services, new BeansXmlParser(services.get(ResourceLoader.class), beanDeploymentArchive.getBeansXml()).parse());
- 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());
+ log.debug(ENABLED_ALTERNATIVES, this.beanManager, beanManager.getEnabledClasses().getAlternativeClasses(), beanManager.getEnabledClasses().getAlternativeStereotypes());
+ log.debug(ENABLED_DECORATORS, this.beanManager, beanManager.getEnabledClasses().getDecorators());
+ log.debug(ENABLED_INTERCEPTORS, this.beanManager, beanManager.getEnabledClasses().getInterceptors());
if (beanManager.getServices().contains(EjbServices.class))
{
// Must populate EJB cache first, as we need it to detect whether a
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -18,7 +18,6 @@
import static org.jboss.weld.logging.Category.BOOTSTRAP;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
-import static org.jboss.weld.logging.messages.ValidatorMessage.SCOPE_ANNOTATION_ON_INJECTION_POINT;
import static org.jboss.weld.logging.messages.ValidatorMessage.ALTERNATIVE_BEAN_CLASS_NOT_ANNOTATED;
import static org.jboss.weld.logging.messages.ValidatorMessage.ALTERNATIVE_BEAN_CLASS_SPECIFIED_MULTIPLE_TIMES;
import static org.jboss.weld.logging.messages.ValidatorMessage.ALTERNATIVE_STEREOTYPE_NOT_ANNOTATED;
@@ -52,6 +51,7 @@
import static org.jboss.weld.logging.messages.ValidatorMessage.NON_SERIALIZABLE_BEAN_INJECTED_INTO_PASSIVATING_BEAN;
import static org.jboss.weld.logging.messages.ValidatorMessage.PASSIVATING_BEAN_WITH_NONSERIALIZABLE_DECORATOR;
import static org.jboss.weld.logging.messages.ValidatorMessage.PASSIVATING_BEAN_WITH_NONSERIALIZABLE_INTERCEPTOR;
+import static org.jboss.weld.logging.messages.ValidatorMessage.SCOPE_ANNOTATION_ON_INJECTION_POINT;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
@@ -471,9 +471,9 @@
{
interceptorBeanClasses.add(interceptor.getBeanClass());
}
- for (Class<?> enabledInterceptorClass : beanManager.getEnabledInterceptorClasses())
+ for (Class<?> enabledInterceptorClass : beanManager.getEnabledClasses().getInterceptors())
{
- if (beanManager.getEnabledInterceptorClasses().indexOf(enabledInterceptorClass) < beanManager.getEnabledInterceptorClasses().lastIndexOf(enabledInterceptorClass))
+ if (beanManager.getEnabledClasses().getInterceptors().indexOf(enabledInterceptorClass) < beanManager.getEnabledClasses().getInterceptors().lastIndexOf(enabledInterceptorClass))
{
throw new DeploymentException(INTERCEPTOR_SPECIFIED_TWICE, enabledInterceptorClass + " specified twice");
}
@@ -492,9 +492,9 @@
{
decoratorBeanClasses.add(bean.getBeanClass());
}
- for (Class<?> clazz : beanManager.getEnabledDecoratorClasses())
+ for (Class<?> clazz : beanManager.getEnabledClasses().getDecorators())
{
- if (beanManager.getEnabledDecoratorClasses().indexOf(clazz) < beanManager.getEnabledDecoratorClasses().lastIndexOf(clazz))
+ if (beanManager.getEnabledClasses().getDecorators().indexOf(clazz) < beanManager.getEnabledClasses().getDecorators().lastIndexOf(clazz))
{
throw new DeploymentException(DECORATOR_SPECIFIED_TWICE, clazz);
}
@@ -508,7 +508,7 @@
private void validateEnabledAlternatives(BeanManagerImpl beanManager)
{
List<Class<?>> seenAlternatives = new ArrayList<Class<?>>();
- for (Class<? extends Annotation> stereotype : beanManager.getEnabledAlternativeStereotypes())
+ for (Class<? extends Annotation> stereotype : beanManager.getEnabledClasses().getAlternativeStereotypes())
{
if (!stereotype.isAnnotationPresent(Alternative.class))
{
@@ -520,7 +520,7 @@
}
seenAlternatives.add(stereotype);
}
- for (Class<?> clazz : beanManager.getEnabledAlternativeClasses())
+ for (Class<?> clazz : beanManager.getEnabledClasses().getAlternativeClasses())
{
if (!clazz.isAnnotationPresent(Alternative.class))
{
@@ -571,7 +571,7 @@
{
if (ij.getBean() instanceof Decorator<?>)
{
- if (beanManager.getEnabledDecoratorClasses().contains(ij.getBean().getBeanClass()))
+ if (beanManager.getEnabledClasses().getDecorators().contains(ij.getBean().getBeanClass()))
{
return resolvedBeans.size() > 0;
}
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 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -78,6 +78,7 @@
import org.jboss.weld.jsf.JsfApiAbstraction;
import org.jboss.weld.logging.messages.VersionMessage;
import org.jboss.weld.manager.BeanManagerImpl;
+import org.jboss.weld.manager.EnabledClasses;
import org.jboss.weld.metadata.TypeStore;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.persistence.PersistenceApiAbstraction;
@@ -98,7 +99,6 @@
import org.jboss.weld.util.serviceProvider.DefaultServiceLoaderFactory;
import org.jboss.weld.util.serviceProvider.ServiceLoaderFactory;
import org.jboss.weld.ws.WSApiAbstraction;
-import org.jboss.weld.xml.EnabledClasses;
import org.slf4j.cal10n.LocLogger;
/**
Modified: core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -116,7 +116,6 @@
import org.jboss.weld.util.collections.IterableToIteratorFunction;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.Reflections;
-import org.jboss.weld.xml.EnabledClasses;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
@@ -466,43 +465,24 @@
*/
public Collection<Class<?>> getEnabledAlternativeClasses()
{
- return getEnabledClasses().getEnabledAlternativeClasses();
+ return getEnabledClasses().getAlternativeClasses();
}
/**
- * @return the enabled alternative stereotypes
+ * Enabled Alternatives, Interceptors and Decorators
+ *
+ * @return
*/
- public Collection<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
+ public EnabledClasses getEnabledClasses()
{
- return getEnabledClasses().getEnabledAlternativeStereotypes();
- }
-
- private EnabledClasses getEnabledClasses()
- {
return enabledClasses;
}
public boolean isBeanEnabled(Bean<?> bean)
{
- return Beans.isBeanEnabled(bean, getEnabledAlternativeClasses(), getEnabledAlternativeStereotypes());
+ return Beans.isBeanEnabled(bean, getEnabledClasses().getAlternativeClasses(), getEnabledClasses().getAlternativeStereotypes());
}
-
- /**
- * @return the enabledDecoratorClasses
- */
- public List<Class<?>> getEnabledDecoratorClasses()
- {
- return getEnabledClasses().getEnabledDecoratorClasses();
- }
- /**
- * @return the enabledInterceptorClasses
- */
- public List<Class<?>> getEnabledInterceptorClasses()
- {
- return getEnabledClasses().getEnabledInterceptorClasses();
- }
-
public Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
{
return beanResolver.resolve(new ResolvableBuilder(beanType).addQualifiers(qualifiers).create());
@@ -860,7 +840,7 @@
{
StringBuilder buffer = new StringBuilder();
buffer.append("Manager\n");
- buffer.append("Enabled alternatives: " + getEnabledAlternativeClasses() + " " + getEnabledAlternativeStereotypes() + "\n");
+ buffer.append("Enabled alternatives: " + getEnabledClasses().getAlternativeClasses() + " " + getEnabledClasses().getAlternativeStereotypes() + "\n");
buffer.append("Registered contexts: " + contexts.keySet() + "\n");
buffer.append("Registered beans: " + getBeans().size() + "\n");
buffer.append("Specialized beans: " + specializedBeans.size() + "\n");
Copied: core/trunk/impl/src/main/java/org/jboss/weld/manager/EnabledClasses.java (from rev 6407, core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java)
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/EnabledClasses.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/EnabledClasses.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., 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.manager;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ *
+ * @author Nicklas Karlsson
+ *
+ */
+public class EnabledClasses
+{
+
+ private final List<Class<? extends Annotation>> alternativeStereotypes;
+ private final List<Class<?>> alternativeClasses;
+ private final List<Class<?>> decorators;
+ private final List<Class<?>> interceptors;
+
+ public EnabledClasses()
+ {
+ this.alternativeClasses = Collections.emptyList();
+ this.alternativeStereotypes = Collections.emptyList();
+ this.decorators = Collections.emptyList();
+ this.interceptors = Collections.emptyList();
+ }
+
+ public EnabledClasses(List<Class<? extends Annotation>> alternativeStereotypes, List<Class<?>> alternativeClasses, List<Class<?>> decorators, List<Class<?>> interceptors)
+ {
+ this.alternativeStereotypes = new ArrayList<Class<? extends Annotation>>(alternativeStereotypes);
+ this.alternativeClasses = new ArrayList<Class<?>>(alternativeClasses);
+ this.decorators = new ArrayList<Class<?>>(decorators);
+ this.interceptors = new ArrayList<Class<?>>(interceptors);
+ }
+
+ public List<Class<? extends Annotation>> getAlternativeStereotypes()
+ {
+ return Collections.unmodifiableList(alternativeStereotypes);
+ }
+
+ public List<Class<?>> getAlternativeClasses()
+ {
+ return Collections.unmodifiableList(alternativeClasses);
+ }
+
+ public List<Class<?>> getDecorators()
+ {
+ return Collections.unmodifiableList(decorators);
+ }
+
+ public List<Class<?>> getInterceptors()
+ {
+ return Collections.unmodifiableList(interceptors);
+ }
+}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeDecoratorResolver.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -45,7 +45,7 @@
{
return Reflections.matches(Collections.singleton(bean.getDelegateType()), resolvable.getTypes())
&& Beans.containsAllBindings(bean.getDelegateQualifiers(), resolvable.getQualifiers(), getBeanManager())
- && getBeanManager().getEnabledDecoratorClasses().contains(bean.getBeanClass());
+ && getBeanManager().getEnabledClasses().getDecorators().contains(bean.getBeanClass());
}
@Override
@@ -56,7 +56,7 @@
public int compare(Decorator<?> o1, Decorator<?> o2)
{
- List<Class<?>> enabledDecorators = getBeanManager().getEnabledDecoratorClasses();
+ List<Class<?>> enabledDecorators = getBeanManager().getEnabledClasses().getDecorators();
int p1 = enabledDecorators.indexOf(((Decorator<?>) o1).getBeanClass());
int p2 = enabledDecorators.indexOf(((Decorator<?>) o2).getBeanClass());
return p1 - p2;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeInterceptorResolver.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeInterceptorResolver.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/resolution/TypeSafeInterceptorResolver.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -18,7 +18,6 @@
package org.jboss.weld.resolution;
import java.util.Comparator;
-import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@@ -45,7 +44,7 @@
@Override
protected boolean matches(InterceptorResolvable resolvable, Interceptor<?> bean)
{
- return bean.intercepts(resolvable.getInterceptionType()) && bean.getInterceptorBindings().size() > 0 && Beans.containsAllInterceptionBindings(bean.getInterceptorBindings(), resolvable.getQualifiers(), getManager()) && getManager().getEnabledInterceptorClasses().contains(bean.getBeanClass());
+ return bean.intercepts(resolvable.getInterceptionType()) && bean.getInterceptorBindings().size() > 0 && Beans.containsAllInterceptionBindings(bean.getInterceptorBindings(), resolvable.getQualifiers(), getManager()) && getManager().getEnabledClasses().getInterceptors().contains(bean.getBeanClass());
}
@Override
@@ -56,9 +55,8 @@
public int compare(Interceptor<?> o1, Interceptor<?> o2)
{
- List<Class<?>> enabledInterceptors = getManager().getEnabledInterceptorClasses();
- int p1 = enabledInterceptors.indexOf(((InterceptorImpl<?>) o1).getType());
- int p2 = enabledInterceptors.indexOf(((InterceptorImpl<?>) o2).getType());
+ int p1 = getManager().getEnabledClasses().getInterceptors().indexOf(((InterceptorImpl<?>) o1).getType());
+ int p2 = getManager().getEnabledClasses().getInterceptors().indexOf(((InterceptorImpl<?>) o2).getType());
return p1 - p2;
}
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 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Beans.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -591,7 +591,7 @@
Set<T> result = new HashSet<T>();
for (T bean : beans)
{
- if (isBeanEnabled(bean, beanManager.getEnabledAlternativeClasses(), beanManager.getEnabledAlternativeStereotypes()) && !isSpecialized(bean, beans, beanManager))
+ if (isBeanEnabled(bean, beanManager.getEnabledClasses().getAlternativeClasses(), beanManager.getEnabledClasses().getAlternativeStereotypes()) && !isSpecialized(bean, beans, beanManager))
{
result.add(bean);
}
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 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -22,12 +22,16 @@
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;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.jboss.weld.manager.EnabledClasses;
import org.jboss.weld.resources.spi.ResourceLoader;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@@ -73,7 +77,33 @@
}
}
- return new EnabledClasses(resourceLoader, mergedElements);
+ List<Class<?>> enabledAlternativeClasses = new ArrayList<Class<?>>();
+ List<Class<? extends Annotation>> enabledAlternativeStereotypes = new ArrayList<Class<? extends Annotation>>();
+ List<Class<?>> enabledDecoratorClasses = new ArrayList<Class<?>>();
+ List<Class<?>> enabledInterceptorClasses = new ArrayList<Class<?>>();
+ for (BeansXmlElement element : mergedElements.getAlternativesElements())
+ {
+ for (Class<?> clazz : element.getClasses(resourceLoader))
+ {
+ if (clazz.isAnnotation())
+ {
+ enabledAlternativeStereotypes.add(clazz.asSubclass(Annotation.class));
+ }
+ else
+ {
+ enabledAlternativeClasses.add(clazz);
+ }
+ }
+ }
+ for (BeansXmlElement element : mergedElements.getDecoratorsElements())
+ {
+ enabledDecoratorClasses.addAll(element.getClasses(resourceLoader));
+ }
+ for (BeansXmlElement element : mergedElements.getInterceptorsElements())
+ {
+ enabledInterceptorClasses.addAll(element.getClasses(resourceLoader));
+ }
+ return new EnabledClasses(enabledAlternativeStereotypes, enabledAlternativeClasses, enabledDecoratorClasses, enabledInterceptorClasses);
}
private Document loadDocument(DocumentBuilder documentBuilder, URL beansXml)
Deleted: core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat, Inc., 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.Collections;
-import java.util.List;
-
-import org.jboss.weld.resources.spi.ResourceLoader;
-
-/**
- *
- * @author Nicklas Karlsson
- *
- */
-public class EnabledClasses
-{
-
- private final List<Class<? extends Annotation>> enabledAlternativeStereotypes;
- private final List<Class<?>> enabledAlternativeClasses;
- private final List<Class<?>> enabledDecoratorClasses;
- private final List<Class<?>> enabledInterceptorClasses;
-
- public EnabledClasses()
- {
- this.enabledAlternativeClasses = new ArrayList<Class<?>>();
- this.enabledAlternativeStereotypes = new ArrayList<Class<? extends Annotation>>();
- this.enabledDecoratorClasses = new ArrayList<Class<?>>();
- this.enabledInterceptorClasses = new ArrayList<Class<?>>();
- }
-
- EnabledClasses(ResourceLoader resourceLoader, MergedElements beanXmlElements)
- {
- this();
- for (BeansXmlElement element : beanXmlElements.getAlternativesElements())
- {
- for (Class<?> clazz : element.getClasses(resourceLoader))
- {
- if (clazz.isAnnotation())
- {
- this.enabledAlternativeStereotypes.add(clazz.asSubclass(Annotation.class));
- }
- else
- {
- this.enabledAlternativeClasses.add(clazz);
- }
- }
- }
- for (BeansXmlElement element : beanXmlElements.getDecoratorsElements())
- {
- this.enabledDecoratorClasses.addAll(element.getClasses(resourceLoader));
- }
- for (BeansXmlElement element : beanXmlElements.getInterceptorsElements())
- {
- this.enabledInterceptorClasses.addAll(element.getClasses(resourceLoader));
- }
- }
-
- public List<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
- {
- return Collections.unmodifiableList(enabledAlternativeStereotypes);
- }
-
- public List<Class<?>> getEnabledAlternativeClasses()
- {
- return Collections.unmodifiableList(enabledAlternativeClasses);
- }
-
- public List<Class<?>> getEnabledDecoratorClasses()
- {
- return Collections.unmodifiableList(enabledDecoratorClasses);
- }
-
- public List<Class<?>> getEnabledInterceptorClasses()
- {
- return Collections.unmodifiableList(enabledInterceptorClasses);
- }
-}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -110,8 +110,8 @@
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
- assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
- assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().iterator().next() == Alt.class;
container.stopContainer();
}
@@ -121,8 +121,8 @@
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("decorator.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
- assert container.getBeanManager().getEnabledDecoratorClasses().size() == 1;
- assert container.getBeanManager().getEnabledDecoratorClasses().iterator().next() == Dec.class;
+ assert container.getBeanManager().getEnabledClasses().getDecorators().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getDecorators().iterator().next() == Dec.class;
container.stopContainer();
}
@@ -132,8 +132,8 @@
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("interceptor.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
- assert container.getBeanManager().getEnabledInterceptorClasses().size() == 1;
- assert container.getBeanManager().getEnabledInterceptorClasses().iterator().next() == Int.class;
+ assert container.getBeanManager().getEnabledClasses().getInterceptors().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getInterceptors().iterator().next() == Int.class;
container.stopContainer();
}
@@ -143,12 +143,12 @@
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.xml"), getClass().getResource("decorator.xml"), getClass().getResource("interceptor.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
- assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
- assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
- assert container.getBeanManager().getEnabledInterceptorClasses().size() == 1;
- assert container.getBeanManager().getEnabledInterceptorClasses().iterator().next() == Int.class;
- assert container.getBeanManager().getEnabledDecoratorClasses().size() == 1;
- assert container.getBeanManager().getEnabledDecoratorClasses().iterator().next() == Dec.class;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().iterator().next() == Alt.class;
+ assert container.getBeanManager().getEnabledClasses().getInterceptors().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getInterceptors().iterator().next() == Int.class;
+ assert container.getBeanManager().getEnabledClasses().getDecorators().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getDecorators().iterator().next() == Dec.class;
container.stopContainer();
}
@@ -165,8 +165,8 @@
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("namespaced.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
- assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
- assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().iterator().next() == Alt.class;
container.stopContainer();
}
@@ -177,8 +177,8 @@
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("nonDefaultNamespaced.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
- assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
- assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().iterator().next() == Alt.class;
container.stopContainer();
}
@@ -191,8 +191,8 @@
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("nonPrettyPrinted.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
- assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
- assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledClasses().getAlternativeClasses().iterator().next() == Alt.class;
container.stopContainer();
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/nonTransitiveResolution/TransitiveResolutionTest.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -49,9 +49,9 @@
BeanManagerImpl warBeanManager = container.getBeanManager();
BeanManagerImpl jar1BeanManager = container.getLifecycle().getBootstrap().getManager(jar1);
BeanManagerImpl jar2BeanManager = container.getLifecycle().getBootstrap().getManager(jar2);
- assert warBeanManager.getEnabledAlternativeClasses().isEmpty();
- assert !jar1BeanManager.getEnabledAlternativeClasses().isEmpty();
- assert jar2BeanManager.getEnabledAlternativeClasses().isEmpty();
+ assert warBeanManager.getEnabledClasses().getAlternativeClasses().isEmpty();
+ assert !jar1BeanManager.getEnabledClasses().getAlternativeClasses().isEmpty();
+ assert jar2BeanManager.getEnabledClasses().getAlternativeClasses().isEmpty();
}
finally
{
@@ -82,9 +82,9 @@
BeanManagerImpl warBeanManager = container.getBeanManager();
BeanManagerImpl jar1BeanManager = container.getLifecycle().getBootstrap().getManager(jar1);
BeanManagerImpl jar2BeanManager = container.getLifecycle().getBootstrap().getManager(jar2);
- assert warBeanManager.getEnabledAlternativeClasses().isEmpty();
- assert !jar1BeanManager.getEnabledAlternativeClasses().isEmpty();
- assert !jar2BeanManager.getEnabledAlternativeClasses().isEmpty();
+ assert warBeanManager.getEnabledClasses().getAlternativeClasses().isEmpty();
+ assert !jar1BeanManager.getEnabledClasses().getAlternativeClasses().isEmpty();
+ assert !jar2BeanManager.getEnabledClasses().getAlternativeClasses().isEmpty();
}
finally
{
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java 2010-06-05 19:11:46 UTC (rev 6407)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java 2010-06-05 20:33:48 UTC (rev 6408)
@@ -31,12 +31,12 @@
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.introspector.jlr.WeldClassImpl;
import org.jboss.weld.manager.BeanManagerImpl;
+import org.jboss.weld.manager.EnabledClasses;
import org.jboss.weld.metadata.TypeStore;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.serialization.ContextualStoreImpl;
import org.jboss.weld.serialization.spi.ContextualStore;
-import org.jboss.weld.xml.EnabledClasses;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
14 years, 7 months
Weld SVN: r6407 - in core/trunk: impl/src/main/java/org/jboss/weld/manager and 2 other directories.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-05 15:11:46 -0400 (Sat, 05 Jun 2010)
New Revision: 6407
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.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/java/org/jboss/weld/xml/WeldXmlException.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java
Log:
re-architect xml parsing to be a split datastructures from logic
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 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -70,7 +70,10 @@
ServiceRegistry services = new SimpleServiceRegistry();
services.addAll(deploymentServices.entrySet());
services.addAll(beanDeploymentArchive.getServices().entrySet());
- this.beanManager = BeanManagerImpl.newManager(deploymentManager, beanDeploymentArchive.getId(), services);
+ this.beanManager = BeanManagerImpl.newManager(deploymentManager, beanDeploymentArchive.getId(), services, new BeansXmlParser(services.get(ResourceLoader.class), beanDeploymentArchive.getBeansXml()).parse());
+ 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());
if (beanManager.getServices().contains(EjbServices.class))
{
// Must populate EJB cache first, as we need it to detect whether a
@@ -81,8 +84,6 @@
// Must at the Manager bean straight away, as it can be injected during startup!
beanManager.addBean(new BeanManagerBean(beanManager));
-
- parseBeansXml();
}
public BeanManagerImpl getBeanManager()
@@ -100,33 +101,6 @@
return beanDeploymentArchive;
}
-
- private void parseBeansXml()
- {
- BeansXmlParser parser = new BeansXmlParser(beanManager.getServices().get(ResourceLoader.class), getBeanDeploymentArchive().getBeansXml());
- parser.parse();
-
- if (parser.getEnabledAlternativeClasses() != null)
- {
- beanManager.setEnabledAlternativeClasses(parser.getEnabledAlternativeClasses());
- }
- if (parser.getEnabledAlternativeStereotypes() != null)
- {
- beanManager.setEnabledAlternativeStereotypes(parser.getEnabledAlternativeStereotypes());
- }
- if (parser.getEnabledDecoratorClasses() != null)
- {
- beanManager.setEnabledDecoratorClasses(parser.getEnabledDecoratorClasses());
- }
- if (parser.getEnabledInterceptorClasses() != null)
- {
- beanManager.setEnabledInterceptorClasses(parser.getEnabledInterceptorClasses());
- }
- 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());
- }
-
// TODO Move class stuff into startContainer phase
// TODO read EJB descriptors after reading classes
public void deployBeans(Environment environment)
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 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -98,6 +98,7 @@
import org.jboss.weld.util.serviceProvider.DefaultServiceLoaderFactory;
import org.jboss.weld.util.serviceProvider.ServiceLoaderFactory;
import org.jboss.weld.ws.WSApiAbstraction;
+import org.jboss.weld.xml.EnabledClasses;
import org.slf4j.cal10n.LocLogger;
/**
@@ -291,7 +292,7 @@
deploymentServices.add(TypeStore.class, implementationServices.get(TypeStore.class));
this.environment = environment;
- this.deploymentManager = BeanManagerImpl.newRootManager("deployment", deploymentServices);
+ this.deploymentManager = BeanManagerImpl.newRootManager("deployment", deploymentServices, new EnabledClasses());
Container.initialize(deploymentManager, ServiceRegistries.unmodifiableServiceRegistry(deployment.getServices()));
Container.instance().setState(ContainerState.STARTING);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -116,6 +116,7 @@
import org.jboss.weld.util.collections.IterableToIteratorFunction;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.Reflections;
+import org.jboss.weld.xml.EnabledClasses;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
@@ -168,10 +169,7 @@
* archive accessibility, and the configuration for this bean deployment
* archive
*/
- 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 EnabledClasses enabledClasses;
private transient final Set<CurrentActivity> currentActivities;
/*
@@ -234,7 +232,7 @@
* @param serviceRegistry
* @return
*/
- public static BeanManagerImpl newRootManager(String id, ServiceRegistry serviceRegistry)
+ public static BeanManagerImpl newRootManager(String id, ServiceRegistry serviceRegistry, EnabledClasses enabledClasses)
{
ListMultimap<Class<? extends Annotation>, Context> contexts = Multimaps.newListMultimap(new ConcurrentHashMap<Class<? extends Annotation>, Collection<Context>>(), CopyOnWriteArrayListSupplier.<Context>instance());
@@ -251,10 +249,7 @@
contexts,
new CopyOnWriteArraySet<CurrentActivity>(),
new HashMap<Contextual<?>, Contextual<?>>(),
- new ArrayList<Class<?>>(),
- new ArrayList<Class<? extends Annotation>>(),
- new ArrayList<Class<?>>(),
- new ArrayList<Class<?>>(),
+ enabledClasses,
id,
new AtomicInteger());
}
@@ -265,7 +260,7 @@
* @param serviceRegistry
* @return
*/
- public static BeanManagerImpl newManager(BeanManagerImpl rootManager, String id, ServiceRegistry services)
+ public static BeanManagerImpl newManager(BeanManagerImpl rootManager, String id, ServiceRegistry services, EnabledClasses enabledClasses)
{
return new BeanManagerImpl(
services,
@@ -280,10 +275,7 @@
rootManager.getContexts(),
new CopyOnWriteArraySet<CurrentActivity>(),
new HashMap<Contextual<?>, Contextual<?>>(),
- new ArrayList<Class<?>>(),
- new ArrayList<Class<? extends Annotation>>(),
- new ArrayList<Class<?>>(),
- new ArrayList<Class<?>>(),
+ enabledClasses,
id,
new AtomicInteger());
}
@@ -319,10 +311,7 @@
parentManager.getContexts(),
parentManager.getCurrentActivities(),
parentManager.getSpecializedBeans(),
- parentManager.getEnabledAlternativeClasses(),
- parentManager.getEnabledAlternativeStereotypes(),
- parentManager.getEnabledDecoratorClasses(),
- parentManager.getEnabledInterceptorClasses(),
+ parentManager.getEnabledClasses(),
new StringBuilder().append(parentManager.getChildIds().incrementAndGet()).toString(),
parentManager.getChildIds());
}
@@ -346,10 +335,7 @@
ListMultimap<Class<? extends Annotation>, Context> contexts,
Set<CurrentActivity> currentActivities,
Map<Contextual<?>, Contextual<?>> specializedBeans,
- Collection<Class<?>> enabledAlternativeClasses,
- Collection<Class<? extends Annotation>> enabledAlternativeStereotypes,
- List<Class<?>> enabledDecoratorClasses,
- List<Class<?>> enabledInterceptorClasses,
+ EnabledClasses enabledClasses,
String id,
AtomicInteger childIds)
{
@@ -364,10 +350,7 @@
this.currentActivities = currentActivities;
this.specializedBeans = specializedBeans;
this.observers = observers;
- this.enabledAlternativeClasses = enabledAlternativeClasses;
- this.enabledAlternativeStereotypes = enabledAlternativeStereotypes;
- setEnabledDecoratorClasses(enabledDecoratorClasses);
- setEnabledInterceptorClasses(enabledInterceptorClasses);
+ this.enabledClasses = enabledClasses;
this.namespaces = namespaces;
this.id = id;
this.childIds = new AtomicInteger();
@@ -483,7 +466,7 @@
*/
public Collection<Class<?>> getEnabledAlternativeClasses()
{
- return Collections.unmodifiableCollection(enabledAlternativeClasses);
+ return getEnabledClasses().getEnabledAlternativeClasses();
}
/**
@@ -491,9 +474,14 @@
*/
public Collection<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
{
- return Collections.unmodifiableCollection(enabledAlternativeStereotypes);
+ return getEnabledClasses().getEnabledAlternativeStereotypes();
}
+ private EnabledClasses getEnabledClasses()
+ {
+ return enabledClasses;
+ }
+
public boolean isBeanEnabled(Bean<?> bean)
{
return Beans.isBeanEnabled(bean, getEnabledAlternativeClasses(), getEnabledAlternativeStereotypes());
@@ -504,7 +492,7 @@
*/
public List<Class<?>> getEnabledDecoratorClasses()
{
- return Collections.unmodifiableList(enabledDecoratorClasses);
+ return getEnabledClasses().getEnabledDecoratorClasses();
}
/**
@@ -512,29 +500,9 @@
*/
public List<Class<?>> getEnabledInterceptorClasses()
{
- return Collections.unmodifiableList(enabledInterceptorClasses);
+ return getEnabledClasses().getEnabledInterceptorClasses();
}
-
- public void setEnabledAlternativeClasses(Collection<Class<?>> enabledAlternativeClasses)
- {
- this.enabledAlternativeClasses = enabledAlternativeClasses;
- }
- public void setEnabledAlternativeStereotypes(Collection<Class<? extends Annotation>> enabledAlternativeSterotypes)
- {
- this.enabledAlternativeStereotypes = enabledAlternativeSterotypes;
- }
-
- public void setEnabledDecoratorClasses(List<Class<?>> enabledDecoratorClasses)
- {
- this.enabledDecoratorClasses = enabledDecoratorClasses;
- }
-
- public void setEnabledInterceptorClasses(List<Class<?>> enabledInterceptorClasses)
- {
- this.enabledInterceptorClasses = enabledInterceptorClasses;
- }
-
public Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
{
return beanResolver.resolve(new ResolvableBuilder(beanType).addQualifiers(qualifiers).create());
@@ -1202,10 +1170,6 @@
this.currentActivities.clear();
this.decoratorResolver.clear();
this.decorators.clear();
- this.enabledDecoratorClasses.clear();
- this.enabledInterceptorClasses.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/xml/BeansXmlElement.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -34,10 +34,10 @@
* @author Nicklas Karlsson
*
*/
-public class BeansXmlElement
+class BeansXmlElement
{
- private URL file;
- private Element element;
+ private final URL file;
+ private final Element element;
BeansXmlElement(URL file, Element element)
{
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 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -22,9 +22,7 @@
import java.io.IOException;
import java.io.InputStream;
-import java.lang.annotation.Annotation;
import java.net.URL;
-import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -47,35 +45,14 @@
private final Iterable<URL> beansXmls;
private final ResourceLoader resourceLoader;
- private EnabledClasses enabledClasses = null;
- public List<Class<?>> getEnabledAlternativeClasses()
+ public BeansXmlParser(ResourceLoader resourceLoader, Iterable<URL> beansXmls)
{
- return enabledClasses.getEnabledAlternativeClasses();
- }
-
- public List<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
- {
- return enabledClasses.getEnabledAlternativeStereotypes();
- }
-
- public List<Class<?>> getEnabledDecoratorClasses()
- {
- return enabledClasses.getEnabledDecoratorClasses();
- }
-
- public List<Class<?>> getEnabledInterceptorClasses()
- {
- return enabledClasses.getEnabledInterceptorClasses();
- }
-
- public BeansXmlParser(ResourceLoader resourceLoader, Iterable<URL> beansXml)
- {
- this.beansXmls = beansXml;
+ this.beansXmls = beansXmls;
this.resourceLoader = resourceLoader;
}
- public void parse()
+ public EnabledClasses parse()
{
DocumentBuilder documentBuilder = createDocumentBuilder();
MergedElements mergedElements = new MergedElements();
@@ -96,7 +73,7 @@
}
}
- enabledClasses = EnabledClasses.of(mergedElements, resourceLoader);
+ return new EnabledClasses(resourceLoader, mergedElements);
}
private Document loadDocument(DocumentBuilder documentBuilder, URL beansXml)
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 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/EnabledClasses.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -18,7 +18,7 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import org.jboss.weld.resources.spi.ResourceLoader;
@@ -30,77 +30,64 @@
*/
public class EnabledClasses
{
- private List<Class<? extends Annotation>> enabledAlternativeStereotypes;
- private List<Class<?>> enabledAlternativeClasses;
- private List<Class<?>> enabledDecoratorClasses;
- private List<Class<?>> enabledInterceptorClasses;
- private ResourceLoader resourceLoader;
+
+ private final List<Class<? extends Annotation>> enabledAlternativeStereotypes;
+ private final List<Class<?>> enabledAlternativeClasses;
+ private final List<Class<?>> enabledDecoratorClasses;
+ private final List<Class<?>> enabledInterceptorClasses;
- private EnabledClasses(MergedElements beanXmlElements, ResourceLoader resourceLoader)
+ public EnabledClasses()
{
- enabledAlternativeStereotypes = new ArrayList<Class<? extends Annotation>>();
- enabledAlternativeClasses = new ArrayList<Class<?>>();
- enabledDecoratorClasses = new ArrayList<Class<?>>();
- enabledInterceptorClasses = new ArrayList<Class<?>>();
- this.resourceLoader = resourceLoader;
- process(beanXmlElements);
+ this.enabledAlternativeClasses = new ArrayList<Class<?>>();
+ this.enabledAlternativeStereotypes = new ArrayList<Class<? extends Annotation>>();
+ this.enabledDecoratorClasses = new ArrayList<Class<?>>();
+ this.enabledInterceptorClasses = new ArrayList<Class<?>>();
}
-
- public static EnabledClasses of(MergedElements beanXmlElements, ResourceLoader resourceLoader)
+
+ EnabledClasses(ResourceLoader resourceLoader, MergedElements beanXmlElements)
{
- return new EnabledClasses(beanXmlElements, resourceLoader);
- }
-
- private void process(MergedElements beanXmlElements)
- {
- processAlternatives(beanXmlElements.getAlternativesElements());
- enabledDecoratorClasses.addAll(getClassesInElements(beanXmlElements.getDecoratorsElements()));
- enabledInterceptorClasses.addAll(getClassesInElements(beanXmlElements.getInterceptorsElements()));
- }
-
- private void processAlternatives(List<BeansXmlElement> alternativesElements)
- {
- Collection<Class<?>> classes = getClassesInElements(alternativesElements);
- for (Class<?> clazz : classes)
+ this();
+ for (BeansXmlElement element : beanXmlElements.getAlternativesElements())
{
- if (clazz.isAnnotation())
+ for (Class<?> clazz : element.getClasses(resourceLoader))
{
- enabledAlternativeStereotypes.add(clazz.asSubclass(Annotation.class));
+ if (clazz.isAnnotation())
+ {
+ this.enabledAlternativeStereotypes.add(clazz.asSubclass(Annotation.class));
+ }
+ else
+ {
+ this.enabledAlternativeClasses.add(clazz);
+ }
}
- else
- {
- enabledAlternativeClasses.add(clazz);
- }
}
- }
-
- private Collection<Class<?>> getClassesInElements(List<BeansXmlElement> elements)
- {
- List<Class<?>> classes = new ArrayList<Class<?>>();
- for (BeansXmlElement element : elements)
+ for (BeansXmlElement element : beanXmlElements.getDecoratorsElements())
{
- classes.addAll(element.getClasses(resourceLoader));
+ this.enabledDecoratorClasses.addAll(element.getClasses(resourceLoader));
}
- return classes;
+ for (BeansXmlElement element : beanXmlElements.getInterceptorsElements())
+ {
+ this.enabledInterceptorClasses.addAll(element.getClasses(resourceLoader));
+ }
}
public List<Class<? extends Annotation>> getEnabledAlternativeStereotypes()
{
- return enabledAlternativeStereotypes;
+ return Collections.unmodifiableList(enabledAlternativeStereotypes);
}
public List<Class<?>> getEnabledAlternativeClasses()
{
- return enabledAlternativeClasses;
+ return Collections.unmodifiableList(enabledAlternativeClasses);
}
public List<Class<?>> getEnabledDecoratorClasses()
{
- return enabledDecoratorClasses;
+ return Collections.unmodifiableList(enabledDecoratorClasses);
}
public List<Class<?>> getEnabledInterceptorClasses()
{
- return enabledInterceptorClasses;
+ return Collections.unmodifiableList(enabledInterceptorClasses);
}
}
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 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -22,6 +22,7 @@
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.jboss.weld.logging.messages.XmlMessage;
@@ -34,11 +35,18 @@
* @author Nicklas Karlsson
*
*/
-public class MergedElements
+class MergedElements
{
- private List<BeansXmlElement> alternativesElements = new ArrayList<BeansXmlElement>();
- private List<BeansXmlElement> decoratorsElements = new ArrayList<BeansXmlElement>();
- private List<BeansXmlElement> interceptorsElements = new ArrayList<BeansXmlElement>();
+ private List<BeansXmlElement> alternativesElements;
+ private List<BeansXmlElement> decoratorsElements;
+ private List<BeansXmlElement> interceptorsElements;
+
+ public MergedElements()
+ {
+ this.alternativesElements = new ArrayList<BeansXmlElement>();
+ this.decoratorsElements = new ArrayList<BeansXmlElement>();
+ this.interceptorsElements = new ArrayList<BeansXmlElement>();
+ }
public void merge(URL url, Document beansXmlDocument, String namespace)
@@ -68,17 +76,17 @@
public List<BeansXmlElement> getAlternativesElements()
{
- return alternativesElements;
+ return Collections.unmodifiableList(alternativesElements);
}
public List<BeansXmlElement> getDecoratorsElements()
{
- return decoratorsElements;
+ return Collections.unmodifiableList(decoratorsElements);
}
public List<BeansXmlElement> getInterceptorsElements()
{
- return interceptorsElements;
+ return Collections.unmodifiableList(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 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/WeldXmlException.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -17,45 +17,24 @@
package org.jboss.weld.xml;
-import javax.enterprise.inject.InjectionException;
-
-import org.jboss.weld.exceptions.WeldExceptionKeyMessage;
-import org.jboss.weld.exceptions.WeldExceptionMessage;
-import org.jboss.weld.exceptions.WeldExceptionStringMessage;
-
/**
* Used for exceptions from the Weld XML parser and provides localization
* support.
*
* @author David Allen
*/
-public class WeldXmlException extends InjectionException
+public class WeldXmlException extends org.jboss.weld.exceptions.InjectionException
{
- private static final long serialVersionUID = 2L;
+ private static final long serialVersionUID = 2L;
- private WeldExceptionMessage message;
-
public WeldXmlException(Throwable throwable)
{
super(throwable);
- message = new WeldExceptionStringMessage(throwable.getLocalizedMessage());
}
public <E extends Enum<?>> WeldXmlException(E key, Object... args)
{
- message = new WeldExceptionKeyMessage(key, args);
+ super(key, args);
}
-
- @Override
- public String getLocalizedMessage()
- {
- return getMessage();
- }
-
- @Override
- public String getMessage()
- {
- return message.getAsString();
- }
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java 2010-06-05 17:38:24 UTC (rev 6406)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java 2010-06-05 19:11:46 UTC (rev 6407)
@@ -36,6 +36,7 @@
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.serialization.ContextualStoreImpl;
import org.jboss.weld.serialization.spi.ContextualStore;
+import org.jboss.weld.xml.EnabledClasses;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -68,9 +69,9 @@
@Test
public void testAccessibleDynamicallySingleLevel()
{
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services, new EnabledClasses());
Container.initialize(root, services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services, new EnabledClasses());
addBean(root, Cow.class);
assert root.getBeans(Cow.class).size() == 1;
assert child.getBeans(Cow.class).size() == 0;
@@ -85,12 +86,12 @@
@Test
public void testAccessibleThreeLevelsWithMultiple()
{
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services, new EnabledClasses());
Container.initialize(root, services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
- BeanManagerImpl child1 = BeanManagerImpl.newRootManager("child1", services);
- BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
- BeanManagerImpl greatGrandchild = BeanManagerImpl.newRootManager("greatGrandchild", services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services, new EnabledClasses());
+ BeanManagerImpl child1 = BeanManagerImpl.newRootManager("child1", services, new EnabledClasses());
+ BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services, new EnabledClasses());
+ BeanManagerImpl greatGrandchild = BeanManagerImpl.newRootManager("greatGrandchild", services, new EnabledClasses());
child.addAccessibleBeanManager(root);
grandchild.addAccessibleBeanManager(child1);
grandchild.addAccessibleBeanManager(child);
@@ -127,10 +128,10 @@
@Test
public void testSameManagerAddedTwice()
{
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services, new EnabledClasses());
Container.initialize(root, services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
- BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services, new EnabledClasses());
+ BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services, new EnabledClasses());
grandchild.addAccessibleBeanManager(child);
child.addAccessibleBeanManager(root);
grandchild.addAccessibleBeanManager(root);
@@ -151,10 +152,10 @@
@Test
public void testCircular()
{
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services, new EnabledClasses());
Container.initialize(root, services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
- BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services, new EnabledClasses());
+ BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services, new EnabledClasses());
grandchild.addAccessibleBeanManager(child);
child.addAccessibleBeanManager(root);
grandchild.addAccessibleBeanManager(root);
14 years, 7 months
Weld SVN: r6406 - core/trunk/impl/src/main/java/org/jboss/weld/xml.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-05 13:38:24 -0400 (Sat, 05 Jun 2010)
New Revision: 6406
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java
core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java
Log:
WELD-467
Modified: core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java 2010-06-05 17:38:08 UTC (rev 6405)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlElement.java 2010-06-05 17:38:24 UTC (rev 6406)
@@ -39,7 +39,7 @@
private URL file;
private Element element;
- private BeansXmlElement(URL file, Element element)
+ BeansXmlElement(URL file, Element element)
{
super();
this.file = file;
@@ -59,11 +59,6 @@
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<?>>();
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 2010-06-05 17:38:08 UTC (rev 6405)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/BeansXmlParser.java 2010-06-05 17:38:24 UTC (rev 6406)
@@ -42,6 +42,9 @@
*/
public class BeansXmlParser
{
+
+ public static final String NAMESPACE = "http://java.sun.com/xml/ns/javaee";
+
private final Iterable<URL> beansXmls;
private final ResourceLoader resourceLoader;
private EnabledClasses enabledClasses = null;
@@ -74,7 +77,7 @@
public void parse()
{
- DocumentBuilder documentBuilder = getDocumentBuilder();
+ DocumentBuilder documentBuilder = createDocumentBuilder();
MergedElements mergedElements = new MergedElements();
for (URL beansXml : beansXmls)
{
@@ -82,13 +85,21 @@
{
continue;
}
- Document document = getDocument(documentBuilder, beansXml);
- mergedElements.merge(beansXml, document);
+ Document document = loadDocument(documentBuilder, beansXml);
+ if (document.getNamespaceURI() == null)
+ {
+ mergedElements.merge(beansXml, document, "*");
+ }
+ else
+ {
+ mergedElements.merge(beansXml, document, NAMESPACE);
+ }
+
}
enabledClasses = EnabledClasses.of(mergedElements, resourceLoader);
}
- private Document getDocument(DocumentBuilder documentBuilder, URL beansXml)
+ private Document loadDocument(DocumentBuilder documentBuilder, URL beansXml)
{
Document document;
InputStream in = null;
@@ -151,11 +162,13 @@
}
}
- private DocumentBuilder getDocumentBuilder()
+ private DocumentBuilder createDocumentBuilder()
{
try
{
- return DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ return factory.newDocumentBuilder();
}
catch (ParserConfigurationException e)
{
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 2010-06-05 17:38:08 UTC (rev 6405)
+++ core/trunk/impl/src/main/java/org/jboss/weld/xml/MergedElements.java 2010-06-05 17:38:24 UTC (rev 6406)
@@ -41,25 +41,25 @@
private List<BeansXmlElement> interceptorsElements = new ArrayList<BeansXmlElement>();
- public void merge(URL url, Document beansXmlDocument)
+ public void merge(URL url, Document beansXmlDocument, String namespace)
{
Element documentElement = beansXmlDocument.getDocumentElement();
- alternativesElements.addAll(getNamedElement(url, documentElement, "alternatives", MULTIPLE_ALTERNATIVES));
- interceptorsElements.addAll(getNamedElement(url, documentElement, "interceptors", MULTIPLE_INTERCEPTORS));
- decoratorsElements.addAll(getNamedElement(url, documentElement, "decorators", MULTIPLE_DECORATORS));
+ alternativesElements.addAll(findNamedElement(url, documentElement, namespace, "alternatives", MULTIPLE_ALTERNATIVES));
+ interceptorsElements.addAll(findNamedElement(url, documentElement, namespace, "interceptors", MULTIPLE_INTERCEPTORS));
+ decoratorsElements.addAll(findNamedElement(url, documentElement, namespace, "decorators", MULTIPLE_DECORATORS));
}
- private List<BeansXmlElement> getNamedElement(URL url, Element beans, String name, XmlMessage multipleViolationMessage)
+ private List<BeansXmlElement> findNamedElement(URL url, Element beans, String namespace, String name, XmlMessage multipleViolationMessage)
{
List<BeansXmlElement> elements = new ArrayList<BeansXmlElement>();
- NodeList nodeList = beans.getElementsByTagName(name);
+ NodeList nodeList = beans.getElementsByTagNameNS(namespace, name);
if (nodeList.getLength() > 1)
{
throw new WeldXmlException(multipleViolationMessage);
}
else if (nodeList.getLength() == 1)
{
- BeansXmlElement element = BeansXmlElement.of(url, nodeList.item(0));
+ BeansXmlElement element = new BeansXmlElement(url, (Element) nodeList.item(0));
elements.add(element);
}
return elements;
14 years, 7 months
Weld SVN: r6405 - in core/trunk/tests/src/test: resources/org/jboss/weld/tests/unit/bootstrap/xml and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-05 13:38:08 -0400 (Sat, 05 Jun 2010)
New Revision: 6405
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/namespaced.xml
core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/nonDefaultNamespaced.xml
Modified:
core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java
Log:
WELD-467
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java 2010-06-05 11:17:19 UTC (rev 6404)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.java 2010-06-05 17:38:08 UTC (rev 6405)
@@ -31,7 +31,7 @@
@SuppressWarnings("unchecked")
public class BeansXmlTest
{
- private class FailedDeployment
+ private static class FailedDeployment
{
private List<Class<?>> beans = Collections.emptyList();
private List<URL> beansXml = Collections.emptyList();
@@ -60,7 +60,7 @@
public void runAndExpect(WeldXmlException expected)
{
- String errorCode = expected.getMessage().substring(0, 12);
+ String errorCode = expected.getMessage().substring(0, 11);
try
{
run();
@@ -77,35 +77,35 @@
}
- private void testWithBeansXmlAndExpectException(String beansXml, WeldXmlException e)
+ private static void checkWithBeansXmlAndExpectException(String beansXml, WeldXmlException e)
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, Plain.class, IntBind.class);
- List<URL> beansXmls = Arrays.asList(getClass().getResource(beansXml));
+ List<URL> beansXmls = Arrays.asList(BeansXmlTest.class.getResource(beansXml));
new FailedDeployment(beans, beansXmls).runAndExpect(e);
}
// Multiple XML blocks
@Test
- public void multipleAlternativeBlocksFail()
+ public void testMultipleAlternativeBlocksFail()
{
- testWithBeansXmlAndExpectException("multipleAlternativeBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_ALTERNATIVES));
+ checkWithBeansXmlAndExpectException("multipleAlternativeBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_ALTERNATIVES));
}
@Test
- public void multipleDecoratorBlocksFail()
+ public void testMultipleDecoratorBlocksFail()
{
- testWithBeansXmlAndExpectException("multipleDecoratorBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_DECORATORS));
+ checkWithBeansXmlAndExpectException("multipleDecoratorBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_DECORATORS));
}
@Test
- public void multipleInterceptorBlocksFail()
+ public void testMultipleInterceptorBlocksFail()
{
- testWithBeansXmlAndExpectException("multipleInterceptorsBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_INTERCEPTORS));
+ checkWithBeansXmlAndExpectException("multipleInterceptorsBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_INTERCEPTORS));
}
@Test
- public void alternativesEnabled()
+ public void testAlternativesEnabled()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.xml"));
@@ -116,7 +116,7 @@
}
@Test
- public void decoratorsEnabled()
+ public void testDecoratorsEnabled()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("decorator.xml"));
@@ -127,7 +127,7 @@
}
@Test
- public void interceptorsEnabled()
+ public void testInterceptorsEnabled()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("interceptor.xml"));
@@ -155,13 +155,33 @@
@Test
public void testBeansXmlDoesntExist()
{
- testWithBeansXmlAndExpectException("nope.xml", new WeldXmlException(XmlMessage.LOAD_ERROR));
+ checkWithBeansXmlAndExpectException("nope.xml", new WeldXmlException(XmlMessage.LOAD_ERROR));
}
-
- @Test(groups="stub")
- public void testCannotGetDocumentBuilder()
+
+ // WELD-467
+ @Test
+ public void testNamespacedBeansXml()
{
+ List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
+ List<URL> beansXmls = Arrays.asList(getClass().getResource("namespaced.xml"));
+ TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
+ assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ container.stopContainer();
}
+
+ // WELD-467
+ @Test
+ public void testNotDefaultNamespacedBeansXml()
+ {
+ List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
+ List<URL> beansXmls = Arrays.asList(getClass().getResource("nonDefaultNamespaced.xml"));
+ TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
+ assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
+ assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
+ container.stopContainer();
+ }
+
/*
* https://jira.jboss.org/jira/browse/WELD-362
*/
@@ -186,13 +206,13 @@
@Test
public void testParsingError()
{
- testWithBeansXmlAndExpectException("unparseable.xml", new WeldXmlException(XmlMessage.PARSING_ERROR));
+ checkWithBeansXmlAndExpectException("unparseable.xml", new WeldXmlException(XmlMessage.PARSING_ERROR));
}
@Test
public void testCannotLoadClass()
{
- testWithBeansXmlAndExpectException("unloadable.xml", new WeldXmlException(XmlMessage.CANNOT_LOAD_CLASS));
+ checkWithBeansXmlAndExpectException("unloadable.xml", new WeldXmlException(XmlMessage.CANNOT_LOAD_CLASS));
}
}
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/namespaced.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/namespaced.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/namespaced.xml 2010-06-05 17:38:08 UTC (rev 6405)
@@ -0,0 +1,11 @@
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:s="urn:java:seam:core"
+ xmlns:p="org.jboss.seam.xml.examples.princess"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://docs.jboss.org/cdi/beans_1_0.xsd">
+ <alternatives>
+ <class>org.jboss.weld.tests.unit.bootstrap.xml.Alt</class>
+ </alternatives>
+</beans>
\ No newline at end of file
Property changes on: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/namespaced.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/nonDefaultNamespaced.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/nonDefaultNamespaced.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/nonDefaultNamespaced.xml 2010-06-05 17:38:08 UTC (rev 6405)
@@ -0,0 +1,12 @@
+<ee:beans xmlns:ee="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:java:seam:core"
+ xmlns:p="org.jboss.seam.xml.examples.princess"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://docs.jboss.org/cdi/beans_1_0.xsd">
+ <ee:alternatives>
+ <ee:class>org.jboss.weld.tests.unit.bootstrap.xml.Alt</ee:class>
+ </ee:alternatives>
+ <foo />
+</ee:beans>
\ No newline at end of file
Property changes on: core/trunk/tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/nonDefaultNamespaced.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 7 months
Weld SVN: r6404 - core/trunk/impl.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-06-05 07:17:19 -0400 (Sat, 05 Jun 2010)
New Revision: 6404
Modified:
core/trunk/impl/
Log:
ignores
Property changes on: core/trunk/impl
___________________________________________________________________
Name: svn:ignore
- cobertura.ser
nb-configuration.xml
test-output
.classpath
.project
target
temp-testng-customsuite.xml
ObjectStore
.settings
pom.xml.releaseBackup
+ cobertura.ser
nb-configuration.xml
test-output
.classpath
.project
target
temp-testng-customsuite.xml
ObjectStore
.settings
pom.xml.releaseBackup
.fbprefs
14 years, 7 months