[webbeans-commits] Webbeans SVN: r2636 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext and 2 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Apr 30 09:51:45 EDT 2009


Author: vitold
Date: 2009-04-30 09:51:45 -0400 (Thu, 30 Apr 2009)
New Revision: 2636

Added:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/JmsResourceBeanChildrenChecker.java
Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/ResourceBeanChildrenChecker.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/JmsResourceElementRegistrator.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/ResourceElementRegistrator.java
   ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml
Log:
make 3.7

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java	2009-04-30 08:45:48 UTC (rev 2635)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java	2009-04-30 13:51:45 UTC (rev 2636)
@@ -42,6 +42,7 @@
 import org.jboss.webbeans.introspector.AnnotatedClass;
 import org.jboss.webbeans.log.Log;
 import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.xml.checker.beanchildren.ext.JmsResourceBeanChildrenChecker;
 import org.jboss.webbeans.xml.checker.beanchildren.ext.NotSimpleBeanChildrenChecker;
 import org.jboss.webbeans.xml.checker.beanchildren.ext.ResourceBeanChildrenChecker;
 import org.jboss.webbeans.xml.checker.beanchildren.ext.SimpleBeanChildrenChecker;
@@ -332,7 +333,7 @@
 
    private void checkBeanElement(Element beanElement, AnnotatedClass<?> beanClass)
    {
-      beanElementRegistrators.add(new JmsResourceElementRegistrator(new NotSimpleBeanChildrenChecker(environment, packagesMap)));
+      beanElementRegistrators.add(new JmsResourceElementRegistrator(new JmsResourceBeanChildrenChecker(environment, packagesMap)));
       beanElementRegistrators.add(new ResourceElementRegistrator(new ResourceBeanChildrenChecker(environment, packagesMap)));
       beanElementRegistrators.add(new SessionBeanElementRegistrator(new NotSimpleBeanChildrenChecker(environment, packagesMap), environment.getEjbDescriptors()));
       beanElementRegistrators.add(new SimpleBeanElementRegistrator(new SimpleBeanChildrenChecker(environment, packagesMap), environment.getEjbDescriptors()));

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java	2009-04-30 08:45:48 UTC (rev 2635)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java	2009-04-30 13:51:45 UTC (rev 2636)
@@ -48,7 +48,6 @@
 import org.jboss.webbeans.xml.ParseXmlHelper;
 import org.jboss.webbeans.xml.XmlConstants;
 import org.jboss.webbeans.xml.XmlEnvironment;
-import org.jboss.webbeans.xml.checker.beanchildren.BeanChildrenChecker;
 import org.jboss.webbeans.xml.checker.beanchildren.impl.BeanChildrenCheckerImpl;
 
 public abstract class AbstractBeanChildrenChecker extends BeanChildrenCheckerImpl

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/JmsResourceBeanChildrenChecker.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/JmsResourceBeanChildrenChecker.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/JmsResourceBeanChildrenChecker.java	2009-04-30 13:51:45 UTC (rev 2636)
@@ -0,0 +1,33 @@
+package org.jboss.webbeans.xml.checker.beanchildren.ext;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.ParseXmlHelper;
+import org.jboss.webbeans.xml.XmlConstants;
+import org.jboss.webbeans.xml.XmlEnvironment;
+
+public class JmsResourceBeanChildrenChecker extends ResourceBeanChildrenChecker
+{
+   private static final String RESOURCE_TYPE = "JMS";
+   
+   public JmsResourceBeanChildrenChecker(XmlEnvironment environment, Map<String, Set<String>> packagesMap)
+   {
+      super(environment, packagesMap);
+   }
+   
+   protected void checkRIBean(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      List<Element> resourceElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.RESOURCE);
+      if (resourceElements.size() > 0)
+         checkResourceElements(resourceElements);
+   }
+   
+   protected String getResourceType()
+   {
+      return RESOURCE_TYPE;
+   }
+}

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/ResourceBeanChildrenChecker.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/ResourceBeanChildrenChecker.java	2009-04-30 08:45:48 UTC (rev 2635)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/ResourceBeanChildrenChecker.java	2009-04-30 13:51:45 UTC (rev 2636)
@@ -30,6 +30,8 @@
 
 public class ResourceBeanChildrenChecker extends NotSimpleBeanChildrenChecker
 {
+   private static final String RESOURCE_TYPE = "Java EE";
+   
    public ResourceBeanChildrenChecker(XmlEnvironment environment, Map<String, Set<String>> packagesMap)
    {
       super(environment, packagesMap);
@@ -73,7 +75,7 @@
       }
    }
 
