| 1 30 31 package com.nightlabs.config; 32 33 import java.io.ObjectInputStream ; 34 import java.io.ObjectOutputStream ; 35 import java.io.Serializable ; 36 37 import com.nightlabs.io.DataBuffer; 38 import com.nightlabs.util.RWLockable; 39 import com.nightlabs.util.RWLock; 40 import com.nightlabs.util.DeadLockException; 41 42 76 public abstract class ConfigModule 77 implements Serializable , Initializable, RWLockable, Cloneable  78 { 79 private transient Config config; 80 81 private String identifier; 82 private String searchClass; 83 84 public ConfigModule() 85 { 86 } 87 88 public void _setConfig(Config _config) 89 { 90 this.config = _config; 91 } 92 public Config _getConfig() 93 { 94 return config; 95 } 96 97 public void init() 98 throws InitException 99 { 100 } 101 102 protected transient RWLock rwLock = new RWLock(this.getClass().getName(), true); 103 104 public void acquireReadLock() throws DeadLockException 105 { 106 rwLock.acquireReadLock(); 107 } 108 109 public void acquireWriteLock() throws DeadLockException 110 { 111 rwLock.acquireWriteLock(); 112 } 113 114 public void releaseLock() 115 { 116 rwLock.releaseLock(); 117 } 118 119 120 private volatile boolean changed = false; 121 122 129 public boolean _isChanged() 130 { 131 return changed; 132 } 133 134 public void setChanged() { 135 setChanged(true); 136 } 137 138 public void setChanged(boolean changed) { 139 this.changed = changed; 140 } 141 142 146 public String getIdentifier() 147 { 148 return identifier; 149 } 150 151 155 public void setIdentifier(String identifier) 156 { 157 if ("null".equals(identifier)) 158 throw new IllegalArgumentException ("null is a reserved word and should not be used as identifier!"); 159 this.identifier = identifier; 160 } 161 162 169 public String getSearchClass() 170 { 171 return searchClass; 172 } 173 174 178 public void setSearchClass(String searchClass) 179 { 180 if ("null".equals(searchClass)) 181 throw new IllegalArgumentException ("null is a reserved word and should not be used as searchClassName!"); 182 this.searchClass = searchClass; 183 } 184 185 190 public Object clone() 191 { 192 try { 193 DataBuffer buf = new DataBuffer(); 194 ObjectOutputStream out = new ObjectOutputStream (buf.createOutputStream()); 195 out.writeObject(this); 196 out.close(); 197 ObjectInputStream in = new ObjectInputStream (buf.createInputStream()); 198 Object n = in.readObject(); 199 in.close(); 200 return n; 201 } catch (Exception e) { 202 throw new RuntimeException (e); 203 } 204 } 205 206 } | Popular Tags |