felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r565713 - /felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java
Date Tue, 14 Aug 2007 11:38:53 GMT
Author: cziegeler
Date: Tue Aug 14 04:38:53 2007
New Revision: 565713

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

Modified:
    felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java

Modified: felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java?view=diff&rev=565713&r1=565712&r2=565713
==============================================================================
--- felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java
(original)
+++ felix/sandbox/cziegeler/maven-scr-plugin/src/main/java/org/apache/felix/sandbox/scrplugin/xml/ComponentDescriptorIO.java
Tue Aug 14 04:38:53 2007
@@ -329,11 +329,29 @@
         /** Pending property. */
         protected Property pendingProperty;
 
+        /** Flag for detecting the first element. */
+        protected boolean firstElement = true;
+
+        /** Override namespace. */
+        protected String overrideNamespace;
+
         public void startElement(String uri, String localName, String name, Attributes attributes)
         throws SAXException {
-            // 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) ) {
 
                 if (localName.equals(COMPONENT)) {
 
@@ -409,9 +427,11 @@
          * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
java.lang.String)
          */
         public void endElement(String uri, String localName, String name) throws SAXException
{
-            // 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") ) {
                     this.components.addComponent(this.currentComponent);
                     this.currentComponent = null;



Mime
View raw message