1 23 24 package org.apache.slide.store.txfile; 25 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.OutputStream ; 29 import java.lang.reflect.Constructor ; 30 import java.text.SimpleDateFormat ; 31 import java.util.Date ; 32 import java.util.Enumeration ; 33 import java.util.Hashtable ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import java.util.Vector ; 37 38 import org.apache.slide.common.*; 39 import org.apache.slide.lock.LockTokenNotFoundException; 40 import org.apache.slide.lock.NodeLock; 41 import org.apache.slide.security.NodePermission; 42 import org.apache.slide.structure.*; 43 import org.apache.slide.content.*; 44 45 import org.jdom.*; 46 import org.jdom.input.*; 47 import org.jdom.output.*; 48 49 57 public abstract class AbstractXMLResourceDescriptor { 58 59 protected final Format outputFormat; 60 protected Object txId; 61 protected String uri; 62 protected SimpleDateFormat dateFormat; 63 protected boolean registeredForSaving = false; 64 65 66 protected ObjectNode object; 67 68 69 protected Vector permissions; 70 71 72 protected Vector locks; 73 74 75 protected NodeRevisionDescriptors revisionDescriptors; 76 77 78 protected Hashtable descriptor; 79 80 81 protected static String booleanToString(boolean aBoolean) { 82 return aBoolean ? "true" : "false"; 83 } 84 85 protected static Element createBindings(String aParent, String aChild, Enumeration aEnum) { 86 Element aElement = new Element(aParent); 87 Element childNode; 88 ObjectNode.Binding binding; 89 while (aEnum.hasMoreElements()) { 90 binding = (ObjectNode.Binding) aEnum.nextElement(); 91 childNode = new Element(aChild); 92 childNode.setAttribute(new Attribute("name", binding.getName())); 93 childNode.setAttribute(new Attribute("uuri", binding.getUuri())); 94 aElement.addContent(childNode); 95 } 96 return aElement; 97 } 98 99 protected static Element createElements(String aParent, String aChild, Enumeration aEnum) { 100 Element aElement = new Element(aParent); 101 while (aEnum.hasMoreElements()) { 102 Object aObject = aEnum.nextElement(); 103 Element aItem = new Element(aChild); 104 aItem.setAttribute("val", aObject.toString()); 105 aElement.addContent(aItem); 106 } 107 return aElement; 108 } 109 110 protected static NodePermission decodePermission(Element aElement, String aUri) { 111 String aRevisionNumber = aElement.getAttributeValue("revisionNumber"); 112 String aSubject = aElement.getAttributeValue("subjectUri"); 113 String aAction = aElement.getAttributeValue("actionUri"); 114 boolean aInheritable = new Boolean (aElement.getAttributeValue("inheritable")).booleanValue(); 115 boolean aNegative = new Boolean (aElement.getAttributeValue("negative")).booleanValue(); 116 return new NodePermission(aUri, aRevisionNumber, aSubject, aAction, aInheritable, aNegative); 117 118 } 119 120 protected static Element encodeNodePermission(NodePermission aPermission) { 121 Element aElementPermission = new Element("permission"); 122 NodeRevisionNumber aRevisionNumber = aPermission.getRevisionNumber(); 123 if (aRevisionNumber != null) { 124 aElementPermission.setAttribute("revisionNumber", encodeRevisionNumber(aRevisionNumber)); 125 } 126 aElementPermission.setAttribute("subjectUri", aPermission.getSubjectUri()); 127 aElementPermission.setAttribute("actionUri", aPermission.getActionUri()); 128 aElementPermission.setAttribute("inheritable", booleanToString(aPermission.isInheritable())); 129 aElementPermission.setAttribute("negative", booleanToString(aPermission.isNegative())); 130 return aElementPermission; 131 } 132 133 protected static Element encodeRevisionDescriptor(NodeRevisionDescriptor aDescriptor) { 134 Element aRevisions = new Element("revisions"); 135 aRevisions.setAttribute("branchName", aDescriptor.getBranchName()); 136 aRevisions.setAttribute("number", encodeRevisionNumber(aDescriptor.getRevisionNumber())); 137 aRevisions.addContent(createElements("labels", "label", aDescriptor.enumerateLabels())); 138 Element aProperties = new Element("properties"); 139 140 for (Enumeration aEnum = aDescriptor.enumerateProperties(); aEnum.hasMoreElements();) { 141 Object aObject = aEnum.nextElement(); 142 NodeProperty aProp = (NodeProperty) aObject; 144 aProperties.addContent(encodeNodeProperty(aProp)); 145 } 146 aRevisions.addContent(aProperties); 147 return aRevisions; 148 } 149 150 protected static Element encodeNodeProperty(NodeProperty aProp) { 151 Element aElement = new Element("property"); 152 aElement.setAttribute("name", aProp.getName()); 153 aElement.setAttribute("namespace", aProp.getNamespace()); 154 aElement.setAttribute("value", aProp.getValue().toString()); 155 aElement.setAttribute("type", aProp.getType()); 156 aElement.setAttribute("protected", booleanToString(aProp.isProtected())); 157 Element aPermissions = new Element("permissions"); 158 159 for (Enumeration aEnum = aProp.enumeratePermissions(); aEnum.hasMoreElements();) { 160 NodePermission aPermission = (NodePermission) aEnum.nextElement(); 161 aPermissions.addContent(encodeNodePermission(aPermission)); 162 } 163 aElement.addContent(aPermissions); 164 return aElement; 165 } 166 167 protected static Vector createVector(Element aElement, String aParentName, String aChildName) { 168 Element aParent = aElement.getChild(aParentName); 169 Vector aRet = new Vector (); 170 List aList = aParent.getChildren(aChildName); 172 for (int i = 0; i < aList.size(); i++) { 174 Element aChild = (Element) aList.get(i); 175 aRet.addElement(aChild.getAttributeValue("val")); 176 } 177 return aRet; 178 } 179 180 protected static Vector createBindingVector( 181 Element aElement, 182 String aParentName, 183 String aChildName, 184 boolean parentBindings) { 185 Element aParent = aElement.getChild(aParentName); 186 Vector aRet = new Vector (); 187 Iterator it = aParent.getChildren().iterator(); 189 while (it.hasNext()) { 190 Element aChild = (Element) it.next(); 191 String name = aChild.getAttributeValue("name"); 192 String uuri = aChild.getAttributeValue("uuri"); 193 if (parentBindings) { 194 aRet.add(new ObjectNode.ParentBinding(name, uuri)); 195 } else { 196 aRet.add(new ObjectNode.Binding(name, uuri)); 197 } 198 } 199 return aRet; 200 } 201 202 protected static String encodeRevisionNumber(NodeRevisionNumber aRevisionNumber) { 203 return aRevisionNumber.getMajor() + "." + aRevisionNumber.getMinor(); 204 } 205 206 protected static Object createObject(String aNomClasse, Class aTypes[], Object aArgs[]) 207 throws UnknownObjectClassException { 208 Class aClasse = null; 209 try { 210 aClasse = Class.forName(aNomClasse); 212 Constructor aConstructor = aClasse.getConstructor(aTypes); 213 if (aConstructor == null) 214 aConstructor = aClasse.getSuperclass().getConstructor(aTypes); 215 return aConstructor.newInstance(aArgs); 216 217 } catch (Exception e) { 218 throw new UnknownObjectClassException(aNomClasse); 219 } 220 } 221 222 protected static NodeRevisionNumber decodeRevisionNumber(Element aElement) { 223 Element aElementRevision = aElement.getChild("revision"); 224 return new NodeRevisionNumber( 225 Integer.parseInt(aElementRevision.getAttributeValue("major")), 226 Integer.parseInt(aElementRevision.getAttributeValue("minor"))); 227 } 228 229 protected static NodeRevisionNumber decodeRevisionNumber(String aStr) { 230 return (aStr == null ? null : new NodeRevisionNumber(aStr)); 231 } 232 233 protected static NodeProperty decodeNodeProperty(Element aElement, String aUri) { 234 String aName = aElement.getAttributeValue("name"); 235 String aValue = aElement.getAttributeValue("value"); 236 String aNamespace = aElement.getAttributeValue("namespace"); 237 String aType = aElement.getAttributeValue("type"); 238 boolean aProtected = new Boolean (aElement.getAttributeValue("protected")).booleanValue(); 239 240 Element aPermisionsElement = aElement.getChild("permissions"); 241 List aList = aPermisionsElement.getChildren(); 242 Vector aPermission = new Vector (); 243 for (int i = 0; i < aList.size(); i++) { 244 Element aChild = (Element) aList.get(i); 245 aPermission.addElement(decodePermission(aChild, aUri)); 246 } 247 return new NodeProperty(aName, aValue, aNamespace, aType, aProtected); 248 } 249 250 258 public AbstractXMLResourceDescriptor( 259 Uri uri, 260 Object txId, 261 String characterEncoding) 262 throws ServiceAccessException { 263 264 outputFormat = Format.getPrettyFormat(); 265 outputFormat.setEncoding(characterEncoding); 266 267 dateFormat = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss z"); 268 269 this.txId = txId; 270 271 if (uri == null) { 272 throw new ServiceAccessException(null, "Trying to initialize XMLResourceDescriptor with null URI"); 273 } 274 this.uri = uri.toString(); 275 } 276 277 279 285 public ObjectNode retrieveObject() throws ServiceAccessException, ObjectNotFoundException { 286 if (object == null) { 287 throw new ObjectNotFoundException(uri); 288 } 289 return object.cloneObject(); 290 } 291 292 299 public void storeObject(ObjectNode aObject) throws ServiceAccessException, ObjectNotFoundException { 300 object = aObject.cloneObject(); 301 } 302 303 310 public void removeObject(ObjectNode aObject) throws ServiceAccessException, ObjectNotFoundException { 311 object = null; 312 } 313 314 320 public void grantPermission(NodePermission permission) throws ObjectNotFoundException, ServiceAccessException { 321 if (permissions == null) 322 permissions = new Vector (); 323 permissions.addElement(permission.cloneObject()); 324 } 325 326 332 public void revokePermission(NodePermission permission) throws ObjectNotFoundException, ServiceAccessException { 333 if (permissions != null) 334 permissions.removeElement(permission); 335 } 336 337 343 public void revokePermissions() throws ObjectNotFoundException, ServiceAccessException { 344 if (permissions != null) 345 permissions.removeAllElements(); 346 } 347 348 354 public Enumeration enumeratePermissions() throws ServiceAccessException { 355 if (permissions == null) 356 permissions = new Vector (); 357 return permissions.elements(); 358 } 359 360 366 public void putLock(NodeLock lock) throws ObjectNotFoundException, ServiceAccessException { 367 if (locks == null) 368 locks = new Vector (); 369 locks.addElement(lock.cloneObject()); 370 } 371 372 379 public void renewLock(NodeLock lock) throws LockTokenNotFoundException, ObjectNotFoundException, ServiceAccessException { 380 if (locks == null) 381 locks = new Vector (); 382 boolean wasPresent = locks.removeElement(lock); 383 if (!wasPresent) { 384 throw new LockTokenNotFoundException(lock); 385 } 386 locks.addElement(lock.cloneObject()); 387 } 388 389 396 public void removeLock(NodeLock lock) throws LockTokenNotFoundException, ObjectNotFoundException, ServiceAccessException { 397 398 if (locks == null) { 399 throw new LockTokenNotFoundException(lock); 400 } 401 boolean wasPresent = locks.removeElement(lock); 402 if (!wasPresent) { 403 throw new LockTokenNotFoundException(lock); 404 } 405 } 406 407 414 public Enumeration enumerateLocks() throws ServiceAccessException { 415 if (locks == null) 416 locks = new Vector (); 417 return locks.elements(); 418 } 419 420 427 public NodeRevisionDescriptors retrieveRevisionDescriptors() 428 throws ServiceAccessException, RevisionDescriptorNotFoundException { 429 if (revisionDescriptors == null) { 430 throw new RevisionDescriptorNotFoundException(uri.toString()); 431 } 432 return revisionDescriptors.cloneObject(); 433 } 434 435 441 public void createRevisionDescriptors(NodeRevisionDescriptors aRevisionDescriptors) 442 throws ObjectNotFoundException, ServiceAccessException { 443 revisionDescriptors = aRevisionDescriptors.cloneObject(); 444 } 445 446 454 public void storeRevisionDescriptors(NodeRevisionDescriptors aRevisionDescriptors) 455 throws RevisionDescriptorNotFoundException, ObjectNotFoundException, ServiceAccessException { 456 if (!revisionDescriptors.getUri().equals(uri.toString())) { 457 throw new RevisionDescriptorNotFoundException(uri.toString()); 458 } 459 revisionDescriptors = aRevisionDescriptors.cloneObject(); 460 } 461 462 467 public void removeRevisionDescriptors() throws ObjectNotFoundException, ServiceAccessException { 468 revisionDescriptors = null; 469 } 470 471 476 public NodeRevisionDescriptor retrieveRevisionDescriptor(NodeRevisionNumber revisionNumber) 477 throws ServiceAccessException, RevisionDescriptorNotFoundException { 478 Object result = null; 479 480 if (descriptor != null && revisionNumber != null) 481 result = descriptor.get(revisionNumber.toString()); 482 483 if (result == null) { 484 throw new RevisionDescriptorNotFoundException(uri.toString()); 485 } 486 return ((NodeRevisionDescriptor) result).cloneObject(); 487 } 488 489 495 public void createRevisionDescriptor(NodeRevisionDescriptor aRevisionDescriptor) 496 throws ObjectNotFoundException, ServiceAccessException { 497 if (descriptor == null) 498 descriptor = new Hashtable (); 499 500 descriptor.put(aRevisionDescriptor.getRevisionNumber().toString(), aRevisionDescriptor.cloneObject()); 501 } 502 503 511 public void storeRevisionDescriptor(NodeRevisionDescriptor aRevisionDescriptor) 512 throws RevisionDescriptorNotFoundException, ObjectNotFoundException, ServiceAccessException { 513 String key = aRevisionDescriptor.getRevisionNumber().toString(); 514 if (descriptor == null || !descriptor.containsKey(key)) { 515 throw new RevisionDescriptorNotFoundException(uri.toString()); 516 } 517 descriptor.put(key, aRevisionDescriptor.cloneObject()); 518 } 519 520 526 public void removeRevisionDescriptor(NodeRevisionNumber number) throws ObjectNotFoundException, ServiceAccessException { 527 if (descriptor == null) 528 return; 529 530 descriptor.remove(number.toString()); 531 } 532 533 535 public void registerForSaving() { 536 registeredForSaving = true; 537 } 538 539 public boolean isRegisteredForSaving() { 540 return registeredForSaving; 541 } 542 543 549 public abstract void save() throws ServiceAccessException, ObjectNotFoundException; 550 551 557 public abstract void load() throws ServiceAccessException, ObjectNotFoundException; 558 559 565 public abstract void create() throws ServiceAccessException, ObjectAlreadyExistsException; 566 567 573 public abstract void delete() throws ServiceAccessException, ObjectNotFoundException; 574 575 580 public String getUri() { 581 return uri; 582 } 583 584 589 public Object getTxId() { 590 return txId; 591 } 592 593 600 public boolean equals(Object o) { 601 return ( 602 this == o 603 || (o != null 604 && o instanceof XMLResourceDescriptor 605 && ((XMLResourceDescriptor) o).uri.equals(uri) 606 && ((XMLResourceDescriptor) o).txId.equals(txId))); 607 } 608 609 public String toString() { 610 return txId + ": " + uri; 611 } 612 613 protected void save(OutputStream os) throws ServiceAccessException, IOException { 614 Element aRoot = encode(); 615 Document aDocument = new Document(aRoot); 616 617 XMLOutputter aOutputter = new XMLOutputter(outputFormat); 618 aOutputter.output(aDocument, os); 619 os.flush(); 620 } 621 622 protected void load(InputStream is) throws ServiceAccessException, JDOMException, IOException { 623 SAXBuilder aBuilder = new SAXBuilder(); 624 Document aDocument = aBuilder.build(is); 625 decode(aDocument.getRootElement()); 626 } 627 628 protected void init() throws ServiceAccessException { 629 object = null; 631 permissions = new Vector (); 632 locks = new Vector (); 633 revisionDescriptors = 634 new NodeRevisionDescriptors(uri, null, new Hashtable (), new Hashtable (), new Hashtable (), false); 635 636 descriptor = new Hashtable (); 637 } 638 639 protected Element encode() throws ServiceAccessException { 640 Element aRoot = new Element("data"); 641 aRoot.addContent(encodeObject()); 642 aRoot.addContent(encodePermissions()); 643 aRoot.addContent(encodeLocks()); 644 aRoot.addContent(encodeRevisionDescriptors()); 645 aRoot.addContent(encodeRevisionDescriptor()); 646 return aRoot; 647 } 648 649 protected Element encodeObject() { 650 Element aElementObjectNode = new Element("objectnode"); 651 if (object != null) { 652 aElementObjectNode.setAttribute("classname", object.getClass().getName()); 653 aElementObjectNode.setAttribute("uri", object.getUri()); 654 if (object instanceof LinkNode) { 655 aElementObjectNode.setAttribute("linkTo", ((LinkNode) object).getLinkedUri()); 656 } 657 aElementObjectNode.addContent(createBindings("children", "child", object.enumerateBindings())); 658 aElementObjectNode.addContent(createBindings("parents", "parent", object.enumerateParentBindings())); 659 aElementObjectNode.addContent(createElements("links", "link", object.enumerateLinks())); 660 } else { 661 aElementObjectNode.setAttribute("classname", "null"); 663 aElementObjectNode.setAttribute("uri", uri.toString()); 664 } 665 return aElementObjectNode; 666 } 667 668 protected Element encodePermissions() { 669 Element aPermissions = new Element("permissions"); 670 if (permissions == null) 671 return aPermissions; 672 673 for (int aSize = permissions.size(), i = 0; i < aSize; i++) { 674 NodePermission aPermission = (NodePermission) permissions.elementAt(i); 675 aPermissions.addContent(encodeNodePermission(aPermission)); 676 } 677 return aPermissions; 678 } 679 680 protected Element encodeLocks() { 681 Element aElementLocks = new Element("locks"); 682 if (locks == null) 683 return aElementLocks; 684 685 for (int aSize = locks.size(), i = 0; i < aSize; i++) { 686 NodeLock aLock = (NodeLock) locks.elementAt(i); 687 Element aElementLock = new Element("lock"); 688 aElementLock.setAttribute("subjectUri", aLock.getSubjectUri()); 689 aElementLock.setAttribute("typeUri", aLock.getTypeUri()); 690 aElementLock.setAttribute("date", dateFormat.format(aLock.getExpirationDate())); 691 aElementLock.setAttribute("inheritance", booleanToString(aLock.isInheritable())); 692 aElementLock.setAttribute("exclusive", booleanToString(aLock.isExclusive())); 693 aElementLock.setAttribute("lockId", aLock.getLockId()); 694 aElementLock.setAttribute("owner", 695 aLock.getOwnerInfo() == null ? "" : aLock.getOwnerInfo()); 696 aElementLocks.addContent(aElementLock); 697 } 698 return aElementLocks; 699 } 700 701 protected Element encodeRevisionDescriptors() { 702 703 Element aRevisionsHistory = new Element("revisionsHistory"); 704 if (revisionDescriptors == null) 705 return aRevisionsHistory; 706 707 aRevisionsHistory.setAttribute( 708 "initialRevision", 709 encodeRevisionNumber(revisionDescriptors.getInitialRevision())); 710 aRevisionsHistory.setAttribute("useVersioning", booleanToString(revisionDescriptors.isVersioned())); 711 712 715 Element aBranchesElement = new Element("branches"); 716 Enumeration aBranches = revisionDescriptors.enumerateBranchNames(); 717 while (aBranches.hasMoreElements()) { 718 String aBranchName = (String ) aBranches.nextElement(); 719 Element aElementBranch = new Element("branch"); 720 aElementBranch.setAttribute("name", aBranchName); 721 NodeRevisionNumber aRevisionNumber = revisionDescriptors.getLatestRevision(aBranchName); 722 aElementBranch.setAttribute("lastestRevision", encodeRevisionNumber(aRevisionNumber)); 723 aBranchesElement.addContent(aElementBranch); 724 } 725 aRevisionsHistory.addContent(aBranchesElement); 726 727 Element aRevisionsElement = new Element("revisions"); 728 Enumeration aRevisions = revisionDescriptors.enumerateRevisionNumbers(); 729 while (aRevisions.hasMoreElements()) { 730 NodeRevisionNumber aRevisionNumber = (NodeRevisionNumber) aRevisions.nextElement(); 731 Element aRevisionElement = new Element("branch"); 732 aRevisionElement.setAttribute("start", encodeRevisionNumber(aRevisionNumber)); 733 734 Enumeration aSuccessors = revisionDescriptors.getSuccessors(aRevisionNumber); 735 while (aSuccessors.hasMoreElements()) { 736 NodeRevisionNumber aSuccessorRevisionNumber = (NodeRevisionNumber) aSuccessors.nextElement(); 737 Element aSuccessorRevisionElement = new Element("revision"); 738 aSuccessorRevisionElement.setAttribute("number", encodeRevisionNumber(aSuccessorRevisionNumber)); 739 aRevisionElement.addContent(aSuccessorRevisionElement); 740 } 741 aRevisionsElement.addContent(aRevisionElement); 742 } 743 aRevisionsHistory.addContent(aRevisionsElement); 744 745 return aRevisionsHistory; 746 } 747 748 protected Element encodeRevisionDescriptor() { 749 Element aRet = new Element("descriptor"); 750 if (descriptor == null) 751 return aRet; 752 753 for (Enumeration aEnum = descriptor.elements(); aEnum.hasMoreElements();) { 754 NodeRevisionDescriptor aRevisionDescriptor = (NodeRevisionDescriptor) aEnum.nextElement(); 755 aRet.addContent(encodeRevisionDescriptor(aRevisionDescriptor)); 756 } 757 return aRet; 758 } 759 760 protected void decode(Element aRoot) throws ServiceAccessException { 761 decodeObject(aRoot); 762 decodePermissions(aRoot); 763 decodeLocks(aRoot); 764 decodeRevisionDescriptors(aRoot); 765 decodeRevisionDescriptor(aRoot); 766 } 767 768 protected void decodeObject(Element aElement) throws ServiceAccessException { 769 Element aElementObjectNode = aElement.getChild("objectnode"); 770 String aClasseName = aElementObjectNode.getAttributeValue("classname"); 771 if (!"null".equals(aClasseName)) { 772 try { 773 String aUri = aElementObjectNode.getAttributeValue("uri"); 774 Vector aChilds = createBindingVector(aElementObjectNode, "children", "child", false); 775 Vector aParents = createBindingVector(aElementObjectNode, "parents", "parent", true); 776 Vector aLinks = createVector(aElementObjectNode, "links", "link"); 777 Class aTypes[] = null; 780 Object aArgs[] = null; 781 782 if (aClasseName.equals(LinkNode.class.getName())) { 783 String aLinkTo = aElementObjectNode.getAttributeValue("linkTo"); 784 aTypes = new Class [] { String .class, Vector .class, Vector .class, String .class }; 785 aArgs = new Object [] { aUri, aChilds, aLinks, aLinkTo }; 786 } else { 787 aTypes = new Class [] { String .class, Vector .class, Vector .class, Vector .class }; 788 aArgs = new Object [] { aUri, aChilds, aParents, aLinks }; 789 } 790 object = (ObjectNode) createObject(aClasseName, aTypes, aArgs); 791 object.setUri(object.getUuri()); 792 } catch (Exception e) { 793 e.printStackTrace(); 794 throw new ServiceAccessException(null, e); 795 } 796 uri = object.getUri(); 797 } else { 798 object = null; 799 uri = aElementObjectNode.getAttributeValue("uri"); 800 } 801 } 802 803 protected void decodePermissions(Element aElement) { 804 permissions = new Vector (); 805 Element aPermissions = aElement.getChild("permissions"); 806 List aList = aPermissions.getChildren(); 807 for (int i = 0; i < aList.size(); i++) { 808 Element aChild = (Element) aList.get(i); 809 permissions.addElement(decodePermission(aChild, uri)); 810 } 811 } 812 813 protected void decodeLocks(Element aElement) throws ServiceAccessException { 814 try { 815 locks = new Vector (); 816 Element aElementLocks = aElement.getChild("locks"); 817 List aList = aElementLocks.getChildren(); 818 819 for (int i = 0; i < aList.size(); i++) { 820 Element aChild = (Element) aList.get(i); 821 String aSubject = aChild.getAttributeValue("subjectUri"); 822 String aType = aChild.getAttributeValue("typeUri"); 823 Date aDateExpiration = dateFormat.parse(aChild.getAttributeValue("date")); 824 boolean aInheritable = new Boolean (aChild.getAttributeValue("inheritance")).booleanValue(); 825 boolean aNegative = new Boolean (aChild.getAttributeValue("exclusive")).booleanValue(); 826 String aLockId = aChild.getAttributeValue("lockId"); 827 String ownerInfo = aChild.getAttributeValue("owner"); 828 829 locks.addElement( 830 new NodeLock(aLockId, uri, aSubject, aType, aDateExpiration, aInheritable, aNegative, ownerInfo)); 831 } 832 } catch (Exception e) { 833 e.printStackTrace(); 834 throw new ServiceAccessException(null, e); 835 } 836 837 } 838 839 protected void decodeRevisionDescriptors(Element aElement) { 840 Element aRevisionsHistory = aElement.getChild("revisionsHistory"); 841 842 NodeRevisionNumber aInitialRevision = 843 decodeRevisionNumber(aRevisionsHistory.getAttributeValue("initialRevision")); 844 boolean aUseVersionning = new Boolean (aRevisionsHistory.getAttributeValue("useVersioning")).booleanValue(); 845 846 Element aBranchesElement = aRevisionsHistory.getChild("branches"); 847 if (aBranchesElement == null) { 848 revisionDescriptors = 849 new NodeRevisionDescriptors( 850 uri, 851 aInitialRevision, 852 new Hashtable (), 853 new Hashtable (), 854 new Hashtable (), 855 aUseVersionning); 856 return; 857 } 858 859 List aList = aBranchesElement.getChildren(); 860 Hashtable aLastestRevisions = new Hashtable (); 861 for (int i = 0; i < aList.size(); i++) { 862 Element aChild = (Element) aList.get(i); 863 String aName = aChild.getAttributeValue("name"); 864 NodeRevisionNumber aRevisionNumber = decodeRevisionNumber(aChild.getAttributeValue("lastestRevision")); 865 aLastestRevisions.put(aName, aRevisionNumber); 866 } 867 Hashtable aBranches = new Hashtable (); 868 Element aRevisionsElement = aRevisionsHistory.getChild("revisions"); 869 aList = aRevisionsElement.getChildren(); 870 for (int i = 0; i < aList.size(); i++) { 871 Element aChild = (Element) aList.get(i); 872 NodeRevisionNumber aStartNumber = decodeRevisionNumber(aChild.getAttributeValue("start")); 873 List aSuccessors = aChild.getChildren(); 874 Vector aSuccessorsNumbers = new Vector (); 875 for (int k = 0; k < aSuccessors.size(); k++) { 876 Element aSuccessor = (Element) aSuccessors.get(k); 877 NodeRevisionNumber aRevisionNumber = decodeRevisionNumber(aSuccessor.getAttributeValue("number")); 878 aSuccessorsNumbers.addElement(aRevisionNumber); 879 } 880 aBranches.put(aStartNumber, aSuccessorsNumbers); 881 } 882 revisionDescriptors = 883 new NodeRevisionDescriptors( 884 uri, 885 aInitialRevision, 886 new Hashtable (), 887 aLastestRevisions, 888 aBranches, 889 aUseVersionning); 890 } 891 892 protected void decodeRevisionDescriptor(Element aParent) { 893 descriptor = new Hashtable (); 894 895 Element aElement = aParent.getChild("descriptor"); 896 if (aElement == null) 897 return; 898 899 List aList = aElement.getChildren(); 900 901 for (int i = 0; i < aList.size(); i++) { 902 Element aChild = (Element) aList.get(i); 903 String aBranchName = aChild.getAttributeValue("branchName"); 904 NodeRevisionNumber aRevisionNumber = decodeRevisionNumber(aChild.getAttributeValue("number")); 905 906 Vector aLabels = new Vector (); 907 Element aLabelsElement = (Element) aChild.getChild("labels"); 908 List aLabelList = aLabelsElement.getChildren(); 909 for (int k = 0; k < aLabelList.size(); k++) { 910 Element aLabel = (Element) aLabelList.get(k); 911 aLabels.addElement(aLabel.getAttributeValue("val")); 912 } 913 914 Hashtable aProperties = new Hashtable (); 915 Element aPropertiesElement = (Element) aChild.getChild("properties"); 916 List aPropertiesList = aPropertiesElement.getChildren(); 917 for (int k = 0; k < aPropertiesList.size(); k++) { 918 Element aProperty = (Element) aPropertiesList.get(k); 919 NodeProperty aProp = decodeNodeProperty(aProperty, uri); 920 String key = aProperty.getAttributeValue("namespace") + aProperty.getAttributeValue("name"); 921 aProperties.put(key, aProp); 922 } 923 NodeRevisionDescriptor aNode = 924 new NodeRevisionDescriptor(aRevisionNumber, aBranchName, aLabels, aProperties); 925 descriptor.put(aRevisionNumber.toString(), aNode); 926 } 927 } 928 929 } 930 | Popular Tags |