snichol 2002/11/18 07:55:11
Modified: java/src/org/apache/soap/util/xml NSStack.java
Log:
Fix bug in popScope (popped URI and prefix stacks two scopes instead of 1)
Fix bug in dump and toString (wrong array index)
Fix bug in addNSDeclaration (prefix can be null)
??TODO: allow namespaceURI to be null?
Revision Changes Path
1.7 +29 -11 xml-soap/java/src/org/apache/soap/util/xml/NSStack.java
Index: NSStack.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/xml/NSStack.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- NSStack.java 18 Nov 2002 14:34:52 -0000 1.6
+++ NSStack.java 18 Nov 2002 15:55:11 -0000 1.7
@@ -81,21 +81,30 @@
*
* @author Sanjiva Weerawarana ([EMAIL PROTECTED])
* @author Pavel Ausianik <[EMAIL PROTECTED]>
+ * @author Scott Nichol (Scott Nichol)
*/
public final class NSStack {
+ // Initial size of stack arrays
+ private static final int START_ARRAY_SIZE = 32;
+
+ // Namespace URI stack
private String[] URIStack;
+ // Namespace prefix stack
private String[] prefixStack;
-
+ // Scope stack: holds iterator at start of each scope
private int[] scope;
+ // Index in scope of current scope
private int top = 0;
+ // Index in URI and prefix stack of top value
private int iterator = -1;
+
+ // For generating namespace prefixes
private final static String NSPREFIX = "ns";
+ // For generating namespace prefixes
private int nsPrefixCount = 0;
-
+ // For caching generated namespace prefixes
private static String[] predefinedNamespaces;
- private static final int START_ARRAY_SIZE = 32;
-
/**
* Default constructor.
*/
@@ -109,11 +118,13 @@
/**
* Creates a predefined Namespace string
* Assuming that in the single application , the number of names is the same
- * between calls. We'll benefit from caching on continuous operations
+ * between calls. We'll benefit from caching on continuous operations.
+ *
+ * @param nsCount The count (for this SOAP message) of prefixes generated.
+ * @return The namespace prefix.
*/
synchronized private static String getPredefinedNamespace(int nsCount) {
- if (predefinedNamespaces == null)
- {
+ if (predefinedNamespaces == null) {
predefinedNamespaces = new String[START_ARRAY_SIZE];
for (int i=0; i<START_ARRAY_SIZE; i++)
predefinedNamespaces[i] = NSPREFIX + (i+1);
@@ -152,9 +163,9 @@
* don't call popScope too many times; that's your problem.
*/
public void popScope() {
+ iterator = scope[top];
scope[top] = 0;
top--;
- iterator = top >= 0 ? scope[top] : 0;
}
/**
@@ -178,6 +189,8 @@
}
// scope too small - expand - very unlikely
URIStack[iterator] = namespaceURI.intern();
+ if (prefix == null)
+ prefix = "";
prefixStack[iterator] = prefix.intern();
}
@@ -280,7 +293,7 @@
System.out.println("Level: " + cursor);
for (int j = start; j <= end; j++) {
- System.out.println(" Map:" + URIStack[cursor] + " -> "
+prefixStack[cursor]);
+ System.out.println(" Map:" + URIStack[j] + " -> "
+prefixStack[j]);
}
}
}
@@ -299,13 +312,18 @@
sb.append("Level: ")
.append(cursor)
+ .append(" (")
+ .append(start)
+ .append(" to ")
+ .append(end)
+ .append(')')
.append(StringUtils.lineSeparator);
for (int j = start; j <= end; j++) {
sb.append(" Map:")
- .append(URIStack[cursor])
+ .append(URIStack[j])
.append(" -> ")
- .append(prefixStack[cursor])
+ .append(prefixStack[j])
.append(StringUtils.lineSeparator);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>