FELIX-3900 @HandlerDeclaration do not convert DOM Attributes to iPOJO Attributes correctly
FELIX-3901 Avoid converting Xml namespace declaration with @HandlerDeclaration

* Use Attr.getLocalName() instead of Attr.getName(): getName returns a concatenation of prefix + ':' + localName
* Ignore 'xmlns' prefixed attributes
* Added tests to avoid future regressions

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1446089 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java
index 2570afc..229f01e 100644
--- a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java
+++ b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitor.java
@@ -120,7 +120,9 @@
             NamedNodeMap attributes = xmlElement.getAttributes();
             for (int i = 0; i < attributes.getLength(); i++) {
                 Attr attr = (Attr) attributes.item(i);
-                root.addAttribute(transformAttribute(attr));
+                if (!"xmlns".equals(attr.getPrefix())) {
+                    root.addAttribute(transformAttribute(attr));
+                }
             }
         }
 
@@ -144,7 +146,7 @@
     }
 
     private static Attribute transformAttribute(Attr attr) {
-        return new Attribute(attr.getName(),
+        return new Attribute(attr.getLocalName(),
                 attr.getNamespaceURI(),
                 attr.getValue());
     }
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java
index b8afe16..4283055 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/ComponentWorkbenchTestCase.java
@@ -81,7 +81,7 @@
     }
 
 
-    private static ClassNode node() {
+    public static ClassNode node() {
         ClassNode node = new ClassNode();
         node.name = "my/Component";
         return node;
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java
new file mode 100644
index 0000000..1d56258
--- /dev/null
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulator/metadata/annotation/visitor/HandlerDeclarationVisitorTestCase.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.ipojo.manipulator.metadata.annotation.visitor;
+
+import junit.framework.TestCase;
+import org.apache.felix.ipojo.manipulator.Reporter;
+import org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench;
+import org.apache.felix.ipojo.metadata.Element;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import static org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbenchTestCase.node;
+import static org.mockito.Mockito.mock;
+
+/**
+ * User: guillaume
+ * Date: 14/02/13
+ * Time: 10:22
+ */
+public class HandlerDeclarationVisitorTestCase extends TestCase {
+
+    private Reporter reporter;
+    private ComponentWorkbench workbench;
+    private HandlerDeclarationVisitor visitor;
+
+    @Override
+    public void setUp() throws Exception {
+        reporter = mock(Reporter.class);
+        workbench = new ComponentWorkbench(null, node());
+        workbench.setRoot(new Element("container", null));
+        visitor = new HandlerDeclarationVisitor(workbench, builder(), reporter);
+    }
+
+    public void testElementConversionWithNoNamespace() throws Exception {
+        visitor.visit(null, "<testing/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(0, testing.getAttributes().length);
+    }
+
+    public void testElementConversionWithNamespace() throws Exception {
+        visitor.visit(null, "<ns:testing xmlns:ns='org.apache.felix.ipojo.testing'/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing", "org.apache.felix.ipojo.testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(0, testing.getAttributes().length);
+        assertNotNull(produced.getElements("org.apache.felix.ipojo.testing:testing"));
+        assertNull(produced.getElements("testing"));
+    }
+
+    public void testAttributeConversionWithNamespace() throws Exception {
+        visitor.visit(null, "<ns:testing xmlns:ns='org.apache.felix.ipojo.testing' ns:name='Guillaume'/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing", "org.apache.felix.ipojo.testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(1, testing.getAttributes().length);
+        assertEquals("Guillaume", testing.getAttribute("name", "org.apache.felix.ipojo.testing"));
+        assertEquals("Guillaume", testing.getAttribute("org.apache.felix.ipojo.testing:name"));
+    }
+
+    public void testAttributeConversionWithNoNamespace() throws Exception {
+        visitor.visit(null, "<ns:testing xmlns:ns='org.apache.felix.ipojo.testing' name='Guillaume'/>");
+        visitor.visitEnd();
+
+        Element produced = workbench.build();
+        Element testing = produced.getElements("testing", "org.apache.felix.ipojo.testing")[0];
+        assertEquals(0, testing.getElements().length);
+        assertEquals(1, testing.getAttributes().length);
+        assertEquals("Guillaume", testing.getAttribute("name"));
+    }
+
+    private DocumentBuilder builder() throws ParserConfigurationException {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        return factory.newDocumentBuilder();
+    }
+}