-   private void checkResourceElements(List<Element> resourceElements)
+   protected void checkResourceElements(List<Element> resourceElements)
    {
       Element resourceElement = resourceElements.get(0);
 
@@ -84,13 +86,18 @@
       List<Element> mappedNameElements = ParseXmlHelper.findElementsInEeNamespace(resourceElement, XmlConstants.MAPPED_NAME);
 
       if (nameElements.size() + mappedNameElements.size() != 1)
-         throw new DefinitionException("For a Java EE resource '" + resourceElement.getParent().getName() + "', JNDI name " + 
+         throw new DefinitionException("For a " + getResourceType() + " resource '" + resourceElement.getParent().getName() + "', JNDI name " + 
                "or mapped name must be specified using the <name> or <mappedName> child elements of the <Resource> element");
 
       if (nameElements.size() == 1)
          checkJndiNameElementValue(nameElements.get(0));
    }
 
+   protected String getResourceType()
+   {
+      return RESOURCE_TYPE;
+   }
+   
    private void checkPersContextElements(List<Element> persContextElements)
    {
       Element persContextElement = persContextElements.get(0);

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/JmsResourceElementRegistrator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/JmsResourceElementRegistrator.java	2009-04-30 08:45:48 UTC (rev 2635)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/JmsResourceElementRegistrator.java	2009-04-30 13:51:45 UTC (rev 2636)
@@ -16,13 +16,24 @@
  */
 package org.jboss.webbeans.xml.registrator.bean.ext;
 
+import java.lang.annotation.Annotation;
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.DefinitionException;
+
 import org.dom4j.Element;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bean.ee.AbstractJavaEEResourceBean;
+import org.jboss.webbeans.bean.ee.jms.JmsQueueBean;
+import org.jboss.webbeans.bean.ee.jms.JmsTopicBean;
 import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.messaging.spi.JmsServices;
 import org.jboss.webbeans.xml.ParseXmlHelper;
 import org.jboss.webbeans.xml.XmlConstants;
 import org.jboss.webbeans.xml.checker.beanchildren.BeanChildrenChecker;
 
-public class JmsResourceElementRegistrator extends NotSimpleBeanElementRegistrator
+public class JmsResourceElementRegistrator extends ResourceElementRegistrator
 {
    public JmsResourceElementRegistrator(BeanChildrenChecker childrenChecker)
    {
@@ -37,4 +48,34 @@
          return true;
       return false;
    }
+   
+   protected void checkElementDeclaration(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      List<Element> resourceElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.RESOURCE);
+      if (resourceElements.size() == 0)
+         throw new DefinitionException("Each JMS resource declaration must contain a child <Resource> element, " +
+               "but there is noone in <" + beanElement.getName() + ">");
+   }
+   
+   protected void register(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      Element resourceElement = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.RESOURCE).get(0);
+      
+      Class<? extends Annotation> deploymentType = obtainDeploymentType(beanElement);
+      Set<Annotation> bindings = obtainBindings(beanElement);
+      String jndiName = obtainElementValue(resourceElement, XmlConstants.JNDI_NAME);
+      String mappedName = obtainElementValue(resourceElement, XmlConstants.MAPPED_NAME);
+
+      RIBean<?> bean = null;
+      
+      if (XmlConstants.TOPIC.equalsIgnoreCase(beanElement.getName()))
+         bean = new JmsTopicBean(environment.getManager(), deploymentType, bindings, jndiName, mappedName);
+      else
+         bean = new JmsQueueBean(environment.getManager(), deploymentType, bindings, jndiName, mappedName);
+      
+      if (environment.getServices().contains(JmsServices.class))
+      {
+         environment.getResourceBeans().add((AbstractJavaEEResourceBean<?>) bean);
+      }
+   }
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/ResourceElementRegistrator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/ResourceElementRegistrator.java	2009-04-30 08:45:48 UTC (rev 2635)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/ResourceElementRegistrator.java	2009-04-30 13:51:45 UTC (rev 2636)
@@ -195,7 +195,7 @@
       }
    }
 
-   private Class<? extends Annotation> obtainDeploymentType(Element beanElement)
+   protected Class<? extends Annotation> obtainDeploymentType(Element beanElement)
    {
       Iterator<?> elIterator = beanElement.elementIterator();
       while (elIterator.hasNext())
@@ -209,7 +209,7 @@
       return null;
    }
 
-   private Set<Annotation> obtainBindings(Element beanElement)
+   protected Set<Annotation> obtainBindings(Element beanElement)
    {
       Set<Annotation> result = new HashSet<Annotation>();
 
@@ -238,7 +238,7 @@
       return result;
    }
 
-   private String obtainElementValue(Element elementParent, String elementName)
+   protected String obtainElementValue(Element elementParent, String elementName)
    {
       List<Element> elements = ParseXmlHelper.findElementsInEeNamespace(elementParent, elementName);
       if (elements.size() > 0)

Modified: ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml
===================================================================
--- ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml	2009-04-30 08:45:48 UTC (rev 2635)
+++ ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml	2009-04-30 13:51:45 UTC (rev 2636)
@@ -2,7 +2,7 @@
 	xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.parser"
 	xmlns:manager="urn:java:javax.inject.manager"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="urn:java:org.jboss.webbeans.test.unit.xml.parser http://mydomain.com/myapp/schema-1.2.xsd">
+	xsi:schemaLocation="urn:java:org.jboss.webbeans.test.unit.xml.parser">
 	<Deploy>
 		<Standard />
 		<Production />
@@ -21,7 +21,7 @@
 		<myapp:TestScopeType />
 		<myapp:TestDeploymentType />
 		<myapp:AnotherTestInterceptorBindingType />
-		<myapp:TestNamed />
+		<Named />
 	</myapp:TestStereotype>
 	
 	<myapp:Order>
@@ -36,7 +36,8 @@
 		<myapp:val />
 		<Integer />
 	</myapp:Order>
-	<myapp:PaymentResource>
+<!--	
+	<myapp:PaymentService>
 		<RequestScoped />
 		<myapp:TestBindingType />
 		<myapp:TestInterceptorBindingType />
@@ -45,8 +46,15 @@
 		<Resource>
 			<name>java:app/service/PaymentService</name>
 		</Resource>
-	</myapp:PaymentResource>
-	
+	</myapp:PaymentService>
+-->
+
+	<Topic>
+		<Resource>
+			<name>java:app/service/PaymentService</name>
+		</Resource>
+	</Topic>
+		
 	<Decorators>
 		<myapp:TestDecorator />	
 	</Decorators>




More information about the weld-commits mailing list