Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 17494 invoked by uid 500); 26 Jun 2002 19:05:11 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 17485 invoked by uid 500); 26 Jun 2002 19:05:11 -0000 Delivered-To: apmail-xml-axis-cvs@apache.org Date: 26 Jun 2002 19:05:10 -0000 Message-ID: <20020626190510.50841.qmail@icarus.apache.org> From: tomj@apache.org To: xml-axis-cvs@apache.org Subject: cvs commit: xml-axis/java/src/org/apache/axis/utils JavaUtils.java X-Spam-Rating: 209.66.108.5 1.6.2 0/1000/N tomj 2002/06/26 12:05:10 Modified: java/test/utils TestJavaUtils.java java/src/org/apache/axis/utils JavaUtils.java Log: Fix a bug in xmlNameToJava() function which prevented the serializer and deserializer from find the meta-data in beans for elements like A1_AAA. Add some new unit test cases to verify. Revision Changes Path 1.7 +5 -0 xml-axis/java/test/utils/TestJavaUtils.java Index: TestJavaUtils.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/utils/TestJavaUtils.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TestJavaUtils.java 17 Apr 2002 15:36:00 -0000 1.6 +++ TestJavaUtils.java 26 Jun 2002 19:05:09 -0000 1.7 @@ -55,6 +55,11 @@ assertEquals("fooBar", JavaUtils.xmlNameToJava("FooBar")); assertEquals("FOOBar", JavaUtils.xmlNameToJava("FOOBar")); assertEquals("FOOBar", JavaUtils.xmlNameToJava("__FOOBar")); + + assertEquals("a1BBB", JavaUtils.xmlNameToJava("A1_BBB")); + assertEquals("ABBB", JavaUtils.xmlNameToJava("A_BBB")); + assertEquals("ACCC", JavaUtils.xmlNameToJava("ACCC")); + // the following cases are ambiguous in JSR-101 assertEquals("fooBar", JavaUtils.xmlNameToJava("foo bar")); 1.51 +13 -22 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.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- JavaUtils.java 21 Jun 2002 13:00:30 -0000 1.50 +++ JavaUtils.java 26 Jun 2002 19:05:10 -0000 1.51 @@ -75,6 +75,7 @@ import java.util.Set; import java.util.ArrayList; import java.util.List; +import java.beans.Introspector; /** Utility class to deal with Java language related issues, such * as type conversions. @@ -563,9 +564,9 @@ /** * Map an XML name to a Java identifier per - * the mapping rules of JSR 101 (in - * version 0.7 this is + * the mapping rules of JSR 101 (in version 1.0 this is * "Chapter 20: Appendix: Mapping of XML Names" + * * @param name is the xml name * @return the java name per JSR 101 specification */ @@ -580,33 +581,18 @@ StringBuffer result = new StringBuffer(nameLen); boolean wordStart = false; - // The mapping indicates to convert first - // character. + // The mapping indicates to convert first character. int i = 0; - int firstRealChar = 0; while (i < nameLen && (isPunctuation(nameArray[i]) || !Character.isJavaIdentifierStart(nameArray[i]))) { i++; - firstRealChar++; } if (i < nameLen) { - // 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. - - // Don't lowercase if this is the first character and the 2nd - // character is also uppercase, to follow Introspector rules. - if (Character.isUpperCase(nameArray[i]) && - ((i != firstRealChar) || - (nameLen == 1) || - (nameLen > 1 && Character.isLowerCase(nameArray[1])))) { - result.append(Character.toLowerCase(nameArray[i])); - } - else { - result.append(nameArray[i]); - } + // Decapitalization code used to be here, but we use the + // Introspector function now after we filter out all bad chars. + + result.append(nameArray[i]); wordStart = !Character.isLetter(nameArray[i]); } else { @@ -651,6 +637,11 @@ // covert back to a String String newName = result.toString(); + + // Follow JavaBean rules, but we need to check if the first + // letter is uppercase first + if (Character.isUpperCase(newName.charAt(0))) + newName = Introspector.decapitalize(newName); // check for Java keywords if (isJavaKeyword(newName))