You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2009/01/28 22:25:19 UTC
svn commit: r738628 - in
/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans:
config/DefinitionUtil.java inject/AbstractInjectable.java
util/WebBeansUtil.java
Author: struberg
Date: Wed Jan 28 21:25:19 2009
New Revision: 738628
URL: http://svn.apache.org/viewvc?rev=738628&view=rev
Log:
OWB-71 adding WebBeansUtil#checkForValidResources
Modified:
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=738628&r1=738627&r2=738628&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Wed Jan 28 21:25:19 2009
@@ -486,6 +486,10 @@
{
WebBeansUtil.checkForNewBindingForDeployment(field.getGenericType(), clazz, field.getName(), anns);
}
+ if (resourceAnns.length > 0)
+ {
+ WebBeansUtil.checkForValidResources(field.getGenericType(), clazz, field.getName(), anns);
+ }
int mod = field.getModifiers();
if (!Modifier.isStatic(mod) && !Modifier.isFinal(mod))
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=738628&r1=738627&r2=738628&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Wed Jan 28 21:25:19 2009
@@ -165,6 +165,7 @@
* @param type the class type which should be created
* @param annotations which has been defined in the web bean
* @return the instance linked with the annotation
+ * @see WebBeansUtil#checkForValidResources(Type, Class, String, Annotation[])
*/
private Object injectResource(Type type, Annotation... annotations)
{
Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=738628&r1=738627&r2=738628&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Wed Jan 28 21:25:19 2009
@@ -59,6 +59,10 @@
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.persistence.Entity;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.persistence.PersistenceUnit;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;
@@ -381,6 +385,55 @@
}
/**
+ * Check conditions for the resources.
+ *
+ * @param annotations annotations
+ * @return Annotation[] with all binding annotations
+ * @throws WebBeansConfigurationException if resource annotations exists and do not fit to the fields type, etc.
+ * @see AnnotationUtil#isResourceAnnotation(Class)
+ */
+ public static Annotation[] checkForValidResources(Type type, Class<?> clazz, String name, Annotation[] annotations)
+ {
+ Asserts.assertNotNull(type, "Type argument can not be null");
+ Asserts.assertNotNull(clazz, "Clazz argument can not be null");
+ Asserts.assertNotNull(annotations, "Annotations argument can not be null");
+
+ Annotation[] as = AnnotationUtil.getResourceAnnotations(annotations);
+ for (Annotation a : annotations)
+ {
+ if (a.annotationType().equals(PersistenceUnit.class))
+ {
+ if (!type.equals(EntityManagerFactory.class))
+ {
+ throw new WebBeansConfigurationException("@PersistenceUnit must only be injected into field with type EntityManagerFactory! class : "
+ + clazz.getName() + " in field/method : " + name);
+ }
+ }
+
+ if (a.annotationType().equals(PersistenceContext.class))
+ {
+ PersistenceContext pc = (PersistenceContext) a;
+
+ if (!type.equals(EntityManagerFactory.class))
+ {
+ throw new WebBeansConfigurationException("@PersistenceContext must only be injected into field with type EntityManager! class : "
+ + clazz.getName() + " in field/method : " + name);
+ }
+
+ if (pc.type().equals(PersistenceContextType.EXTENDED))
+ {
+ throw new WebBeansConfigurationException("type of @PersistenceContext must not be 'EXTENDED'! class : "
+ + clazz.getName() + " in field/method : " + name);
+
+ }
+ }
+ }
+
+ //X TODO add checks for other resources
+ return as;
+ }
+
+ /**
* Returns true if src scope encloses the target.
*
* @param src src scope