Dave,

If you read the JAX-RPC Appendix, there is a complete description of how XML names are 
mapped to Java names.  While I didn't implement 100% of the algorithm described 
within, we are pretty close. 

JAX-RPC says to remove punctuation characters, which is why we don't use the 
isJavaIdentifier* APIs.

If you are interested in implementing the entire standard algorithm, I would be more 
than happy to review it and check it in.

--
Tom Jordahl
Macromedia

-----Original Message-----
From: Dave Dunkin [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 06, 2002 9:10 PM
To: Axis-Dev (E-mail)
Subject: JavaUtils.xmlNameToJava and special characters


The xmlNameToJava function munges strings so that they only contain letters and 
numbers. However, other characters (such as '$' and '_') are valid in Java 
identifiers. Instead of using the Character.isLetter() and 
Character.isLetterOrDigit(), why not use Character.isJavaIdentifierStart() and 
Character.isJavaIdentifierPart()? Here's a diff:
*** JavaUtils.java      1 Feb 2002 04:38:18 -0000       1.24 
--- JavaUtils.java      7 Feb 2002 01:28:24 -0000 
*************** 
*** 315,325 **** 
          char[] nameArray = name.toCharArray(); 
          int nameLen = name.length(); 
          StringBuffer result = new StringBuffer(nameLen); 
          
          // First character, lower case 
          int i = 0; 
          while (i < nameLen 
!                 && !Character.isLetter(nameArray[i])) { 
              i++; 
          } 
          if (i < nameLen) { 
--- 315,325 ---- 
          char[] nameArray = name.toCharArray(); 
          int nameLen = name.length(); 
          StringBuffer result = new StringBuffer(nameLen); 
          
          // First character, lower case 
          int i = 0; 
          while (i < nameLen 
!                 && !Character.isJavaIdentifierStart(nameArray[i])) { 
              i++; 
          } 
          if (i < nameLen) { 
*************** 
*** 336,342 **** 
  
              // if this is a bad char, skip it a remember to capitalize next 
              // good character we encounter 
!             if( !Character.isLetterOrDigit(c)) { 
                  wordStart = true; 
                  continue; 
              } 
--- 336,342 ---- 
  
              // if this is a bad char, skip it a remember to capitalize next 
              // good character we encounter 
!             if( !Character.isJavaIdentifierPart(c)) { 
                  wordStart = true; 
                  continue; 
              } 


Dave Dunkin 

Reply via email to