Weld SVN: r6746 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 05:10:14 -0400 (Thu, 22 Jul 2010)
New Revision: 6746
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java
Log:
add more convenience methods
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java 2010-07-22 08:58:28 UTC (rev 6745)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java 2010-07-22 09:10:14 UTC (rev 6746)
@@ -24,6 +24,8 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
+import org.jboss.weld.extensions.literal.DefaultLiteral;
+
/**
* Utility class to resolve and acquire references to Beans
*
@@ -55,6 +57,26 @@
}
/**
+ * Resolves a bean with the qualifier @Default
+ *
+ */
+ public static Bean<?> resolveDefaultBean(Type beanType, BeanManager manager) throws AmbiguousBeanException, BeanResolutionException, BeanNotFoundException
+ {
+ Annotation[] qualifiers = new Annotation[1];
+ qualifiers[0] = DefaultLiteral.INSTANCE;
+ Set<Bean<?>> beans = manager.getBeans(beanType, qualifiers);
+ if (beans.size() == 0)
+ {
+ throw new BeanNotFoundException(beanType, qualifiers);
+ }
+ if (beans.size() != 1)
+ {
+ throw new AmbiguousBeanException(beanType, qualifiers, beans);
+ }
+ return beans.iterator().next();
+ }
+
+ /**
* gets a reference to a bean with the given type and qualifiers
*/
public static Object getReference(Type beanType, Annotation[] qualifiers, BeanManager manager) throws AmbiguousBeanException, BeanResolutionException, BeanNotFoundException
@@ -71,4 +93,23 @@
{
return (T) getReference((Type) beanType, qualifiers, manager);
}
+
+ /**
+ * gets a reference to a bean with the given type and qualifier @Default
+ */
+ public static Object getDefaultReference(Type beanType, BeanManager manager) throws AmbiguousBeanException, BeanResolutionException, BeanNotFoundException
+ {
+ Bean<?> bean = resolveDefaultBean(beanType, manager);
+ CreationalContext<?> context = manager.createCreationalContext(bean);
+ return manager.getReference(bean, beanType, context);
+ }
+
+ /**
+ * gets a reference to a bean with the given type and qualifier @Default
+ */
+ public static <T> T getDefaultReference(Class<T> beanType, BeanManager manager) throws AmbiguousBeanException, BeanResolutionException, BeanNotFoundException
+ {
+ return (T) getDefaultReference((Type) beanType, manager);
+ }
+
}
13 years, 10 months
Weld SVN: r6745 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 04:58:28 -0400 (Thu, 22 Jul 2010)
New Revision: 6745
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AmbiguousBeanException.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanNotFoundException.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolutionException.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
Log:
add utility class to resolve beans
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AmbiguousBeanException.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AmbiguousBeanException.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/AmbiguousBeanException.java 2010-07-22 08:58:28 UTC (rev 6745)
@@ -0,0 +1,42 @@
+/*
+ * 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.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+
+/**
+ * Exception thrown when more than 1 beans with the given type and qualifiers
+ * could be found
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class AmbiguousBeanException extends BeanResolutionException
+{
+
+ private static final long serialVersionUID = -6513493477765900752L;
+
+ public AmbiguousBeanException(Type type, Annotation[] qualifiers, Set<Bean<?>> beans)
+ {
+ super(type, qualifiers, "More than one bean found with type " + type + "and qualifiers. Bean found: " + beans);
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanNotFoundException.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanNotFoundException.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanNotFoundException.java 2010-07-22 08:58:28 UTC (rev 6745)
@@ -0,0 +1,40 @@
+/*
+ * 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.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+/**
+ * Exception thrown when no beans with the given type and qualifiers could be
+ * found
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class BeanNotFoundException extends BeanResolutionException
+{
+
+ private static final long serialVersionUID = -6513493477765900752L;
+
+ public BeanNotFoundException(Type type, Annotation[] qualifiers)
+ {
+ super(type, qualifiers, "No bean found with type " + type + "and qualifiers " + qualifiers);
+
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolutionException.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolutionException.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolutionException.java 2010-07-22 08:58:28 UTC (rev 6745)
@@ -0,0 +1,50 @@
+/*
+ * 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.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+/**
+ * Superclass for exceptions that result from bean lookup
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class BeanResolutionException extends Exception
+{
+ private static final long serialVersionUID = -4376259139316630962L;
+ private final Type type;
+ private final Annotation[] qualifiers;
+
+ public BeanResolutionException(Type type, Annotation[] qualifiers, String message)
+ {
+ this.type = type;
+ this.qualifiers = qualifiers;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public Annotation[] getQualifiers()
+ {
+ return qualifiers;
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/BeanResolver.java 2010-07-22 08:58:28 UTC (rev 6745)
@@ -0,0 +1,74 @@
+/*
+ * 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.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Utility class to resolve and acquire references to Beans
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class BeanResolver
+{
+ private BeanResolver()
+ {
+ }
+
+ /**
+ * Resolves a bean
+ *
+ */
+ public static Bean<?> resolveBean(Type beanType, Annotation[] qualifiers, BeanManager manager) throws AmbiguousBeanException, BeanResolutionException, BeanNotFoundException
+ {
+ Set<Bean<?>> beans = manager.getBeans(beanType, qualifiers);
+ if (beans.size() == 0)
+ {
+ throw new BeanNotFoundException(beanType, qualifiers);
+ }
+ if (beans.size() != 1)
+ {
+ throw new AmbiguousBeanException(beanType, qualifiers, beans);
+ }
+ return beans.iterator().next();
+ }
+
+ /**
+ * gets a reference to a bean with the given type and qualifiers
+ */
+ public static Object getReference(Type beanType, Annotation[] qualifiers, BeanManager manager) throws AmbiguousBeanException, BeanResolutionException, BeanNotFoundException
+ {
+ Bean<?> bean = resolveBean(beanType, qualifiers, manager);
+ CreationalContext<?> context = manager.createCreationalContext(bean);
+ return manager.getReference(bean, beanType, context);
+ }
+
+ /**
+ * gets a reference to a bean with the given type and qualifiers
+ */
+ public static <T> T getReference(Class<T> beanType, Annotation[] qualifiers, BeanManager manager) throws AmbiguousBeanException, BeanResolutionException, BeanNotFoundException
+ {
+ return (T) getReference((Type) beanType, qualifiers, manager);
+ }
+}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-07-22 06:46:07 UTC (rev 6744)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-07-22 08:58:28 UTC (rev 6745)
@@ -227,4 +227,23 @@
}
}
+ public static Object invokeAndWrap(Method method, Object target, Object... args)
+ {
+ try
+ {
+ return method.invoke(target, args);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof RuntimeException)
+ {
+ throw (RuntimeException) e;
+ }
+ else
+ {
+ throw new RuntimeException("exception invoking: " + method.getName(), e);
+ }
+ }
+ }
+
}
13 years, 10 months
Weld SVN: r6744 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 02:46:07 -0400 (Thu, 22 Jul 2010)
New Revision: 6744
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
Log:
add utility method to reflections
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-07-22 06:45:47 UTC (rev 6743)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/Reflections.java 2010-07-22 06:46:07 UTC (rev 6744)
@@ -36,9 +36,11 @@
*/
public class Reflections
{
-
- private Reflections() {}
+ private Reflections()
+ {
+ }
+
public static Set<Field> getFields(Class<?> clazz)
{
HashSet<Field> ret = new HashSet<Field>();
@@ -71,7 +73,7 @@
}
return null;
}
-
+
public static <X> AnnotatedField<? super X> getField(AnnotatedType<X> annotatedType, Field field)
{
for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
@@ -83,7 +85,7 @@
}
return null;
}
-
+
public static Set<Annotation> getAnnotationsWithMetatype(Set<Annotation> annotations, Class<? extends Annotation> metaAnnotationType)
{
Set<Annotation> set = new HashSet<Annotation>();
@@ -110,7 +112,6 @@
return set;
}
-
public static boolean methodExists(Class<?> parent, String name)
{
Class<?> p = parent;
@@ -193,7 +194,7 @@
}
return ret;
}
-
+
public static Class<?> getMemberType(Member member)
{
if (member instanceof Field)
@@ -213,5 +214,17 @@
throw new UnsupportedOperationException("Cannot operate on a member of type " + member.getClass());
}
}
-
+
+ public static Class classForName(String name) throws ClassNotFoundException
+ {
+ try
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(name);
+ }
+ catch (Exception e)
+ {
+ return Class.forName(name);
+ }
+ }
+
}
13 years, 10 months
Weld SVN: r6743 - extensions/trunk/src/main/java/org/jboss/weld/extensions/bean.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 02:45:47 -0400 (Thu, 22 Jul 2010)
New Revision: 6743
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java
Log:
use DummyInjectionTarget if type is an interface type
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java 2010-07-22 06:44:48 UTC (rev 6742)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java 2010-07-22 06:45:47 UTC (rev 6743)
@@ -61,13 +61,17 @@
this.type = type;
this.beanManager = beanManager;
}
-
+
public BeanBuilder<T> defineBeanFromAnnotatedType()
{
if (!type.getJavaClass().isInterface())
{
this.injectionTarget = beanManager.createInjectionTarget(type);
}
+ else
+ {
+ this.injectionTarget = new DummyInjectionTarget<T>();
+ }
this.qualifiers = new HashSet<Annotation>();
this.stereotypes = new HashSet<Class<? extends Annotation>>();
for (Annotation annotation : type.getAnnotations())
@@ -136,6 +140,7 @@
this.injectionTarget = injectionTarget;
return this;
}
+
public Set<Annotation> getQualifiers()
{
return qualifiers;
13 years, 10 months
Weld SVN: r6742 - extensions/trunk/src/main/java/org/jboss/weld/extensions/bean.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 02:44:48 -0400 (Thu, 22 Jul 2010)
New Revision: 6742
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/DummyInjectionTarget.java
Log:
add dummy injection target
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/DummyInjectionTarget.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/DummyInjectionTarget.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/DummyInjectionTarget.java 2010-07-22 06:44:48 UTC (rev 6742)
@@ -0,0 +1,61 @@
+/*
+ * 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.bean;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+/**
+ * Injection target implementation that does nothing
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class DummyInjectionTarget<T> implements InjectionTarget<T>
+{
+
+ public void inject(T instance, CreationalContext<T> ctx)
+ {
+ }
+
+ public void postConstruct(T instance)
+ {
+ }
+
+ public void preDestroy(T instance)
+ {
+ }
+
+ public void dispose(T instance)
+ {
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return Collections.emptySet();
+ }
+
+ public T produce(CreationalContext<T> ctx)
+ {
+ return null;
+ }
+
+}
13 years, 10 months
Weld SVN: r6741 - cdi-tck/trunk.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-21 09:07:38 -0400 (Wed, 21 Jul 2010)
New Revision: 6741
Modified:
cdi-tck/trunk/pom.xml
Log:
update parent to 12
Modified: cdi-tck/trunk/pom.xml
===================================================================
--- cdi-tck/trunk/pom.xml 2010-07-21 12:54:35 UTC (rev 6740)
+++ cdi-tck/trunk/pom.xml 2010-07-21 13:07:38 UTC (rev 6741)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-parent</artifactId>
- <version>10</version>
+ <version>12</version>
</parent>
<!-- Metadata -->
13 years, 10 months
Weld SVN: r6740 - in core/trunk: bom and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-07-21 08:54:35 -0400 (Wed, 21 Jul 2010)
New Revision: 6740
Modified:
core/trunk/bom/pom.xml
core/trunk/pom.xml
Log:
use newer parent
Modified: core/trunk/bom/pom.xml
===================================================================
--- core/trunk/bom/pom.xml 2010-07-21 12:03:30 UTC (rev 6739)
+++ core/trunk/bom/pom.xml 2010-07-21 12:54:35 UTC (rev 6740)
@@ -8,7 +8,7 @@
<parent>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-parent</artifactId>
- <version>11</version>
+ <version>12</version>
<relativePath />
</parent>
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2010-07-21 12:03:30 UTC (rev 6739)
+++ core/trunk/pom.xml 2010-07-21 12:54:35 UTC (rev 6740)
@@ -9,7 +9,7 @@
<parent>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-parent</artifactId>
- <version>10</version>
+ <version>12</version>
</parent>
<name>Weld Build Aggregator</name>
13 years, 10 months
Weld SVN: r6737 - build/trunk/dist.
by weld-commits@lists.jboss.org
Author: kpiwko(a)redhat.com
Date: 2010-07-21 08:02:37 -0400 (Wed, 21 Jul 2010)
New Revision: 6737
Modified:
build/trunk/dist/build.xml
Log:
Replaced URL to JBoss Nexus Snapshots repository on sonatype
Modified: build/trunk/dist/build.xml
===================================================================
--- build/trunk/dist/build.xml 2010-07-21 12:02:20 UTC (rev 6736)
+++ build/trunk/dist/build.xml 2010-07-21 12:02:37 UTC (rev 6737)
@@ -57,7 +57,7 @@
<dependency groupId="org.jboss.weld.servlet" artifactId="weld-servlet" version="${weld.servlet.version}" />
<dependency groupId="org.jboss.weld.servlet" artifactId="weld-servlet-int" version="${weld.servlet.version}" />
<remoteRepository id="repository.jboss.org" url="https://repository.jboss.org/nexus/content/groups/public/" />
- <remoteRepository id="oss.sonatype.org/jboss-snapshots" url="http://oss.sonatype.org/content/repositories/jboss-snapshots/" />
+ <remoteRepository id="oss.sonatype.org/jboss-snapshots" url="http://oss.sonatype.org/content/repositories/snapshots/" />
</artifact:dependencies>
<delete dir="target" failonerror="false" />
@@ -111,7 +111,7 @@
<arg line="-Dpackaging=zip" />
<arg line="-Dversion=${weld.version}" />
<arg line="-Dfile=${basedir}/weld-${weld.version}.zip" />
- <arg line="-Durl=http://oss.sonatype.org/content/repositories/jboss-snapshots/" />
+ <arg line="-Durl=http://oss.sonatype.org/content/repositories/snapshots/" />
<arg line="-DrepositoryId=oss.sonatype.org/jboss-snapshots" />
<arg line="-DuniqueVersion=false" />
</maven>
13 years, 10 months