1 23 24 29 30 package com.sun.enterprise.web; 31 32 import java.util.logging.Logger ; 33 import java.util.logging.Level ; 34 import com.sun.logging.LogDomains; 35 import org.apache.catalina.Context; 36 37 38 public class PersistenceStrategyBuilderFactory { 39 40 45 protected final String DEFAULT_EE_BUILDER_PATH = "com.sun.enterprise.ee.web.initialization"; 46 47 54 private String getEEBuilderPath() { 55 if(_eeBuilderPath == null) { 56 ServerConfigLookup lookup = new ServerConfigLookup(); 57 _eeBuilderPath = lookup.getEEBuilderPathFromConfig(); 58 } 59 _logger.finest("_eeBuilderPath = " + _eeBuilderPath); 60 return _eeBuilderPath; 61 } 62 63 64 public PersistenceStrategyBuilderFactory() { 65 if (_logger == null) { 66 _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 67 } 68 } 69 70 80 PersistenceStrategyBuilder createPersistenceStrategyBuilder(String persistenceType, String frequency, String scope, Context ctx) { 81 82 PersistenceStrategyBuilder builder = new MemoryStrategyBuilder(); 83 String className = createClassNameFrom(persistenceType, frequency, scope); 84 _logger.finest("PersistenceStrategyBuilderFactory>>createPersistenceStrategyBuilder: " 85 + "CandidateBuilderClassName = " + className); 86 try { 87 builder = 88 (PersistenceStrategyBuilder) (Class.forName(className)).newInstance(); 89 } catch (Exception ex) { 90 Object [] params = { getApplicationId(ctx), persistenceType, frequency, scope }; 91 _logger.log(Level.WARNING, 92 "webcontainer.invalidSessionManagerConfig", 93 params); 94 } 95 builder.setPersistenceFrequency(frequency); 96 builder.setPersistenceScope(scope); 97 return builder; 98 } 99 100 109 PersistenceStrategyBuilder createPersistenceStrategyBuilder(String persistenceType, String frequency, String scope) { 110 111 PersistenceStrategyBuilder builder = new MemoryStrategyBuilder(); 112 String className = createClassNameFrom(persistenceType, frequency, scope); 113 _logger.finest("PersistenceStrategyBuilderFactory>>createPersistenceStrategyBuilder: " 114 + "CandidateBuilderClassName = " + className); 115 try { 116 builder = 117 (PersistenceStrategyBuilder) (Class.forName(className)).newInstance(); 118 } catch (Exception ex) { 119 Object [] params = { persistenceType, frequency, scope }; 120 _logger.log(Level.WARNING, 121 "webcontainer.invalidSessionManagerConfig", 122 params); 123 } 124 builder.setPersistenceFrequency(frequency); 125 builder.setPersistenceScope(scope); 126 return builder; 127 } 128 129 134 public String getApplicationId(Context ctx) { 135 com.sun.enterprise.web.WebModule wm = 136 (com.sun.enterprise.web.WebModule)ctx; 137 return wm.getID(); 138 } 139 140 public PersistenceStrategyBuilder testCreatePersistenceStategyBuilder(String persistenceType, String frequency, String scope) { 143 return this.createPersistenceStrategyBuilder(persistenceType, frequency, scope); 144 } 145 146 158 private String createClassNameFrom(String persistenceType, String frequency, String scope) { 159 StringBuffer sb = new StringBuffer (); 160 String pkg = this.getClass().getPackage().getName(); 163 if( !(persistenceType.equalsIgnoreCase("memory") 164 | persistenceType.equalsIgnoreCase("file")) ) 165 { 166 pkg = this.getEEBuilderPath(); 173 } 174 sb.append(pkg + "."); 175 sb.append(camelCase(persistenceType)); 176 if(frequency != null) { 177 sb.append(camelCase(frequency)); 178 } 179 if(scope != null) { 180 sb.append(camelCase(scope)); 181 } 182 sb.append("StrategyBuilder"); 183 String classname = sb.toString(); 184 return classname; 185 } 186 187 192 private String camelCase(String inputString) { 193 String strippedString = stripNonAlphas(inputString); 194 String firstLetter = (strippedString.substring(0, 1)).toUpperCase(); 195 String remainingPart = 196 (strippedString.substring(1, strippedString.length())).toLowerCase(); 197 return firstLetter + remainingPart; 198 } 199 200 205 private String stripNonAlphas(String inputString) { 206 StringBuffer sb = new StringBuffer (50); 207 for(int i=0; i<inputString.length(); i++) { 208 char nextChar = inputString.charAt(i); 209 if(Character.isLetter(nextChar)) { 210 sb.append(nextChar); 211 } 212 } 213 return sb.toString(); 214 } 215 216 219 private static Logger _logger = null; 220 221 224 private String _eeBuilderPath = null; 225 226 } 227 | Popular Tags |