1 23 24 package com.sun.ejb.base.sfsb.initialization; 25 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 29 import com.sun.logging.LogDomains; 30 31 import com.sun.ejb.base.sfsb.store.FileTxStoreManager; 32 33 import com.sun.ejb.spi.sfsb.store.SFSBTxStoreManager; 34 35 42 public class SFSBTxStoreManagerFactory { 43 44 private static Logger _logger = 45 LogDomains.getLogger(LogDomains.EJB_LOGGER); 46 47 protected static final String DEFAULT_EE_PACKAGE = 48 "com.sun.ejb.ee.sfsb.store"; 49 50 public static SFSBTxStoreManager createSFSBTxStoreManager( 51 String persistenceType) 52 { 53 if ("file".equalsIgnoreCase(persistenceType)) { 54 return new FileTxStoreManager(); 55 } 56 57 try { 58 String className = createClassNameFrom(persistenceType); 59 return (SFSBTxStoreManager) 60 (Class.forName(className)).newInstance(); 61 } catch (ClassNotFoundException cnfEx) { 62 _logger.log(Level.FINE, 63 "Exception while creating SFSBTxStoreManager for persistence " 64 + "type: " + persistenceType + ". Exception: " + cnfEx); 65 } catch (Exception ex) { 66 _logger.log(Level.FINE, 67 "Exception while creating SFSBTxStoreManager for " 68 + "persistence type: " + persistenceType, ex); 69 } 70 71 _logger.log(Level.WARNING, "Created FileTxStorManager for persistence" 72 + " type: " + persistenceType); 73 74 return new FileTxStoreManager(); 75 } 76 77 81 private static String createClassNameFrom(String persistenceType) { 82 StringBuffer sbuf = new StringBuffer (); 83 sbuf.append(getEEPackage()).append(".") 84 .append(camelCase(persistenceType)) 85 .append("TxStoreManager"); 86 String classname = sbuf.toString(); 87 return classname; 88 } 89 90 95 private static String camelCase(String inputString) { 96 String strippedString = stripNonAlphas(inputString); 97 String firstLetter = (strippedString.substring(0, 1)).toUpperCase(); 98 String remainingPart = 99 (strippedString.substring(1, strippedString.length())).toLowerCase(); 100 return firstLetter + remainingPart; 101 } 102 103 108 private static String stripNonAlphas(String inputString) { 109 StringBuffer sb = new StringBuffer (50); 110 for(int i=0; i<inputString.length(); i++) { 111 char nextChar = inputString.charAt(i); 112 if(Character.isLetter(nextChar)) { 113 sb.append(nextChar); 114 } 115 } 116 return sb.toString(); 117 } 118 119 126 private static String getEEPackage() { 127 return DEFAULT_EE_PACKAGE; 128 } 129 130 } 131 | Popular Tags |