The following patch fixes a few cases that aren't mapped correctly:
An identifier where the first character is a mark (e.g. "\u2160foo" maps
to "\u2160Foo").
An identifier where the first character is a valid Java identifier
start, but is puctuation (e.g. "_foo" maps to "foo").
It also handles identifiers that don't contain any characters that are
valid in Java identifiers (e.g. "-").
Index: JavaUtils.java
===================================================================
RCS file: /home/cvspublic/xml-axis/java/src/org/apache/axis/utils/JavaUtils.java,v
retrieving revision 1.29
diff -u -r1.29 JavaUtils.java
--- JavaUtils.java 12 Feb 2002 21:04:01 -0000 1.29
+++ JavaUtils.java 12 Feb 2002 22:25:26 -0000
@@ -423,12 +423,14 @@
char[] nameArray = name.toCharArray();
int nameLen = name.length();
StringBuffer result = new StringBuffer(nameLen);
+ boolean wordStart = false;
// The mapping indicates to convert first
// character.
int i = 0;
while (i < nameLen
- && !Character.isJavaIdentifierStart(nameArray[i])) {
+ && (isPunctuation(nameArray[i])
+ || !Character.isJavaIdentifierStart(nameArray[i]))) {
i++;
}
if (i < nameLen) {
@@ -442,9 +444,20 @@
else {
result.append(nameArray[i]);
}
+ wordStart = !Character.isLetter(nameArray[i]);
}
else {
- result.append("_" + nameArray[0]);
+ // The identifier cannot be mapped strictly according to
+ // JSR 101
+ if (Character.isJavaIdentifierPart(nameArray[0])) {
+ result.append("_" + nameArray[0]);
+ }
+ else {
+ // The XML identifier does not contain any characters
+ // we can map to Java. Using the length of the string
+ // will make it somewhat unique.
+ result.append("_" + nameArray.length);
+ }
}
// The mapping indicates to skip over
@@ -452,7 +465,6 @@
// digits. The first letter/digit
// following a skipped character is
// upper-cased.
- boolean wordStart = false;
for (++i; i < nameLen; ++i) {
char c = nameArray[i];
Index: TestJavaUtils.java
===================================================================
RCS file: /home/cvspublic/xml-axis/java/test/utils/TestJavaUtils.java,v
retrieving revision 1.1
diff -u -r1.1 TestJavaUtils.java
--- TestJavaUtils.java 12 Feb 2002 21:04:01 -0000 1.1
+++ TestJavaUtils.java 12 Feb 2002 22:26:08 -0000
@@ -29,8 +29,9 @@
JavaUtils.xmlNameToJava("other_punct\u00B7chars"));
assertEquals("answer42", JavaUtils.xmlNameToJava("Answer42"));
- assertEquals("\u2160foo", JavaUtils.xmlNameToJava("\u2160foo"));
+ assertEquals("\u2160Foo", JavaUtils.xmlNameToJava("\u2160foo"));
assertEquals("foo", JavaUtils.xmlNameToJava("2foo"));
+ assertEquals("foo", JavaUtils.xmlNameToJava("_foo_"));
assertEquals("foobar", JavaUtils.xmlNameToJava("--foobar--"));
assertEquals("foo22Bar", JavaUtils.xmlNameToJava("foo22bar"));
@@ -47,6 +48,8 @@
assertEquals("fOOBar", JavaUtils.xmlNameToJava("FOOBar"));
// the following cases are ambiguous in JSR-101
- assertEquals("fooBar", JavaUtils.xmlNameToJava("foo bar"), "fooBar");
+ assertEquals("fooBar", JavaUtils.xmlNameToJava("foo bar"));
+ assertEquals("_1", JavaUtils.xmlNameToJava("-"));
+ assertEquals("__", JavaUtils.xmlNameToJava("_"));
}
}
Dave
On Tuesday, February 12, 2002, at 01:26 PM, Tom Jordahl wrote:
>
> Thanks for doing this Russell and Dave.
>
> Dave, do you believe we are 100% up to the spec now?
>
> --
> Tom Jordahl
> Macromedia
>
> -----Original Message-----
> From: Russell Butek [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 12, 2002 4:06 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PATCH] JavaUtils.xmlNameToJava() updates
>
>
> Dave, I just committed this (with a couple tweaks of my own). Thanks!
>
> Russell Butek
> [EMAIL PROTECTED]
>
>
> Russell Butek/Austin/IBM@IBMUS on 02/12/2002 08:12:01 AM
>
> Please respond to [EMAIL PROTECTED]
>
> To: [EMAIL PROTECTED]
> cc:
> Subject: Re: [PATCH] JavaUtils.xmlNameToJava() updates
>
>
>
> Well, strictly speaking, "FOOBar" stays "FOOBar" if it's a class name
> but
> becomes "fOOBar" for a method name. Rather odd-looking, but it keeps
> the
> rules simple.
>
> I'll take a look at your patch as I get the chance sometime in the next
> day
> or two.
>
> Thanks for the work!
>
> Russell Butek
> [EMAIL PROTECTED]
>
>
> Dave Dunkin <[EMAIL PROTECTED]> on 02/11/2002 05:34:03 PM
>
> Please respond to [EMAIL PROTECTED]
>
> To: [EMAIL PROTECTED]
> cc:
> Subject: [PATCH] JavaUtils.xmlNameToJava() updates
>
>
>
> Here is a patch to bring JavaUtils.xmlNameToJava() in line with the
> JAX-RPC spec. Also attached is a junit test case for the method. The one
> case that I'm not sure about is what to do with "FOOBar." From my
> reading of the spec I would think the correct mapping would be "FOOBar"
> to "FOOBar" (and that's how I implemented it), but it might also be
> "fooBar."
>
> Dave Dunkin
>
>
>
>
>
>
>