jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r439864 - /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
Date Sun, 03 Sep 2006 22:45:06 GMT
Author: jukka
Date: Sun Sep  3 15:45:05 2006
New Revision: 439864

URL: http://svn.apache.org/viewvc?view=rev&rev=439864
Log:
JCR-97: Improved checkstyle conformance AbstractSAXEventGenerator.
JCR-482: Use composition instead of inheritance in NamespaceStack.

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java?view=diff&rev=439864&r1=439863&r2=439864
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
Sun Sep  3 15:45:05 2006
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.xml;
 
 import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.jackrabbit.name.NameException;
 import org.apache.jackrabbit.name.QName;
@@ -73,7 +74,7 @@
     protected final Node startNode;
     protected final boolean skipBinary;
     protected final boolean noRecurse;
-    
+
     /**
      * the set of namespace declarations that have already been serialized
      */
@@ -218,18 +219,18 @@
             throws RepositoryException {
         String[] prefixes = session.getNamespacePrefixes();
         NamespaceStack newNamespaces = null;
-        
+
         for (int i = 0; i < prefixes.length; i++) {
             String prefix = prefixes[i];
-            
+
             if (prefix.length() > 0
                     && !QName.NS_XML_PREFIX.equals(prefix)) {
                 String uri = session.getNamespaceURI(prefix);
-                
+
                 // get the matching namespace from previous declarations
                 String mappedToNs = this.namespaces.getNamespaceURI(prefix);
-            
-                if (! uri.equals(mappedToNs)) {
+
+                if (!uri.equals(mappedToNs)) {
                     // when not the same, add a declaration
                     attributes.addAttribute(
                         QName.NS_XMLNS_URI,
@@ -237,17 +238,16 @@
                         QName.NS_XMLNS_PREFIX + ":" + prefix,
                         "CDATA",
                         uri);
-                    
+
                     if (newNamespaces == null) {
                         // replace current namespace stack when needed
                         newNamespaces = new NamespaceStack(this.namespaces);
                         this.namespaces = newNamespaces;
                     }
-                    
+
                     // remember the new declaration
                     newNamespaces.setNamespacePrefix(prefix, uri);
                 }
-                
             }
         }
     }
@@ -308,17 +308,15 @@
             while (nodeIter.hasNext()) {
                 // recurse
                 Node childNode = nodeIter.nextNode();
-                
                 // remember the current namespace declarations
                 NamespaceStack previousNamespaces = this.namespaces;
-                
+
                 process(childNode, level + 1);
-                
-                // restore the effective namespace declarations 
+
+                // restore the effective namespace declarations
                 // (from before visiting the child node)
                 this.namespaces = previousNamespaces;
             }
-            
         }
 
         // leaving node
@@ -392,59 +390,60 @@
     protected abstract void leaving(Property prop, int level)
             throws RepositoryException, SAXException;
 
-
-    
     /**
-     * Implements a simple stack of namespace
-     * declarations.
+     * Implements a simple stack of namespace declarations.
      */
-    
-    private static class NamespaceStack extends HashMap {
-      
+    private static class NamespaceStack {
+
         /**
          * Parent stack (may be <code>null</code>)
          */
         private final NamespaceStack parent;
-              
+
+        /**
+         * Local namespace declarations.
+         */
+        private final Map namespaces;
+
         /**
          * Instantiate a new stack
+         *
          * @param parent parent stack (may be <code>null</code> for the initial
stack)
          */
         public NamespaceStack(NamespaceStack parent) {
             this.parent = parent;
+            this.namespaces = new HashMap();
         }
-      
+
         /**
          * Obtain namespace URI for a prefix
+         *
          * @param prefix prefix
          * @return namespace URI (or <code>null</code> when unknown)
          */
         public String getNamespaceURI(String prefix) {
-          
-            String namespace = (String)super.get(prefix);
-    
+            String namespace = (String) namespaces.get(prefix);
             if (namespace != null) {
                 // found in this element, return right away
                 return namespace;
-            }
-            else {
+            } else if (parent != null) {
                 // ask parent, when present
-                if (this.parent == null) {
-                    return null;
-                }
-                else {
-                    return this.parent.getNamespaceURI(prefix);
-                }
-              }
+                return parent.getNamespaceURI(prefix);
+            } else {
+                return null;
+            }
         }
-      
+
         /**
          * Add a new prefix mapping
+         *
          * @param prefix namespace prefix
          * @param uri namespace URI
          */
         public void setNamespacePrefix(String prefix, String uri) {
-            super.put(prefix, uri);
+            namespaces.put(prefix, uri);
         }
+
     }
+
 }



Mime
View raw message