butek 02/02/12 13:04:02
Modified: java/src/org/apache/axis/utils JavaUtils.java
java/test/utils PackageTests.java
Added: java/test/utils TestJavaUtils.java
Log:
Modified XML name to Java name mapping to better align with JAX-RPC. Also
added a test.
Most of this is from Dave Dunkin ([EMAIL PROTECTED]) with some minor
tweaks of my own.
Revision Changes Path
1.29 +42 -7 xml-axis/java/src/org/apache/axis/utils/JavaUtils.java
Index: JavaUtils.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/JavaUtils.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- JavaUtils.java 11 Feb 2002 19:02:53 -0000 1.28
+++ JavaUtils.java 12 Feb 2002 21:04:01 -0000 1.29
@@ -428,11 +428,20 @@
// character.
int i = 0;
while (i < nameLen
- && !Character.isLetter(nameArray[i])) {
+ && !Character.isJavaIdentifierStart(nameArray[i])) {
i++;
}
if (i < nameLen) {
- result.append(Character.toLowerCase(nameArray[i]));
+ // I've got to check for uppercaseness before lowercasing
+ // because toLowerCase will lowercase some characters that
+ // isUpperCase will return false for. Like \u2160, Roman
+ // numeral one.
+ if (Character.isUpperCase(nameArray[i])) {
+ result.append(Character.toLowerCase(nameArray[i]));
+ }
+ else {
+ result.append(nameArray[i]);
+ }
}
else {
result.append("_" + nameArray[0]);
@@ -444,14 +453,25 @@
// following a skipped character is
// upper-cased.
boolean wordStart = false;
- for(int j = i + 1; j < nameLen; ++j) {
- char c = nameArray[j];
- if( !Character.isLetterOrDigit(c)) {
+ for (++i; i < nameLen; ++i) {
+ char c = nameArray[i];
+
+ // if this is a bad char, skip it and remember to capitalize next
+ // good character we encounter
+ if (isPunctuation(c) || !Character.isJavaIdentifierPart(c)) {
wordStart = true;
continue;
}
- result.append( wordStart ? Character.toUpperCase(c) : c );
- wordStart = false;
+ if (wordStart && Character.isLowerCase(c)) {
+ result.append(Character.toUpperCase(c));
+ }
+ else {
+ result.append(c);
+ }
+ // If c is not a character, but is a legal Java
+ // identifier character, capitalize the next character.
+ // For example: "22hi" becomes "22Hi"
+ wordStart = !Character.isLetter(c);
}
// covert back to a String
@@ -463,6 +483,21 @@
return newName;
} // xmlNameToJava
+
+ /**
+ * Is this an XML punctuation character?
+ */
+ private static boolean isPunctuation(char c)
+ {
+ return '-' == c
+ || '.' == c
+ || ':' == c
+ || '_' == c
+ || '\u00B7' == c
+ || '\u0387' == c
+ || '\u06DD' == c
+ || '\u06DE' == c;
+ } // isPunctuation
// Message resource bundle.
private static ResourceBundle messages = null;
1.4 +1 -0 xml-axis/java/test/utils/PackageTests.java
Index: PackageTests.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/utils/PackageTests.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PackageTests.java 5 Nov 2001 18:39:54 -0000 1.3
+++ PackageTests.java 12 Feb 2002 21:04:01 -0000 1.4
@@ -20,6 +20,7 @@
// class is a mess
suite.addTest(TestQName.suite());
suite.addTest(TestQFault.suite());
+ suite.addTest(TestJavaUtils.suite());
suite.addTest(TestXMLUtils.suite());
suite.addTest(TestMessages.suite());
1.1 xml-axis/java/test/utils/TestJavaUtils.java
Index: TestJavaUtils.java
===================================================================
package test.utils;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.axis.utils.JavaUtils;
public class TestJavaUtils extends TestCase
{
public TestJavaUtils (String name) {
super(name);
}
public static Test suite() {
return new TestSuite(TestJavaUtils.class);
}
public void setup() {
}
/**
* See JSR-101: JAX-RPC, Appendix: Mapping of XML Names
*/
public void testXmlNameToJava() {
assertEquals("mixedCaseName", JavaUtils.xmlNameToJava("mixedCaseName"));
assertEquals("nameWithDashes",
JavaUtils.xmlNameToJava("name-with-dashes"));
assertEquals("otherPunctChars",
JavaUtils.xmlNameToJava("other_punct\u00B7chars"));
assertEquals("answer42", JavaUtils.xmlNameToJava("Answer42"));
assertEquals("\u2160foo", JavaUtils.xmlNameToJava("\u2160foo"));
assertEquals("foo", JavaUtils.xmlNameToJava("2foo"));
assertEquals("foobar", JavaUtils.xmlNameToJava("--foobar--"));
assertEquals("foo22Bar", JavaUtils.xmlNameToJava("foo22bar"));
assertEquals("foo\u2160Bar", JavaUtils.xmlNameToJava("foo\u2160bar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo-bar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo.bar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo:bar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo_bar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo\u00B7bar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo\u0387bar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo\u06DDbar"));
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo\u06DEbar"));
assertEquals("fOOBar", JavaUtils.xmlNameToJava("FOOBar"));
// the following cases are ambiguous in JSR-101
assertEquals("fooBar", JavaUtils.xmlNameToJava("foo bar"), "fooBar");
}
}