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

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Apr 15 13:42:08 EDT 2009


Author: vitold
Date: 2009-04-15 13:42:07 -0400 (Wed, 15 Apr 2009)
New Revision: 2420

Added:
   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/
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/BeanElementRegistrator.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/
   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/NotSimpleBeanElementRegistrator.java
   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/SessionBeanElementRegistrator.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/SimpleBeanElementRegistrator.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/impl/
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/impl/BeanElementRegistratorImpl.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/PaymentService.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/AnotherTestInterceptorBindingType.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestBindingType.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestDeploymentType.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestInterceptorBindingType.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestNamed.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestScopeType.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestStereotype.java
   ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema.xsd
Removed:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/bean/
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/TestDeploymentType.java
Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/BeanChildrenChecker.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/NotSimpleBeanChildrenChecker.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/SimpleBeanChildrenChecker.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java
   ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/namespace
   ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml
Log:
some changes with 3.6

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlConstants.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -29,8 +29,12 @@
    public static final String EJB = "EJB";
 
    public static final String EJB_NAME = "ejbName";
+   
+   public static final String EJB_LINK = "ejbLink";
 
    public static final String WEB_SERVICE_REF = "WebServiceRef";
+   
+   public static final String WSDL_LOCATION = "wsdlLocation";
 
    public static final String TOPIC = "Topic";
 
@@ -45,6 +49,8 @@
    public static final String NAME = "name";
 
    public static final String MAPPED_NAME = "mappedName";
+   
+   public static final String UNIT_NAME = "unitName";
 
    public static final String STANDARD = "Standard";
 
@@ -59,4 +65,10 @@
    public static final String VALUE = "value";
    
    public static final String ARRAY = "Array";
+   
+   public static final String JNDI_NAME = "jndiName";
+   
+   public static final String JAVA_GLOBAL = "java:global/";
+   
+   public static final String JAVA_APP = "java:app/";
 }

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-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -3,7 +3,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -13,7 +12,6 @@
 import java.util.Set;
 
 import javax.annotation.Named;
-import javax.annotation.Stereotype;
 import javax.context.ScopeType;
 import javax.inject.DefinitionException;
 import javax.inject.DeploymentException;
@@ -25,16 +23,16 @@
 import org.dom4j.Element;
 import org.dom4j.io.SAXReader;
 import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.introspector.AnnotatedField;
 import org.jboss.webbeans.log.Log;
 import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.xml.checker.bean.BeanElementChecker;
-import org.jboss.webbeans.xml.checker.bean.ext.JmsResourceElementChecker;
-import org.jboss.webbeans.xml.checker.bean.ext.ResourceElementChecker;
-import org.jboss.webbeans.xml.checker.bean.ext.SessionBeanElementChecker;
-import org.jboss.webbeans.xml.checker.bean.ext.SimpleBeanElementChecker;
 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;
