1 23 24 25 26 31 32 package com.sun.jdo.spi.persistence.support.ejb.ejbc; 33 34 import java.io.*; 35 36 import java.text.MessageFormat ; 37 import java.util.HashMap ; 38 import java.util.Properties ; 39 import java.util.StringTokenizer ; 40 41 import com.sun.jdo.spi.persistence.utility.generator.JavaClassWriterHelper; 42 43 49 public class CMPTemplateFormatter extends JavaClassWriterHelper{ 50 51 private final static String templateFile = 52 "com/sun/jdo/spi/persistence/support/ejb/ejbc/CMPTemplates.properties"; 54 public final static String ejb_ = "ejb"; public final static String ejbObject_ = "EJBObject"; public final static String ejbHome_ = "EJBHome"; public final static String ejbContext_ = "EJBContext"; public final static String context_ = "context"; public final static String key_ = "key"; public final static String keys_ = "keys"; public final static String oid_ = "jdoObjectId"; public final static String oids_ = "oids"; public final static String pc_ = "pc"; public final static String cmpImplComments_ = "cmpImplComments"; public final static String imports_ = "imports"; public final static String interfaces_ = "interfaces"; public final static String helperImports_ = "helperImports"; public final static String staticTransientPackageVariables_ = "staticTransientPackageVariables"; public final static String privateStaticVariables_ = "privateStaticVariables"; public final static String privateTransientVariables_ = "privateTransientVariables"; public final static String privateStaticFinalVariables_ = "privateStaticFinalVariables"; public final static String publicStaticFinalVariables_ = "publicStaticFinalVariables"; public final static String finderSelectorStaticVariables_ = "finderSelectorStaticVariables"; public final static String finderSelectorStaticFinalVariables_ = "finderSelectorStaticFinalVariables"; public final static String otherVariables_ = "otherVariables"; public final static String setNull_ = "setNull"; public final static String commonPrivateMethods_ = "commonPrivateMethods"; public final static String commonPublicMethods_ = "commonPublicMethods"; public final static String otherPublicMethods_ = "otherPublicMethods"; public final static String jdoLookupPersistenceManagerFactory_ 82 = "jdoLookupPersistenceManagerFactory"; public final static String helperMethods_ = "helperMethods"; public final static String getInstance_ = "jdoGetInstance"; public final static String findByPrimaryKey_ = "findByPrimaryKey"; public final static String ejbFindByPrimaryKey_ = "ejbFindByPrimaryKey"; public final static String ejbFinderSelectorBody_ = "ejbFinderSelectorBody"; public final static String ejbQueryExecutionParamConvBody_ = "ejbQueryExecutionParamConvBody"; public final static String ejbQueryExecutionParamConvBodyArgument_ = "ejbQueryExecutionParamConvBodyArgument"; public final static String ejbQueryExecutionBody_ = "ejbQueryExecutionBody"; public final static String ejbAggregateQueryExecutionBody_ = "ejbAggregateQueryExecutionBody"; public final static String ejbAggregateQueryExecutionParamConvBody_ = "ejbAggregateQueryExecutionParamConvBody"; public final static String ejbMultiFinderBody_ = "ejbMultiFinderBody"; public final static String ejbMultiFinderBodyEnumeration_ = "ejbMultiFinderBodyEnumeration"; public final static String ejbSingleFinderBody_ = "ejbSingleFinderBody"; public final static String jdoGetJdoInstanceClass_ = "jdoGetJdoInstanceClass"; public final static String find_ = "find"; public final static String catchClause_ = "catchClause"; public final static String ejbSelect_ = "ejbSelect"; public final static String create_ = "create"; public final static String remove_ = "remove"; public final static String ejbCreate_ = "ejbCreate"; public final static String ejbCreateUnknownPK_ = "ejbCreateUnknownPK"; public final static String ejbPostCreate_ = "ejbPostCreate"; public final static String ejbRemove_ = "ejbRemove"; public final static String ejbLoad_ = "ejbLoad"; public final static String CreateException_ = "javax.ejb.CreateException"; public final static String DuplicateKeyException_ = "javax.ejb.DuplicateKeyException"; public final static String RemoveException_ = "javax.ejb.RemoveException"; public final static String ejbException_ = "EJBException"; public final static String finderException_ = "javax.ejb.FinderException"; public final static String assertInTransaction_ = "assertInTransaction"; public final static String assertPersistenceManagerIsNull_ 114 = "assertPersistenceManagerIsNull"; public final static String assertPersistenceManagerIsNullCall_ 116 = "assertPersistenceManagerIsNullCall"; public final static String setEntityContext_ = "setEntityContext"; public final static String EntityContext_ = "javax.ejb.EntityContext"; public final static String castKey_ = "castKey"; public final static String castOid_ = "castOid"; public final static String getPK_ = "getPK"; public final static String getPKClone_ = "getPKClone"; public final static String newPK_ = "newPK"; public final static String newOid_ = "newOid"; public final static String getPK1_ = "getPK1"; public final static String getPK1Clone_ = "getPK1Clone"; public final static String getPK1primitive_ = "getPK1primitive"; public final static String getOid_ = "getOid"; public final static String getOidString_ = "getOidString"; public final static String getOidClone_ = "getOidClone"; public final static String getOid1_ = "getOid1"; public final static String getOid1primitive_ = "getOid1primitive"; public final static String getOid1String_ = "getOid1String"; public final static String getOid1Clone_ = "getOid1Clone"; public final static String getObjectId_ = "jdoGetObjectId"; public final static String convertObjectIdToPrimaryKey_ 137 = "convertObjectIdToPrimaryKey"; public final static String convertPrimaryKeyToObjectId_ 139 = "convertPrimaryKeyToObjectId"; 141 public final static String convertPCToEJBObject_ = "convertPCToEJBObject"; public final static String convertEJBObjectToPC_ = "convertEJBObjectToPC"; public final static String convertEJBLocalObjectToPC_ 144 = "convertEJBLocalObjectToPC"; 146 public final static String jdoPersistenceManager_ = "_jdoPersistenceManager"; public final static String jdoPersistenceManagerClass_ 148 = "com.sun.jdo.api.persistence.support.PersistenceManager"; public final static String jdoGetPersistenceManager_ = "jdoGetPersistenceManager"; public final static String jdoClosePersistenceManager_= "jdoClosePersistenceManager"; public final static String jdoReleasePersistenceManager_ 152 = "jdoReleasePersistenceManager"; 154 public final static String jdoArrayCopy_ = "jdoArrayCopy"; public final static String jdoCleanAllRefs_ = "jdoCleanAllRefs"; public final static String returnKey_ = "return key;"; public final static String returnOid_ = "return jdoObjectId;"; 159 public final static String helperComments_ = "helperComments"; public final static String helperVariables_ = "helperVariables"; public final static String getHelperInstance_ = "getHelperInstance"; 164 public final static String getPCClass_ = "getPCClass"; public final static String getContainer_ = "getContainer"; public final static String assertInstanceOfRemoteInterfaceImpl_ 167 = "assertInstanceOfRemoteInterfaceImpl"; public final static String assertPKNotNull_ = "assertPKNotNull"; public final static String assertPKFieldNotNull_ = "assertPKFieldNotNull"; public final static String assertOidNotNull_ = "assertOidNotNull"; public final static String afterCompletion_ = "afterCompletion"; public final static String ejb__flush_ = "ejb__flush"; public final static String ejb__refresh_ = "ejb__refresh"; public final static String ejb__remove_ = "ejb__remove"; 176 public final static String signature_ = "signature"; 179 public final static String signatureDelimiter_ = " ## "; 181 public static Properties helpers = null; 183 184 public static MessageFormat hcomformatter = null; 186 187 public static MessageFormat privatetransientvformatter = null; public static MessageFormat privatestaticfinalvformatter = null; public static MessageFormat publicstaticfinalvformatter = null; public static MessageFormat finderselectorstaticvformatter = null; public static MessageFormat finderselectorstaticfinalvformatter = null; public static MessageFormat hvformatter = null; 195 public static MessageFormat giformatter = null; public static MessageFormat goidformatter = null; public static MessageFormat intxformatter = null; public static MessageFormat jdolookuppmfformatter = null; public static MessageFormat jdoarraycopyformatter = null; 202 public static MessageFormat finderselectorformatter = null; public static MessageFormat queryexecformatter = null; public static MessageFormat aggqueryexecformatter = null; public static MessageFormat queryexecparamconvformatter = null; public static MessageFormat queryexecparamconvargumentformatter = null; public static MessageFormat aggqueryexecparamconvformatter = null; public static MessageFormat multifinderformatter = null; public static MessageFormat multifinderenumerationformatter = null; public static MessageFormat singlefinderformatter = null; 213 public static MessageFormat pkcformatter = null; public static MessageFormat oidcformatter = null; public static MessageFormat npkformatter = null; public static MessageFormat noidformatter = null; public static MessageFormat pkformatter = null; 219 public static MessageFormat oidformatter = null; 220 public static MessageFormat oidstringformatter = null; public static MessageFormat pkcloneformatter = null; public static MessageFormat oidcloneformatter = null; public static MessageFormat pk1formatter = null; 224 public static MessageFormat oid1formatter = null; 225 public static MessageFormat pk1pformatter = null; 226 public static MessageFormat oid1pformatter = null; 227 public static MessageFormat oid1stringformatter = null; public static MessageFormat pk1cloneformatter = null; public static MessageFormat oid1cloneformatter = null; public static MessageFormat assertpkfieldformatter = null; 232 public static MessageFormat pcclassgetterformatter = null; 234 235 public static String cmpImplCommentsTemplate = null; 238 public static String privateStaticVariablesTemplate = null; 239 public static String otherVariablesTemplate = null; 240 public static String jdoGetJdoInstanceClassTemplate = null; 241 public static String assertPersistenceManagerIsNullTemplate = null; 242 public static String assertInstanceOfRemoteInterfaceImplTemplate = null; 243 public static String getHelperInstanceTemplate = null; 244 public static String catchClauseTemplate = null; 245 public static String signatureTemplate = null; 246 public static String assertPKNotNullTemplate = null; 247 public static String assertOidNotNullTemplate = null; 248 249 public static String [] importsArray = null; 252 public static String [] interfacesArray = null; 253 public static String [] helperImportsArray = null; 254 public static String [] commonPublicMethodsArray = null; 255 public static String [] otherPublicMethodsArray = null; 256 public static String [] commonPrivateMethodsArray = null; 257 258 259 public static String [] ejbFindByPrimaryKeyBody = null; 262 public static String [] afterCompletionBody = null; 263 public static String [] jdoGetPersistenceManagerBody = null; 264 public static String [] assertPersistenceManagerIsNullBody = null; 265 public static String [] jdoClosePersistenceManagerBody = null; 266 public static String [] jdoReleasePersistenceManagerBody = null; 267 public static String [] setEntityContextBody = null; 268 public static String [] getContainerBody = null; 269 270 273 CMPTemplateFormatter() { 274 } 275 276 279 static synchronized void initHelpers() throws IOException { 280 if (helpers == null) { 281 helpers = new Properties (); 282 loadProperties(helpers, templateFile); 283 initFormatters(); 284 initTemplates(); 285 } 286 } 287 288 291 static synchronized void loadProperties(Properties helpers, 292 final String templateFile) throws IOException { 293 294 BufferedInputStream bin = null; 295 try { 296 final ClassLoader loader = CMPTemplateFormatter.class.getClassLoader(); 297 InputStream in = (InputStream)java.security.AccessController.doPrivileged( 298 new java.security.PrivilegedAction () { 299 public Object run() { 300 if (loader != null) { 301 return loader.getResourceAsStream(templateFile); 302 } else { 303 return ClassLoader.getSystemResourceAsStream(templateFile); 304 } 305 } 306 } 307 ); 308 309 bin = new BufferedInputStream(in); 310 helpers.load(bin); 311 } finally { 312 try { 313 bin.close(); 314 } catch (Exception e) { 315 } 317 } 318 } 319 320 323 private static void initFormatters() { 324 hcomformatter = new MessageFormat (helpers.getProperty(helperComments_)); 326 327 privatetransientvformatter = new MessageFormat (helpers.getProperty(privateTransientVariables_)); 329 privatestaticfinalvformatter = new MessageFormat (helpers.getProperty(privateStaticFinalVariables_)); 330 publicstaticfinalvformatter = new MessageFormat (helpers.getProperty(publicStaticFinalVariables_)); 331 finderselectorstaticvformatter = new MessageFormat (helpers.getProperty(finderSelectorStaticVariables_)); 332 finderselectorstaticfinalvformatter = new MessageFormat (helpers.getProperty(finderSelectorStaticFinalVariables_)); 333 hvformatter = new MessageFormat (helpers.getProperty(helperVariables_)); 334 335 giformatter = new MessageFormat (helpers.getProperty(getInstance_)); 337 goidformatter = new MessageFormat (helpers.getProperty(getObjectId_)); 338 intxformatter = new MessageFormat (helpers.getProperty(assertInTransaction_)); 339 jdolookuppmfformatter = new MessageFormat (helpers.getProperty(jdoLookupPersistenceManagerFactory_)); 340 jdoarraycopyformatter = new MessageFormat (helpers.getProperty(jdoArrayCopy_)); 341 342 finderselectorformatter = new MessageFormat (helpers.getProperty(ejbFinderSelectorBody_)); 344 queryexecparamconvformatter = new MessageFormat (helpers.getProperty(ejbQueryExecutionParamConvBody_)); 345 queryexecparamconvargumentformatter = new MessageFormat (helpers.getProperty(ejbQueryExecutionParamConvBodyArgument_)); 346 queryexecformatter = new MessageFormat (helpers.getProperty(ejbQueryExecutionBody_)); 347 aggqueryexecformatter = new MessageFormat (helpers.getProperty(ejbAggregateQueryExecutionBody_)); 348 aggqueryexecparamconvformatter = new MessageFormat (helpers.getProperty(ejbAggregateQueryExecutionParamConvBody_)); 349 multifinderformatter = new MessageFormat (helpers.getProperty(ejbMultiFinderBody_)); 350 multifinderenumerationformatter = new MessageFormat (helpers.getProperty(ejbMultiFinderBodyEnumeration_)); 351 singlefinderformatter = new MessageFormat (helpers.getProperty(ejbSingleFinderBody_)); 352 353 pkcformatter = new MessageFormat (helpers.getProperty(castKey_)); 355 oidcformatter = new MessageFormat (helpers.getProperty(castOid_)); 356 npkformatter = new MessageFormat (helpers.getProperty(newPK_)); 357 noidformatter = new MessageFormat (helpers.getProperty(newOid_)); 358 pk1formatter = new MessageFormat (helpers.getProperty(getPK1_)); 359 pk1cloneformatter = new MessageFormat (helpers.getProperty(getPK1Clone_)); 360 oid1formatter = new MessageFormat (helpers.getProperty(getOid1_)); 361 pk1pformatter = new MessageFormat (helpers.getProperty(getPK1primitive_)); 362 oid1pformatter = new MessageFormat (helpers.getProperty(getOid1primitive_)); 363 oid1stringformatter = new MessageFormat (helpers.getProperty(getOid1String_)); 364 oid1cloneformatter = new MessageFormat (helpers.getProperty(getOid1Clone_)); 365 pkformatter = new MessageFormat (helpers.getProperty(getPK_)); 366 pkcloneformatter = new MessageFormat (helpers.getProperty(getPKClone_)); 367 oidformatter = new MessageFormat (helpers.getProperty(getOid_)); 368 oidstringformatter = new MessageFormat (helpers.getProperty(getOidString_)); 369 oidcloneformatter = new MessageFormat (helpers.getProperty(getOidClone_)); 370 371 assertpkfieldformatter = new MessageFormat (helpers.getProperty(assertPKFieldNotNull_)); 372 373 pcclassgetterformatter = new MessageFormat (helpers.getProperty(getPCClass_)); 375 376 } 377 378 381 private static void initTemplates() { 382 cmpImplCommentsTemplate = helpers.getProperty(cmpImplComments_); 383 privateStaticVariablesTemplate = helpers.getProperty(privateStaticVariables_); 384 otherVariablesTemplate = helpers.getProperty(otherVariables_); 385 jdoGetJdoInstanceClassTemplate = helpers.getProperty(jdoGetJdoInstanceClass_); 386 assertPersistenceManagerIsNullTemplate = helpers.getProperty( 387 assertPersistenceManagerIsNullCall_); 388 assertInstanceOfRemoteInterfaceImplTemplate = helpers.getProperty( 389 assertInstanceOfRemoteInterfaceImpl_); 390 getHelperInstanceTemplate = helpers.getProperty(getHelperInstance_); 391 catchClauseTemplate = helpers.getProperty(catchClause_); 392 signatureTemplate = helpers.getProperty(signature_); 393 assertPKNotNullTemplate = helpers.getProperty(assertPKNotNull_); 394 assertOidNotNullTemplate = helpers.getProperty(assertOidNotNull_); 395 396 importsArray = tokenize(imports_); 397 interfacesArray = tokenize(interfaces_); 398 helperImportsArray = tokenize(helperImports_); 399 commonPublicMethodsArray = tokenize(commonPublicMethods_); 400 otherPublicMethodsArray = tokenize(otherPublicMethods_); 401 commonPrivateMethodsArray = tokenize(commonPrivateMethods_); 402 403 ejbFindByPrimaryKeyBody = getBodyAsStrings(helpers.getProperty(ejbFindByPrimaryKey_)); 404 afterCompletionBody = getBodyAsStrings(helpers.getProperty(afterCompletion_)); 405 jdoGetPersistenceManagerBody = getBodyAsStrings(helpers.getProperty(jdoGetPersistenceManager_)); 406 jdoClosePersistenceManagerBody = getBodyAsStrings(helpers.getProperty(jdoClosePersistenceManager_)); 407 jdoReleasePersistenceManagerBody = getBodyAsStrings(helpers.getProperty(jdoReleasePersistenceManager_)); 408 setEntityContextBody = getBodyAsStrings(helpers.getProperty(setEntityContext_)); 409 getContainerBody = getBodyAsStrings(helpers.getProperty(getContainer_)); 410 assertPersistenceManagerIsNullBody = getBodyAsStrings(helpers.getProperty(assertPersistenceManagerIsNull_)); 411 } 412 413 static String [] tokenize(String template) { 414 StringTokenizer st = new StringTokenizer (helpers.getProperty(template), delim_); 415 String [] rc = new String [st.countTokens()]; 416 417 int i = 0; 418 while (st.hasMoreElements()) { 419 rc[i++] = st.nextToken(); 420 } 421 422 return rc; 423 } 424 } 425 | Popular Tags |