1 7 package org.jboss.cache.config; 8 9 import org.jboss.cache.xml.XmlHelper; 10 11 import java.io.ByteArrayInputStream ; 12 import java.io.IOException ; 13 import java.util.ArrayList ; 14 import java.util.List ; 15 import java.util.Properties ; 16 17 24 public class CacheLoaderConfig extends ConfigurationComponent 25 { 26 private static final long serialVersionUID = 2210349340378984424L; 27 28 private boolean passivation; 29 private String preload; 30 private List <IndividualCacheLoaderConfig> cacheLoaderConfigs = new ArrayList <IndividualCacheLoaderConfig>(); 31 32 private boolean shared; 33 34 public CacheLoaderConfig() 35 { 36 } 37 38 public String getPreload() 39 { 40 return preload; 41 } 42 43 public void setPreload(String preload) 44 { 45 testImmutability("preload"); 46 this.preload = preload; 47 } 48 49 public void setPassivation(boolean passivation) 50 { 51 testImmutability("passivation"); 52 this.passivation = passivation; 53 } 54 55 public boolean isPassivation() 56 { 57 return passivation; 58 } 59 60 public void addIndividualCacheLoaderConfig(IndividualCacheLoaderConfig clc) 61 { 62 testImmutability("cacheLoaderConfigs"); 63 cacheLoaderConfigs.add(clc); 64 addChildConfig(clc); 66 } 67 68 public List <IndividualCacheLoaderConfig> getIndividualCacheLoaderConfigs() 69 { 70 return cacheLoaderConfigs; 71 } 72 73 public void setIndividualCacheLoaderConfigs(List <IndividualCacheLoaderConfig> configs) 74 { 75 testImmutability("cacheLoaderConfigs"); 76 replaceChildConfigs(this.cacheLoaderConfigs, configs); 78 this.cacheLoaderConfigs = configs == null ? new ArrayList <IndividualCacheLoaderConfig>() : configs; 79 } 80 81 public IndividualCacheLoaderConfig getFirstCacheLoaderConfig() 82 { 83 if (cacheLoaderConfigs.size() == 0) return null; 84 return cacheLoaderConfigs.get(0); 85 } 86 87 public boolean useChainingCacheLoader() 88 { 89 return !isPassivation() && cacheLoaderConfigs.size() > 1; 90 } 91 92 public String toString() 93 { 94 return new StringBuffer ().append("CacheLoaderConfig{").append("shared=").append(shared).append(", passivation=").append(passivation).append(", preload='").append(preload).append('\'').append(", cacheLoaderConfigs.size()=").append(cacheLoaderConfigs.size()).append('}').toString(); 95 } 96 97 public void setShared(boolean shared) 98 { 99 testImmutability("shared"); 100 this.shared = shared; 101 } 102 103 public boolean isShared() 104 { 105 return shared; 106 } 107 108 public boolean equals(Object obj) 109 { 110 if (this == obj) 111 return true; 112 113 if (obj instanceof CacheLoaderConfig) 114 { 115 CacheLoaderConfig other = (CacheLoaderConfig) obj; 116 return (this.passivation == other.passivation) 117 && (this.shared == other.shared) 118 && safeEquals(this.preload, other.preload) 119 && safeEquals(this.cacheLoaderConfigs, other.cacheLoaderConfigs); 120 } 121 return false; 122 } 123 124 public int hashCode() 125 { 126 int result = 19; 127 result = 51 * result + (passivation ? 0 : 1); 128 result = 51 * result + (shared ? 0 : 1); 129 result = 51 * result + (preload == null ? 0 : preload.hashCode()); 130 result = 51 * result + (cacheLoaderConfigs == null ? 0 : cacheLoaderConfigs.hashCode()); 131 return result; 132 } 133 134 135 140 public static class IndividualCacheLoaderConfig extends ConfigurationComponent 141 { 142 private static final long serialVersionUID = -2282396799100828593L; 143 144 private String className; 145 private boolean async; 146 private boolean ignoreModifications; 147 private boolean fetchPersistentState; 148 private boolean singletonStore; 149 private boolean pushStateWhenCoordinator; 150 151 private boolean purgeOnStartup; 152 153 private Properties properties; 154 155 public IndividualCacheLoaderConfig() 156 { 157 } 158 159 protected void populateFromBaseConfig(IndividualCacheLoaderConfig base) 160 { 161 if (base != null) 162 { 163 setAsync(base.isAsync()); 164 setIgnoreModifications(base.isIgnoreModifications()); 165 setFetchPersistentState(base.isFetchPersistentState()); 166 setSingletonStore(base.isSingletonStore()); 167 setPushStateWhenCoordinator(base.isPushStateWhenCoordinator()); 168 setPurgeOnStartup(base.isPurgeOnStartup()); 169 Properties props = base.getProperties(); 170 if (props != null) 171 setProperties(props); 172 } 173 } 174 175 public boolean isPurgeOnStartup() 176 { 177 return purgeOnStartup; 178 } 179 180 public boolean isFetchPersistentState() 181 { 182 return fetchPersistentState; 183 } 184 185 public void setFetchPersistentState(boolean fetchPersistentState) 186 { 187 testImmutability("fetchPersistentState"); 188 this.fetchPersistentState = fetchPersistentState; 189 } 190 191 public void setClassName(String className) 192 { 193 testImmutability("className"); 194 this.className = className; 195 } 196 197 public String getClassName() 198 { 199 return className; 200 } 201 202 public void setAsync(boolean async) 203 { 204 testImmutability("async"); 205 this.async = async; 206 } 207 208 public boolean isAsync() 209 { 210 return async; 211 } 212 213 public void setIgnoreModifications(boolean ignoreModifications) 214 { 215 testImmutability("ignoreModifications"); 216 this.ignoreModifications = ignoreModifications; 217 } 218 219 public boolean isIgnoreModifications() 220 { 221 return ignoreModifications; 222 } 223 224 public void setProperties(String properties) throws IOException 225 { 226 if (properties == null) return; 227 228 testImmutability("properties"); 229 properties = XmlHelper.escapeBackslashes(properties); 232 ByteArrayInputStream is = new ByteArrayInputStream (properties.trim().getBytes("ISO8859_1")); 233 this.properties = new Properties (); 234 this.properties.load(is); 235 is.close(); 236 } 237 238 public void setProperties(Properties properties) 239 { 240 testImmutability("properties"); 241 this.properties = properties; 242 } 243 244 public Properties getProperties() 245 { 246 return properties; 247 } 248 249 public void setPurgeOnStartup(boolean purgeOnStartup) 250 { 251 testImmutability("purgeOnStartup"); 252 this.purgeOnStartup = purgeOnStartup; 253 } 254 255 public boolean isSingletonStore() 256 { 257 return singletonStore; 258 } 259 260 public void setSingletonStore(boolean singletonStore) 261 { 262 testImmutability("singletonStore"); 263 this.singletonStore = singletonStore; 264 } 265 266 public boolean isPushStateWhenCoordinator() 267 { 268 return pushStateWhenCoordinator; 269 } 270 271 public void setPushStateWhenCoordinator(boolean pushStateWhenCoordinator) 272 { 273 testImmutability("pushStateWhenCoordinator"); 274 if (singletonStore) 275 { 276 278 this.pushStateWhenCoordinator = pushStateWhenCoordinator; 279 } 280 } 281 282 public boolean equals(Object obj) 283 { 284 return equalsExcludingProperties(obj) 285 && safeEquals(this.properties, ((IndividualCacheLoaderConfig) obj).properties); 286 } 287 288 protected boolean equalsExcludingProperties(Object obj) 289 { 290 if (this == obj) 291 return true; 292 293 if (obj instanceof IndividualCacheLoaderConfig) 294 { 295 IndividualCacheLoaderConfig other = (IndividualCacheLoaderConfig) obj; 296 return safeEquals(this.className, other.className) 297 && (this.async == other.async) 298 && (this.ignoreModifications == other.ignoreModifications) 299 && (this.fetchPersistentState == other.fetchPersistentState) 300 && (this.singletonStore == other.singletonStore) 301 && (this.pushStateWhenCoordinator == other.pushStateWhenCoordinator); 302 } 303 return false; 304 305 } 306 307 public int hashCode() 308 { 309 return 31 * hashCodeExcludingProperties() + (properties == null ? 0 : properties.hashCode()); 310 } 311 312 protected int hashCodeExcludingProperties() 313 { 314 int result = 17; 315 result = 31 * result + (className == null ? 0 : className.hashCode()); 316 result = 31 * result + (async ? 0 : 1); 317 result = 31 * result + (ignoreModifications ? 0 : 1); 318 result = 31 * result + (fetchPersistentState ? 0 : 1); 319 result = 31 * result + (singletonStore ? 0 : 1); 320 result = 31 * result + (pushStateWhenCoordinator ? 0 : 1); 321 result = 31 * result + (purgeOnStartup ? 0 : 1); 322 return result; 323 } 324 325 public String toString() 326 { 327 return new StringBuffer ().append("IndividualCacheLoaderConfig{").append("className='").append(className).append('\'') 328 .append(", async=").append(async) 329 .append(", ignoreModifications=").append(ignoreModifications) 330 .append(", fetchPersistentState=").append(fetchPersistentState) 331 .append(", properties=").append(properties).append('}') 332 .append(", purgeOnStartup=").append(purgeOnStartup) 333 .append(", singletonStore=").append(singletonStore) 334 .append(", singletonStore.pushStateWhenCoordinator=").append(pushStateWhenCoordinator) 335 .toString(); 336 } 337 } 338 } 339 | Popular Tags |