+import org.jboss.webbeans.xml.registrator.bean.BeanElementRegistrator;
+import org.jboss.webbeans.xml.registrator.bean.ext.JmsResourceElementRegistrator;
+import org.jboss.webbeans.xml.registrator.bean.ext.ResourceElementRegistrator;
+import org.jboss.webbeans.xml.registrator.bean.ext.SessionBeanElementRegistrator;
+import org.jboss.webbeans.xml.registrator.bean.ext.SimpleBeanElementRegistrator;
 
 public class XmlParser
 {
@@ -42,7 +40,7 @@
    
    private final XmlEnvironment environment;
    
-   private List<BeanElementChecker> beanElementCheckers = new ArrayList<BeanElementChecker>();
+   private List<BeanElementRegistrator> beanElementRegistrators = new ArrayList<BeanElementRegistrator>();
    
    private boolean haveAnyDeployElement = false;
    
@@ -145,18 +143,12 @@
          
    private void parseForBeans(Document document)
    {
-      List<AnnotatedClass<?>> beanClasses = new ArrayList<AnnotatedClass<?>>();
-      
       List<Element> beanElements = findBeans(document);      
       for (Element beanElement : beanElements)
       {
          AnnotatedClass<?> beanClass = ParseXmlHelper.loadElementClass(beanElement, Object.class, environment, packagesMap);
          checkBeanElement(beanElement, beanClass);
-         checkProduces(beanElement, beanClass);
-         beanClasses.add(beanClass);
       }
-      
-      environment.getClasses().addAll(beanClasses);
    }
    
    private void parseForDeploy(Document document)
@@ -317,17 +309,17 @@
    
    private void checkBeanElement(Element beanElement, AnnotatedClass<?> beanClass)
    {
-      beanElementCheckers.add(new JmsResourceElementChecker(new NotSimpleBeanChildrenChecker(environment, packagesMap)));
-      beanElementCheckers.add(new ResourceElementChecker(new NotSimpleBeanChildrenChecker(environment, packagesMap)));
-      beanElementCheckers.add(new SessionBeanElementChecker(new NotSimpleBeanChildrenChecker(environment, packagesMap), environment.getEjbDescriptors()));
-      beanElementCheckers.add(new SimpleBeanElementChecker(new SimpleBeanChildrenChecker(environment, packagesMap), environment.getEjbDescriptors()));
+      beanElementRegistrators.add(new JmsResourceElementRegistrator(new NotSimpleBeanChildrenChecker(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()));
       
       boolean isValidType = false;
-      for(BeanElementChecker beanElementChecker : beanElementCheckers)
+      for(BeanElementRegistrator beanElementRegistrator : beanElementRegistrators)
       {
-         if(beanElementChecker.accept(beanElement, beanClass))
+         if(beanElementRegistrator.accept(beanElement, beanClass))
          {
-            beanElementChecker.checkBeanElement(beanElement, beanClass);
+            beanElementRegistrator.registerBeanElement(beanElement, beanClass);
             isValidType = true;
             break;
          }
@@ -337,110 +329,6 @@
          throw new DefinitionException("Can't determine type of bean element <" + beanElement.getName() + ">");
    }
    
-   private void checkProduces(Element beanElement, AnnotatedClass<?> beanClass)
-   {//TODO: will refactor
-      Iterator<?> beanIterator = beanElement.elementIterator();
-      while(beanIterator.hasNext())
-      {
-         Element beanChild = (Element)beanIterator.next();  
-         List<Element> producesElements = ParseXmlHelper.findElementsInEeNamespace(beanChild, XmlConstants.PRODUCES);
-         
-         if(producesElements.size() == 0)
-            continue;
-         
-         if(producesElements.size() > 1)
-            throw new DefinitionException("There is more than one child <Produces> element for <" + beanChild.getName()  + "> element");
-         
-         List<AnnotatedClass<?>> producesChildTypes = new ArrayList<AnnotatedClass<?>>();
-         
-         Element producesElement = producesElements.get(0);
-         Iterator<?> producesIt = producesElement.elementIterator();
-         while(producesIt.hasNext())
-         {
-            Element producesChild = (Element)producesIt.next();
-            AnnotatedClass<?> producesChildClass = ParseXmlHelper.loadElementClass(producesChild, Object.class, environment, packagesMap);
-            Class<?> producesChildType = producesChildClass.getRawType();
-            boolean isJavaClass = !producesChildType.isEnum() && !producesChildType.isPrimitive() && !producesChildType.isInterface();
-            boolean isInterface = producesChildType.isInterface() && !producesChildType.isAnnotation();
-            if(isJavaClass || isInterface)
-            {
-               producesChildTypes.add(producesChildClass);
-               continue;
-            }
-            if(producesChildType.isAnnotation())
-            {
-               if(producesChildClass.isAnnotationPresent(DeploymentType.class) || 
-                     producesChildClass.isAnnotationPresent(ScopeType.class) || 
-                     producesChildClass.isAnnotationPresent(Stereotype.class) ||
-                     producesChildClass.isAnnotationPresent(Named.class))
-                  continue;
-                                             
-               throw new DefinitionException("<" + producesChild.getName() + "> direct child of <Produces> element for <" + beanChild.getName() 
-                     + "> in bean" + beanElement.getName() + "must be DeploymentType or ScopeType or Stereotype or Named");
-            }
-            throw new DefinitionException("Only Java class, interface type and Java annotation type can be " +
-            		"direct child of <Produces> element for <" + beanChild.getName() + "> in bean" + beanElement.getName() + 
-            		". Element <" + producesChild.getName() + "> is incorrect");
-         }
-         
-         if(producesChildTypes.size() != 1)
-            throw new DefinitionException("More than one or no one child element of <Produces> element for <" + beanChild.getName() + 
-                  "> in bean" + beanElement.getName() + " represents a Java class or interface type");
-         
-         AnnotatedClass<?> expectedType = producesChildTypes.get(0);
-                  
-         Method beanMethod = null;         
-         AnnotatedField<?> beanField = beanClass.getDeclaredField(beanChild.getName(), expectedType);
-
-         try
-         {
-            List<Class<?>> paramClassesList = new ArrayList<Class<?>>();
-            Iterator<?> beanChildIt = beanChild.elementIterator();
-            while(beanChildIt.hasNext())
-            {
-               Element methodChild = (Element)beanChildIt.next();
-               if(methodChild.getName().equalsIgnoreCase(XmlConstants.PRODUCES))
-                  continue;
-               paramClassesList.add(ParseXmlHelper.loadElementClass(methodChild, Object.class, environment, packagesMap).getRawType());
-            }
-            Class<?>[] paramClasses = (Class<?>[])paramClassesList.toArray(new Class[0]);
-            beanMethod = beanClass.getRawType().getDeclaredMethod(beanChild.getName(), paramClasses);
-         }
-         catch (SecurityException e)
-         {}
-         catch (NoSuchMethodException e)
-         {}
-         
-         if(beanField != null && beanMethod != null)
-            throw new DefinitionException("Class '" + beanClass.getName() + "' has produser field and method with the same name '" + 
-                  beanField.getName() + "'");
-         
-         if(beanField != null)
-         {
-            if(beanChild.elements().size() > 1)
-               throw new DefinitionException("There is more than one direct child element for producer field <" + beanChild.getName() + ">");
-            continue;
-         }
-         
-         if(beanMethod != null)
-         {
-            Iterator<?> beanChildIt = producesElement.elementIterator();
-            while(beanChildIt.hasNext())
-            {
-               Element element = (Element)beanChildIt.next();
-               if(!element.getName().equalsIgnoreCase(XmlConstants.PRODUCES) && 
-                     ParseXmlHelper.findElementsInEeNamespace(beanChild, XmlConstants.INTERCEPTOR).size() == 0)
-                  throw new DefinitionException("Only Produces and interceptor binding types can be direct childs of a producer " +
-                  		"method '" + beanChild.getName() + "' declaration in bean '" + beanElement.getName() + "'");
-            }
-            continue;
-         }
-         
-         throw new DefinitionException("A producer '" + beanChild.getName() + "' doesn't declared in '" + beanElement.getName() + 
-               "' class file as method or field");
-      }                  
-   }
-   
    private void fullFillPackagesMap(Document document, URL xmlUrl)
    {
       Element root = document.getRootElement();      

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/BeanChildrenChecker.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/BeanChildrenChecker.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/BeanChildrenChecker.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -1,9 +1,17 @@
 package org.jboss.webbeans.xml.checker.beanchildren;
 
+import java.util.Map;
+import java.util.Set;
+
 import org.dom4j.Element;
 import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.XmlEnvironment;
 
 public interface BeanChildrenChecker
 {   
    void checkChildren(Element beanElement, AnnotatedClass<?> beanClass);
+   
+   XmlEnvironment getXmlEnvironment();
+   
+   Map<String, Set<String>> getPackagesMap();
 }

Added: 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	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,233 @@
+package org.jboss.webbeans.xml.checker.beanchildren.ext;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Named;
+import javax.annotation.Resource;
+import javax.annotation.Stereotype;
+import javax.context.ScopeType;
+import javax.decorator.Decorator;
+import javax.ejb.EJB;
+import javax.inject.BindingType;
+import javax.inject.DefinitionException;
+import javax.inject.DeploymentType;
+import javax.inject.Realizes;
+import javax.inject.Specializes;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InterceptorBindingType;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+import javax.xml.ws.WebServiceRef;
+
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedField;
+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
+{
+   
+   private Set<AnnotatedField<?>> beanFields;
+   
+   private List<Method> beanMethods; 
+   
+   private boolean haveBeanDeploymentTypeDeclaration = false;
+   
+   private boolean haveBeanScopeTypeDeclaration = false;
+   
+   protected boolean haveBeanInterceptorDeclaration = false;
+   
+   protected boolean haveBeanDecoratorDeclaration = false;
+   
+   protected List<AnnotatedClass<?>> constructorParameters = new ArrayList<AnnotatedClass<?>>();
+         
+   protected abstract void checkForInterceptorChild(Element beanElement);
+   
+   protected abstract void checkForDecoratorChild(Element beanElement);
+   
+   protected abstract void checkChildForInterceptorType(Element beanElement);
+   
+   protected abstract void checkChildForDecoratorType(Element beanElement);
+   
+   protected abstract void checkForConstructor(Element beanElement, AnnotatedClass<?> beanClass);
+   
+   protected AbstractBeanChildrenChecker(XmlEnvironment environment, Map<String, Set<String>> packagesMap)
+   {
+      super(environment, packagesMap);
+   }
+   
+   public void checkChildren(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      beanFields = beanClass.getFields();
+      beanMethods = Arrays.asList(beanClass.getRawType().getDeclaredMethods());
+      
+      checkForInterceptorChild(beanElement);
+      checkForDecoratorChild(beanElement);
+      
+      haveBeanDeploymentTypeDeclaration = false;
+      haveBeanScopeTypeDeclaration = false;
+      haveBeanInterceptorDeclaration = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.INTERCEPTOR).size() > 0;
+      haveBeanDecoratorDeclaration = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.DECORATOR).size() > 0;
+      
+      Iterator<?> beanIterator = beanElement.elementIterator();
+      while(beanIterator.hasNext())
+      {
+         Element beanChildElement = (Element)beanIterator.next();
+         checkBeanChild(beanChildElement, beanClass);
+      }
+      checkForConstructor(beanElement, beanClass);
+   }
+   
+   private void checkBeanChild(Element beanChildElement, AnnotatedClass<?> beanClass)
+   {
+      try
+      {
+         if(beanChildElement.getName().equalsIgnoreCase(XmlConstants.ARRAY))
+            return;
+         AnnotatedClass<?> beanChildClass = ParseXmlHelper.loadElementClass(beanChildElement, Object.class, environment, packagesMap);
+         Class<?> beanChildType = beanChildClass.getRawType();
+         boolean isJavaClass = !beanChildType.isEnum() && !beanChildType.isPrimitive() && !beanChildType.isInterface();
+         boolean isInterface = beanChildType.isInterface() && !beanChildType.isAnnotation();
+         if(beanChildType.isAnnotation())
+         {
+            //bean child element declaring type-level metadata
+            checkAnnotationChild(beanChildElement, beanChildClass);
+            return;
+         }
+         if(isJavaClass || isInterface)
+         {
+            //bean child element declaring a parameter of the bean constructor
+            constructorParameters.add(beanChildClass);
+            return;
+         }
+         throw new DefinitionException(new DefinitionException(beanChildElement.getName() + " can't be interpreted as a Java class or interface or Java Annotation type"));
+      }
+      catch(DefinitionException e)
+      {
+         if(!(e.getCause() instanceof DefinitionException))
+         {
+            throw new DefinitionException(e);
+         }
+         
+         Element beanElement = beanChildElement.getParent();
+         Namespace beanNamespace = beanElement.getNamespace();
+         Namespace beanChildNamespace = beanChildElement.getNamespace();
+         if(beanChildNamespace.equals(beanNamespace))
+         {
+            //bean child element declaring a method or field of the bean.
+            checkFieldOrMethodChild(beanChildElement, beanClass);
+            return;
+         }
+         throw new DefinitionException("Can't determine type of element <" + beanChildElement.getName() + "> in bean '" + 
+               beanElement.getName() + "'");
+      }
+   }
+   
+   private void checkAnnotationChild(Element beanChildElement, AnnotatedClass<?> beanChildClass)
+   {
+      if(beanChildClass.isAnnotationPresent(DeploymentType.class))
+      {
+         if(haveBeanDeploymentTypeDeclaration)
+            throw new DefinitionException("Only one deployment type declaration allowed for bean '" + 
+                  beanChildElement.getParent().getName() + "'");
+         haveBeanDeploymentTypeDeclaration = true;
+         return;
+      }
+      if(beanChildClass.isAnnotationPresent(ScopeType.class))
+      {
+         if(haveBeanScopeTypeDeclaration)
+            throw new DefinitionException("Only one scope type declaration allowed for bean '" + 
+                  beanChildElement.getParent().getName() + "'");
+         haveBeanScopeTypeDeclaration = true;
+         return;
+      }
+      if(beanChildClass.isAnnotationPresent(Interceptor.class))
+      {
+         checkChildForInterceptorType(beanChildElement);
+         return;
+      }
+      if(beanChildClass.isAnnotationPresent(Decorator.class))
+      {
+         checkChildForDecoratorType(beanChildElement);
+         return;
+      }
+      if(beanChildClass.isAnnotationPresent(BindingType.class) || beanChildClass.isAnnotationPresent(InterceptorBindingType.class) || 
+            beanChildClass.isAnnotationPresent(Stereotype.class) || beanChildClass.isAnnotationPresent(Named.class) || 
+            beanChildClass.isAnnotationPresent(Specializes.class) || beanChildClass.isAnnotationPresent(Realizes.class) || 
+            beanChildClass.isAnnotationPresent(Resource.class) || beanChildClass.isAnnotationPresent(EJB.class) || 
+            beanChildClass.isAnnotationPresent(WebServiceRef.class) || beanChildClass.isAnnotationPresent(PersistenceContext.class) || 
+            beanChildClass.isAnnotationPresent(PersistenceUnit.class))
+         return;
+      
+      throw new DefinitionException("Can't determine annotation type of <" + beanChildElement.getName() + "> element in bean '" + 
+            beanChildElement.getParent().getName() + "'");
+   }
+   
+   private void checkFieldOrMethodChild(Element beanChildElement, AnnotatedClass<?> beanClass)
+   {  //TODO: not finished    
+      boolean isField = false;
+      boolean isMethod = false;
+      
+      for(AnnotatedField<?> field : beanFields)
+      {
+         if(beanChildElement.getName().equalsIgnoreCase(field.getName()))
+         {
+            if(isField)
+               throw new DefinitionException("Bean class '" + beanClass.getName() + "' does not have exactly one field " +
+               		"with the specified name '" + beanChildElement.getName() + "'");
+            isField = true;
+         }
+      }
+      
+      for(Method method : beanMethods)
+      {
+         if(beanChildElement.getName().equalsIgnoreCase(method.getName()))
+            isMethod = true;
+      }
+      
+      if(isField && isMethod)
+         throw new DefinitionException("The name of the child element <" + beanChildElement.getName() + 
+               "> matches the name of both a method and a field of the bean class '" + beanClass.getName() + "'");
+      
+      if(isField)
+         checkFieldChild(beanChildElement, beanClass);
+      
+      if(isMethod)
+         checkMethodChild(beanChildElement, beanClass);
+   }
+   
+   private void checkFieldChild(Element beanChildElement, AnnotatedClass<?> beanClass)
+   {//TODO: not finished
+      Element elementParent = beanChildElement.getParent();
+      String elementName = beanChildElement.getName();
+      String elementPrefix = beanChildElement.getNamespacePrefix();
+      String elementUri = beanChildElement.getNamespaceURI();
+      
+      if(ParseXmlHelper.findElements(elementParent, elementName, elementPrefix, elementUri).size() > 1)
+         throw new DefinitionException("More than one child element of a bean '" + elementParent.getName() + 
+               "' declaration represents the same field'" + elementName + "'");
+      
+      if(beanChildElement.elements().size() > 1 && 
+            beanChildElement.elements().size() != ParseXmlHelper.findElementsInEeNamespace(beanChildElement, XmlConstants.VALUE).size())
+         throw new DefinitionException("Declaration of a field '" + beanChildElement.getName() + "' has more than one direct child element, " +
+         		"and at least one of these elements is something other than a <value> element in the Java EE namespace");
+      
+      
+   }
+   
+   private void checkMethodChild(Element beanChildElement, AnnotatedClass<?> beanClass)
+   {
+      //TODO: not finished
+   }
+}

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/NotSimpleBeanChildrenChecker.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/NotSimpleBeanChildrenChecker.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/NotSimpleBeanChildrenChecker.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -10,42 +10,41 @@
 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.impl.BeanChildrenCheckerImpl;
 
-public class NotSimpleBeanChildrenChecker extends BeanChildrenCheckerImpl
+public class NotSimpleBeanChildrenChecker extends AbstractBeanChildrenChecker
 {
    public NotSimpleBeanChildrenChecker(XmlEnvironment environment, Map<String, Set<String>> packagesMap)
    {
       super(environment, packagesMap);
    }
 
-   public void checkForInterceptorChild(Element beanElement)
+   protected void checkForInterceptorChild(Element beanElement)
    {
       if(ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.INTERCEPTOR).size() > 1)
          throw new DefinitionException("Not a simple bean '" + beanElement.getName() + "' contains direct child <" + 
                XmlConstants.INTERCEPTOR + ">");            
    }
    
-   public void checkForDecoratorChild(Element beanElement)
+   protected void checkForDecoratorChild(Element beanElement)
    {
       if(ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.DECORATOR).size() > 1)
          throw new DefinitionException("Not a simple bean '" + beanElement.getName() + "' contains direct child <" + 
                XmlConstants.DECORATOR + ">");
    }
    
-   public void checkChildForInterceptorType(Element beanChildElement)
+   protected void checkChildForInterceptorType(Element beanChildElement)
    {
       throw new DefinitionException("Declaration of not a simple bean '" + beanChildElement.getParent().getName() + 
          "' contains a child <" + beanChildElement.getName() + "> which type is javax.interceptor.Interceptor");
    }
    
-   public void checkChildForDecoratorType(Element beanChildElement)
+   protected void checkChildForDecoratorType(Element beanChildElement)
    {
       throw new DefinitionException("Declaration of not a simple bean '" + beanChildElement.getParent().getName() + 
          "' contains a child <" + beanChildElement.getName() + "> which type is javax.decorator.Decorator");
    }
    
-   public void checkForConstructor(Element beanElement, AnnotatedClass<?> beanClass)
+   protected void checkForConstructor(Element beanElement, AnnotatedClass<?> beanClass)
    {
       //There is nothing to validate
    }

Added: 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	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/ResourceBeanChildrenChecker.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,152 @@
+package org.jboss.webbeans.xml.checker.beanchildren.ext;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.DefinitionException;
+
+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;
+import org.jboss.webbeans.xml.checker.beanchildren.impl.BeanChildrenCheckerImpl;
+
+public class ResourceBeanChildrenChecker extends BeanChildrenCheckerImpl
+{
+   public ResourceBeanChildrenChecker(XmlEnvironment environment, Map<String, Set<String>> packagesMap)
+   {
+      super(environment, packagesMap);
+   }
+
+   public void checkChildren(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      List<Element> resourceElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.RESOURCE);
+      if(resourceElements.size() > 0)
+      {
+         checkResourceElements(resourceElements);
+         return;
+      }
+      
+      List<Element> persContextElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.PERSISTENCE_CONTEXT);
+      if(persContextElements.size() > 0)
+      {
+         checkPersContextElements(persContextElements);
+         return;
+      }
+         
+      List<Element> persUnitElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.PERSISTENCE_UNIT);
+      if(persUnitElements.size() > 0)
+      {
+         checkPersUnitElements(persUnitElements);
+         return;
+      }
+         
+      List<Element> ejbElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.EJB);
+      if(ejbElements.size() > 0)
+      {
+         checkEjbElements(ejbElements);
+         return;
+      }
+         
+      List<Element> webServiceRefElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.WEB_SERVICE_REF);
+      if(webServiceRefElements.size() > 0)
+      {
+         checkWebServiceRefElements(webServiceRefElements);
+         return;
+      }         
+   }
+   
+   private void checkResourceElements(List<Element> resourceElements)
+   {
+      Element resourceElement = resourceElements.get(0);
+      
+      if(resourceElements.size() > 1)
+         throw new DefinitionException("There is more than one <Resource> elements in '" + resourceElement.getParent().getName() + "'");
+                  
+      List<Element> nameElements = ParseXmlHelper.findElementsInEeNamespace(resourceElement, XmlConstants.NAME);
+      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 " +
+               "or mapped name must be specified using the <name> or <mappedName> child elements of the <Resource> element");
+      
+      if(nameElements.size() == 1)
+         checkNameElementValue(nameElements.get(0));
+   }
+   
+   private void checkPersContextElements(List<Element> persContextElements)
+   {
+      Element persContextElement = persContextElements.get(0);
+      
+      if(persContextElements.size() > 1)
+         throw new DefinitionException("There is more than one <PersistenceContext> elements in '" + 
+               persContextElement.getParent().getName() + "'");
+      
+      List<Element> unitNameElements = ParseXmlHelper.findElementsInEeNamespace(persContextElement, XmlConstants.UNIT_NAME);
+      
+      if(unitNameElements.size() != 1)
+         throw new DefinitionException("For a persistence context '" + persContextElement.getParent().getName() + "', " +
+               "a persistence unit name must be specified using the <unitName> child element of the <PersistenceContext> element");
+   }
+   
+   private void checkPersUnitElements(List<Element> persUnitElements)
+   {
+      Element persUnitElement = persUnitElements.get(0);
+      
+      if(persUnitElements.size() > 1)
+         throw new DefinitionException("There is more than one <PersistenceUnit> elements in '" + persUnitElement.getParent().getName() + "'");
+      
+      List<Element> unitNameElements = ParseXmlHelper.findElementsInEeNamespace(persUnitElement, XmlConstants.UNIT_NAME);
+      if(unitNameElements.size() != 1)
+         throw new DefinitionException("For a persistence unit '" + persUnitElement.getParent().getName() + "', " +
+               "a persistence unit name must be specified using the <unitName> child element of the <PersistenceUnit> element");
+   }
+   
+   private void checkEjbElements(List<Element> ejbElements)
+   {
+      Element ejbElement = ejbElements.get(0);
+      
+      if(ejbElements.size() > 1)
+         throw new DefinitionException("There is more than one <EJB> elements in '" + ejbElement.getParent().getName() + "'");
+      
+      List<Element> nameElements = ParseXmlHelper.findElementsInEeNamespace(ejbElement, XmlConstants.NAME);
+      List<Element> mappedNameElements = ParseXmlHelper.findElementsInEeNamespace(ejbElement, XmlConstants.MAPPED_NAME);
+      List<Element> ejbLinkElements = ParseXmlHelper.findElementsInEeNamespace(ejbElement, XmlConstants.EJB_LINK);
+      
+      if(nameElements.size() + mappedNameElements.size() + ejbLinkElements.size() != 1)
+         throw new DefinitionException("For a remote EJB '" + ejbElement.getParent().getName() + "', JNDI name, mapped name or EJB link " +
+               "must be specified using the <name>, <mappedName> or <ejbLink> child elements of the <EJB> element");
+      
+      if(nameElements.size() == 1)
+         checkNameElementValue(nameElements.get(0));
+   }
+   
+   private void checkWebServiceRefElements(List<Element> webServiceRefElements)
+   {
+      Element webServiceRefElement = webServiceRefElements.get(0);
+      
+      if(webServiceRefElements.size() > 1)
+         throw new DefinitionException("There is more than one <WebServiceRef> elements in '" + 
+               webServiceRefElement.getParent().getName() + "'");
+      
+      List<Element> nameElements = ParseXmlHelper.findElementsInEeNamespace(webServiceRefElement, XmlConstants.NAME);
+      List<Element> mappedNameElements = ParseXmlHelper.findElementsInEeNamespace(webServiceRefElement, XmlConstants.MAPPED_NAME);
+      
+      if(nameElements.size() == 0 && mappedNameElements.size() == 0)
+         throw new DefinitionException("For a web service '" + webServiceRefElement.getParent().getName() + "', JNDI name " +
+               "or mapped name must be specified using the <name> or <mappedName> child elements of the <WebServiceRef> element");
+      
+      if(nameElements.size() == 1)
+         checkNameElementValue(nameElements.get(0));
+   }
+   
+   private void checkNameElementValue(Element nameElement)
+   {
+      String nameValue = nameElement.getData().toString();
+      if(!nameValue.startsWith(XmlConstants.JAVA_GLOBAL) && !nameValue.startsWith(XmlConstants.JAVA_APP))
+         throw new DefinitionException("The JNDI name specified by the <name> element in <" + nameElement.getParent().getName() + "> for '" +
+         		nameElement.getParent().getParent().getName() + "' must be a name in the global java:global or application java:app naming context");
+   }
+}

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/SimpleBeanChildrenChecker.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/SimpleBeanChildrenChecker.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/SimpleBeanChildrenChecker.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -14,30 +14,29 @@
 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.impl.BeanChildrenCheckerImpl;
 
