svn commit: r566464 - in /xml/xindice/trunk/java: src/org/apache/xindice/core/indexer/ src/org/apache/xindice/xml/ src/org/apache/xindice/xml/sax/ tests/src/org/apache/xindice/xml/

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Wed Aug 15 18:21:52 2007
New Revision: 566464

URL: http://svn.apache.org/viewvc?view=rev&rev=566464
Log:
finish symbol table refactoring - remove last static methods

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/DocumentHandler.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexPattern.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/SymbolTable.java
    xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java
    xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/SymbolTableTest.java

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/DocumentHandler.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/DocumentHandler.java?view=diff&rev=566464&r1=566463&r2=566464
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/DocumentHandler.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/DocumentHandler.java Wed Aug 15 18:21:52 2007
@@ -176,8 +176,7 @@
     public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
         // Modify the stack info to normalize the symbolID
         if (namespaceURI != null && namespaceURI.length() > 0) {
-            String elemNSID = SymbolTable.getNormalizedQName(localName, namespaceURI);
-            info.symbolID = symbols.getSymbol(elemNSID, namespaceURI, true);
+            info.symbolID = symbols.getNormalizedSymbol(localName, namespaceURI, true);
         }
 
         int size = atts.getLength();
@@ -185,10 +184,9 @@
             String nsURI = atts.getURI(i);
             short id;
             if (nsURI != null && nsURI.length() > 0) {
-                String attrNSID = SymbolTable.getNormalizedQName(atts.getLocalName(i), nsURI);
-                id = symbols.getSymbol(attrNSID, nsURI, true);
+                id = symbols.getNormalizedSymbol(atts.getLocalName(i), nsURI, true);
             } else {
-                id = symbols.getSymbol(atts.getQName(i));
+                id = symbols.getSymbol(atts.getQName(i), true);
             }
 
             processEntry(new IndexPattern(symbols, info.symbolID, id), atts.getValue(i), info.pos, info.len);

Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexPattern.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexPattern.java?view=diff&rev=566464&r1=566463&r2=566464
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexPattern.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/IndexPattern.java Wed Aug 15 18:21:52 2007
@@ -60,7 +60,7 @@
         if (elemName.equals("*")) {
             elemID = PATTERN_WILDCARD;
         } else {
-            elemID = SymbolTable.getNormalizedSymbol(symbols, elemName, nsMap, true);
+            elemID = symbols.getNormalizedSymbol(elemName, nsMap, true);
         }
 
         if (st.hasMoreTokens()) {
@@ -69,7 +69,7 @@
                 attrID = PATTERN_WILDCARD;
             } else {
                 attrID = elemID == PATTERN_WILDCARD ? PATTERN_NAME
-                        : SymbolTable.getNormalizedSymbol(symbols, attrName, nsMap, true);
+                        : symbols.getNormalizedSymbol(attrName, nsMap, true);
             }
         }
     }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/SymbolTable.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/SymbolTable.java?view=diff&rev=566464&r1=566463&r2=566464
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/SymbolTable.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/SymbolTable.java Wed Aug 15 18:21:52 2007
@@ -81,43 +81,6 @@
     }
 
     //
-    // Static Methods
-    //
-
-    public static String getNormalizedQName(String localName, String namespaceURI) {
-        return "ns" + namespaceURI.hashCode() + ':' + localName;
-    }
-
-    public static short getNormalizedSymbol(SymbolTable symbols, String lookup, NamespaceMap nsMap, boolean create) {
-        // Parse [<namespaceURI>]<nsPrefix>:<localName> with optional nsPrefix
-        if (lookup.startsWith("[")) {
-            int idx = lookup.indexOf(']');
-            String nsURI = lookup.substring(1, idx);
-            int cidx = lookup.indexOf(':', idx + 1);
-            String name = cidx != -1 ? lookup.substring(cidx + 1) : lookup.substring(idx + 1);
-
-            return symbols.getSymbol(getNormalizedQName(name, nsURI), nsURI, create);
-        }
-
-        // Parse <nsPrefix>:<localName> with passed in nsMap
-        int idx = lookup.indexOf(':');
-        if (idx != -1) {
-            String pfx = lookup.substring(0, idx);
-            String nsURI = (String) nsMap.get(pfx);
-            if (nsURI != null) {
-                String name = lookup.substring(idx + 1);
-                return symbols.getSymbol(getNormalizedQName(name, nsURI), nsURI, create);
-            }
-        }
-
-        return symbols.getSymbol(lookup, create);
-    }
-
-    private static String getLookupName(String qname, String namespaceURI) {
-        return '[' + namespaceURI + ']' + qname;
-    }
-
-    //
     // Instance Methods
     //
 
@@ -214,6 +177,68 @@
     }
 
     //
