1 22 package org.jboss.system.pm; 23 24 import org.jboss.mx.persistence.AttributePersistenceManager; 25 import org.jboss.system.ServiceMBean; 26 import org.jboss.system.ServiceMBeanSupport; 27 import org.w3c.dom.Element ; 28 29 60 public class AttributePersistenceService 61 extends ServiceMBeanSupport 62 implements AttributePersistenceServiceMBean 63 { 64 66 67 public static final String DEFAULT_APM = "org.jboss.system.pm.XMLAttributePersistenceManager"; 68 69 70 public static final boolean DEFAULT_DESTROY_APM_ON_STOP = false; 71 72 74 75 private AttributePersistenceManager apm = null; 76 77 78 private Element apmConfig = null; 79 80 81 private String apmClass = DEFAULT_APM; 82 83 84 private boolean apmDestroyOnStop = DEFAULT_DESTROY_APM_ON_STOP; 85 86 87 private String versionTag = null; 88 89 91 94 public AttributePersistenceService() 95 { 96 super(AttributePersistenceService.class); 98 } 99 100 102 106 public String getVersionTag() 107 { 108 return versionTag; 109 } 110 111 115 public void setVersionTag(String versionTag) 116 { 117 checkNotStarted(); 118 this.versionTag = versionTag; 119 } 120 121 125 public String getAttributePersistenceManagerClass() 126 { 127 return apmClass; 128 } 129 130 134 public void setAttributePersistenceManagerClass(String apmClass) 135 { 136 checkNotStarted(); 137 this.apmClass = apmClass; 138 } 139 140 144 public Element getAttributePersistenceManagerConfig() 145 { 146 return apmConfig; 147 } 148 149 153 public void setAttributePersistenceManagerConfig(Element apmConfig) 154 { 155 checkNotStarted(); 156 this.apmConfig = apmConfig; 157 } 158 159 163 public boolean getApmDestroyOnServiceStop() 164 { 165 return apmDestroyOnStop; 166 } 167 171 public void setApmDestroyOnServiceStop(boolean apmDestroyOnStop) 172 { 173 checkNotStarted(); 174 this.apmDestroyOnStop = apmDestroyOnStop; 175 } 176 177 179 public void startService() 180 throws Exception 181 { 182 this.apm = (AttributePersistenceManager)this.getServer().instantiate(this.apmClass); 184 185 this.apm.create(this.versionTag, this.apmConfig); 187 } 188 189 public void stopService() 190 { 191 if (this.apmDestroyOnStop) { 193 this.apm.destroy(); 194 } 195 196 this.apm = null; 198 } 199 200 202 205 public AttributePersistenceManager apmCreate() 206 { 207 checkStarted(); 208 209 return this.apm; 210 } 211 212 215 public boolean apmExists(String id) 216 throws Exception 217 { 218 checkStarted(); 219 220 return this.apm.exists(id); 221 } 222 223 226 public void apmRemove(String id) 227 throws Exception 228 { 229 checkStarted(); 230 231 this.apm.remove(id); 232 } 233 234 237 public void apmRemoveAll() 238 throws Exception 239 { 240 checkStarted(); 241 242 this.apm.removeAll(); 243 } 244 245 248 public String [] apmListAll() 249 throws Exception 250 { 251 checkStarted(); 252 253 return this.apm.listAll(); 254 } 255 256 259 public String apmListAllAsString() 260 throws Exception 261 { 262 checkStarted(); 263 264 StringBuffer sbuf = new StringBuffer (1024); 265 String [] list = this.apm.listAll(); 266 267 for (int i = 0; i < list.length; i++) { 268 sbuf.append(list[i]).append("\n"); 269 } 270 return sbuf.toString(); 271 } 272 273 275 private void checkStarted() 276 { 277 int state = this.getState(); 278 279 if (state != ServiceMBean.STARTED) { 280 throw new IllegalStateException ("Cannot perform operations unless service is started"); 281 } 282 } 283 284 private void checkNotStarted() 285 { 286 int state = this.getState(); 287 288 if (state == ServiceMBean.STARTING || state == ServiceMBean.STARTED) { 289 throw new IllegalStateException ("Cannot modify attributes while service is started"); 290 } 291 } 292 } | Popular Tags |