-public class SimpleBeanChildrenChecker extends BeanChildrenCheckerImpl
+public class SimpleBeanChildrenChecker extends AbstractBeanChildrenChecker
 {
    public SimpleBeanChildrenChecker(XmlEnvironment environment, Map<String, Set<String>> packagesMap)
    {
       super(environment, packagesMap);
    }
 
-   public void checkForDecoratorChild(Element beanElement)
+   protected void checkForDecoratorChild(Element beanElement)
    {
       if(ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.INTERCEPTOR).size() > 1)
          throw new DefinitionException("A simple bean element <" + beanElement.getName() + "> has more than one direct child <" + 
                XmlConstants.INTERCEPTOR + ">");            
    }
    
-   public void checkForInterceptorChild(Element beanElement)
+   protected void checkForInterceptorChild(Element beanElement)
    {
       if(ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.DECORATOR).size() > 1)
          throw new DefinitionException("A simple bean element <" + beanElement.getName() + "> has more than one direct child <" + 
                XmlConstants.DECORATOR + ">");
    }
    
-   public void checkChildForInterceptorType(Element beanChildElement)
+   protected void checkChildForInterceptorType(Element beanChildElement)
    {
       if(haveBeanInterceptorDeclaration)
          throw new DefinitionException("There is second element of interceptor type <" + beanChildElement.getName() + 
@@ -45,7 +44,7 @@
          haveBeanInterceptorDeclaration = true;
    }
    
-   public void checkChildForDecoratorType(Element beanChildElement)
+   protected void checkChildForDecoratorType(Element beanChildElement)
    {
       if(haveBeanDecoratorDeclaration)
          throw new DefinitionException("There is second element of decorator type <" + beanChildElement.getName() + 
@@ -53,7 +52,7 @@
          haveBeanDecoratorDeclaration = true;
    }
    
-   public void checkForConstructor(Element beanElement, AnnotatedClass<?> beanClass)
+   protected void checkForConstructor(Element beanElement, AnnotatedClass<?> beanClass)
    {
       if(constructorParameters.size() == 0)
          return;

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/impl/BeanChildrenCheckerImpl.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -1,236 +1,30 @@
 package org.jboss.webbeans.xml.checker.beanchildren.impl;
 
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import javax.annotation.Named;
-import javax.annotation.Resource;
-import javax.annotation.Stereotype;
-import javax.context.ScopeType;
-import javax.decorator.Decorator;
-import javax.ejb.EJB;
-import javax.inject.BindingType;
-import javax.inject.DefinitionException;
-import javax.inject.DeploymentType;
-import javax.inject.Realizes;
-import javax.inject.Specializes;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InterceptorBindingType;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
-import javax.xml.ws.WebServiceRef;
-
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.introspector.AnnotatedField;
-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;
 
 public abstract class BeanChildrenCheckerImpl implements BeanChildrenChecker
 {
-   private final XmlEnvironment environment;
+   protected final XmlEnvironment environment;
    
-   private final Map<String, Set<String>> packagesMap;
+   protected final Map<String, Set<String>> packagesMap;
    
-   private Set<AnnotatedField<?>> beanFields;
-   
-   private List<Method> beanMethods; 
-   
-   private boolean haveBeanDeploymentTypeDeclaration = false;
-   
-   private boolean haveBeanScopeTypeDeclaration = false;
-   
-   protected boolean haveBeanInterceptorDeclaration = false;
-   
-   protected boolean haveBeanDecoratorDeclaration = false;
-   
-   protected List<AnnotatedClass<?>> constructorParameters = new ArrayList<AnnotatedClass<?>>();
-         
-   public abstract void checkForInterceptorChild(Element beanElement);
-   
-   public abstract void checkForDecoratorChild(Element beanElement);
-   
-   public abstract void checkChildForInterceptorType(Element beanElement);
-   
-   public abstract void checkChildForDecoratorType(Element beanElement);
-   
-   public abstract void checkForConstructor(Element beanElement, AnnotatedClass<?> beanClass);
-   
    public BeanChildrenCheckerImpl(XmlEnvironment environment, Map<String, Set<String>> packagesMap)
    {
       this.environment = environment;
       this.packagesMap = packagesMap;
    }
    
-   public void checkChildren(Element beanElement, AnnotatedClass<?> beanClass)
+   public XmlEnvironment getXmlEnvironment()
    {
-      beanFields = beanClass.getFields();
-      beanMethods = Arrays.asList(beanClass.getRawType().getDeclaredMethods());
-      
-      checkForInterceptorChild(beanElement);
-      checkForDecoratorChild(beanElement);
-      
-      haveBeanDeploymentTypeDeclaration = false;
-      haveBeanScopeTypeDeclaration = false;
-      haveBeanInterceptorDeclaration = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.INTERCEPTOR).size() > 0;
-      haveBeanDecoratorDeclaration = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.DECORATOR).size() > 0;
-      
-      Iterator<?> beanIterator = beanElement.elementIterator();
-      while(beanIterator.hasNext())
-      {
-         Element beanChildElement = (Element)beanIterator.next();
-         checkBeanChild(beanChildElement, beanClass);
-      }
-      checkForConstructor(beanElement, beanClass);
+      return this.environment;
    }
    
-   private void checkBeanChild(Element beanChildElement, AnnotatedClass<?> beanClass)
+   public Map<String, Set<String>> getPackagesMap()
    {
-      try
-      {
-         if(beanChildElement.getName().equalsIgnoreCase(XmlConstants.ARRAY))
-            return;
-         AnnotatedClass<?> beanChildClass = ParseXmlHelper.loadElementClass(beanChildElement, Object.class, environment, packagesMap);
-         Class<?> beanChildType = beanChildClass.getRawType();
-         boolean isJavaClass = !beanChildType.isEnum() && !beanChildType.isPrimitive() && !beanChildType.isInterface();
-         boolean isInterface = beanChildType.isInterface() && !beanChildType.isAnnotation();
-         if(beanChildType.isAnnotation())
-         {
-            //bean child element declaring type-level metadata
-            checkAnnotationChild(beanChildElement, beanChildClass);
-            return;
-         }
-         if(isJavaClass || isInterface)
-         {
-            //bean child element declaring a parameter of the bean constructor
-            constructorParameters.add(beanChildClass);
-            return;
-         }
-         throw new DefinitionException(new DefinitionException(beanChildElement.getName() + " can't be interpreted as a Java class or interface or Java Annotation type"));
-      }
-      catch(DefinitionException e)
-      {
-         if(!(e.getCause() instanceof DefinitionException))
-         {
-            throw new DefinitionException(e);
-         }
-         
-         Element beanElement = beanChildElement.getParent();
-         Namespace beanNamespace = beanElement.getNamespace();
-         Namespace beanChildNamespace = beanChildElement.getNamespace();
-         if(beanChildNamespace.equals(beanNamespace))
-         {
-            //bean child element declaring a method or field of the bean.
-            checkFieldOrMethodChild(beanChildElement, beanClass);
-            return;
-         }
-         throw new DefinitionException("Can't determine type of element <" + beanChildElement.getName() + "> in bean '" + 
-               beanElement.getName() + "'");
-      }
+      return this.packagesMap;
    }
-   
-   private void checkAnnotationChild(Element beanChildElement, AnnotatedClass<?> beanChildClass)
-   {
-      if(beanChildClass.isAnnotationPresent(DeploymentType.class))
-      {
-         if(haveBeanDeploymentTypeDeclaration)
-            throw new DefinitionException("Only one deployment type declaration allowed for bean '" + 
-                  beanChildElement.getParent().getName() + "'");
-         haveBeanDeploymentTypeDeclaration = true;
-         return;
-      }
-      if(beanChildClass.isAnnotationPresent(ScopeType.class))
-      {
-         if(haveBeanScopeTypeDeclaration)
-            throw new DefinitionException("Only one scope type declaration allowed for bean '" + 
-                  beanChildElement.getParent().getName() + "'");
-         haveBeanScopeTypeDeclaration = true;
-         return;
-      }
-      if(beanChildClass.isAnnotationPresent(Interceptor.class))
-      {
-         checkChildForInterceptorType(beanChildElement);
-         return;
-      }
-      if(beanChildClass.isAnnotationPresent(Decorator.class))
-      {
-         checkChildForDecoratorType(beanChildElement);
-         return;
-      }
-      if(beanChildClass.isAnnotationPresent(BindingType.class) || beanChildClass.isAnnotationPresent(InterceptorBindingType.class) || 
-            beanChildClass.isAnnotationPresent(Stereotype.class) || beanChildClass.isAnnotationPresent(Named.class) || 
-            beanChildClass.isAnnotationPresent(Specializes.class) || beanChildClass.isAnnotationPresent(Realizes.class) || 
-            beanChildClass.isAnnotationPresent(Resource.class) || beanChildClass.isAnnotationPresent(EJB.class) || 
-            beanChildClass.isAnnotationPresent(WebServiceRef.class) || beanChildClass.isAnnotationPresent(PersistenceContext.class) || 
-            beanChildClass.isAnnotationPresent(PersistenceUnit.class))
-         return;
-      
-      throw new DefinitionException("Can't determine annotation type of <" + beanChildElement.getName() + "> element in bean '" + 
-            beanChildElement.getParent().getName() + "'");
-   }
-   
-   private void checkFieldOrMethodChild(Element beanChildElement, AnnotatedClass<?> beanClass)
-   {  //TODO: not finished    
-      boolean isField = false;
-      boolean isMethod = false;
-      
-      for(AnnotatedField<?> field : beanFields)
-      {
-         if(beanChildElement.getName().equalsIgnoreCase(field.getName()))
-         {
-            if(isField)
-               throw new DefinitionException("Bean class '" + beanClass.getName() + "' does not have exactly one field " +
-               		"with the specified name '" + beanChildElement.getName() + "'");
-            isField = true;
-         }
-      }
-      
-      for(Method method : beanMethods)
-      {
-         if(beanChildElement.getName().equalsIgnoreCase(method.getName()))
-            isMethod = true;
-      }
-      
-      if(isField && isMethod)
-         throw new DefinitionException("The name of the child element <" + beanChildElement.getName() + 
-               "> matches the name of both a method and a field of the bean class '" + beanClass.getName() + "'");
-      
-      if(isField)
-         checkFieldChild(beanChildElement, beanClass);
-      
-      if(isMethod)
-         checkMethodChild(beanChildElement, beanClass);
-   }
-   
-   private void checkFieldChild(Element beanChildElement, AnnotatedClass<?> beanClass)
-   {//TODO: not finished
-      Element elementParent = beanChildElement.getParent();
-      String elementName = beanChildElement.getName();
-      String elementPrefix = beanChildElement.getNamespacePrefix();
-      String elementUri = beanChildElement.getNamespaceURI();
-      
-      if(ParseXmlHelper.findElements(elementParent, elementName, elementPrefix, elementUri).size() > 1)
-         throw new DefinitionException("More than one child element of a bean '" + elementParent.getName() + 
-               "' declaration represents the same field'" + elementName + "'");
-      
-      if(beanChildElement.elements().size() > 1 && 
-            beanChildElement.elements().size() != ParseXmlHelper.findElementsInEeNamespace(beanChildElement, XmlConstants.VALUE).size())
-         throw new DefinitionException("Declaration of a field '" + beanChildElement.getName() + "' has more than one direct child element, " +
-         		"and at least one of these elements is something other than a <value> element in the Java EE namespace");
-      
-      
-   }
-   
-   private void checkMethodChild(Element beanChildElement, AnnotatedClass<?> beanClass)
-   {
-      //TODO: not finished
-   }
 }

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/BeanElementRegistrator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/BeanElementRegistrator.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/BeanElementRegistrator.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.xml.registrator.bean;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+
+public interface BeanElementRegistrator
+{
+   boolean accept(Element beanElement, AnnotatedClass<?> beanClass);
+   
+   void registerBeanElement(Element beanElement, AnnotatedClass<?> beanClass);
+}

Added: 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	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/JmsResourceElementRegistrator.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,24 @@
+package org.jboss.webbeans.xml.registrator.bean.ext;
+
+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.checker.beanchildren.BeanChildrenChecker;
+
+public class JmsResourceElementRegistrator extends NotSimpleBeanElementRegistrator
+{
+   public JmsResourceElementRegistrator(BeanChildrenChecker childrenChecker)
+   {
+      super(childrenChecker);
+   }
+
+   public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      if (ParseXmlHelper.isJavaEeNamespace(beanElement) && 
+            (beanElement.getName().equalsIgnoreCase(XmlConstants.TOPIC) || 
+                  beanElement.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
+         return true;
+      return false;
+   }
+}

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/NotSimpleBeanElementRegistrator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/NotSimpleBeanElementRegistrator.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/NotSimpleBeanElementRegistrator.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,19 @@
+package org.jboss.webbeans.xml.registrator.bean.ext;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.checker.beanchildren.BeanChildrenChecker;
+import org.jboss.webbeans.xml.registrator.bean.impl.BeanElementRegistratorImpl;
+
+public abstract class NotSimpleBeanElementRegistrator extends BeanElementRegistratorImpl
+{
+   public NotSimpleBeanElementRegistrator(BeanChildrenChecker childrenChecker)
+   {
+      super(childrenChecker);
+   }
+   
+   protected void checkElementDeclaration(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      // There is nothing to validate      
+   }
+}

Added: 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	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/ResourceElementRegistrator.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,191 @@
+package org.jboss.webbeans.xml.registrator.bean.ext;
+
+import java.lang.annotation.Annotation;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bean.ee.AbstractJavaEEResourceBean;
+import org.jboss.webbeans.bean.ee.PersistenceContextBean;
+import org.jboss.webbeans.bean.ee.PersistenceUnitBean;
+import org.jboss.webbeans.bean.ee.RemoteEjbBean;
+import org.jboss.webbeans.bean.ee.ResourceBean;
+import org.jboss.webbeans.bean.ee.WebServiceBean;
+import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.persistence.spi.JpaServices;
+import org.jboss.webbeans.resources.spi.ResourceServices;
+import org.jboss.webbeans.ws.spi.WebServices;
+import org.jboss.webbeans.xml.ParseXmlHelper;
+import org.jboss.webbeans.xml.XmlConstants;
+import org.jboss.webbeans.xml.checker.beanchildren.BeanChildrenChecker;
+
+public class ResourceElementRegistrator extends NotSimpleBeanElementRegistrator
+{
+   public ResourceElementRegistrator(BeanChildrenChecker childrenChecker)
+   {
+      super(childrenChecker);
+   }
+
+   public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      if (ParseXmlHelper.isJavaEeNamespace(beanElement) && 
+            (beanElement.getName().equalsIgnoreCase(XmlConstants.TOPIC) || 
+                  beanElement.getName().equalsIgnoreCase(XmlConstants.QUEUE)))
+         return false;
+      
+      Iterator<?> elIterator = beanElement.elementIterator();
+      while (elIterator.hasNext())
+      {
+         Element child = (Element) elIterator.next();
+         if (ParseXmlHelper.isJavaEeNamespace(child) && 
+               (child.getName().equalsIgnoreCase(XmlConstants.RESOURCE) || 
+                     child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_CONTEXT) || 
+                     child.getName().equalsIgnoreCase(XmlConstants.PERSISTENCE_UNIT) || 
+                     child.getName().equalsIgnoreCase(XmlConstants.EJB) || 
+                     child.getName().equalsIgnoreCase(XmlConstants.WEB_SERVICE_REF)))
+            return true;
+      }
+      return false;
+   }
+   
+   protected void register(Element beanElement, AnnotatedClass<?> beanClass)
+   {            
+      List<Element> resourceElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.RESOURCE);
+      if(resourceElements.size() > 0)
+      {
+         registerResourceBean(resourceElements.get(0), beanClass);
+         return;
+      }
+      
+      List<Element> persContextElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.PERSISTENCE_CONTEXT);
+      if(persContextElements.size() > 0)
+      {
+         registerPersContextBean(persContextElements.get(0), beanClass);
+         return;
+      }
+         
+      List<Element> persUnitElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.PERSISTENCE_UNIT);
+      if(persUnitElements.size() > 0)
+      {
+         registerPersUnitBean(persUnitElements.get(0), beanClass);
+         return;
+      }
+         
+      List<Element> ejbElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.EJB);
+      if(ejbElements.size() > 0)
+      {
+         registerEjbBean(ejbElements.get(0), beanClass);
+         return;
+      }
+         
+      List<Element> webServiceRefElements = ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.WEB_SERVICE_REF);
+      if(webServiceRefElements.size() > 0)
+      {
+         registerWebServiceRefBean(webServiceRefElements.get(0), beanClass);
+         return;
+      }
+   }
+   
+   private void registerResourceBean(Element resourceElement, AnnotatedClass<?> beanClass)
+   {
+      Class<? extends Annotation> deploymentType = null;
+      Set<Annotation> bindings = null;
+      Class<?> type = beanClass.getRawType();
+      String jndiName = obtainElementValue(resourceElement, XmlConstants.JNDI_NAME);
+      String mappedName = obtainElementValue(resourceElement, XmlConstants.MAPPED_NAME);
+      
+      RIBean<?> bean = new ResourceBean(environment.getManager(), deploymentType, bindings, type, jndiName, mappedName);
+      
+      if (environment.getServices().contains(ResourceServices.class))
+      {
+         environment.getResourceBeans().add((AbstractJavaEEResourceBean<?>) bean);
+      }
+   }
+   
+   private void registerPersContextBean(Element persContextElement, AnnotatedClass<?> beanClass)
+   {
+      Class<? extends Annotation> deploymentType = null;
+      Set<Annotation> bindings = null;
+      String unitName = obtainElementValue(persContextElement, XmlConstants.UNIT_NAME);
+      
+      RIBean<?> bean = new PersistenceContextBean(environment.getManager(), deploymentType, bindings, unitName);
+      
+      if (environment.getServices().contains(JpaServices.class))
+      {
+         environment.getResourceBeans().add((AbstractJavaEEResourceBean<?>) bean);
+      }            
+   }
+   
+   private void registerPersUnitBean(Element persUnitElement, AnnotatedClass<?> beanClass)
+   {
+      Class<? extends Annotation> deploymentType = null;
+      Set<Annotation> bindings = null;
+      String unitName = obtainElementValue(persUnitElement, XmlConstants.UNIT_NAME);
+      
+      RIBean<?> bean = new PersistenceUnitBean(environment.getManager(), deploymentType, bindings, unitName);
+      
+      if (environment.getServices().contains(JpaServices.class))
+      {
+         environment.getResourceBeans().add((AbstractJavaEEResourceBean<?>) bean);
+      }
+   }
+   
+   private void registerEjbBean(Element ejbElement, AnnotatedClass<?> beanClass)
+   {
+      Class<? extends Annotation> deploymentType = null;
+      Set<Annotation> bindings = null;
+      Class<?> type = beanClass.getRawType();
+      String jndiName = obtainElementValue(ejbElement, XmlConstants.JNDI_NAME);
+      String mappedName = obtainElementValue(ejbElement, XmlConstants.MAPPED_NAME);
+      String ejbLink = obtainElementValue(ejbElement, XmlConstants.EJB_LINK);;
+      
+      RIBean<?> bean = new RemoteEjbBean(environment.getManager(), deploymentType, bindings, type, jndiName, mappedName, ejbLink);
+      
+      if (environment.getServices().contains(EjbServices.class))
+      {
+         environment.getResourceBeans().add((AbstractJavaEEResourceBean<?>) bean);
+      }
+   }
+   
+   private void registerWebServiceRefBean(Element webServiceRefElement, AnnotatedClass<?> beanClass)
+   {
+      Class<? extends Annotation> deploymentType = null;
+      Set<Annotation> bindings = null;
+      Class<?> type = beanClass.getRawType();
+      String jndiName = obtainElementValue(webServiceRefElement, XmlConstants.JNDI_NAME);
+      String mappedName = obtainElementValue(webServiceRefElement, XmlConstants.MAPPED_NAME);
+      String wsdlLocation = obtainElementValue(webServiceRefElement, XmlConstants.WSDL_LOCATION);
+      
+      RIBean<?> bean = new WebServiceBean(environment.getManager(), deploymentType, bindings, type, jndiName, mappedName, wsdlLocation);
+      
+      if (environment.getServices().contains(WebServices.class))
+      {
+         environment.getResourceBeans().add((AbstractJavaEEResourceBean<?>) bean);
+      }
+   }
+   
+   private String obtainElementValue(Element elementParent, String elementName)
+   {
+      List<Element> elements = ParseXmlHelper.findElementsInEeNamespace(elementParent, elementName);
+      if(elements.size() > 0)
+      {
+         Element element = elements.get(0);
+         return element.getData().toString();
+      }
+      return null;
+   }
+   
+   private String obtainUnitName(Element persistenceElement)
+   {
+      List<Element> unitNameElements = ParseXmlHelper.findElementsInEeNamespace(persistenceElement, XmlConstants.UNIT_NAME);
+      if(unitNameElements.size() > 0)
+      {
+         Element unitNameElement = unitNameElements.get(0);
+         return unitNameElement.getData().toString();
+      }
+      return null;
+   }
+}

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/SessionBeanElementRegistrator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/SessionBeanElementRegistrator.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/SessionBeanElementRegistrator.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,28 @@
+package org.jboss.webbeans.xml.registrator.bean.ext;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.XmlConstants;
+import org.jboss.webbeans.xml.checker.beanchildren.BeanChildrenChecker;
+
+public class SessionBeanElementRegistrator extends NotSimpleBeanElementRegistrator
+{
+   private final EjbDescriptorCache ejbDescriptors;
+	
+   public SessionBeanElementRegistrator(BeanChildrenChecker childrenChecker, EjbDescriptorCache ejbDescriptors)
+   {
+      super(childrenChecker);
+      this.ejbDescriptors = ejbDescriptors;
+   }
+
+   public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      if (ejbDescriptors.containsKey(beanElement.getName()) ||
+            beanElement.attribute(XmlConstants.EJB_NAME) != null)
+      {
+         return true;
+      }
+      return false;
+   }
+}

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/SimpleBeanElementRegistrator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/SimpleBeanElementRegistrator.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/ext/SimpleBeanElementRegistrator.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,54 @@
+package org.jboss.webbeans.xml.registrator.bean.ext;
+
+import javax.decorator.Decorator;
+import javax.inject.DefinitionException;
+import javax.interceptor.Interceptor;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.xml.ParseXmlHelper;
+import org.jboss.webbeans.xml.XmlConstants;
+import org.jboss.webbeans.xml.checker.beanchildren.BeanChildrenChecker;
+import org.jboss.webbeans.xml.registrator.bean.impl.BeanElementRegistratorImpl;
+
+public class SimpleBeanElementRegistrator extends BeanElementRegistratorImpl
+{
+   private final EjbDescriptorCache ejbDescriptors;
+	
+   public SimpleBeanElementRegistrator(BeanChildrenChecker childrenChecker, EjbDescriptorCache ejbDescriptors)
+   {
+      super(childrenChecker);
+      this.ejbDescriptors = ejbDescriptors;
+   }
+
+   public boolean accept(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      boolean isSessionBean = ejbDescriptors.containsKey(beanElement.getName()) || 
+                                          beanElement.attribute(XmlConstants.EJB_NAME) != null;
+      
+      if (!beanClass.isAbstract() && !isSessionBean && !beanClass.isParameterizedType())
+      {
+         return true;
+      }
+
+      return false;
+   }
+
+   protected void checkElementDeclaration(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      if(beanClass.isNonStaticMemberClass())
+         throw new DefinitionException("Bean class '" + beanClass.getName() + "' of a simple bean <" + beanElement.getName() + 
+               "> is a non static member class");
+      
+      if(beanClass.getRawType().isAnnotationPresent(Interceptor.class) && 
+            ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.INTERCEPTOR).size() != 1)
+         throw new DefinitionException("A simple bean defined in XML as <" + beanElement.getName() +  "> has a bean class '" + 
+               beanClass.getName() + "' annotated @Interceptor and is not declared as an interceptor in XML");
+      
+      if(beanClass.getRawType().isAnnotationPresent(Decorator.class) && 
+            ParseXmlHelper.findElementsInEeNamespace(beanElement, XmlConstants.DECORATOR).size() != 1)
+         throw new DefinitionException("A simple bean defined in XML as <" + beanElement.getName() +  "> has a bean class '" + 
+               beanClass.getName() + "' annotated @Decorator and is not declared as an decorator in XML");
+   }
+}

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/impl/BeanElementRegistratorImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/impl/BeanElementRegistratorImpl.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/registrator/bean/impl/BeanElementRegistratorImpl.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,161 @@
+package org.jboss.webbeans.xml.registrator.bean.impl;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Named;
+import javax.annotation.Stereotype;
+import javax.context.ScopeType;
+import javax.inject.DefinitionException;
+import javax.inject.DeploymentType;
+
+import org.dom4j.Element;
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedField;
+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.registrator.bean.BeanElementRegistrator;
+
+
+public abstract class BeanElementRegistratorImpl implements BeanElementRegistrator
+{
+   protected final BeanChildrenChecker childrenChecker;
+   
+   protected final XmlEnvironment environment;
+   
+   protected final Map<String, Set<String>> packagesMap;
+   
+   protected BeanElementRegistratorImpl(BeanChildrenChecker childrenChecker)
+   {
+      this.childrenChecker = childrenChecker;
+      this.environment = childrenChecker.getXmlEnvironment();
+      this.packagesMap = childrenChecker.getPackagesMap();
+   }
+   
+   public abstract boolean accept(Element beanElement, AnnotatedClass<?> beanClass);
+
+   protected abstract void checkElementDeclaration(Element beanElement, AnnotatedClass<?> beanClass);
+   
+   public void registerBeanElement(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      checkElementDeclaration(beanElement, beanClass);
+      childrenChecker.checkChildren(beanElement, beanClass);
+      checkProduces(beanElement, beanClass);
+      register(beanElement, beanClass);
+   }
+   
+   protected void register(Element beanElement, AnnotatedClass<?> beanClass)
+   {
+      environment.getClasses().add(beanClass);
+   }
+   
+   private void checkProduces(Element beanElement, AnnotatedClass<?> beanClass)
+   {//TODO: will refactor
+      Iterator<?> beanIterator = beanElement.elementIterator();
+      while(beanIterator.hasNext())
+      {
+         Element beanChild = (Element)beanIterator.next();  
+         List<Element> producesElements = ParseXmlHelper.findElementsInEeNamespace(beanChild, XmlConstants.PRODUCES);
+         
+         if(producesElements.size() == 0)
+            continue;
+         
+         if(producesElements.size() > 1)
+            throw new DefinitionException("There is more than one child <Produces> element for <" + beanChild.getName()  + "> element");
+         
+         List<AnnotatedClass<?>> producesChildTypes = new ArrayList<AnnotatedClass<?>>();
+                  
+         Element producesElement = producesElements.get(0);
+         Iterator<?> producesIt = producesElement.elementIterator();
+         while(producesIt.hasNext())
+         {
+            Element producesChild = (Element)producesIt.next();
+            AnnotatedClass<?> producesChildClass = ParseXmlHelper.loadElementClass(producesChild, Object.class, environment, packagesMap);
+            Class<?> producesChildType = producesChildClass.getRawType();
+            boolean isJavaClass = !producesChildType.isEnum() && !producesChildType.isPrimitive() && !producesChildType.isInterface();
+            boolean isInterface = producesChildType.isInterface() && !producesChildType.isAnnotation();
+            if(isJavaClass || isInterface)
+            {
+               producesChildTypes.add(producesChildClass);
+               continue;
+            }
+            if(producesChildType.isAnnotation())
+            {
+               if(producesChildClass.isAnnotationPresent(DeploymentType.class) || 
+                     producesChildClass.isAnnotationPresent(ScopeType.class) || 
+                     producesChildClass.isAnnotationPresent(Stereotype.class) ||
+                     producesChildClass.isAnnotationPresent(Named.class))
+                  continue;
+                                             
+               throw new DefinitionException("<" + producesChild.getName() + "> direct child of <Produces> element for <" + beanChild.getName() 
+                     + "> in bean" + beanElement.getName() + "must be DeploymentType or ScopeType or Stereotype or Named");
+            }
+            throw new DefinitionException("Only Java class, interface type and Java annotation type can be " +
+                  "direct child of <Produces> element for <" + beanChild.getName() + "> in bean" + beanElement.getName() + 
+                  ". Element <" + producesChild.getName() + "> is incorrect");
+         }
+         
+         if(producesChildTypes.size() != 1)
+            throw new DefinitionException("More than one or no one child element of <Produces> element for <" + beanChild.getName() + 
+                  "> in bean" + beanElement.getName() + " represents a Java class or interface type");
+         
+         AnnotatedClass<?> expectedType = producesChildTypes.get(0);
+                  
+         Method beanMethod = null;         
+         AnnotatedField<?> beanField = beanClass.getDeclaredField(beanChild.getName(), expectedType);
+
+         try
+         {
+            List<Class<?>> paramClassesList = new ArrayList<Class<?>>();
+            Iterator<?> beanChildIt = beanChild.elementIterator();
+            while(beanChildIt.hasNext())
+            {
+               Element methodChild = (Element)beanChildIt.next();
+               if(methodChild.getName().equalsIgnoreCase(XmlConstants.PRODUCES))
+                  continue;
+               paramClassesList.add(ParseXmlHelper.loadElementClass(methodChild, Object.class, environment, packagesMap).getRawType());
+            }
+            Class<?>[] paramClasses = (Class<?>[])paramClassesList.toArray(new Class[0]);
+            beanMethod = beanClass.getRawType().getDeclaredMethod(beanChild.getName(), paramClasses);
+         }
+         catch (SecurityException e)
+         {}
+         catch (NoSuchMethodException e)
+         {}
+         
+         if(beanField != null && beanMethod != null)
+            throw new DefinitionException("Class '" + beanClass.getName() + "' has produser field and method with the same name '" + 
+                  beanField.getName() + "'");
+         
+         if(beanField != null)
+         {
+            if(beanChild.elements().size() > 1)
+               throw new DefinitionException("There is more than one direct child element for producer field <" + beanChild.getName() + ">");
+            continue;
+         }
+         
+         if(beanMethod != null)
+         {
+            Iterator<?> beanChildIt = producesElement.elementIterator();
+            while(beanChildIt.hasNext())
+            {
+               Element element = (Element)beanChildIt.next();
+               if(!element.getName().equalsIgnoreCase(XmlConstants.PRODUCES) && 
+                     ParseXmlHelper.findElementsInEeNamespace(beanChild, XmlConstants.INTERCEPTOR).size() == 0)
+                  throw new DefinitionException("Only Produces and interceptor binding types can be direct childs of a producer " +
+                        "method '" + beanChild.getName() + "' declaration in bean '" + beanElement.getName() + "'");
+            }
+            continue;
+         }
+         
+         throw new DefinitionException("A producer '" + beanChild.getName() + "' doesn't declared in '" + beanElement.getName() + 
+               "' class file as method or field");
+      }                  
+   }
+}

Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/Order.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -1,6 +1,25 @@
 package org.jboss.webbeans.test.unit.xml.beans;
 
