1 6 7 package SOFA.SOFAnet.Repository; 8 9 import java.io.*; 10 import java.util.*; 11 import java.text.*; 12 import SOFA.Util.XML; 13 import org.w3c.dom.*; 14 import org.xml.sax.SAXException ; 15 16 44 public class LocalInfo extends XMLStorageItem implements StorageItem, Serializable 45 { 46 final static public int STATE_NONE = 0; 47 final static public int STATE_INSTALLED = 1; 48 final static public int STATE_SHARE_MANAGER = 2; 49 final static public int STATE_SHARE_CLIENT = 4; 50 final static public int STATE_SHARE_PRECLIENT = 8; 52 private Licence licence; 53 private int state; 54 private ShareGroups smShareGroups; private NodeNameFilter smNodeFilter; private NodeNameList smClients; private boolean smEquality; private String scManager; private int inMemoryCounter; 60 private boolean inMemory; 61 62 63 public LocalInfo(String name, File file) 64 { 65 super(name, file, "local_info"); 66 reset(); 67 } 68 69 72 protected void reset() 73 { 74 licence = new Licence(); 75 state = STATE_NONE; 76 smShareGroups = null; 77 smNodeFilter = null; 78 smClients = null; 79 smEquality = false; 80 scManager = ""; 81 inMemoryCounter = 0; 82 inMemory = false; 83 } 84 85 118 public void loadFromXML(Element element) throws SAXException 119 { 120 reset(); 121 NodeList nl = element.getChildNodes(); 122 for (int i = 0; i < nl.getLength(); i++) 123 { 124 Node node = nl.item(i); 125 if (node.getNodeType() == Node.ELEMENT_NODE) 126 { 127 Element el = (Element)node; 128 String nodeName = node.getNodeName(); 129 130 if (nodeName.compareTo("licence") == 0) 131 { 132 licence.loadFromXML(el); 133 } 134 else 135 if (nodeName.compareTo("state") == 0) 136 { 137 String installed = el.getAttribute("installed").trim().toLowerCase(); 138 if (installed.compareTo("1") == 0 || 139 installed.compareTo("true") == 0) state |= STATE_INSTALLED; 140 141 String sharing = el.getAttribute("sharing").trim().toLowerCase(); 142 if (sharing.length() > 0) 143 { 144 if (sharing.compareTo("manager") == 0) state |= STATE_SHARE_MANAGER; 145 else if (sharing.compareTo("client") == 0) state |= STATE_SHARE_CLIENT; 146 else if (sharing.compareTo("preclient") == 0) state |= STATE_SHARE_PRECLIENT; 147 else throw new SAXException ("Invalid content of 'sharing' attribute ('state' tag)"); 148 } 149 150 String in_memory = el.getAttribute("in_memory").trim().toLowerCase(); 151 if (in_memory.compareTo("1") == 0 || 152 in_memory.compareTo("true") == 0) 153 { 154 inMemory = true; 155 inMemoryCounter = 1; } 157 } 158 else 159 if (nodeName.compareTo("share_manager") == 0) 160 { 161 String equality = el.getAttribute("equality").trim().toLowerCase(); 162 if (equality.compareTo("1") == 0 || 163 equality.compareTo("true") == 0) smEquality = true; 164 165 NodeList nl2 = el.getChildNodes(); 166 for (int i2 = 0; i2 < nl2.getLength(); i2++) 167 { 168 Node node2 = nl2.item(i2); 169 if (node2.getNodeType() == Node.ELEMENT_NODE) 170 { 171 Element el2 = (Element)node2; 172 String nodeName2 = node2.getNodeName(); 173 174 if (nodeName2.compareTo("share_groups") == 0) 175 { 176 smShareGroups = new ShareGroups(); 177 smShareGroups.loadFromXML(el2); 178 } 179 else 180 if (nodeName2.compareTo("node_filter") == 0) 181 { 182 smNodeFilter = new NodeNameFilter(); 183 smNodeFilter.loadFromXML(el2); 184 } 185 else 186 if (nodeName2.compareTo("clients") == 0) 187 { 188 smClients = new NodeNameList(); 189 smClients.loadFromXML(el2); 190 } 191 } 192 } 193 } 194 else 195 if (nodeName.compareTo("share_client") == 0) 196 { 197 scManager = el.getAttribute("manager"); 198 } 199 } 200 } 201 202 if (isShareManager() && smClients == null) smClients = new NodeNameList(); 203 } 204 205 208 public void saveToXML(Element element) 209 { 210 Document doc = element.getOwnerDocument(); 211 Element el; 212 213 el = doc.createElement("licence"); 214 licence.saveToXML(el); 215 element.appendChild(el); 216 217 el = doc.createElement("state"); 218 219 if ((state & STATE_INSTALLED) != 0) el.setAttribute("installed", "true"); 220 else el.setAttribute("installed", "false"); 221 222 if ((state & STATE_SHARE_MANAGER) != 0) el.setAttribute("sharing", "manager"); 223 else if ((state & STATE_SHARE_CLIENT) != 0) el.setAttribute("sharing", "client"); 224 else if ((state & STATE_SHARE_PRECLIENT) != 0) el.setAttribute("sharing", "preclient"); 225 226 if (inMemory) el.setAttribute("in_memory", "true"); 227 228 element.appendChild(el); 229 230 if (isShareManager()) 231 { 232 el = doc.createElement("share_manager"); 233 234 if (smEquality) el.setAttribute("equality", "true"); 235 else el.setAttribute("equality", "false"); 236 237 if (smShareGroups != null) 238 { 239 Element el2 = doc.createElement("share_groups"); 240 smShareGroups.saveToXML(el2); 241 el.appendChild(el2); 242 } 243 244 if (smNodeFilter != null) 245 { 246 Element el2 = doc.createElement("node_filter"); 247 smNodeFilter.saveToXML(el2); 248 el.appendChild(el2); 249 } 250 251 if (smClients != null) 252 { 253 Element el2 = doc.createElement("clients"); 254 smClients.saveToXML(el2); 255 el.appendChild(el2); 256 } 257 258 element.appendChild(el); 259 } 260 261 if (isShareClient()) 262 { 263 el = doc.createElement("share_client"); 264 el.setAttribute("manager", scManager); 265 element.appendChild(el); 266 } 267 } 268 269 public Licence getLicence() 270 { 271 return licence; 272 } 273 274 public int getState() 275 { 276 return state; 277 } 278 279 public ShareGroups getSMShareGroups() 280 { 281 return smShareGroups; 282 } 283 284 public NodeNameFilter getSMNodeFilter() 285 { 286 return smNodeFilter; 287 } 288 289 public NodeNameList getSMClients() 290 { 291 return smClients; 292 } 293 294 public boolean isSMEquality() 295 { 296 return smEquality; 297 } 298 299 public String getSCManager() 300 { 301 return scManager; 302 } 303 304 public int getInMemoryCounter() 305 { 306 return inMemoryCounter; 307 } 308 309 public void setLicence(Licence licence) 310 { 311 this.licence = licence; 312 } 313 314 public void setState(int state) 315 { 316 this.state = state; 317 } 318 319 public void setSMShareGroups(ShareGroups shareGroups) 320 { 321 this.smShareGroups = shareGroups; 322 } 323 324 public void setSMNodeFilter(NodeNameFilter nodeFilter) 325 { 326 this.smNodeFilter = nodeFilter; 327 } 328 329 public void setSMClients(NodeNameList clients) 330 { 331 this.smClients = clients; 332 } 333 334 public void setSMEquality(boolean smEquality) 335 { 336 this.smEquality = smEquality; 337 } 338 339 public void setSCManager(String manager) 340 { 341 this.scManager = manager; 342 } 343 344 347 public boolean setInMemoryCounter(int inMemoryCounter) 348 { 349 this.inMemoryCounter = inMemoryCounter; 350 boolean oldInMemory = inMemory; 351 inMemory = inMemoryCounter > 0; 352 return oldInMemory != inMemory; 353 } 354 355 public void increaseInMemoryCounter() 356 { 357 if (inMemoryCounter == 0) inMemory = true; 358 inMemoryCounter++; 359 } 360 361 public void decreaseInMemoryCounter() 362 { 363 inMemoryCounter--; 364 if (inMemoryCounter < 0) inMemoryCounter = 0; 365 if (inMemoryCounter == 0) inMemory = false; 366 } 367 368 public boolean isInstalled() 369 { 370 return (state & STATE_INSTALLED) != 0; 371 } 372 373 public void setInstalled(boolean installed) 374 { 375 if (installed) state |= STATE_INSTALLED; 376 else state &= ~STATE_INSTALLED; 377 } 378 379 public boolean isShareManager() 380 { 381 return (state & STATE_SHARE_MANAGER) != 0; 382 } 383 384 public void setShareManager(boolean shareManager) 385 { 386 if (shareManager) state |= STATE_SHARE_MANAGER; 387 else state &= ~STATE_SHARE_MANAGER; 388 } 389 390 public boolean isShareClient() 391 { 392 return (state & STATE_SHARE_CLIENT) != 0; 393 } 394 395 public boolean areShareClientModes() 396 { 397 return (state & (STATE_SHARE_CLIENT | STATE_SHARE_PRECLIENT)) != 0; 398 } 399 400 public boolean isSharePreClient() 401 { 402 return (state & STATE_SHARE_PRECLIENT) != 0; 403 } 404 405 public void setShareClient(boolean shareClient) 406 { 407 if (shareClient) state |= STATE_SHARE_CLIENT; 408 else state &= ~STATE_SHARE_CLIENT; 409 } 410 411 public void setSharePreClient(boolean sharePreClient) 412 { 413 if (sharePreClient) state |= STATE_SHARE_PRECLIENT; 414 else state &= ~STATE_SHARE_PRECLIENT; 415 } 416 417 public boolean isInSharing() 418 { 419 return (state & (STATE_SHARE_MANAGER | STATE_SHARE_CLIENT | STATE_SHARE_PRECLIENT)) != 0; 420 } 421 422 public boolean isInMemory() 423 { 424 return inMemory; 425 } 426 427 public void setInMemoryFlag(boolean inMemory) 428 { 429 this.inMemory = inMemory; 430 } 431 432 } 433 | Popular Tags |