1 30 package com.genimen.djeneric.tools.strongtyper; 31 32 import java.util.List ; 33 34 import com.genimen.djeneric.repository.DjDomain; 35 import com.genimen.djeneric.repository.DjExtent; 36 import com.genimen.djeneric.repository.DjProperty; 37 import com.genimen.djeneric.util.DjStringReplacer; 38 39 public abstract class Generator 40 { 41 public final static String IMPL_SUFFIX = "Impl"; 42 43 public final static String ABSTRACT_SESSION_CLASS_NAME = "AbstractSessionImpl"; 44 public final static String SESSION_CLASS_NAME = "SessionImpl"; 45 public final static String SESSION_INTERFACE_NAME = "Session"; 46 public final static String MANAGER_CLASS_NAME = "PersistenceManager"; 47 public final static String EXCEPTION_CLASS_NAME = "Exception"; 48 public final static String NOT_FOUND_EXCEPTION_CLASS_NAME = "NotFoundException"; 49 public final static String MULTIPLE_FOUND_EXCEPTION_CLASS_NAME = "MultipleFoundException"; 50 public final static String PARENT_CLASS_NAME = "ObjectImpl"; 51 public final static String PARENT_INTERFACE_NAME = "Object"; 52 public final static String QBE_CLASS_NAME = "QbeImpl"; 53 public final static String QBE_INTERFACE_NAME = "Qbe"; 54 public final static String OQL_CLASS_NAME = "OqlImpl"; 55 public final static String OQL_INTERFACE_NAME = "Oql"; 56 public final static String CURSOR_CLASS_NAME = "CursorImpl"; 57 public final static String CURSOR_INTERFACE_NAME = "Cursor"; 58 59 String _itfPackageName = ""; 60 String _implPackageName = ""; 61 String _busPackageName = ""; 62 String _busImplPackageName = ""; 63 String _uiPackageName = ""; 64 String _systemPrefix = ""; 65 String _systemName = ""; 66 String _prefix = ""; 67 String _suffix = ""; 68 69 boolean _isAbstract = false; 70 71 private List _extentSet; 72 73 public Generator() 74 { 75 } 76 77 public abstract String getClassName(); 78 79 public abstract String getCode() throws Exception ; 80 81 public String getGeneratedSuffix() 82 83 { 84 return "Gtd"; 85 } 86 87 public boolean isInSelectedSet(DjExtent ext) 88 { 89 return _extentSet.contains(ext); 90 } 91 92 public void setAbstract(boolean b) 93 { 94 _isAbstract = b; 95 } 96 97 public boolean isAbstract() 98 { 99 return _isAbstract; 100 } 101 102 public String translateNativeType(String tp) 103 { 104 if (tp.equals("Date")) return "java.util.Date"; 105 return tp; 106 } 107 108 public boolean containsBigDecimal(DjExtent extent) 109 { 110 DjProperty props[] = extent.getProperties(); 111 112 for (int i = 0; i < props.length; i++) 113 { 114 if (props[i].getTypeCode() == DjDomain.BIGDECIMAL_TYPE) return true; 115 } 116 return false; 117 } 118 119 public String getPrefix() 120 { 121 return _prefix; 122 } 123 124 public void setPrefix(String prefix) 125 { 126 _prefix = prefix; 127 } 128 129 public String getSystemPrefix() 130 { 131 return _systemPrefix; 132 } 133 134 public void setSystemPrefix(String prefix) 135 { 136 _systemPrefix = prefix; 137 } 138 139 public String getSystemName() 140 { 141 return _systemName; 142 } 143 144 public void setSystemName(String name) 145 { 146 _systemName = name; 147 } 148 149 public String getItfPackageName() 150 { 151 return _itfPackageName; 152 } 153 154 public void setItfPackageName(String packageName) 155 { 156 _itfPackageName = packageName; 157 } 158 159 public String getBusinessPackageName() 160 { 161 return _busPackageName; 162 } 163 164 public void setBusinessPackageName(String packageName) 165 { 166 _busPackageName = packageName; 167 } 168 169 public String getBusinessImplPackageName() 170 { 171 return _busImplPackageName; 172 } 173 174 public void setBusinessImplPackageName(String packageName) 175 { 176 _busImplPackageName = packageName; 177 } 178 179 public String getUiPackageName() 180 { 181 return _uiPackageName; 182 } 183 184 public void setUiPackageName(String packageName) 185 { 186 _uiPackageName = packageName; 187 } 188 189 public abstract String getPackageName(); 190 191 public String getImplPackageName() 192 { 193 return _implPackageName; 194 } 195 196 public void setImplPackageName(String packageName) 197 { 198 _implPackageName = packageName; 199 } 200 201 public String getSuffix() 202 { 203 return _suffix; 204 } 205 206 public void setSuffix(String suffix) 207 { 208 _suffix = suffix; 209 } 210 211 public String getClassName(DjExtent extent) 212 { 213 return getPrefix() + extent.getObjectType() + getSuffix() + IMPL_SUFFIX; 214 } 215 216 public String getInterfaceName(DjExtent extent) 217 { 218 return getPrefix() + extent.getObjectType() + getSuffix(); 219 } 220 221 public String getQbeClassName(DjExtent extent) 222 { 223 return getPrefix() + extent.getObjectType() + QBE_CLASS_NAME; 224 } 225 226 public String getQbeInterfaceName(DjExtent extent) 227 { 228 return getPrefix() + extent.getObjectType() + QBE_INTERFACE_NAME; 229 } 230 231 public String getCursorClassName(DjExtent extent) 232 { 233 return getPrefix() + extent.getObjectType() + CURSOR_CLASS_NAME; 234 } 235 236 public String getCursorInterfaceName(DjExtent extent) 237 { 238 return getPrefix() + extent.getObjectType() + CURSOR_INTERFACE_NAME; 239 } 240 241 public String getAbstractSessionClassName() 242 { 243 return getSystemPrefix() + ABSTRACT_SESSION_CLASS_NAME; 244 } 245 246 public String getSessionClassName() 247 { 248 return getSystemPrefix() + SESSION_CLASS_NAME; 249 } 250 251 public String getSessionInterfaceName() 252 { 253 return getSystemPrefix() + SESSION_INTERFACE_NAME; 254 } 255 256 public String getExceptionClassName() 257 { 258 return getSystemPrefix() + EXCEPTION_CLASS_NAME; 259 } 260 261 public String getNotFoundExceptionClassName() 262 { 263 return getSystemPrefix() + NOT_FOUND_EXCEPTION_CLASS_NAME; 264 } 265 266 public String getMultipleFoundExceptionClassName() 267 { 268 return getSystemPrefix() + MULTIPLE_FOUND_EXCEPTION_CLASS_NAME; 269 } 270 271 public String getManagerClassName() 272 { 273 return getSystemPrefix() + MANAGER_CLASS_NAME; 274 } 275 276 public String getOqlClassName() 277 { 278 return OQL_CLASS_NAME; 279 } 280 281 public String getOqlInterfaceName() 282 { 283 return OQL_INTERFACE_NAME; 284 } 285 286 public String getParentObjectClassName() 287 { 288 return getSystemPrefix() + PARENT_CLASS_NAME; 289 } 290 291 public String getParentInterfaceClassName() 292 { 293 return getSystemPrefix() + PARENT_INTERFACE_NAME; 294 } 295 296 public String initCap(String str) 297 { 298 if (str == null) return str; 299 DjStringReplacer sr = new DjStringReplacer(str); 300 str = sr.replace(" ", ""); 301 302 if (str.length() < 2) return str.toUpperCase(); 303 304 return str.substring(0, 1).toUpperCase() + str.substring(1); 305 } 306 307 public String constCap(String str) 308 { 309 if (str == null) return str; 310 String result = ""; 311 312 DjStringReplacer sr = new DjStringReplacer(str); 313 str = sr.replace(" ", ""); 314 315 boolean prevWasLower = false; 316 for (int i = 0; i < str.length(); i++) 317 { 318 boolean curIsLower = str.charAt(i) == str.toUpperCase().charAt(i); 320 if (prevWasLower && curIsLower) 321 { 322 result += "_"; 323 } 324 prevWasLower = !curIsLower; 325 result += str.toUpperCase().charAt(i); 326 } 327 return result; 328 } 329 330 public void setExtentSet(List set) 331 { 332 _extentSet = set; 333 334 } 335 } | Popular Tags |