+import org.jboss.webbeans.test.unit.xml.beans.annotationtype.TestBindingType;
+import org.jboss.webbeans.test.unit.xml.beans.annotationtype.TestInterceptorBindingType;
+import org.jboss.webbeans.test.unit.xml.beans.annotationtype.TestStereotype;
+
+ at TestBindingType
+ at TestInterceptorBindingType
+ at TestStereotype
 public class Order
 {
-
+   public int val;
+   
+   public String[] strArray;
+   
+   public Order(int val)
+   {
+      this.val = val;
+   }
+   
+   public int getVal()
+   {
+      return val;
+   }
 }

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/PaymentService.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/PaymentService.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/PaymentService.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans;
+
+import javax.xml.ws.WebServiceRef;
+
+ at WebServiceRef
+public class PaymentService
+{
+
+}

Deleted: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/TestDeploymentType.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/TestDeploymentType.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/TestDeploymentType.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -1,9 +0,0 @@
-package org.jboss.webbeans.test.unit.xml.beans;
-
-import javax.inject.DeploymentType;
-
- at DeploymentType
-public @interface TestDeploymentType
-{
-
-}

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/AnotherTestInterceptorBindingType.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/AnotherTestInterceptorBindingType.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/AnotherTestInterceptorBindingType.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans.annotationtype;
+
+import javax.interceptor.InterceptorBindingType;
+
+ at InterceptorBindingType
+public @interface AnotherTestInterceptorBindingType
+{
+
+}

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestBindingType.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestBindingType.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestBindingType.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans.annotationtype;
+
+import javax.inject.BindingType;
+
+ at BindingType
+public @interface TestBindingType
+{
+
+}

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestDeploymentType.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestDeploymentType.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestDeploymentType.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans.annotationtype;
+
+import javax.inject.DeploymentType;
+
+ at DeploymentType
+public @interface TestDeploymentType
+{
+
+}

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestInterceptorBindingType.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestInterceptorBindingType.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestInterceptorBindingType.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans.annotationtype;
+
+import javax.interceptor.InterceptorBindingType;
+
+ at InterceptorBindingType
+public @interface TestInterceptorBindingType
+{
+
+}

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestNamed.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestNamed.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestNamed.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans.annotationtype;
+
+import javax.annotation.Named;
+
+ at Named
+public @interface TestNamed
+{
+
+}

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestScopeType.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestScopeType.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestScopeType.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans.annotationtype;
+
+import javax.context.ScopeType;
+
+ at ScopeType
+public @interface TestScopeType
+{
+
+}

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestStereotype.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestStereotype.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/beans/annotationtype/TestStereotype.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.xml.beans.annotationtype;
+
+import javax.annotation.Stereotype;
+
+ at Stereotype
+public @interface TestStereotype
+{
+
+}

Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/XmlParserImplTest.java	2009-04-15 17:42:07 UTC (rev 2420)
@@ -1,36 +1,23 @@
 package org.jboss.webbeans.test.unit.xml.parser;
 
