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.ejb.spi.sfsb.initialization.PersistenceStrategyBuilder; 30 31 import com.sun.logging.LogDomains; 32 33 37 public class PersistenceStrategyBuilderFactory { 38 39 44 protected final String DEFAULT_EE_BUILDER_PATH = "com.sun.ejb.ee.sfsb.initialization"; 45 46 47 public PersistenceStrategyBuilderFactory() { 48 if (_logger == null) { 49 _logger = LogDomains.getLogger(LogDomains.EJB_LOGGER); 50 } 51 } 52 53 54 63 public PersistenceStrategyBuilder createPersistenceStrategyBuilder( 64 String persistenceType) 65 { 66 PersistenceStrategyBuilder builder = new FileStrategyBuilder(); 67 String className = createClassNameFrom(persistenceType); 68 _logger.finest("PersistenceStrategyBuilderFactory>>createPersistenceStrategyBuilder: " 69 + "CandidateBuilderClassName = " + className); 70 boolean requestedBuilderCreated = false; 71 try { 72 builder = 73 (PersistenceStrategyBuilder) (Class.forName(className)).newInstance(); 74 requestedBuilderCreated = true; 75 } catch (ClassNotFoundException clnfEx) { 76 _logger.log(Level.WARNING, "Couldn't find class: " 77 + className + " for persistenceType: " 78 + persistenceType); 79 _logger.log(Level.FINE, "Exception while creating Builder", clnfEx); 80 } catch (Exception ex) { 81 _logger.log(Level.WARNING, "Exception while creating Builder", ex); 82 } 83 if (! requestedBuilderCreated) { 84 _logger.log(Level.WARNING, "Couldn't create builder for " 85 + "persistence type: " + persistenceType 86 +". Instead created FileStrategyBuilder...."); 87 } 88 return builder; 89 } 90 91 103 private String createClassNameFrom(String persistenceType) { 104 StringBuffer sb = new StringBuffer (); 105 String pkg = this.getClass().getPackage().getName(); 108 if( !(persistenceType.equalsIgnoreCase("file")) ) 109 { 110 pkg = this.getEEBuilderPath(); 117 } 118 sb.append(pkg + "."); 119 sb.append(camelCase(persistenceType)); 120 sb.append("StrategyBuilder"); 121 String classname = sb.toString(); 122 return classname; 123 } 124 125 130 private String camelCase(String inputString) { 131 String strippedString = stripNonAlphas(inputString); 132 String firstLetter = (strippedString.substring(0, 1)).toUpperCase(); 133 String remainingPart = 134 (strippedString.substring(1, strippedString.length())).toLowerCase(); 135 return firstLetter + remainingPart; 136 } 137 138 143 private String stripNonAlphas(String inputString) { 144 StringBuffer sb = new StringBuffer (50); 145 for(int i=0; i<inputString.length(); i++) { 146 char nextChar = inputString.charAt(i); 147 if(Character.isLetter(nextChar)) { 148 sb.append(nextChar); 149 } 150 } 151 return sb.toString(); 152 } 153 154 161 private String getEEBuilderPath() { 162 return DEFAULT_EE_BUILDER_PATH; 163 } 164 165 168 private static Logger _logger = null; 169 170 } 171 | Popular Tags |