[seam-commits] Seam SVN: r11999 - in modules/xml/trunk/src: main/java/org/jboss/seam/xml/model and 6 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Jan 30 17:39:48 EST 2010


Author: swd847
Date: 2010-01-30 17:39:47 -0500 (Sat, 30 Jan 2010)
New Revision: 11999

Modified:
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
   modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlConfigurationException.java
   modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java
   modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml
   modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml
Log:
updated error handling to better report where in the XML document the error occurred



Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -32,7 +32,6 @@
 import org.jboss.seam.xml.parser.ParserMain;
 import org.jboss.seam.xml.parser.SaxNode;
 import org.jboss.seam.xml.util.FileDataReader;
-import org.jboss.seam.xml.util.XmlParseException;
 import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
 
 public class XmlExtension implements Extension
@@ -55,16 +54,13 @@
     */
    Map<Integer, List<FieldValueObject>> fieldValues = new HashMap<Integer, List<FieldValueObject>>();
 
-   List<XmlParseException> parseErrors = new ArrayList<XmlParseException>();
+   List<Exception> errors = new ArrayList<Exception>();
 
    /**
     * This is the entry point for the extension
     */
    public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
    {
-      boolean problems = false;
-      StringBuilder problemString = new StringBuilder();
-
       List<Class<? extends XmlDocumentProvider>> providers = getDocumentProviders();
       for (Class<? extends XmlDocumentProvider> cl : providers)
       {
@@ -77,14 +73,14 @@
             {
                ParserMain parser = new ParserMain();
                ModelBuilder builder = new ModelBuilder();
-               SaxNode parentNode = parser.parse(d.getInputSource(), d.getFileUrl(), parseErrors);
+               SaxNode parentNode = parser.parse(d.getInputSource(), d.getFileUrl(), errors);
                ;
                results.add(builder.build(parentNode));
             }
          }
          catch (Exception e)
          {
-            throw new RuntimeException(e);
+            errors.add(e);
          }
       }
 
@@ -92,11 +88,10 @@
       {
          if (!r.getProblems().isEmpty())
          {
-            problems = true;
+
             for (String i : r.getProblems())
             {
-               problemString.append(i);
-               problemString.append("\n");
+               errors.add(new RuntimeException(i));
             }
          }
          for (BeanResult<?> b : r.getFieldValues().keySet())
@@ -146,10 +141,6 @@
          veto.addAll(r.getVeto());
 
       }
-      if (problems)
-      {
-         throw new RuntimeException(problemString.toString());
-      }
    }
 
    public <T> void processAnotated(@Observes ProcessAnnotatedType<T> event)
