You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2007/08/14 13:28:36 UTC

svn commit: r565707 - in /felix/trunk/scr/src/main/java/org/apache/felix/scr: XmlHandler.java parser/KXml2SAXParser.java

Author: cziegeler
Date: Tue Aug 14 04:28:35 2007
New Revision: 565707

URL: http://svn.apache.org/viewvc?view=rev&rev=565707
Log:
Correctly handle namespaces (namespace is required if component is not the root element)

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/XmlHandler.java
    felix/trunk/scr/src/main/java/org/apache/felix/scr/parser/KXml2SAXParser.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/XmlHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/XmlHandler.java?view=diff&rev=565707&r1=565706&r2=565707
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/XmlHandler.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/XmlHandler.java Tue Aug 14 04:28:35 2007
@@ -45,6 +45,12 @@
     // PropertyMetaData whose value attribute is missing, hence has element data
     private PropertyMetadata m_pendingProperty;
 
+    /** Flag for detecting the first element. */
+    protected boolean firstElement = true;
+
+    /** Override namespace. */
+    protected String overrideNamespace;
+
     /**
      * Method called when a tag opens
      *
@@ -55,9 +61,20 @@
     **/
     public void startElement(String uri, String localName, Properties attrib)
     throws ParseException {
-        // we process elements in the default namespace and in the scr namespace only
-        // TODO - To be 100% correct we should only listen to the scr namespace
-        if ( "".equals(uri) || NAMESPACE_URI.equals(uri) ) {
+        // according to the spec, the elements should have the namespace,
+        // except when the root element is the "component" element
+        // So we check this for the first element, we receive.
+        if ( this.firstElement ) {
+            this.firstElement = false;
+            if ( localName.equals("component") && "".equals(uri) ) {
+                this.overrideNamespace = NAMESPACE_URI;
+            }
+        }
+
+        if ( this.overrideNamespace != null && "".equals(uri) ) {
+            uri = this.overrideNamespace;
+        }
+        if ( NAMESPACE_URI.equals(uri) ) {
         	try {
 
     	    	// 112.4.3 Component Element
@@ -175,9 +192,11 @@
     */
     public void endElement(String uri, String localName) throws ParseException
     {
-        // we process elements in the default namespace and in the scr namespace only
-        // TODO - To be 100% correct we should only listen to the scr namespace
-        if ( "".equals(uri) || NAMESPACE_URI.equals(uri) ) {
+        if ( this.overrideNamespace != null && "".equals(uri) ) {
+            uri = this.overrideNamespace;
+        }
+
+        if ( NAMESPACE_URI.equals(uri) ) {
             if (localName.equals("component"))
             {
             	// When the closing tag for a component is found, the component is validated to check if

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/parser/KXml2SAXParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/parser/KXml2SAXParser.java?view=diff&rev=565707&r1=565706&r2=565707
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/parser/KXml2SAXParser.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/parser/KXml2SAXParser.java Tue Aug 14 04:28:35 2007
@@ -32,9 +32,7 @@
  */
 public class KXml2SAXParser extends KXmlParser {
 
-	public String uri="uri";
-
-	/**
+    /**
 	* The constructor for a parser, it receives a java.io.Reader.
 	*
 	* @param   reader  The reader