1 17 package org.alfresco.repo.domain.hibernate; 18 19 import org.alfresco.repo.domain.ChildAssoc; 20 import org.alfresco.repo.domain.Node; 21 import org.alfresco.service.cmr.repository.ChildAssociationRef; 22 import org.alfresco.service.namespace.QName; 23 import org.alfresco.util.EqualsHelper; 24 25 28 public class ChildAssocImpl implements ChildAssoc 29 { 30 private Long id; 31 private Node parent; 32 private Node child; 33 private QName typeQName; 34 private QName qName; 35 private boolean isPrimary; 36 private int index; 37 private transient ChildAssociationRef childAssocRef; 38 39 public ChildAssocImpl() 40 { 41 setIndex(Integer.MAX_VALUE); } 43 44 public void buildAssociation(Node parentNode, Node childNode) 45 { 46 this.setParent(parentNode); 48 this.setChild(childNode); 49 parentNode.getChildAssocs().add(this); 51 childNode.getParentAssocs().add(this); 52 } 53 54 public void removeAssociation() 55 { 56 this.getParent().getChildAssocs().remove(this); 58 this.getChild().getParentAssocs().remove(this); 60 } 61 62 public synchronized ChildAssociationRef getChildAssocRef() 63 { 64 if (childAssocRef == null) 65 { 66 childAssocRef = new ChildAssociationRef( 67 this.typeQName, 68 getParent().getNodeRef(), 69 this.qName, 70 getChild().getNodeRef(), 71 this.isPrimary, 72 -1); 73 } 74 return childAssocRef; 75 } 76 77 public String toString() 78 { 79 StringBuffer sb = new StringBuffer (32); 80 sb.append("ChildAssoc") 81 .append("[ parent=").append(parent) 82 .append(", child=").append(child) 83 .append(", name=").append(getQname()) 84 .append(", isPrimary=").append(isPrimary) 85 .append("]"); 86 return sb.toString(); 87 } 88 89 public boolean equals(Object obj) 90 { 91 if (obj == null) 92 { 93 return false; 94 } 95 else if (obj == this) 96 { 97 return true; 98 } 99 else if (!(obj instanceof ChildAssoc)) 100 { 101 return false; 102 } 103 ChildAssoc that = (ChildAssoc) obj; 104 return (this.getIsPrimary() == that.getIsPrimary() 105 && EqualsHelper.nullSafeEquals(this.getTypeQName(), that.getTypeQName()) 106 && EqualsHelper.nullSafeEquals(this.getQname(), that.getQname()) 107 && EqualsHelper.nullSafeEquals(this.getParent(), that.getParent()) 108 && EqualsHelper.nullSafeEquals(this.getChild(), that.getChild())); 109 } 110 111 public int hashCode() 112 { 113 return (qName == null ? 0 : qName.hashCode()); 114 } 115 116 120 public int compareTo(ChildAssoc another) 121 { 122 if (this == another) 123 { 124 return 0; 125 } 126 127 int thisIndex = this.getIndex(); 128 int anotherIndex = another.getIndex(); 129 130 Long thisId = this.getId(); 131 Long anotherId = another.getId(); 132 133 if (thisId == null) { 135 return -1; 136 } 137 else if (anotherId == null) { 139 return 1; 140 } 141 else if (thisIndex == anotherIndex) { 143 return thisId.compareTo(anotherId); 144 } 145 else { 147 return (thisIndex > anotherIndex) ? 1 : -1; } 149 } 150 151 public Long getId() 152 { 153 return id; 154 } 155 156 159 private void setId(Long id) 160 { 161 this.id = id; 162 } 163 164 public Node getParent() 165 { 166 return parent; 167 } 168 169 172 private void setParent(Node parentNode) 173 { 174 this.parent = parentNode; 175 } 176 177 public Node getChild() 178 { 179 return child; 180 } 181 182 185 private void setChild(Node node) 186 { 187 child = node; 188 } 189 190 public QName getTypeQName() 191 { 192 return typeQName; 193 } 194 195 public void setTypeQName(QName typeQName) 196 { 197 this.typeQName = typeQName; 198 } 199 200 public QName getQname() 201 { 202 return qName; 203 } 204 205 public void setQname(QName qname) 206 { 207 this.qName = qname; 208 } 209 210 public boolean getIsPrimary() 211 { 212 return isPrimary; 213 } 214 215 public void setIsPrimary(boolean isPrimary) 216 { 217 this.isPrimary = isPrimary; 218 } 219 220 public int getIndex() 221 { 222 return index; 223 } 224 225 public void setIndex(int index) 226 { 227 this.index = index; 228 } 229 } 230 | Popular Tags |