1 16 package org.apache.commons.betwixt.strategy; 17 18 19 20 33 public class HyphenatedNameMapper implements NameMapper { 34 35 36 private String separator = "-"; 37 38 39 private boolean upperCase = false; 40 41 45 public HyphenatedNameMapper() { 46 } 47 48 53 public HyphenatedNameMapper(boolean upperCase) { 54 this.upperCase = upperCase; 55 } 56 57 65 public HyphenatedNameMapper(boolean upperCase, String separator) { 66 this.upperCase = upperCase; 67 this.separator = separator; 68 } 69 70 89 public String mapTypeToElementName(String typeName) { 90 91 int length = typeName.length(); 92 if (length == 0) { 93 return ""; 94 } 95 96 StringBuffer sb = new StringBuffer (); 97 98 sb.append(convertChar(typeName.charAt(0))); 99 100 for (int i = 1; i < length; i++) { 101 if (Character.isUpperCase(typeName.charAt(i))) { 102 sb.append(separator); 103 sb.append(convertChar(typeName.charAt(i))); 104 } else { 105 if ( upperCase ) { 106 sb.append(convertChar(typeName.charAt(i))); 107 } else { 108 sb.append(typeName.charAt(i)); 109 } 110 } 111 } 112 113 return sb.toString(); 114 } 115 116 123 public String getSeparator() { 124 return separator; 125 } 126 127 132 public void setSeparator(String separator) { 133 this.separator = separator; 134 } 135 136 143 public boolean isUpperCase() { 144 return upperCase; 145 } 146 147 153 public void setUpperCase(boolean upperCase) { 154 this.upperCase = upperCase; 155 } 156 157 160 167 protected char convertChar(char ch) { 168 if ( upperCase ) { 169 return Character.toUpperCase(ch); 170 171 } else { 172 return Character.toLowerCase(ch); 173 } 174 } 175 } 176 | Popular Tags |