+    // Lookup normalized symbol
+    //
+
+    public final short getNormalizedSymbol(String localName, String namespaceURI) {
+        return getNormalizedSymbol(localName, namespaceURI, false);
+    }
+
+    /**
+     * Lookup normalized symbol by element (or attribute) local name and namespace URI.
+     *
+     * @param localName element (attribute) local name
+     * @param namespaceURI element (attribute) namespace URI
+     * @param create when true, creates symbol if it is missing
+     * @return symbol id or -1
+     */
+    public final short getNormalizedSymbol(String localName, String namespaceURI, boolean create) {
+        String normalizedQName = SymbolTable.getNormalizedQName(localName, namespaceURI);
+        return getSymbol(normalizedQName, namespaceURI, create);
+    }
+
+    /**
+     * Lookup normalized symbol by lookup string and (optional) namespace map. Lookup
+     * string can take one of the following forms:
+     * <ul>
+     * <li> [<namespaceURI>]<nsPrefix>:<localName>, where nsPrefix can be empty
+     * <li> <nsPrefix>:<localName>, any regular qName
+     * </ul>
+     *
+     * Namespace map is used to determine namespaceURI for passed in lookup string and
+     * normalize namespace prefix.
+     *
+     * @param lookup lookup string
+     * @param nsMap namespace map
+     * @param create when true, creates symbol if it is missing
+     * @return symbol id or -1
+     */
+    public final short getNormalizedSymbol(String lookup, NamespaceMap nsMap, boolean create) {
+        // Parse [<namespaceURI>]<nsPrefix>:<localName> with optional nsPrefix
+        if (lookup.startsWith("[")) {
+            int idx = lookup.indexOf(']');
+            String nsURI = lookup.substring(1, idx);
+            int cidx = lookup.indexOf(':', idx + 1);
+            String name = cidx != -1 ? lookup.substring(cidx + 1) : lookup.substring(idx + 1);
+
+            return getSymbol(getNormalizedQName(name, nsURI), nsURI, create);
+        }
+
+        // Parse <nsPrefix>:<localName> with passed in nsMap
+        int idx = lookup.indexOf(':');
+        if (idx != -1) {
+            String pfx = lookup.substring(0, idx);
+            String nsURI = (String) nsMap.get(pfx);
+            if (nsURI != null) {
+                String name = lookup.substring(idx + 1);
+                return getSymbol(getNormalizedQName(name, nsURI), nsURI, create);
+            }
+        }
+
+        return getSymbol(lookup, create);
+    }
+
+    //
     // XMLSerializable
     //
 
@@ -269,5 +294,17 @@
 
             names.put(new Short(id), info);
         }
+    }
+
+    //
+    // Implementation methods
+    //
+
+    private static String getNormalizedQName(String localName, String namespaceURI) {
+        return "ns" + namespaceURI.hashCode() + ':' + localName;
+    }
+
+    private String getLookupName(String qname, String namespaceURI) {
+        return '[' + namespaceURI + ']' + qname;
     }
 }

Modified: xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java?view=diff&rev=566464&r1=566463&r2=566464
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/xml/sax/SAXEventGenerator.java Wed Aug 15 18:21:52 2007
@@ -323,7 +323,6 @@
                 case Node.CDATA_SECTION_NODE:
                 case Node.COMMENT_NODE:
                     {
-
                         ByteArrayInput tbis = new ByteArrayInput(data, pos, len);
                         XMLCompressedInput tin = new XMLCompressedInput(tbis, symbols);
 
@@ -383,13 +382,11 @@
         }
 
         if (element && !interrupt) {
-
             // First, close element ...
             content.endElement(nsURI != null ? nsURI : "", localName, elemName);
 
             // ... and then any mapped NS prefixes
             for (int i = 0; i < nsMapCount; i++) {
-
                 content.endPrefixMapping(mappedPrefixes[i]);
             }
         }
@@ -409,17 +406,6 @@
         }
         return result;
     }
-
-    /*public boolean start() {
-       try {
-          return processDocument();
-       }
-       catch ( Exception e ) {
-          org.apache.xindice.Debug.printStackTrace(e);
-          throw(e);
-          return false;
-       }
-    }*/
 
     public void stop() {
         interrupt = true;

Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/SymbolTableTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/SymbolTableTest.java?view=diff&rev=566464&r1=566463&r2=566464
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/SymbolTableTest.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/xml/SymbolTableTest.java Wed Aug 15 18:21:52 2007
@@ -124,21 +124,21 @@
     }
 
     public void testGetNormalizedSymbol() {
-        assertEquals(1, SymbolTable.getNormalizedSymbol(symbols, "simple", null, false));
+        assertEquals(1, symbols.getNormalizedSymbol("simple", (NamespaceMap) null, false));
 
-        assertEquals(-1, SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]spaced", null, false));
-        assertEquals(-1, SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]a:spaced", null, false));
-        assertEquals(-1, SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]b:spaced", null, false));
+        assertEquals(-1, symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]spaced", (NamespaceMap) null, false));
+        assertEquals(-1, symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]a:spaced", (NamespaceMap) null, false));
+        assertEquals(-1, symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]b:spaced", (NamespaceMap) null, false));
 
-        short s = SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]spaced", null, true);
+        short s = symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]spaced", (NamespaceMap) null, true);
 
-        assertEquals(s, SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]spaced", null, false));
-        assertEquals(s, SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]a:spaced", null, false));
-        assertEquals(s, SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]b:spaced", null, false));
-        assertEquals(s, SymbolTable.getNormalizedSymbol(symbols, "[http://www.w3.org/1999/xhtml]x:spaced", null, false));
+        assertEquals(s, symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]spaced", (NamespaceMap) null, false));
+        assertEquals(s, symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]a:spaced", (NamespaceMap) null, false));
+        assertEquals(s, symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]b:spaced", (NamespaceMap) null, false));
+        assertEquals(s, symbols.getNormalizedSymbol("[http://www.w3.org/1999/xhtml]x:spaced", (NamespaceMap) null, false));
 
         NamespaceMap m = new NamespaceMap();
         m.setNamespace("z", "http://www.w3.org/1999/xhtml");
-        assertEquals(s, SymbolTable.getNormalizedSymbol(symbols, "z:spaced", m, false));
+        assertEquals(s, symbols.getNormalizedSymbol("z:spaced", m, false));
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.