-import java.io.IOException;
-import java.io.InputStream;
+import java.lang.annotation.Annotation;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Set;
 
-import javax.inject.DeploymentException;
+import javax.inject.manager.Bean;
 
-import org.dom4j.Attribute;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.Namespace;
-import org.dom4j.io.SAXReader;
 import org.jboss.testharness.impl.packaging.Artifact;
 import org.jboss.testharness.impl.packaging.Classes;
 import org.jboss.testharness.impl.packaging.Resource;
 import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.ejb.EjbDescriptorCache;
 import org.jboss.webbeans.introspector.AnnotatedClass;
 import org.jboss.webbeans.introspector.AnnotatedItem;
 import org.jboss.webbeans.mock.MockXmlEnvironment;
 import org.jboss.webbeans.test.AbstractWebBeansTest;
 import org.jboss.webbeans.test.unit.xml.beans.Order;
-import org.jboss.webbeans.test.unit.xml.beans.TestBean;
-import org.jboss.webbeans.test.unit.xml.beans.TestDeploymentType;
-import org.jboss.webbeans.xml.ParseXmlHelper;
-import org.jboss.webbeans.xml.XmlConstants;
 import org.jboss.webbeans.xml.XmlEnvironment;
 import org.jboss.webbeans.xml.XmlParser;
 import org.testng.annotations.Test;
