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

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu May 7 11:36:16 EDT 2009


Author: vitold
Date: 2009-05-07 11:36:15 -0400 (Thu, 07 May 2009)
New Revision: 2665

Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.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/ext/AbstractBeanChildrenChecker.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/SimpleBeanChildrenChecker.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/schema/foo/Order.java
   ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema/beans.xml
   ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml
Log:
implement <Array> for constructor parameters

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java	2009-05-07 11:02:50 UTC (rev 2664)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/ParseXmlHelper.java	2009-05-07 15:36:15 UTC (rev 2665)
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -36,7 +37,12 @@
 import org.dom4j.Namespace;
 import org.dom4j.QName;
 import org.dom4j.io.SAXReader;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
 import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.resources.ClassTransformer;
+import org.jboss.webbeans.resources.spi.ResourceLoader;
 import org.jboss.webbeans.resources.spi.ResourceLoadingException;
 import org.xml.sax.SAXException;
 
@@ -309,4 +315,38 @@
          throw new DefinitionException("A certain annotation type is declared more than once as a binding type, " + 
                "interceptor binding type or stereotype using XML");
    }
+   
+   public static AnnotatedClass<?> obtainArray(Element arrayElement, XmlEnvironment environment, Map<String, Set<String>> packagesMap)
+   {  
+      AnnotatedClass<?> arrayType = obtainArrayType(arrayElement, environment, packagesMap);
+      Object array = Array.newInstance(arrayType.getRawType(), 0);      
+      AnnotatedClass<?> result = AnnotatedClassImpl.of(array.getClass(), new ClassTransformer());      
+      return result;
+   }
+   
+   public static AnnotatedClass<?> obtainArrayType(Element arrayElement, XmlEnvironment environment, Map<String, Set<String>> packagesMap)
+   {
+      AnnotatedClass<?> arrayType = null;
+      
+      boolean haveNotAnnotation = false;
+      Iterator<?> arrayIterator = arrayElement.elementIterator();
+      while (arrayIterator.hasNext())
+      {
+         Element arrayChild = (Element) arrayIterator.next();
+         AnnotatedClass<?> arrayChildType = ParseXmlHelper.loadElementClass(arrayChild, Object.class, environment, packagesMap);
+         boolean isAnnotation = arrayChildType.getRawType().isAnnotation();
+         if (!isAnnotation)
+         {
+            if (haveNotAnnotation)
+               throw new DefinitionException("<Array> element have second child which is not annotation, it is '" + 
+                     arrayChild.getName() + "'");
+            haveNotAnnotation = true;
+            arrayType = arrayChildType;
+         }
+      }
+      if (!haveNotAnnotation)
+         throw new DefinitionException("<Array> element must have one child elemen which is not annotation");
+      
+      return arrayType;
+   }
 }

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-05-07 11:02:50 UTC (rev 2664)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/XmlParser.java	2009-05-07 15:36:15 UTC (rev 2665)
@@ -98,25 +98,7 @@
          Element child = (Element) childIterator.next();
 
          if (XmlConstants.ARRAY.equalsIgnoreCase(child.getName()))