@@ -176,7 +167,7 @@
 
    public void processAfterBeanDeployment(@Observes AfterBeanDiscovery event)
    {
-      for (XmlParseException t : parseErrors)
+      for (Exception t : errors)
       {
          event.addDefinitionError(t);
       }

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -23,12 +23,16 @@
    final String innerText;
    final Map<String, String> attributes;
 
+   final int lineno;
+
+   final String document;
+
    public String getInnerText()
    {
       return innerText;
    }
 
-   public AbstractXmlItem(XmlItemType type, XmlItem parent, Class<?> javaClass, String innerText, Map<String, String> attributes)
+   public AbstractXmlItem(XmlItemType type, XmlItem parent, Class<?> javaClass, String innerText, Map<String, String> attributes, String document, int lineno)
    {
       this.type = type;
       this.parent = parent;
@@ -42,8 +46,20 @@
       {
          this.attributes = attributes;
       }
+      this.lineno = lineno;
+      this.document = document;
    }
 
+   public int getLineno()
+   {
+      return lineno;
+   }
+
+   public String getDocument()
+   {
+      return document;
+   }
+
    final List<XmlItem> children = new ArrayList<XmlItem>();
 
    public void addChild(XmlItem xmlItem)

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -21,9 +21,9 @@
     * @param innerText
     * @param attributes
     */
-   public AnnotationXmlItem(XmlItem parent, Class<?> c, String innerText, Map<String, String> attributes)
+   public AnnotationXmlItem(XmlItem parent, Class<?> c, String innerText, Map<String, String> attributes, String document, int lineno)
    {
-      super(XmlItemType.ANNOTATION, parent, c, innerText, attributes);
+      super(XmlItemType.ANNOTATION, parent, c, innerText, attributes, document, lineno);
       if (innerText != null)
       {
          if (!innerText.trim().equals(""))

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -13,6 +13,7 @@
 import java.util.Set;
 
 import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.util.XmlConfigurationException;
 
 public class ArrayXmlItem implements XmlItem
 {
@@ -21,12 +22,28 @@
 
    Class<?> javaClass;
 
-   public ArrayXmlItem(XmlItem parent)
+   final String document;
+
+   final int lineno;
+
+   public ArrayXmlItem(XmlItem parent, String document, int lineno)
    {
       allowed.add(XmlItemType.CLASS);
       this.parent = parent;
+      this.document = document;
+      this.lineno = lineno;
    }
 
+   public String getDocument()
+   {
+      return document;
+   }
+
+   public int getLineno()
+   {
+      return lineno;
+   }
+
    Set<XmlItemType> allowed = new HashSet<XmlItemType>();
 
    public Set<XmlItemType> getAllowedItem()
@@ -38,7 +55,7 @@
    {
       if (child != null)
       {
-         throw new RuntimeException("Array elements can only have one child");
+         throw new XmlConfigurationException("Array elements can only have one child", getDocument(), getLineno());
       }
       child = xmlItem;
    }
@@ -93,7 +110,7 @@
    {
       if (child == null)
       {
-         throw new RuntimeException("<array>  element must have a child specifying the array type");
+         throw new XmlConfigurationException("<array>  element must have a child specifying the array type", getDocument(), getLineno());
       }
       Class<?> l = child.getJavaClass();
       try
@@ -108,7 +125,7 @@
          }
          catch (ClassNotFoundException e2)
          {
-            throw new RuntimeException("Cannot create array class from " + l.getName());
+            throw new XmlConfigurationException("Cannot create array class from " + l.getName(), getDocument(), getLineno());
          }
       }
       return true;

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -22,9 +22,9 @@
     * @param innerText
     * @param attributes
     */
-   public ClassXmlItem(XmlItem parent, Class<?> c)
+   public ClassXmlItem(XmlItem parent, Class<?> c, String document, int lineno)
    {
-      super(XmlItemType.CLASS, parent, c, null, null);
+      super(XmlItemType.CLASS, parent, c, null, null, document, lineno);
       if (innerText != null)
       {
          if (!innerText.trim().equals(""))

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -10,9 +10,9 @@
 public class DependsXmlItem extends AbstractXmlItem
 {
 
-   public DependsXmlItem(XmlItem parent, String innerTest)
+   public DependsXmlItem(XmlItem parent, String innerTest, String document, int lineno)
    {
-      super(XmlItemType.DEPENDENCY, parent, null, innerTest, null);
+      super(XmlItemType.DEPENDENCY, parent, null, innerTest, null, document, lineno);
    }
 
    public Set<XmlItemType> getAllowedItem()

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -7,6 +7,8 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.jboss.seam.xml.util.XmlConfigurationException;
+
 public class EntryXmlItem extends AbstractXmlItem
 {
 
@@ -15,9 +17,9 @@
    XmlItem key;
    XmlItem value;
 
-   public EntryXmlItem(XmlItem parent)
+   public EntryXmlItem(XmlItem parent, String document, int lineno)
    {
-      super(XmlItemType.ENTRY, parent, null, null, null);
+      super(XmlItemType.ENTRY, parent, null, null, null, document, lineno);
       allowed.add(XmlItemType.VALUE);
       allowed.add(XmlItemType.KEY);
    }
@@ -32,7 +34,7 @@
    {
       if (children.size() != 2)
       {
-         throw new RuntimeException("<entry> tags must have two children, a <key> and a <value>");
+         throw new XmlConfigurationException("<entry> tags must have two children, a <key> and a <value>", getDocument(), getLineno());
       }
       for (XmlItem i : children)
       {
@@ -40,7 +42,7 @@
          {
             if (value != null)
             {
-               throw new RuntimeException("<entry> tags must have two children, a <key> and a <value>");
+               throw new XmlConfigurationException("<entry> tags must have two children, a <key> and a <value>", getDocument(), getLineno());
             }
             value = i;
          }
@@ -48,7 +50,7 @@
          {
             if (key != null)
             {
-               throw new RuntimeException("<entry> tags must have two children, a <key> and a <value>");
+               throw new XmlConfigurationException("<entry> tags must have two children, a <key> and a <value>", getDocument(), getLineno());
             }
             key = i;
          }

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -21,6 +21,7 @@
 import org.jboss.seam.xml.fieldset.MapFieldSet;
 import org.jboss.seam.xml.fieldset.MethodFieldSetter;
 import org.jboss.seam.xml.fieldset.SimpleFieldValue;
+import org.jboss.seam.xml.util.XmlConfigurationException;
 
 public class FieldXmlItem extends AbstractXmlItem
 {
@@ -30,9 +31,9 @@
    Field field;
    HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
 
-   public FieldXmlItem(XmlItem parent, Field c, String innerText)
+   public FieldXmlItem(XmlItem parent, Field c, String innerText, String document, int lineno)
    {
-      super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null);
+      super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null, document, lineno);
       this.field = c;
       this.fieldSetter = getFieldValueSetter(c);
       if (innerText != null && innerText.length() > 0)
@@ -80,7 +81,7 @@
          {
             if (!valueEntries.isEmpty())
             {
-               throw new RuntimeException("Map fields cannot have <value> elements as children,only <entry> elements Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+               throw new XmlConfigurationException("Map fields cannot have <value> elements as children,only <entry> elements Field:" + field.getDeclaringClass().getName() + '.' + field.getName(), getDocument(), getLineno());
             }
             if (!mapEntries.isEmpty())
             {
@@ -91,7 +92,7 @@
          {
             if (!mapEntries.isEmpty())
             {
-               throw new RuntimeException("Collection fields must be set using <value> not <entry> Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+               throw new XmlConfigurationException("Collection fields must be set using <value> not <entry> Field:" + field.getDeclaringClass().getName() + '.' + field.getName(), getDocument(), getLineno());
             }
             if (!valueEntries.isEmpty())
             {
@@ -109,11 +110,11 @@
          {
             if (!mapEntries.isEmpty())
             {
-               throw new RuntimeException("Only Map fields can be set using <entry> Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+               throw new XmlConfigurationException("Only Map fields can be set using <entry> Field:" + field.getDeclaringClass().getName() + '.' + field.getName(), getDocument(), getLineno());
             }
             if (valueEntries.size() != 1)
             {
-               throw new RuntimeException("Non collection fields can only have a single <value> element Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+               throw new XmlConfigurationException("Non collection fields can only have a single <value> element Field:" + field.getDeclaringClass().getName() + '.' + field.getName(), getDocument(), getLineno());
             }
             fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter, valueEntries.get(0).getInnerText());
          }

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -10,9 +10,9 @@
 public class KeyXmlItem extends AbstractXmlItem
 {
 
-   public KeyXmlItem(XmlItem parent, String innerText)
+   public KeyXmlItem(XmlItem parent, String innerText, String document, int lineno)
    {
-      super(XmlItemType.KEY, parent, null, innerText, null);
+      super(XmlItemType.KEY, parent, null, innerText, null, document, lineno);
    }
 
    public Set<XmlItemType> getAllowedItem()

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -10,6 +10,8 @@
 import java.util.List;
 import java.util.Set;
 
+import org.jboss.seam.xml.util.XmlConfigurationException;
+
 public class MethodXmlItem extends AbstractXmlItem
 {
 
@@ -18,9 +20,9 @@
    Method method;
    HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
 
-   public MethodXmlItem(XmlItem parent, String methodName)
+   public MethodXmlItem(XmlItem parent, String methodName, String document, int lineno)
    {
-      super(XmlItemType.METHOD, parent, parent.getJavaClass(), null, null);
+      super(XmlItemType.METHOD, parent, parent.getJavaClass(), null, null, document, lineno);
       // methods are lazily resolved once we know the parameter types
       this.methodName = methodName;
       Method found = null;
@@ -83,11 +85,11 @@
       }
       catch (SecurityException e)
       {
-         throw new RuntimeException("Security Exception resolving method " + methodName + " on class " + javaClass.getName());
+         throw new XmlConfigurationException("Security Exception resolving method " + methodName + " on class " + javaClass.getName(), getDocument(), getLineno());
       }
       catch (NoSuchMethodException e)
       {
-         throw new RuntimeException("NoSuchMethodException resolving method " + methodName + " on class " + javaClass.getName());
+         throw new XmlConfigurationException("NoSuchMethodException resolving method " + methodName + " on class " + javaClass.getName(), getDocument(), getLineno());
       }
    }
 

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -21,14 +21,13 @@
 import org.jboss.seam.xml.core.XmlResult;
 import org.jboss.seam.xml.fieldset.FieldValueObject;
 import org.jboss.seam.xml.parser.SaxNode;
-import org.jboss.seam.xml.parser.namespace.InvalidElementException;
+import org.jboss.seam.xml.parser.namespace.CompositeNamespaceElementResolver;
 import org.jboss.seam.xml.parser.namespace.NamespaceElementResolver;
-import org.jboss.seam.xml.parser.namespace.PackageNamespaceElementResolver;
 import org.jboss.seam.xml.parser.namespace.RootNamespaceElementResolver;
+import org.jboss.seam.xml.util.XmlConfigurationException;
 import org.jboss.seam.xml.util.XmlObjectConverter;
 import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
 import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
-import org.w3c.dom.DOMException;
 
 /**
  * Parser for xml configration
@@ -54,11 +53,11 @@
 
       if (!root.getName().equals("Beans"))
       {
-         throw new RuntimeException("Wrong root element for XML config file, expected:<Beans> found:" + root.getName());
+         throw new XmlConfigurationException("Wrong root element for XML config file, expected:<Beans> found:" + root.getName(), root.getDocument(), root.getLineNo());
       }
       if (!ROOT_NAMESPACE.equals(root.getNamespaceUri()))
       {
-         throw new RuntimeException("Wrong root namespace for XML config file, expected:" + ROOT_NAMESPACE + " found:" + root.getNamespaceUri());
+         throw new XmlConfigurationException("Wrong root namespace for XML config file, expected:" + ROOT_NAMESPACE + " found:" + root.getNamespaceUri(), root.getDocument(), root.getLineNo());
       }
 
       resolvers.put(ROOT_NAMESPACE, new RootNamespaceElementResolver());
@@ -86,7 +85,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   private void addNodeToResult(XmlResult ret, XmlItem rb) throws InvalidElementException
+   private void addNodeToResult(XmlResult ret, XmlItem rb)
    {
 
       if (rb.getType() == XmlItemType.CLASS || rb.getType() == XmlItemType.ANNOTATION)
@@ -136,21 +135,15 @@
       }
    }
 
-   protected XmlItem resolveNode(SaxNode node, XmlItem parent) throws DOMException, InvalidElementException
+   protected XmlItem resolveNode(SaxNode node, XmlItem parent)
    {
       NamespaceElementResolver resolver = resolveNamepsace(node.getNamespaceUri());
 
-      Map<String, String> attributes = node.getAttributes();
-      String innerText = node.getInnerText().trim();
-      if (innerText.equals(""))
-      {
-         innerText = null;
-      }
-      XmlItem ret = resolver.getItemForNamespace(node.getName(), parent, innerText, attributes);
+      XmlItem ret = resolver.getItemForNamespace(node, parent);
 
       if (ret == null)
       {
-         throw new InvalidElementException("Could not resolve node " + node.getName() + " in namespace " + node.getNamespaceUri());
+         throw new XmlConfigurationException("Could not resolve node " + node.getName() + " in namespace " + node.getNamespaceUri(), node.getDocument(), node.getLineNo());
       }
       List<SaxNode> children = node.getChildren();
       for (SaxNode n : children)
@@ -173,7 +166,7 @@
          return resolvers.get(namespaceURI);
       }
       String ns = namespaceURI.replaceFirst("urn:java:", "");
-      PackageNamespaceElementResolver res = new PackageNamespaceElementResolver(ns);
+      CompositeNamespaceElementResolver res = new CompositeNamespaceElementResolver(ns.split(":"));
       resolvers.put(namespaceURI, res);
       return res;
    }
@@ -181,7 +174,7 @@
    /**
     * Determines the type of an element by examining its child nodes
     */
-   protected ResultType getItemType(XmlItem item) throws InvalidElementException
+   protected ResultType getItemType(XmlItem item)
    {
 
       ResultType ret = null;
@@ -193,7 +186,7 @@
             {
                if (ret != null)
                {
-                  throw new InvalidElementException("Element cannot be both an INTERCEPTOR_BINDING and a " + ret.toString());
+                  throw new XmlConfigurationException("Element cannot be both an INTERCEPTOR_BINDING and a " + ret.toString(), item.getDocument(), item.getLineno());
                }
                else
                {
@@ -204,7 +197,7 @@
             {
                if (ret != null)
                {
-                  throw new InvalidElementException("Element cannot be both an QUALIFIER and a " + ret.toString());
+                  throw new XmlConfigurationException("Element cannot be both an QUALIFIER and a " + ret.toString(), item.getDocument(), item.getLineno());
                }
                else
                {
@@ -215,7 +208,7 @@
             {
                if (ret != null)
                {
-                  throw new InvalidElementException("Element cannot be both an STEREOTYPE and a " + ret.toString());
+                  throw new XmlConfigurationException("Element cannot be both an STEREOTYPE and a " + ret.toString(), item.getDocument(), item.getLineno());
                }
                else
                {
@@ -227,7 +220,7 @@
          {
             if (ret != null)
             {
-               throw new InvalidElementException("Element cannot be both an VETO and a " + ret.toString());
+               throw new XmlConfigurationException("Element cannot be both an VETO and a " + ret.toString(), item.getDocument(), item.getLineno());
             }
             else
             {
@@ -244,7 +237,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   <T> BeanResult<T> buildAnnotatedType(XmlItem rb) throws InvalidElementException
+   <T> BeanResult<T> buildAnnotatedType(XmlItem rb)
    {
       BeanResult<T> result = new BeanResult<T>(rb.getJavaClass());
       NewAnnotatedTypeBuilder<T> type = result.getBuilder();
@@ -298,7 +291,7 @@
                      }
                      else
                      {
-                        throw new RuntimeException("Method parameters may only have annotations as children in " + item.getJavaClass().getName());
+                        throw new XmlConfigurationException("Method parameters may only have annotations as children in " + item.getJavaClass().getName(), rb.getDocument(), rb.getLineno());
                      }
                   }
                }
@@ -317,7 +310,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   void addSteriotypeToResult(XmlResult ret, XmlItem rb) throws InvalidElementException
+   void addSteriotypeToResult(XmlResult ret, XmlItem rb)
    {
 
       Annotation[] values = new Annotation[rb.getChildren().size()];
@@ -331,7 +324,7 @@
          }
          else
          {
-            throw new InvalidElementException("Setereotype " + rb.getJavaClass() + " has an item that does not represent an annotation in its XML configurations");
+            throw new XmlConfigurationException("Setereotype " + rb.getJavaClass() + " has an item that does not represent an annotation in its XML configurations", rb.getDocument(), rb.getLineno());
          }
          count++;
       }
@@ -340,7 +333,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   Annotation createAnnotation(XmlItem item) throws InvalidElementException
+   Annotation createAnnotation(XmlItem item)
    {
       Map<String, Object> typedVars = new HashMap<String, Object>();
       Class<?> anClass = item.getJavaClass();
@@ -354,7 +347,7 @@
          }
          catch (Exception e1)
          {
-            throw new InvalidElementException("Annotation " + item.getJavaClass().getName() + " does not have a member named " + mname + " ,error in XML");
+            throw new XmlConfigurationException("Annotation " + item.getJavaClass().getName() + " does not have a member named " + mname + " ,error in XML", item.getDocument(), item.getLineno());
          }
          Class<?> returnType = m.getReturnType();
          typedVars.put(mname, XmlObjectConverter.convert(returnType, e.getValue()));
@@ -370,7 +363,7 @@
       {
          if (!allowed.contains(item.getType()))
          {
-            throw new RuntimeException("Item " + item.getType() + " is not allowed to contain " + i.getType());
+            throw new XmlConfigurationException("Item " + item.getType() + " is not allowed to contain " + i.getType(), item.getDocument(), item.getLineno());
          }
          validateXmlItem(i);
       }

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -10,9 +10,9 @@
 public class ValueXmlItem extends AbstractXmlItem
 {
 
-   public ValueXmlItem(XmlItem parent, String innerText)
+   public ValueXmlItem(XmlItem parent, String innerText, String document, int lineno)
    {
-      super(XmlItemType.VALUE, parent, null, innerText, null);
+      super(XmlItemType.VALUE, parent, null, innerText, null, document, lineno);
    }
 
    public Set<XmlItemType> getAllowedItem()

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -10,9 +10,9 @@
 public class VetoXmlItem extends AbstractXmlItem
 {
 
-   public VetoXmlItem(XmlItem parent)
+   public VetoXmlItem(XmlItem parent, String document, int lineno)
    {
-      super(XmlItemType.VETO, parent, null, null, null);
+      super(XmlItemType.VETO, parent, null, null, null, document, lineno);
 
    }
 

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -45,4 +45,8 @@
 
    public Set<XmlItemType> getAllowedItem();
 
+   int getLineno();
+
+   String getDocument();
+
 }
\ No newline at end of file

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -38,9 +38,9 @@
 
    String document;
 
-   List<XmlParseException> errors;
+   List<Exception> errors;
 
-   public SaxNode parse(InputSource inputSource, String fileUrl, List<XmlParseException> errors)
+   public SaxNode parse(InputSource inputSource, String fileUrl, List<Exception> errors)
    {
       this.errors = errors;
       document = fileUrl;

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -12,7 +12,7 @@
 public class SaxNode
 {
 
-   SaxNode(String name, String uri, Map<String, String> attributes, SaxNode parent, String document, int lineNo)
+   public SaxNode(String name, String uri, Map<String, String> attributes, SaxNode parent, String document, int lineNo)
    {
       this.name = name;
       this.namespaceUri = uri;
@@ -33,12 +33,16 @@
 
    public String getInnerText()
    {
+      if (innerText != null && innerText.isEmpty())
+      {
+         return null;
+      }
       return innerText;
    }
 
    public void setInnerText(String innerText)
    {
-      this.innerText = innerText;
+      this.innerText = innerText.trim();
    }
 
    public String getNamespaceUri()

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -8,10 +8,10 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.parser.SaxNode;
 
 /**
  * Namespace resolver that searches through a list of packages
@@ -41,22 +41,22 @@
       }
    }
 
-   public XmlItem getItemForNamespace(String item, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException
+   public XmlItem getItemForNamespace(SaxNode node, XmlItem parent)
    {
-      if (notFound.contains(item))
+      if (notFound.contains(node.getName()))
       {
          return null;
       }
 
       for (PackageNamespaceElementResolver p : resolvers)
       {
-         XmlItem xi = p.getItemForNamespace(item, parent, innerText, attributes);
+         XmlItem xi = p.getItemForNamespace(node, parent);
          if (xi != null)
          {
             return xi;
          }
       }
-      notFound.add(item);
+      notFound.add(node.getName());
       return null;
    }
 

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -4,13 +4,12 @@
  */
 package org.jboss.seam.xml.parser.namespace;
 
-import java.util.Map;
-
 import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.parser.SaxNode;
 
 public interface NamespaceElementResolver
 {
 
-   XmlItem getItemForNamespace(String item, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException;
+   XmlItem getItemForNamespace(SaxNode node, XmlItem parent);
 
 }

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -10,10 +10,11 @@
 import org.jboss.seam.xml.model.FieldXmlItem;
 import org.jboss.seam.xml.model.MethodXmlItem;
 import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.util.XmlConfigurationException;
 
 class NamespaceUtils
 {
-   static XmlItem resolveMethodOrField(String name, XmlItem parent, String innerText) throws InvalidElementException
+   static XmlItem resolveMethodOrField(String name, XmlItem parent, String innerText, String document, int lineno)
    {
       Class<?> p = parent.getJavaClass();
       Field f = null;
@@ -29,15 +30,15 @@
       }
       if (methodFound && f != null)
       {
-         throw new InvalidElementException(parent.getJavaClass().getName() + " has both a method and a field named " + name + " and so cannot be configured via XML");
+         throw new XmlConfigurationException(parent.getJavaClass().getName() + " has both a method and a field named " + name + " and so cannot be configured via XML", document, lineno);
       }
       if (methodFound)
       {
-         return new MethodXmlItem(parent, name);
+         return new MethodXmlItem(parent, name, document, lineno);
       }
       else if (f != null)
       {
-         return new FieldXmlItem(parent, f, innerText);
+         return new FieldXmlItem(parent, f, innerText, document, lineno);
       }
       return null;
    }

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -13,6 +13,7 @@
 import org.jboss.seam.xml.model.ClassXmlItem;
 import org.jboss.seam.xml.model.XmlItem;
 import org.jboss.seam.xml.model.XmlItemType;
+import org.jboss.seam.xml.parser.SaxNode;
 
 public class PackageNamespaceElementResolver implements NamespaceElementResolver
 {
@@ -25,8 +26,9 @@
       this.pack = pack + ".";
    }
 
-   public XmlItem getItemForNamespace(String name, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException
+   public XmlItem getItemForNamespace(SaxNode node, XmlItem parent)
    {
+      String name = node.getName();
       if (notFound.contains(name))
       {
          return null;
@@ -46,11 +48,11 @@
          }
          if (c.isAnnotation())
          {
-            return new AnnotationXmlItem(parent, c, innerText, attributes);
+            return new AnnotationXmlItem(parent, c, node.getInnerText(), node.getAttributes(), node.getDocument(), node.getLineNo());
          }
          else
          {
-            return new ClassXmlItem(parent, c);
+            return new ClassXmlItem(parent, c, node.getDocument(), node.getLineNo());
          }
 
       }
@@ -68,7 +70,7 @@
          // if the item can be a method of a FIELD
          if (parent.getAllowedItem().contains(XmlItemType.METHOD) || parent.getAllowedItem().contains(XmlItemType.FIELD))
          {
-            return NamespaceUtils.resolveMethodOrField(name, parent, innerText);
+            return NamespaceUtils.resolveMethodOrField(name, parent, node.getInnerText(), node.getDocument(), node.getLineNo());
          }
          else
          {

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -4,8 +4,6 @@
  */
 package org.jboss.seam.xml.parser.namespace;
 
-import java.util.Map;
-
 import org.jboss.seam.xml.model.ArrayXmlItem;
 import org.jboss.seam.xml.model.DependsXmlItem;
 import org.jboss.seam.xml.model.EntryXmlItem;
@@ -13,6 +11,7 @@
 import org.jboss.seam.xml.model.ValueXmlItem;
 import org.jboss.seam.xml.model.VetoXmlItem;
 import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.parser.SaxNode;
 
 public class RootNamespaceElementResolver implements NamespaceElementResolver
 {
@@ -25,40 +24,41 @@
       delegate = new CompositeNamespaceElementResolver(namspaces);
    }
 
-   public XmlItem getItemForNamespace(String item, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException
+   public XmlItem getItemForNamespace(SaxNode node, XmlItem parent)
    {
-      XmlItem ret = getRootItem(item, parent, innerText);
+      XmlItem ret = getRootItem(node, parent);
       if (ret != null)
          return ret;
-      return delegate.getItemForNamespace(item, parent, innerText, attributes);
+      return delegate.getItemForNamespace(node, parent);
 
    }
 
-   XmlItem getRootItem(String item, XmlItem parent, String innerText)
+   XmlItem getRootItem(SaxNode node, XmlItem parent)
    {
+      String item = node.getName();
       if (item.equals("value") || item.equals("v"))
       {
-         return new ValueXmlItem(parent, innerText);
+         return new ValueXmlItem(parent, node.getInnerText(), node.getDocument(), node.getLineNo());
       }
       else if (item.equals("key") || item.equals("k"))
       {
-         return new KeyXmlItem(parent, innerText);
+         return new KeyXmlItem(parent, node.getInnerText(), node.getDocument(), node.getLineNo());
       }
       else if (item.equals("entry") || item.equals("e"))
       {
-         return new EntryXmlItem(parent);
+         return new EntryXmlItem(parent, node.getDocument(), node.getLineNo());
       }
       else if (item.equals("array"))
       {
-         return new ArrayXmlItem(parent);
+         return new ArrayXmlItem(parent, node.getDocument(), node.getLineNo());
       }
       else if (item.equals("veto"))
       {
-         return new VetoXmlItem(parent);
+         return new VetoXmlItem(parent, node.getDocument(), node.getLineNo());
       }
       else if (item.equals("depends"))
       {
-         return new DependsXmlItem(parent, innerText);
+         return new DependsXmlItem(parent, node.getInnerText(), node.getDocument(), node.getLineNo());
       }
       return null;
    }

Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlConfigurationException.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlConfigurationException.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlConfigurationException.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -1,6 +1,6 @@
 package org.jboss.seam.xml.util;
 
-public class XmlConfigurationException extends Exception
+public class XmlConfigurationException extends RuntimeException
 {
    int lineno;
    String document;

Modified: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java	2010-01-30 22:39:47 UTC (rev 11999)
@@ -9,8 +9,8 @@
 
 import org.jboss.seam.xml.model.XmlItem;
 import org.jboss.seam.xml.model.XmlItemType;
+import org.jboss.seam.xml.parser.SaxNode;
 import org.jboss.seam.xml.parser.namespace.CompositeNamespaceElementResolver;
-import org.jboss.seam.xml.parser.namespace.InvalidElementException;
 import org.jboss.seam.xml.parser.namespace.NamespaceElementResolver;
 import org.jboss.seam.xml.parser.namespace.PackageNamespaceElementResolver;
 import org.jboss.seam.xml.test.simple.Bean1;
@@ -20,14 +20,14 @@
 {
 
    @Test
-   public void testPackageResolver() throws InvalidElementException
+   public void testPackageResolver()
    {
       PackageNamespaceElementResolver resolver = new PackageNamespaceElementResolver("org.jboss.seam.xml.test.simple");
       testResolver(resolver);
    }
 
    @Test
-   public void testCompositePackageResolver() throws InvalidElementException
+   public void testCompositePackageResolver()
    {
       List<String> namespaces = new ArrayList<String>();
       namespaces.add("java.lang");
@@ -37,13 +37,13 @@
       testResolver(resolver);
    }
 
-   public void testResolver(NamespaceElementResolver resolver) throws InvalidElementException
+   public void testResolver(NamespaceElementResolver resolver)
    {
 
-      XmlItem item = resolver.getItemForNamespace("Bean1", null, null, null);
+      XmlItem item = resolver.getItemForNamespace(new SaxNode("Bean1", null, null, null, null, 0), null);
       assert item.getJavaClass() == Bean1.class : "Namespace resolver returned wrong class type";
       assert item.getType() == XmlItemType.CLASS : "Namespace resolver did not return class";
-      XmlItem method = resolver.getItemForNamespace("method1", item, null, null);
+      XmlItem method = resolver.getItemForNamespace(new SaxNode("method1", null, null, null, null, 0), item);
       assert method.getType() == XmlItemType.METHOD : "Item returned wrong type";
 
       method.resolveChildren();
@@ -51,7 +51,7 @@
       assert method.getMethod() != null : "Could not resolve method";
       assert method.getMethod().getParameterTypes().length == 0 : "Wrong method was resolved";
 
-      XmlItem field = resolver.getItemForNamespace("field1", item, null, null);
+      XmlItem field = resolver.getItemForNamespace(new SaxNode("field1", null, null, null, null, 0), item);
       assert field.getType() == XmlItemType.FIELD : "Element of wrong type returned";
       assert field.getField() != null : "field was not set";
 

Modified: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml	2010-01-30 22:39:47 UTC (rev 11999)
@@ -2,6 +2,10 @@
 <Beans xmlns="urn:seam:core"
           xmlns:test="urn:java:org.jboss.seam.xml.test.injection">
    
+   <veto>
+   	<test:QualifierTestBean/>
+   </veto>
+   
     <test:OtherQualifier>
         <Qualifier/>
     </test:OtherQualifier>

Modified: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml	2010-01-28 15:13:41 UTC (rev 11998)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml	2010-01-30 22:39:47 UTC (rev 11999)
@@ -22,7 +22,6 @@
         <test:method>
             <Produces/>
             <test:Qualifier1/>
-            
             <test:MethodValueBean>
                 <test:Qualifier2/>
             </test:MethodValueBean>



More information about the seam-commits mailing list