1 17 package org.apache.ws.jaxme.generator.util; 18 19 import org.apache.ws.jaxme.generator.sg.SchemaSG; 20 21 22 25 public class JavaNamer { 26 27 28 public static final char[] PUNCTUATION_CHARS = {'-', '.', ':', '_', '\u00B7', '\u0387', '\u06DD', '\u06DE'}; 29 30 37 public static boolean isPunctuationCharacter(char c, SchemaSG pSchema) { 38 for (int i = 0; i < PUNCTUATION_CHARS.length; i++) { 39 char pc = PUNCTUATION_CHARS[i]; 40 if (pc == '_') { 41 if (!pSchema.isUnderscoreWordSeparator()) { 42 continue; 43 } 44 } 45 if (c == pc) { 46 return true; 47 } 48 } 49 return false; 50 } 51 52 59 60 public static String convert(String pLocalName, SchemaSG pSchema) { 61 if (!pSchema.isJavaNamingConventionsEnabled()) { 62 return pLocalName; 63 } 64 StringBuffer result = new StringBuffer (); 65 char c = pLocalName.charAt(0); 66 if (Character.isJavaIdentifierStart(c)) { 67 result.append(Character.toUpperCase(c)); 68 } else { 69 result.append('_'); 70 } 71 for (int i = 1; i < pLocalName.length(); i++) { 72 c = pLocalName.charAt(i); 73 if (Character.isJavaIdentifierPart(c) && (c != '_')) { 74 result.append(c); 75 } else { 76 if (isPunctuationCharacter(c, pSchema)) { 77 i++; 78 c = pLocalName.charAt(i); 79 result.append(Character.toUpperCase(c)); 80 } else { 81 result.append('_'); 82 } 83 } 84 } 85 return result.toString(); 86 } 87 } 88 | Popular Tags |