felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r916282 - /felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
Date Thu, 25 Feb 2010 13:21:36 GMT
Author: gnodet
Date: Thu Feb 25 13:21:36 2010
New Revision: 916282

URL: http://svn.apache.org/viewvc?rev=916282&view=rev
Log:
FELIX-483: Better exception thrown when there is an error parsing a resource

Modified:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java?rev=916282&r1=916281&r2=916282&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
Thu Feb 25 13:21:36 2010
@@ -19,6 +19,7 @@
 package org.apache.felix.bundlerepository;
 
 import java.io.InputStream;
+import javax.xml.stream.Location;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
@@ -159,40 +160,54 @@
     private ResourceImpl parseResource(XMLStreamReader reader) throws Exception
     {
         ResourceImpl resource = new ResourceImpl();
-        for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
-        {
-            resource.put(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
-        }
-        int event;
-        while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT)
+        try
         {
-            String element = reader.getLocalName();
-            if (CATEGORY.equals(element))
+            for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++)
             {
-                CategoryImpl category = parseCategory(reader);
-                resource.addCategory(category);
+                resource.put(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
             }
-            else if (CAPABILITY.equals(element))
+            int event;
+            while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT)
             {
-                CapabilityImpl capability = parseCapability(reader);
-                resource.addCapability(capability);
+                String element = reader.getLocalName();
+                if (CATEGORY.equals(element))
+                {
+                    CategoryImpl category = parseCategory(reader);
+                    resource.addCategory(category);
+                }
+                else if (CAPABILITY.equals(element))
+                {
+                    CapabilityImpl capability = parseCapability(reader);
+                    resource.addCapability(capability);
+                }
+                else if (REQUIRE.equals(element))
+                {
+                    RequirementImpl requirement = parseRequire(reader);
+                    resource.addRequire(requirement);
+                }
+                else
+                {
+                    ignoreTag(reader);
+                }
             }
-            else if (REQUIRE.equals(element))
+            // Sanity check
+            if (event != XMLStreamConstants.END_ELEMENT || !RESOURCE.equals(reader.getLocalName()))
             {
-                RequirementImpl requirement = parseRequire(reader);
-                resource.addRequire(requirement);
+                throw new Exception("Unexpected state");
+            }
+            return resource;
+        }
+        catch (Exception e)
+        {
+            Location loc = reader.getLocation();
+            if (loc != null) {
+                throw new Exception("Error while parsing resource " + resource.getId() +
" at line " + loc.getLineNumber() + " and column " + loc.getColumnNumber(), e);
             }
             else
             {
-                ignoreTag(reader);
+                throw new Exception("Error while parsing resource " + resource.getId(), e);
             }
         }
-        // Sanity check
-        if (event != XMLStreamConstants.END_ELEMENT || !RESOURCE.equals(reader.getLocalName()))
-        {
-            throw new Exception("Unexpected state");
-        }
-        return resource;
     }
 
     private CategoryImpl parseCategory(XMLStreamReader reader) throws XMLStreamException



Mime
View raw message