1 23 24 package org.apache.slide.content; 25 26 import java.io.Serializable ; 27 import java.util.Enumeration ; 28 import java.util.Hashtable ; 29 import java.util.Vector ; 30 31 import org.apache.slide.common.ObjectValidationFailedException; 32 import org.apache.slide.util.Messages; 33 34 39 public final class NodeRevisionDescriptors implements Serializable , Cloneable { 40 41 42 44 45 public static final String MAIN_BRANCH = "main"; 46 47 48 protected static final NodeRevisionNumber initialRevision 49 = new NodeRevisionNumber(); 50 51 52 54 55 58 public NodeRevisionDescriptors() { 59 this.latestRevisionNumbers = new Hashtable (); 60 this.branches = new Hashtable (); 61 this.workingRevisions = new Hashtable (); 62 this.useVersioning = false; 63 } 64 65 66 69 public NodeRevisionDescriptors(boolean isVersioned) { 70 this.latestRevisionNumbers = new Hashtable (); 71 this.branches = new Hashtable (); 72 this.workingRevisions = new Hashtable (); 73 this.useVersioning = isVersioned; 74 } 75 76 77 80 public NodeRevisionDescriptors(String uri, 81 NodeRevisionNumber initialRevision, 82 Hashtable workingRevisions, 83 Hashtable latestRevisionNumbers, 84 Hashtable branches, boolean isVersioned) { 85 this.uri = uri; 86 this.latestRevisionNumbers = latestRevisionNumbers; 87 this.branches = branches; 88 this.workingRevisions = workingRevisions; 89 this.useVersioning = isVersioned; 90 } 91 92 93 95 96 99 private boolean useVersioning; 100 101 102 105 private String uri; 106 107 108 111 private String originalUri; 112 113 114 119 private Hashtable workingRevisions; 120 121 122 125 private Hashtable latestRevisionNumbers; 126 127 128 131 private Hashtable branches; 132 133 134 136 137 140 public boolean isVersioned() { 141 return this.useVersioning; 142 } 143 144 145 148 void setVersioned(boolean useVersioning) { 149 this.useVersioning = useVersioning; 150 } 151 152 153 156 public boolean hasRevisions() { 157 return !(this.latestRevisionNumbers.isEmpty()); 158 } 159 160 161 164 public String getUri() { 165 return this.uri; 166 } 167 168 169 172 public String getOriginalUri() { 173 if( this.originalUri != null ) 174 return this.originalUri; 175 else 176 return this.uri; 177 } 178 179 180 183 void setOriginalUri( String originalUri ) { 184 this.originalUri = originalUri; 185 } 186 187 188 191 public void setUri(String uri) { 192 this.uri = uri; 193 } 194 195 196 199 public NodeRevisionNumber getInitialRevision() { 200 return NodeRevisionDescriptors.initialRevision; 201 } 202 203 204 207 public NodeRevisionNumber getLatestRevision() { 208 return getLatestRevision(MAIN_BRANCH); 209 } 210 211 212 215 public NodeRevisionNumber getLatestRevision(String branchName) { 216 Object number = null; 217 number = this.latestRevisionNumbers.get(branchName); 218 if (number != null) { 219 return (NodeRevisionNumber) number; 220 } else { 221 return null; 222 } 223 } 224 225 226 229 void setLatestRevision(NodeRevisionNumber number) { 230 this.latestRevisionNumbers.put(MAIN_BRANCH, number); 231 } 232 233 234 237 void setLatestRevision(String branch, NodeRevisionNumber number) { 238 this.latestRevisionNumbers.put(branch, number); 239 } 240 241 242 244 245 248 public Enumeration getSuccessors(NodeRevisionNumber number) { 249 Object result = this.branches.get(number); 250 if (result != null) { 251 return ((Vector ) result).elements(); 252 } else { 253 return null; 254 } 255 } 256 257 261 public boolean isAncestorDescendant( NodeRevisionNumber ancNrn, NodeRevisionNumber descNrn ) { 262 263 if( ancNrn.equals(descNrn) ) 264 return true; 265 266 Enumeration ancSuccs = getSuccessors( ancNrn ); 267 while( ancSuccs != null && ancSuccs.hasMoreElements() ) { 268 NodeRevisionNumber ancSuccNrn = (NodeRevisionNumber)ancSuccs.nextElement(); 269 if( isAncestorDescendant(ancSuccNrn, descNrn) ) 270 return true; 271 } 272 273 return false; 274 } 275 278 public boolean isRedirected() { 279 return( !uri.equals(originalUri) ); 280 } 281 282 284 285 288 void setSuccessors(NodeRevisionNumber number, 289 NodeRevisionNumber successor) { 290 Vector tempVector = new Vector (); 291 tempVector.addElement(successor); 292 setSuccessors(number, tempVector); 293 } 294 295 296 299 void setSuccessors(NodeRevisionNumber number, Vector successors) { 300 this.branches.put(number, successors); 301 } 302 303 304 307 void addSuccessor(NodeRevisionNumber number, 308 NodeRevisionNumber successor) { 309 Object result = this.branches.get(number); 310 if (result != null) { 311 ((Vector ) result).addElement(successor); 312 } else { 313 setSuccessors(number, successor); 314 } 315 } 316 317 318 321 void removeSuccessor(NodeRevisionNumber number, 322 NodeRevisionNumber successor) { 323 Object result = this.branches.get(number); 324 if (result != null) { 325 ((Vector ) result).removeElement(successor); 326 } 327 } 328 329 330 333 public Enumeration enumerateRevisionNumbers() { 334 return this.branches.keys(); 335 } 336 337 338 341 public Enumeration enumerateBranchNames() { 342 return this.latestRevisionNumbers.keys(); 343 } 344 345 346 347 348 349 351 352 357 public NodeRevisionDescriptors cloneObject() { 358 NodeRevisionDescriptors result = null; 359 try { 360 result = (NodeRevisionDescriptors) super.clone(); 361 Hashtable branchesClone = new Hashtable (); 364 Enumeration branchesList = this.branches.keys(); 365 while (branchesList.hasMoreElements()) { 366 Object key = branchesList.nextElement(); 367 Vector value = (Vector ) this.branches.get(key); 368 branchesClone.put(key, value.clone()); 369 } 370 result.branches = branchesClone; 371 result.latestRevisionNumbers = 373 (Hashtable ) this.latestRevisionNumbers.clone(); 374 } catch(CloneNotSupportedException e) { 375 e.printStackTrace(); 376 } 377 return result; 378 } 379 380 381 389 public boolean equals(Object obj) { 390 boolean result = false; 391 if ((obj != null) && (obj instanceof NodeRevisionDescriptors)) { 392 NodeRevisionDescriptors revisionDescriptors = 393 (NodeRevisionDescriptors) obj; 394 result = this.getUri().equals(revisionDescriptors.getUri()); 395 } 396 return result; 397 } 398 399 400 403 public void validate(String expectedUri) { 404 405 if (uri == null) 406 throw new ObjectValidationFailedException 407 (expectedUri, Messages.message 408 (NodeRevisionDescriptors.class.getName() + ".nullUri")); 409 410 if (!(uri.equals(expectedUri) || uri.equals(expectedUri + "/"))) { 411 System.out.println("Uri1 : " + uri + " Uri2 : " + expectedUri); 412 } 416 417 if (workingRevisions == null) 418 throw new ObjectValidationFailedException 419 (uri, Messages.message 420 (NodeRevisionDescriptors.class.getName() 421 + ".nullWorkingRevisions")); 422 423 if (latestRevisionNumbers == null) 424 throw new ObjectValidationFailedException 425 (uri, Messages.message 426 (NodeRevisionDescriptors.class.getName() 427 + ".nullLatestRevisionNumbers")); 428 429 if (branches == null) 430 throw new ObjectValidationFailedException 431 (uri, Messages.message 432 (NodeRevisionDescriptors.class.getName() 433 + ".nullBranches")); 434 435 437 } 438 439 440 } 441 442 | Popular Tags |