Author: shane.bryzak(a)jboss.com
Date: 2009-01-09 06:57:21 -0500 (Fri, 09 Jan 2009)
New Revision: 846
Added:
tck/trunk/impl/src/main/java/org/
tck/trunk/impl/src/main/java/org/jboss/
tck/trunk/impl/src/main/java/org/jboss/webbeans/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/TckUtils.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/BindingTypeTest.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecAssertion.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecVersion.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnimalStereotype.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnotherDeploymentType.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Chunky.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/HornedAnimalDeploymentType.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Synchronous.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Tame.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Whitefish.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Animal.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Barn.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/BlackWidow.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cat.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cod.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DaddyLongLegs.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlyAnimal.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlySpider.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DefangedTarantula.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/FunnelWeaver.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/LadybirdSpider.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Order.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/ScottishFish.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Spider.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/SpiderProducer.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tarantula.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/TrapdoorSpider.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tuna.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/WolfSpider.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/DeploymentProperties.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java
Log:
moved from api
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/TckUtils.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/TckUtils.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/TckUtils.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,85 @@
+package org.jboss.webbeans.tck.api;
+
+import java.lang.reflect.Constructor;
+
+import org.jboss.webbeans.tck.api.util.DeploymentProperties;
+import org.jboss.webbeans.tck.api.util.Reflections;
+
+/**
+ *
+ * @author Shane Bryzak
+ *
+ */
+public class TckUtils
+{
+ private static DeploymentProperties deploymentProperties = new
DeploymentProperties();
+
+ public static Managers getManagers()
+ {
+ Managers managers = null;
+
+ for (Class<? extends Managers> cls :
deploymentProperties.getClasses(Managers.class.getName(), Managers.class))
+ {
+ Constructor<? extends Managers> constructor =
Reflections.getConstructor(cls);
+ if (constructor != null)
+ {
+ try
+ {
+ managers = constructor.newInstance();
+ }
+ catch (Exception ex)
+ {
+ // Do something with the exception (log it?)
+ }
+ }
+ }
+
+ return managers;
+ }
+
+ public static Contexts getContexts()
+ {
+ Contexts contexts = null;
+
+ for (Class<? extends Contexts> cls :
deploymentProperties.getClasses(Contexts.class.getName(), Contexts.class))
+ {
+ Constructor<? extends Contexts> constructor =
Reflections.getConstructor(cls);
+ if (constructor != null)
+ {
+ try
+ {
+ contexts = constructor.newInstance();
+ }
+ catch (Exception ex)
+ {
+ // Do something with the exception (log it?)
+ }
+ }
+ }
+
+ return contexts;
+ }
+
+ public static Beans getBeans()
+ {
+ Beans beans = null;
+
+ for (Class<? extends Beans> cls :
deploymentProperties.getClasses(Beans.class.getName(), Beans.class))
+ {
+ Constructor<? extends Beans> constructor =
Reflections.getConstructor(cls);
+ if (constructor != null)
+ {
+ try
+ {
+ beans = constructor.newInstance();
+ }
+ catch (Exception ex)
+ {
+ // Do something with the exception (log it?)
+ }
+ }
+ }
+
+ return beans;
+ }
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/BindingTypeTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/BindingTypeTest.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/BindingTypeTest.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,186 @@
+package org.jboss.webbeans.tck.test;
+
+import java.lang.reflect.Method;
+
+import javax.webbeans.Current;
+import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Manager;
+
+import org.jboss.webbeans.tck.api.Managers;
+import org.jboss.webbeans.tck.api.TckUtils;
+import org.jboss.webbeans.tck.api.util.Reflections;
+import org.jboss.webbeans.tck.test.annotations.Synchronous;
+import org.jboss.webbeans.tck.test.beans.Barn;
+import org.jboss.webbeans.tck.test.beans.Cat;
+import org.jboss.webbeans.tck.test.beans.Cod;
+import org.jboss.webbeans.tck.test.beans.DefangedTarantula;
+import org.jboss.webbeans.tck.test.beans.Order;
+import org.jboss.webbeans.tck.test.beans.Spider;
+import org.jboss.webbeans.tck.test.beans.SpiderProducer;
+import org.jboss.webbeans.tck.test.beans.Tarantula;
+import org.jboss.webbeans.tck.test.beans.Tuna;
+
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.binding.CurrentBinding;
+
+import org.testng.annotations.Test;
+
+@SpecVersion("2001206")
+public class BindingTypeTest
+{
+
+ @SuppressWarnings("unchecked")
+ @Test @SpecAssertion(section={"2.3.3", "2.3.1"})
+ public void testDefaultBindingTypeDeclaredInJava()
+ {
+ Manager manager = TckUtils.getManagers().createManager();
+
+ Bean<Order> order = TckUtils.getBeans().createSimpleBean(Order.class,
manager);
+ assert order.getBindingTypes().size() == 1;
+ order.getBindingTypes().iterator().next().annotationType().equals(Current.class);
+ }
+
+ @Test(groups={"stub", "annotationDefinition"})
@SpecAssertion(section="2.3.2")
+ public void testBindingTypeHasCorrectTarget()
+ {
+ assert false;
+ }
+
+ @Test(groups={"stub", "annotationDefinition"})
@SpecAssertion(section="2.3.2")
+ public void testBindingTypeHasCorrectRetention()
+ {
+ assert false;
+ }
+
+ @Test(groups={"stub", "annotationDefinition"})
@SpecAssertion(section="2.3.2")
+ public void testBindingTypeDeclaresBindingTypeAnnotation()
+ {
+ assert false;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test @SpecAssertion(section="2.3.3")
+ public void testBindingTypesDeclaredInJava()
+ {
+ Manager manager = TckUtils.getManagers().createManager();
+
+ SimpleBean<Cat> cat = SimpleBean.of(Cat.class, manager);
+ assert cat.getBindingTypes().size() == 1;
+ assert Reflections.annotationSetMatches(cat.getBindingTypes(), Synchronous.class);
+ }
+
+ @Test @SpecAssertion(section="2.3.3")
+ public void testMultipleBindingTypes()
+ {
+ Manager manager = TckUtils.getManagers().createManager();
+
+ SimpleBean<?> model = SimpleBean.of(Cod.class, manager);
+ assert model.getBindingTypes().size() == 2;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(groups={"stub", "webbeansxml"})
@SpecAssertion(section="2.3.4")
+ public void testBindingTypesDeclaredInXml()
+ {
+ //Map<Class<? extends Annotation>, Annotation> annotations = new
HashMap<Class<? extends Annotation>, Annotation>();
+ //annotations.put(Asynchronous.class, new AsynchronousAnnotationLiteral());
+ //AnnotatedClass annotatedItem = new SimpleAnnotatedClass(Antelope.class,
annotations);
+
+ //SimpleBean<Antelope> antelope = createSimpleBean(Antelope.class,
annotatedItem, manager);
+ // assert Reflections.annotationSetMatches(antelope.getBindingTypes(),
Asynchronous.class);
+ assert false;
+ }
+
+ @Test(groups={"stub", "webbeansxml"})
@SpecAssertion(section="2.3.4")
+ public void testXmlBindingTypeOverridesAndIgnoresJava()
+ {
+ //Map<Class<? extends Annotation>, Annotation> annotations = new
HashMap<Class<? extends Annotation>, Annotation>();
+ //annotations.put(Asynchronous.class, new AsynchronousAnnotationLiteral());
+ //AnnotatedClass<Cat> annotatedItem = new
SimpleAnnotatedClass<Cat>(Cat.class, annotations);
+
+ //SimpleBean<Cat> cat = createSimpleBean(Cat.class, annotatedItem, manager);
+ //assert cat.getBindingTypes().size() == 1;
+ //assert cat.getBindingTypes().contains(new AnnotationLiteral<Asynchronous>()
{});
+ assert false;
+ }
+
+ @Test(groups={"stub", "webbeansxml"})
@SpecAssertion(section="2.3.4")
+ public void testNoBindingTypesDeclaredInXml()
+ {
+ //Map<Class<? extends Annotation>, Annotation> annotations = new
HashMap<Class<? extends Annotation>, Annotation>();
+ //AnnotatedClass<Cat> annotatedItem = new
SimpleAnnotatedClass<Cat>(Cat.class, annotations);
+
+ //SimpleBean<Cat> cat = createSimpleBean(Cat.class, annotatedItem, manager);
+ //assert cat.getBindingTypes().size() == 1;
+ //assert cat.getBindingTypes().contains(new AnnotationLiteral<Synchronous>()
{});
+ assert false;
+ }
+
+ @Test(groups={"stub", "webbeansxml"})
@SpecAssertion(section={"2.3.4", "2.3.1"})
+ public void testDefaultBindingTypeDeclaredInXml()
+ {
+ Manager manager = TckUtils.getManagers().createManager();
+
+ SimpleBean<?> model = SimpleBean.of(Tuna.class, manager);
+ assert model.getBindingTypes().size() == 1;
+ assert model.getBindingTypes().contains(new CurrentBinding());
+ assert false;
+ }
+
+
+
+ @Test(groups={"injection", "producerMethod"})
@SpecAssertion(section="2.3.5")
+ public void testFieldInjectedFromProducerMethod() throws Exception
+ {
+ Manager manager = TckUtils.getManagers().createManager();
+
+ SimpleBean<SpiderProducer> spiderProducer =
SimpleBean.of(SpiderProducer.class, manager);
+ manager.addBean(spiderProducer);
+ Method method = SpiderProducer.class.getMethod("produceTameTarantula");
+ manager.addBean(ProducerMethodBean.of(method, spiderProducer, manager));
+ Barn barn = SimpleBean.of(Barn.class, manager).create();
+ assert barn.petSpider != null;
+ assert barn.petSpider instanceof DefangedTarantula;
+ }
+
+ @Test(groups={"stub", "injection", "webbeansxml"})
@SpecAssertion(section="2.3.5")
+ public void testFieldWithBindingTypeInXml()
+ {
+ assert false;
+ }
+
+ @Test(groups={"stub", "injection", "webbeansxml"})
@SpecAssertion(section="2.3.5")
+ public void testFieldWithBindingTypeInXmlIgnoresAnnotations()
+ {
+ assert false;
+ }
+
+ @Test(groups={"injection", "producerMethod"})
+ public void testMethodWithBindingAnnotationsOnParametersAreInjected() throws
Exception
+ {
+ Manager manager = TckUtils.getManagers().createManager();
+
+ SimpleBean<SpiderProducer> spiderProducer =
SimpleBean.of(SpiderProducer.class, manager);
+ manager.addBean(spiderProducer);
+ Method method = SpiderProducer.class.getMethod("produceTameTarantula");
+ manager.addBean(ProducerMethodBean.of(method, spiderProducer, manager));
+ method = SpiderProducer.class.getMethod("produceSpiderFromInjection",
Tarantula.class);
+ ProducerMethodBean<Spider> spiderBean = ProducerMethodBean.of(method,
spiderProducer, manager);
+ Spider spider = spiderBean.create();
+ assert spider != null;
+ assert spider instanceof DefangedTarantula;
+ }
+
+ @Test(groups={"stub", "injection", "webbeansxml"})
@SpecAssertion(section="2.3.6")
+ public void testMethodWithBindingAnnotationsOnParametersDeclaredInXml()
+ {
+ assert false;
+ }
+
+ @Test(groups={"stub", "injection", "webbeansxml"})
@SpecAssertion(section="2.3.6")
+ public void
testMethodWithBindingAnnotationsOnParametersDeclaredInXmlIgnoresAnnotations()
+ {
+ assert false;
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecAssertion.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecAssertion.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecAssertion.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.tck.test;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+(a)Target(ElementType.METHOD)
+@Documented
+public @interface SpecAssertion
+{
+
+ public String[] section();
+
+ public String note() default "";
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecVersion.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecVersion.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/SpecVersion.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.tck.test;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+@Documented
+(a)Target(ElementType.TYPE)
+public @interface SpecVersion {
+
+ String value();
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnimalStereotype.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnimalStereotype.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnimalStereotype.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,23 @@
+package org.jboss.webbeans.tck.test.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.RequestScoped;
+import javax.webbeans.Stereotype;
+
+import org.jboss.webbeans.tck.test.beans.Animal;
+
+(a)Stereotype(requiredTypes=Animal.class)
+@Target( { TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+@RequestScoped
+public @interface AnimalStereotype
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnotherDeploymentType.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnotherDeploymentType.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/AnotherDeploymentType.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.tck.test.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.DeploymentType;
+
+@Target( { TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+@DeploymentType
+public @interface AnotherDeploymentType
+{
+
+}
\ No newline at end of file
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Chunky.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Chunky.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Chunky.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,24 @@
+package org.jboss.webbeans.tck.test.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface Chunky
+{
+
+ boolean realChunky();
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/HornedAnimalDeploymentType.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/HornedAnimalDeploymentType.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/HornedAnimalDeploymentType.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.tck.test.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.DeploymentType;
+
+@Target( { TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+@DeploymentType
+public @interface HornedAnimalDeploymentType
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Synchronous.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Synchronous.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Synchronous.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.tck.test.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface Synchronous
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Tame.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Tame.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Tame.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.tck.test.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface Tame
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Whitefish.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Whitefish.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/annotations/Whitefish.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.tck.test.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface Whitefish
+{
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Animal.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Animal.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Animal.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public interface Animal
+{
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Barn.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Barn.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Barn.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.tck.test.beans;
+
+import org.jboss.webbeans.tck.test.annotations.Tame;
+
+public class Barn
+{
+ @Tame
+ public Tarantula petSpider;
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/BlackWidow.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/BlackWidow.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/BlackWidow.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class BlackWidow extends Spider implements DeadlySpider
+{
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cat.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cat.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cat.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.tck.test.beans;
+
+import javax.webbeans.Production;
+
+import org.jboss.webbeans.test.annotations.Synchronous;
+
+@Production
+@Synchronous
+public class Cat
+{
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cod.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cod.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Cod.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.tck.test.beans;
+
+import javax.webbeans.Named;
+import javax.webbeans.Production;
+
+import org.jboss.webbeans.tck.test.annotations.Chunky;
+import org.jboss.webbeans.tck.test.annotations.Whitefish;
+
+@Production
+@Whitefish
+@Chunky(realChunky=true)
+@Named("whitefish")
+public class Cod implements ScottishFish
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DaddyLongLegs.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DaddyLongLegs.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DaddyLongLegs.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class DaddyLongLegs extends Spider
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlyAnimal.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlyAnimal.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlyAnimal.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public interface DeadlyAnimal
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlySpider.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlySpider.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DeadlySpider.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public interface DeadlySpider extends DeadlyAnimal
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DefangedTarantula.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DefangedTarantula.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/DefangedTarantula.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class DefangedTarantula extends Tarantula
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/FunnelWeaver.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/FunnelWeaver.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/FunnelWeaver.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class FunnelWeaver<T>
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/LadybirdSpider.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/LadybirdSpider.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/LadybirdSpider.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.tck.test.beans;
+
+import javax.webbeans.ApplicationScoped;
+
+@ApplicationScoped
+public class LadybirdSpider extends Spider
+{
+
+ public void spinWeb()
+ {
+
+ }
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Order.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Order.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Order.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.tck.test.beans;
+
+import javax.webbeans.Production;
+
+@Production
+public class Order
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/ScottishFish.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/ScottishFish.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/ScottishFish.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public interface ScottishFish extends Animal
+{
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Spider.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Spider.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Spider.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class Spider implements Animal
+{
+
+ public final void layEggs()
+ {
+
+ }
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/SpiderProducer.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/SpiderProducer.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/SpiderProducer.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,104 @@
+package org.jboss.webbeans.tck.test.beans;
+
+import javax.webbeans.Dependent;
+import javax.webbeans.Named;
+import javax.webbeans.Produces;
+import javax.webbeans.Production;
+import javax.webbeans.RequestScoped;
+
+import org.jboss.webbeans.tck.test.annotations.AnimalStereotype;
+import org.jboss.webbeans.tck.test.annotations.AnotherDeploymentType;
+import org.jboss.webbeans.tck.test.annotations.Tame;
+
+@AnotherDeploymentType
+public class SpiderProducer
+{
+
+ private static Spider[] ALL_SPIDERS = { new Tarantula(), new LadybirdSpider(), new
DaddyLongLegs() };
+
+ @Produces @Tame public Tarantula produceTameTarantula()
+ {
+ return new DefangedTarantula();
+ }
+
+ @Produces public Tarantula produceTarantula()
+ {
+ return new Tarantula();
+ }
+
+ @Produces @Dependent public final TrapdoorSpider produceTrapdoorSpider()
+ {
+ return new TrapdoorSpider();
+ }
+
+ @Produces @Named("blackWidow") public BlackWidow produceBlackWidow()
+ {
+ return new BlackWidow();
+ }
+
+ @Produces @Named @RequestScoped public DaddyLongLegs produceDaddyLongLegs()
+ {
+ return new DaddyLongLegs();
+ }
+
+ @Produces @Named @Production public LadybirdSpider getLadybirdSpider()
+ {
+ return new LadybirdSpider();
+ }
+
+ @Produces @Named("Shelob") public Tarantula produceShelob()
+ {
+ return null;
+ }
+
+ @Produces @AnimalStereotype public WolfSpider produceWolfSpider()
+ {
+ return new WolfSpider();
+ }
+
+ @Produces public Animal makeASpider()
+ {
+ return new WolfSpider();
+ }
+
+ @Produces public int getWolfSpiderSize()
+ {
+ return 4;
+ }
+
+ @Produces public Spider[] getSpiders()
+ {
+ return ALL_SPIDERS;
+ }
+
+ @Produces public String[] getStrings()
+ {
+ return new String[0];
+ }
+
+ @Produces public <T> FunnelWeaver<T> getFunnelWeaver()
+ {
+ return new FunnelWeaver<T>();
+ }
+
+ @Produces public FunnelWeaver<?> getAnotherFunnelWeaver()
+ {
+ return new FunnelWeaver<Object>();
+ }
+
+ @Produces public FunnelWeaver<Spider> getFunnelWeaverSpider()
+ {
+ return new FunnelWeaver<Spider>();
+ }
+
+ @Produces public Spider getNullSpider()
+ {
+ return null;
+ }
+
+ @Produces public Spider produceSpiderFromInjection(@Tame Tarantula tarantula)
+ {
+ return tarantula;
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tarantula.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tarantula.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tarantula.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class Tarantula extends Spider implements DeadlySpider
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/TrapdoorSpider.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/TrapdoorSpider.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/TrapdoorSpider.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class TrapdoorSpider
+{
+
+}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tuna.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tuna.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/Tuna.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.tck.test.beans;
+
+import javax.webbeans.RequestScoped;
+
+import org.jboss.webbeans.tck.test.annotations.AnotherDeploymentType;
+
+@AnotherDeploymentType
+@RequestScoped
+public class Tuna
+{
+
+ public String getName()
+ {
+ return "Ophir";
+ }
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/WolfSpider.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/WolfSpider.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/test/beans/WolfSpider.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.test.beans;
+
+public class WolfSpider implements Animal
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/DeploymentProperties.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/DeploymentProperties.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/DeploymentProperties.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,148 @@
+package org.jboss.webbeans.tck.api.util;
+
+import static org.jboss.webbeans.tck.api.util.Strings.split;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * Utility class to load deployment properties
+ *
+ * @author Pete Muir
+ */
+public class DeploymentProperties
+{
+ // The resource bundle used to control Web Beans RI deployment
+ public static final String RESOURCE_BUNDLE =
"META-INF/web-beans-ri.properties";
+
+ // The class to work from
+ private SimpleResourceLoader resourceLoader;
+
+ /**
+ * Constructor
+ *
+ * @param classLoader The classloader to work on
+ */
+ public DeploymentProperties()
+ {
+ this.resourceLoader = new SimpleResourceLoader();
+ }
+
+ /**
+ * Get a list of possible values for a given key.
+ *
+ * First, System properties are tried, followed by the specified resource
+ * bundle (first in classpath only).
+ *
+ * @param key The key to search for
+ * @return A list of possible values. An empty list is returned if there are
+ * no matches.
+ */
+ public List<String> getPropertyValues(String key)
+ {
+ List<String> values = new ArrayList<String>();
+ addPropertiesFromSystem(key, values);
+ addPropertiesFromResourceBundle(key, values);
+ return values;
+ }
+
+ /**
+ * Adds matches from system properties
+ *
+ * @param key The key to match
+ * @param values The currently found values
+ */
+ private void addPropertiesFromSystem(String key, List<String> values)
+ {
+ addProperty(key, System.getProperty(key), values);
+ }
+
+ /**
+ * Adds matches from detected resource bundles
+ *
+ * @param key The key to match
+ * @param values The currently found values
+ */
+ private void addPropertiesFromResourceBundle(String key, List<String> values)
+ {
+ try
+ {
+ for (URL url : resourceLoader.getResources(RESOURCE_BUNDLE))
+ {
+ Properties properties = new Properties();
+ InputStream propertyStream = url.openStream();
+ try
+ {
+ properties.load(propertyStream);
+ addProperty(key, properties.getProperty(key), values);
+ }
+ finally
+ {
+ if (propertyStream != null)
+ {
+ propertyStream.close();
+ }
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ // No - op, file is optional
+ }
+ }
+
+ /**
+ * Add the property to the set of properties only if it hasn't already been
+ * added
+ *
+ * @param key The key searched for
+ * @param value The value of the property
+ * @param values The currently found values
+ */
+ private void addProperty(String key, String value, List<String> values)
+ {
+ if (value != null)
+ {
+ String[] properties = split(value, ":");
+ for (String property : properties)
+ {
+ values.add(property);
+ }
+
+ }
+ }
+
+ /**
+ * Gets the possible implementation class for a given property for which the
+ * values are classanames
+ *
+ * @param deploymentProperties The deployment properties object to use
+ * @param resourceLoader The resource laoder to use to attempt
+ * @param propertyName The name of the property to load
+ * @return A set of classes specified
+ */
+ @SuppressWarnings("unchecked")
+ public <T> Set<Class<? extends T>> getClasses(String propertyName,
Class<T> expectedType)
+ {
+ Set<Class<? extends T>> classes = new HashSet<Class<? extends
T>>();
+ for (String className : getPropertyValues(propertyName))
+ {
+ try
+ {
+ classes.add((Class<? extends T>)
resourceLoader.classForName(className));
+ }
+ catch (ResourceLoadingException e)
+ {
+ //log.debug("Unable to load class " + className + " for
property " + propertyName, e);
+ }
+ }
+ return classes;
+ }
+
+}
\ No newline at end of file
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,37 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An Enumeration -> Iteratble adaptor
+ *
+ * @author Pete Muir
+ * @see org.jboss.webbeans.util.EnumerationIterator
+ */
+public class EnumerationIterable<T> implements Iterable<T>
+{
+ // The enumeration-iteartor
+ private EnumerationIterator<T> iterator;
+
+ /**
+ * Constructor
+ *
+ * @param enumeration The enumeration
+ */
+ public EnumerationIterable(Enumeration<T> enumeration)
+ {
+ this.iterator = new EnumerationIterator<T>(enumeration);
+ }
+
+ /**
+ * Gets an iterator
+ *
+ * @return The iterator
+ */
+ public Iterator<T> iterator()
+ {
+ return iterator;
+ }
+
+}
\ No newline at end of file
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,55 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An enumeration -> iterator adapter
+ *
+ * @author Pete Muir
+ */
+@SuppressWarnings("unchecked")
+public class EnumerationIterator<T> implements Iterator<T>
+{
+ // The enumeration
+ private Enumeration e;
+
+ /**
+ * Constructor
+ *
+ * @param e The enumeration
+ */
+ public EnumerationIterator(Enumeration e)
+ {
+ this.e = e;
+ }
+
+ /**
+ * Indicates if there are more items to iterate
+ *
+ * @return True if more, false otherwise
+ */
+ public boolean hasNext()
+ {
+ return e.hasMoreElements();
+ }
+
+ /**
+ * Gets the next item
+ *
+ * @return The next items
+ */
+ public T next()
+ {
+ return (T) e.nextElement();
+ }
+
+ /**
+ * Removes an item. Not supported
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,629 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.beans.Introspector;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.webbeans.BindingType;
+import javax.webbeans.ExecutionException;
+
+/**
+ * Utility class for static reflection-type operations
+ *
+ * @author Pete Muir
+ *
+ */
+public class Reflections
+{
+
+ /**
+ * Gets the property name from a getter method
+ *
+ * @param method The getter method
+ * @return The name of the property. Returns null if method wasn't JavaBean
+ * getter-styled
+ */
+ public static String getPropertyName(Method method)
+ {
+ String methodName = method.getName();
+ if (methodName.matches("^(get).*") &&
method.getParameterTypes().length == 0)
+ {
+ return Introspector.decapitalize(methodName.substring(3));
+ }
+ else if (methodName.matches("^(is).*") &&
method.getParameterTypes().length == 0)
+ {
+ return Introspector.decapitalize(methodName.substring(2));
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+
+ /**
+ * Checks if class is final
+ *
+ * @param clazz The class to check
+ * @return True if final, false otherwise
+ */
+ public static boolean isFinal(Class<?> clazz)
+ {
+ return Modifier.isFinal(clazz.getModifiers());
+ }
+
+ /**
+ * Checks if member is final
+ *
+ * @param member The member to check
+ * @return True if final, false otherwise
+ */
+ public static boolean isFinal(Member member)
+ {
+ return Modifier.isFinal(member.getModifiers());
+ }
+
+ /**
+ * Checks if type or member is final
+ *
+ * @param type Type or member
+ * @return True if final, false otherwise
+ */
+ public static boolean isTypeOrAnyMethodFinal(Class<?> type)
+ {
+ if (isFinal(type))
+ {
+ return true;
+ }
+ for (Method method : type.getDeclaredMethods())
+ {
+ if (isFinal(method))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks if type is primitive
+ *
+ * @param type Type to check
+ * @return True if primitive, false otherwise
+ */
+ public static boolean isPrimitive(Class<?> type)
+ {
+ return type.isPrimitive();
+ }
+
+ /**
+ * Checks if type is static
+ *
+ * @param type Type to check
+ * @return True if static, false otherwise
+ */
+ public static boolean isStatic(Class<?> type)
+ {
+ return Modifier.isStatic(type.getModifiers());
+ }
+
+ /**
+ * Checks if member is static
+ *
+ * @param member Member to check
+ * @return True if static, false otherwise
+ */
+ public static boolean isStatic(Member member)
+ {
+ return Modifier.isStatic(member.getModifiers());
+ }
+
+ public static boolean isTransient(Member member)
+ {
+ return Modifier.isTransient(member.getModifiers());
+ }
+
+ /**
+ * Checks if clazz is abstract
+ *
+ * @param clazz Class to check
+ * @return True if abstract, false otherwise
+ */
+ public static boolean isAbstract(Class<?> clazz)
+ {
+ return Modifier.isAbstract(clazz.getModifiers());
+ }
+
+ /**
+ * Checks if class is a static inner one
+ *
+ * @param clazz Class to check
+ * @return True if static, false otherwise
+ */
+ public static boolean isStaticInnerClass(Class<?> clazz)
+ {
+ return clazz.isMemberClass() && isStatic(clazz);
+ }
+
+ /**
+ * Checks if class is a non-static inner one
+ *
+ * @param clazz Class to Check
+ * @return True if static, false otherwise
+ */
+ public static boolean isNonStaticInnerClass(Class<?> clazz)
+ {
+ return clazz.isMemberClass() && !isStatic(clazz);
+ }
+
+ /**
+ * Gets a constructor with matching parameter types
+ *
+ * @param <T> The type
+ * @param clazz The class
+ * @param parameterTypes The parameter types
+ * @return The matching constructor. Null is returned if none is found
+ */
+ public static <T> Constructor<T> getConstructor(Class<T> clazz,
Class<?>... parameterTypes)
+ {
+ try
+ {
+ return clazz.getConstructor(parameterTypes);
+ }
+ catch (NoSuchMethodException e)
+ {
+ return null;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error accessing constructor (with parameters
" + parameterTypes + ") of " + clazz, e);
+ }
+ }
+
+ /**
+ * Gets all methods with a given annotation
+ *
+ * @param clazz The class the examine
+ * @param annotationType The annotation type to search for
+ * @return A list of matching methods. An empty list is returned if no
+ * matches are found
+ */
+ public static List<Method> getMethods(Class<?> clazz, Class<? extends
Annotation> annotationType)
+ {
+ List<Method> methods = new ArrayList<Method>();
+ for (Method method : clazz.getMethods())
+ {
+ if (method.isAnnotationPresent(annotationType))
+ {
+ methods.add(method);
+ }
+ }
+ return methods;
+ }
+
+ /**
+ * Gets all constructors with a given annotation
+ *
+ * @param <T> The type of the class
+ * @param clazz The class
+ * @param annotationType The annotation type
+ * @return A list of matching constructors. An empty list is returned if no
+ * matches are found
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<Constructor<T>>
getAnnotatedConstructors(Class<? extends T> clazz, Class<? extends Annotation>
annotationType)
+ {
+ List<Constructor<T>> constructors = new
ArrayList<Constructor<T>>();
+ for (Constructor<?> constructor : clazz.getConstructors())
+ {
+ if (constructor.isAnnotationPresent(annotationType))
+ {
+ constructors.add((Constructor<T>) constructor);
+ }
+ }
+ return constructors;
+ }
+
+ /**
+ * Gets constructors with a given annotated parameter
+ *
+ * @param <T> The type
+ * @param clazz The class
+ * @param parameterAnnotationType The parameter annotation type
+ * @return A list of matching constructors. An empty list is returned if no
+ * matches are found
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<Constructor<T>>
getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends
Annotation> parameterAnnotationType)
+ {
+ List<Constructor<T>> constructors = new
ArrayList<Constructor<T>>();
+ for (Constructor<?> constructor : clazz.getConstructors())
+ {
+ for (Annotation[] annotations : constructor.getParameterAnnotations())
+ {
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().equals(parameterAnnotationType))
+ {
+ constructors.add((Constructor<T>) constructor);
+ }
+ }
+ }
+ }
+ return constructors;
+ }
+
+ /**
+ * Gets constructors with a given meta-annotated parameter
+ *
+ * @param <T> The type
+ * @param clazz The class
+ * @param metaAnnotationType The parameter meta-annotation type
+ * @return A list of matching constructors. An empty list is returned if no
+ * matches are found
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> List<Constructor<T>>
getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<?
extends Annotation> metaAnnotationType)
+ {
+ List<Constructor<T>> constructors = new
ArrayList<Constructor<T>>();
+ for (Constructor<?> constructor : clazz.getConstructors())
+ {
+ for (Annotation[] annotations : constructor.getParameterAnnotations())
+ {
+ for (Annotation annotation : annotations)
+ {
+ if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
+ {
+ constructors.add((Constructor<T>) constructor);
+ }
+ }
+ }
+ }
+ return constructors;
+ }
+
+ /**
+ * Checks if all annotations types are in a given set of annotations
+ *
+ * @param annotations The annotation set
+ * @param annotationTypes The annotation types to match
+ * @return True if match, false otherwise
+ */
+ public static boolean annotationTypeSetMatches(Set<Class<? extends
Annotation>> annotations, Class<? extends Annotation>... annotationTypes)
+ {
+ List<Class<? extends Annotation>> annotationTypeList = new
ArrayList<Class<? extends Annotation>>();
+ annotationTypeList.addAll(Arrays.asList(annotationTypes));
+ for (Class<? extends Annotation> annotation : annotations)
+ {
+ if (annotationTypeList.contains(annotation))
+ {
+ annotationTypeList.remove(annotation);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return annotationTypeList.size() == 0;
+ }
+
+ /**
+ * Checks if all annotations are in a given set of annotations
+ *
+ * @param annotations The annotation set
+ * @param annotationTypes The annotations to match
+ * @return True if match, false otherwise
+ */
+ public static boolean annotationSetMatches(Set<Annotation> annotations,
Class<? extends Annotation>... annotationTypes)
+ {
+ List<Class<? extends Annotation>> annotationTypeList = new
ArrayList<Class<? extends Annotation>>();
+ annotationTypeList.addAll(Arrays.asList(annotationTypes));
+ for (Annotation annotation : annotations)
+ {
+ if (annotationTypeList.contains(annotation.annotationType()))
+ {
+ annotationTypeList.remove(annotation.annotationType());
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return annotationTypeList.size() == 0;
+ }
+
+ /**
+ * Gets the actual type arguments of a class
+ *
+ * @param clazz The class to examine
+ * @return The type arguments
+ */
+ public static Type[] getActualTypeArguments(Class<?> clazz)
+ {
+ if (clazz.getGenericSuperclass() instanceof ParameterizedType)
+ {
+ return ((ParameterizedType)
clazz.getGenericSuperclass()).getActualTypeArguments();
+ }
+ else
+ {
+ return new Type[0];
+ }
+ }
+
+ /**
+ * Checks if raw type is array type
+ *
+ * @param rawType The raw type to check
+ * @return True if array, false otherwise
+ */
+ public static boolean isArrayType(Class<?> rawType)
+ {
+ return rawType.isArray();
+ }
+
+ /**
+ * Checks if type is parameterized type
+ *
+ * @param type The type to check
+ * @return True if parameterized, false otherwise
+ */
+ public static boolean isParameterizedType(Class<?> type)
+ {
+ return type.getTypeParameters().length > 0;
+ }
+
+ /**
+ * Invokes a method and wraps exceptions
+ *
+ * @param method The method to invoke
+ * @param instance The instance to invoke on
+ * @param parameters The parameters
+ * @return The return value
+ */
+ public static Object invokeAndWrap(Method method, Object instance, Object...
parameters)
+ {
+ try
+ {
+ return method.invoke(instance, parameters);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error invoking method " +
method.getName() + " on " + method.getDeclaringClass(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error invoking method " +
method.getName() + " on " + method.getDeclaringClass(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new ExecutionException("Error invoking method " +
method.getName() + " on " + method.getDeclaringClass(), e);
+ }
+ }
+
+ /**
+ * Invokes a method and wraps exceptions
+ *
+ * @param methodName The method name to find on the instance and invoke
+ * @param parameterTypes The method name to find on the instance and invoke
+ * @param instance The instance to invoke on
+ * @param parameterValues The parameters values
+ * @return The return value
+ */
+ public static Object invokeAndWrap(String methodName, Class<?>[] parameterTypes,
Object instance, Object[] parameterValues)
+ {
+ try
+ {
+ return instance.getClass().getMethod(methodName,
parameterTypes).invoke(instance, parameterValues);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error invoking method " + methodName +
" on " + instance.getClass(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error invoking method " + methodName +
" on " + instance.getClass(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new ExecutionException("Error invoking method " + methodName +
" on " + instance.getClass(), e);
+ }
+ catch (SecurityException e)
+ {
+ throw new ExecutionException("Error invoking method " + methodName +
" on " + instance.getClass(), e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new ExecutionException("Error invoking method " + methodName +
" on " + instance.getClass(), e);
+ }
+ }
+
+ /**
+ * Sets value of a field and wraps exceptions
+ *
+ * @param field The field to set on
+ * @param target The instance to set on
+ * @param value The value to set
+ */
+ public static void setAndWrap(Field field, Object target, Object value)
+ {
+ try
+ {
+ field.set(target, value);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error setting field " + field.getName()
+ " on " + field.getDeclaringClass(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error setting field " + field.getName()
+ " on " + field.getDeclaringClass(), e);
+ }
+ }
+
+ /**
+ * Sets value of a field and wraps exceptions
+ *
+ * @param field The field to set on
+ * @param target The instance to set on
+ * @param value The value to set
+ */
+ public static void setAndWrap(String fieldName, Object target, Object value)
+ {
+ try
+ {
+ target.getClass().getField(fieldName).set(target, value);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error setting field " + fieldName +
" on " + target.getClass(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error setting field " + fieldName +
" on " + target.getClass(), e);
+ }
+ catch (SecurityException e)
+ {
+ throw new ExecutionException("Error setting field " + fieldName +
" on " + target.getClass(), e);
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw new ExecutionException("Error setting field " + fieldName +
" on " + target.getClass(), e);
+ }
+ }
+
+ /**
+ * Gets value of a field and wraps exceptions
+ *
+ * @param field The field to set on
+ * @param target The instance to set on
+ * @return The value to set
+ */
+ public static Object getAndWrap(Field field, Object target)
+ {
+ try
+ {
+ return field.get(target);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error getting field " + field.getName()
+ " on " + field.getDeclaringClass(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error getting field " + field.getName()
+ " on " + field.getDeclaringClass(), e);
+ }
+ }
+
+ /**
+ * Looks up a method in the type hierarchy of an instance
+ *
+ * @param method The method to look for
+ * @param instance The instance to start from
+ * @return The method found, or an NoSuchMethodException if it is not found
+ */
+ public static Method lookupMethod(Method method, Object instance)
+ {
+ for (Class<? extends Object> clazz = instance.getClass(); clazz != null;
clazz = clazz.getSuperclass())
+ {
+ try
+ {
+ Method targetMethod = clazz.getDeclaredMethod(method.getName(),
method.getParameterTypes());
+ if (!targetMethod.isAccessible())
+ {
+ targetMethod.setAccessible(true);
+ }
+ return targetMethod;
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ // Expected, nothing to see here.
+ }
+ }
+ throw new IllegalArgumentException("Method " + method.getName() + "
not implemented by instance");
+ }
+
+ /**
+ * Indicates if an instance is a Javassist proxy
+ *
+ * @param instance The instance to examine
+ * @return True if proxy, false otherwise
+ */
+ public static boolean isProxy(Object instance)
+ {
+ return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
+ }
+
+ /**
+ * Gets the type hierarchy for a class
+ *
+ * A recursive function that adds the class to the set of type and then calls
+ * itself with the suprerclass as paramater until the top of the hierarchy is
+ * reached. For each steps, adds all interfaces of the class to the set.
+ * Since the data structure is a set, duplications are eliminated
+ *
+ * @param clazz The class to examine
+ * @return The set of classes and interfaces in the hierarchy
+ * @see #getTypeHierachy(Class, Set)
+ */
+ public static Set<Class<?>> getTypeHierachy(Class<?> clazz)
+ {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ getTypeHierachy(clazz, classes);
+ return classes;
+ }
+
+ /**
+ * Gets the flattened type hierarchy for a class, including all super classes
+ * and the entire interface type hierarchy
+ *
+ * @param clazz the class to examine
+ * @param classes the set of types
+ */
+ public static void getTypeHierachy(Class<?> clazz, Set<? super
Class<?>> classes)
+ {
+ if (clazz != null)
+ {
+ classes.add(clazz);
+ getTypeHierachy(clazz.getSuperclass(), classes);
+ for (Class<?> c : clazz.getInterfaces())
+ {
+ getTypeHierachy(c, classes);
+ }
+ }
+ }
+
+ /**
+ * Checks the bindingType to make sure the annotation was declared properly
+ * as a binding type (annotated with @BindingType).
+ *
+ * @param bindingType The binding type to check
+ * @return true only if the annotation is really a binding type
+ */
+ public static boolean isBindingType(Annotation bindingType)
+ {
+ boolean isBindingAnnotation = false;
+ if (bindingType.annotationType().isAnnotationPresent(BindingType.class))
+ {
+ isBindingAnnotation = true;
+ }
+ return isBindingAnnotation;
+ }
+
+ public static boolean isSerializable(Class<?> clazz)
+ {
+ return getTypeHierachy(clazz).contains(Serializable.class);
+ }
+}
\ No newline at end of file
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,54 @@
+package org.jboss.webbeans.tck.api.util;
+
+import javax.webbeans.ExecutionException;
+
+/**
+ * Exception thrown when errors occur while loading resource
+ *
+ * @author Pete Muir
+ *
+ */
+public class ResourceLoadingException extends ExecutionException
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor
+ */
+ public ResourceLoadingException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message The message
+ * @param throwable The exception
+ */
+ public ResourceLoadingException(String message, Throwable throwable)
+ {
+ super(message, throwable);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message The message
+ */
+ public ResourceLoadingException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param throwable The exception
+ */
+ public ResourceLoadingException(Throwable throwable)
+ {
+ super(throwable);
+ }
+
+}
\ No newline at end of file
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,43 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.io.IOException;
+import java.net.URL;
+
+public class SimpleResourceLoader
+{
+
+ public Class<?> classForName(String name)
+ {
+
+ try
+ {
+ return Class.forName(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ catch (NoClassDefFoundError e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+ public URL getResource(String name)
+ {
+ return getClass().getResource(name);
+ }
+
+ public Iterable<URL> getResources(String name)
+ {
+ try
+ {
+ return new
EnumerationIterable<URL>(getClass().getClassLoader().getResources(name));
+ }
+ catch (IOException e)
+ {
+ throw new ResourceLoadingException(e);
+ }
+ }
+
+}
\ No newline at end of file
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java 2009-01-09
11:57:21 UTC (rev 846)
@@ -0,0 +1,25 @@
+package org.jboss.webbeans.tck.api.util;
+
+import java.util.StringTokenizer;
+
+public class Strings
+{
+ public static String[] split(String strings, String delims)
+ {
+ if (strings == null)
+ {
+ return new String[0];
+ }
+ else
+ {
+ StringTokenizer tokens = new StringTokenizer(strings, delims);
+ String[] result = new String[tokens.countTokens()];
+ int i = 0;
+ while (tokens.hasMoreTokens())
+ {
+ result[i++] = tokens.nextToken();
+ }
+ return result;
+ }
+ }
+}