FELIX-483: Better exception thrown when there is an error parsing a resource

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@916282 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
index 9811ca4..5da9bf4 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/StaxParser.java
@@ -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++)
+        try
         {
-            resource.put(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
+            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)
+            {
+                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);
+                }
+            }
+            // Sanity check
+            if (event != XMLStreamConstants.END_ELEMENT || !RESOURCE.equals(reader.getLocalName()))
+            {
+                throw new Exception("Unexpected state");
+            }
+            return resource;
         }
-        int event;
-        while ((event = reader.nextTag()) == XMLStreamConstants.START_ELEMENT)
+        catch (Exception e)
         {
-            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);
+            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