-         {
-            boolean haveNotAnnotation = false;
-            Iterator<?> arrayIterator = child.elementIterator();
-            while (arrayIterator.hasNext())
-            {
-               Element arrayChild = (Element) arrayIterator.next();
-               AnnotatedClass<?> arrayChildType = ParseXmlHelper.loadElementClass(arrayChild, Object.class, environment, packagesMap);
-               boolean isAnnotation = arrayChildType.getRawType().isAnnotation();
-               if (!isAnnotation)
-               {
-                  if (haveNotAnnotation)
-                     throw new DefinitionException("<Array> element have second child which is not annotation, it is '" + 
-                           arrayChild.getName() + "'");
-                  haveNotAnnotation = true;
-               }
-            }
-            if (!haveNotAnnotation)
-               throw new DefinitionException("<Array> element must have one child elemen which is not annotation");
-         }
+            ParseXmlHelper.obtainArrayType(child, environment, packagesMap);
          else
             checkChildrenForArray(child);
       }

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-05-07 11:02:50 UTC (rev 2664)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/AbstractBeanChildrenChecker.java	2009-05-07 15:36:15 UTC (rev 2665)
@@ -109,7 +109,12 @@
    private void checkBeanChild(Element beanChildElement, AnnotatedClass<?> beanClass)
    {
       if (XmlConstants.ARRAY.equalsIgnoreCase(beanChildElement.getName()))
+      {
+         // bean child element declaring an array parameter of the bean constructor
+         AnnotatedClass<?> array = ParseXmlHelper.obtainArray(beanChildElement, environment, packagesMap);
+         constructorParameters.add(array);
          return;
+      }         
 
       List<AnnotatedClass<?>> beanChildClassList = ParseXmlHelper.tryLoadElementClass(beanChildElement, Object.class, environment, packagesMap);
 
@@ -120,7 +125,7 @@
          Namespace beanChildNamespace = beanChildElement.getNamespace();
          if (beanChildNamespace.equals(beanNamespace))
          {
-            // bean child element declaring a method or field of the bean.
+            // bean child element declaring a method or field of the bean
             checkFieldOrMethodChild(beanChildElement, beanClass);
             return;
          }

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-05-07 11:02:50 UTC (rev 2664)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/checker/beanchildren/ext/SimpleBeanChildrenChecker.java	2009-05-07 15:36:15 UTC (rev 2665)
@@ -82,18 +82,18 @@
          if (parameters.size() != constructorParameters.size())
             continue;
 
-         boolean isMacthable = true;
+         boolean isMatchable = true;
 
          for (int i = 0; i < parameters.size(); i++)
          {
             if (!parameters.get(i).isAssignableFrom(constructorParameters.get(i)))
             {
-               isMacthable = false;
+               isMatchable = false;
                break;
             }
          }
 
-         if (isMacthable)
+         if (isMatchable)
             matchableConstructors.add(constructor);
       }
 

Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/schema/foo/Order.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/schema/foo/Order.java	2009-05-07 11:02:50 UTC (rev 2664)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/xml/parser/schema/foo/Order.java	2009-05-07 15:36:15 UTC (rev 2665)
@@ -14,9 +14,10 @@
       this.val = 0;
    }
 
-   public Order(int val)
+   public Order(int val, String[] strArr)
    {
       this.val = val;
+      this.strArr = strArr;
    }
 
    public int getVal()

Modified: ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema/beans.xml
===================================================================
--- ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema/beans.xml	2009-05-07 11:02:50 UTC (rev 2664)
+++ ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/schema/beans.xml	2009-05-07 15:36:15 UTC (rev 2665)
@@ -3,11 +3,11 @@
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="urn:java:org.jboss.webbeans.test.unit.xml.parser.schema.valid http://mydomain.com/myapp/schema-1.2.xsd">	
 	<myapp:Order>
+		<myapp:getVal />
+		<myapp:val />
+		<Integer />
 		<Array>
 			<String />
 		</Array>
-		<myapp:getVal />
-		<myapp:val />
-		<Integer />
 	</myapp:Order>
 </Beans>
\ 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-05-07 11:02:50 UTC (rev 2664)
+++ ri/trunk/tests/src/test/resources/org/jboss/webbeans/test/unit/xml/parser/user-defined-beans.xml	2009-05-07 15:36:15 UTC (rev 2665)
@@ -29,12 +29,12 @@
 		<myapp:TestInterceptorBindingType />
 		<myapp:TestStereotype />
 		<myapp:TestDeploymentType />
+		<myapp:getVal />
+		<myapp:val />
+		<Integer />
 		<Array>
 			<String />
 		</Array>
-		<myapp:getVal />
-		<myapp:val />
-		<Integer />
 	</myapp:Order>
 <!--	
 	<myapp:PaymentService>
@@ -48,13 +48,13 @@
 		</Resource>
 	</myapp:PaymentService>
 -->
-
+<!--
 	<Topic>
 		<Resource>
 			<name>java:app/service/PaymentService</name>
 		</Resource>
 	</Topic>
-		
+-->		
 	<Decorators>
 		<myapp:TestDecorator />	
 	</Decorators>




More information about the weld-commits mailing list