1 45 package org.openejb.util; 46 47 import java.lang.reflect.Method ; 48 import java.util.StringTokenizer ; 49 50 55 public class StringUtilities { 56 57 public static final String CRLF = "\r\n"; 58 59 private StringUtilities() {} 61 62 68 public static String getLastToken(String tokenString, String delimeter) { 69 StringTokenizer token = new StringTokenizer (tokenString, delimeter); 70 71 String returnValue = null; 72 while (token.hasMoreTokens()) { 73 returnValue = token.nextToken(); 74 } 75 76 return returnValue; 77 } 78 79 85 public static String nullToBlankString(String stringToCheckForNull) { 86 return (stringToCheckForNull == null) ? "" : stringToCheckForNull; 87 } 88 89 94 public static boolean checkNullBlankString(String stringToCheck) { 95 return (stringToCheck == null || "".equals(stringToCheck.trim())); 96 } 97 98 104 public static String blankToNullString(String stringToCheckForBlank) { 105 if(stringToCheckForBlank != null) stringToCheckForBlank = stringToCheckForBlank.trim(); 106 return ("".equals(stringToCheckForBlank)) ? null : stringToCheckForBlank; 107 } 108 109 115 public static String replaceNullOrBlankStringWithNonBreakingSpace(String stringToCheckForNull) { 116 if ((stringToCheckForNull == null) || (stringToCheckForNull.equals(""))) { 117 return " "; 118 } else { 119 return stringToCheckForNull; 120 } 121 } 122 123 134 public static String createMethodString(Method method, String lineBreak) { 135 Class [] parameterList = method.getParameterTypes(); 136 Class [] exceptionList = method.getExceptionTypes(); 137 StringBuffer methodString = new StringBuffer (); 138 139 methodString.append(method.getName()).append("("); 140 141 for (int j = 0; j < parameterList.length; j++) { 142 methodString.append(StringUtilities.getLastToken(parameterList[j].getName(), ".")); 143 144 if (j != (parameterList.length - 1)) { 145 methodString.append(", "); 146 } 147 } 148 methodString.append(") "); 149 150 if (exceptionList.length > 0) { 151 methodString.append(lineBreak); 152 methodString.append("throws "); 153 } 154 155 for (int j = 0; j < exceptionList.length; j++) { 156 methodString.append(StringUtilities.getLastToken(exceptionList[j].getName(), ".")); 157 158 if (j != (exceptionList.length - 1)) { 159 methodString.append(", "); 160 } 161 } 162 163 return methodString.toString(); 164 } 165 166 171 public static String stringArrayToCommaDelimitedStringList(String [] stringArray) { 172 StringBuffer stringList = new StringBuffer (); 173 for (int i = 0; i < stringArray.length; i++) { 174 stringList.append(stringArray[i]); 175 if (i != (stringArray.length - 1)) { 176 stringList.append(","); 177 } 178 } 179 180 return stringList.toString(); 181 } 182 183 } | Popular Tags |