@@ -64,6 +51,23 @@
 
       assert parserEnv.getClasses().size() == 1;
    }
+   
+//   @Test
+   public void testDd()
+   {      
+      XmlEnvironment parserEnv = new MockXmlEnvironment(getResources("user-defined-beans.xml"), new EjbDescriptorCache());
+      XmlParser parser = new XmlParser(parserEnv);
+      parser.parse();
+      
+      ManagerImpl manager = parserEnv.getManager();
+      
+      Set<Bean<Order>> beansSet = manager.resolveByType(Order.class);
+      for(Bean<Order> bean : beansSet)
+      {
+         Class<? extends Annotation> deploymentType = bean.getDeploymentType();
+         System.out.println(bean.getClass());
+      }
+   }
 }
 
 	/*

Modified: ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/namespace
===================================================================
--- ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/namespace	2009-04-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/namespace	2009-04-15 17:42:07 UTC (rev 2420)
@@ -1 +1,2 @@
-org.jboss.webbeans.test.unit.xml.parser.bean org.jboss.webbeans.test.unit.xml.parser.deploymenttype
\ No newline at end of file
+org.jboss.webbeans.test.unit.xml.beans
+org.jboss.webbeans.test.unit.xml.beans.annotationtype
\ No newline at end of file

Added: ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema.xsd
===================================================================
--- ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema.xsd	                        (rev 0)
+++ ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema.xsd	2009-04-15 17:42:07 UTC (rev 2420)
@@ -0,0 +1,10 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:java:ee">
+	<xs:element name="Beans">
+		<xs:complexType>
+			<xs:sequence minOccurs="0" maxOccurs="unbounded">
+				<xs:any namespace="##any" processContents="skip"  />
+			</xs:sequence>
+			<xs:anyAttribute namespace="##any" processContents="skip" />
+		</xs:complexType>
+	</xs:element>
+</xs:schema>
\ No newline at end of file

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-15 16:33:39 UTC (rev 2419)
+++ ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml	2009-04-15 17:42:07 UTC (rev 2420)
@@ -1,22 +1,54 @@
-<Beans xmlns="urn:java:ee" xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.beans"
-	xmlns:test="urn:java:org.jboss.webbeans.test.unit.xml.parser"
+<Beans xmlns="urn:java:ee" 
+	xmlns:myapp="urn:java:org.jboss.webbeans.test.unit.xml.parser"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="urn:java:ee http://java.sun.com/jee/ee/schema-1.0.xsd
+	xsi:schemaLocation="urn:java:ee 
 						urn:java:org.jboss.webbeans.test.unit.xml.parser http://mydomain.com/myapp/schema-1.2.xsd">
 	<Deploy>
 		<Standard />
 		<Production />
-		<myapp:AnotherDeploymentType />
+		<myapp:TestDeploymentType />
 	</Deploy>
-	<xsi:Order>
-		<ConversationScoped />
-		<myapp:PaymentProcessor>
-			<test:Asynchronous />
-		</myapp:PaymentProcessor>
-		<myapp:User />
-	</xsi:Order>
-	<myapp:Login>
-		<ConversationScoped />
+	
+	<myapp:TestBindingType>
 		<BindingType />
-	</myapp:Login>
+	</myapp:TestBindingType>
+	<myapp:TestInterceptorBindingType>
+		<InterceptorBindingType />
+		<myapp:AnotherTestInterceptorBindingType />
+	</myapp:TestInterceptorBindingType>
+	<myapp:TestStereotype>
+		<Stereotype />
+		<myapp:TestScopeType />
+		<myapp:TestDeploymentType />
+		<myapp:AnotherTestInterceptorBindingType />
+		<myapp:TestNamed />
+	</myapp:TestStereotype>
+	
+	<myapp:Order>
+		<RequestScoped />
+		<myapp:TestBindingType />
+		<myapp:TestInterceptorBindingType />
+		<myapp:TestStereotype />
+		<myapp:TestDeploymentType />		
+		<myapp:val />
+		<Array>
+			<String />
+		</Array>
+		<Integer />
+		<myapp:getVal />
+	</myapp:Order>
+	<myapp:PaymentService>
+		<WebServiceRef>
+			<name>java:app/service/PaymentService</name>
+			<wsdlLocation>http://theirdomain.com/services/PaymentService.wsdl</wsdlLocation>
+		</WebServiceRef>
+	</myapp:PaymentService>
+	
+	<Decorators>
+		<myapp:TestDecorator />	
+	</Decorators>
+	
+	<Interceptors>
+		<myapp:TestInterceptor />
+	</Interceptors>
 </Beans>
\ No newline at end of file




More information about the weld-commits mailing list