1 17 package org.alfresco.repo.domain.hibernate; 18 19 import org.alfresco.repo.domain.Node; 20 import org.alfresco.repo.domain.NodeAssoc; 21 import org.alfresco.service.cmr.repository.AssociationRef; 22 import org.alfresco.service.namespace.QName; 23 import org.alfresco.util.EqualsHelper; 24 25 30 public class NodeAssocImpl implements NodeAssoc 31 { 32 private long id; 33 private Node source; 34 private Node target; 35 private QName typeQName; 36 private transient AssociationRef nodeAssocRef; 37 38 public NodeAssocImpl() 39 { 40 } 41 42 public void buildAssociation(Node sourceNode, Node targetNode) 43 { 44 this.setTarget(targetNode); 46 this.setSource(sourceNode); 47 sourceNode.getTargetNodeAssocs().add(this); 49 targetNode.getSourceNodeAssocs().add(this); 50 } 51 52 public void removeAssociation() 53 { 54 this.getSource().getTargetNodeAssocs().remove(this); 56 this.getTarget().getSourceNodeAssocs().remove(this); 58 } 59 60 public synchronized AssociationRef getNodeAssocRef() 61 { 62 if (nodeAssocRef == null) 63 { 64 nodeAssocRef = new AssociationRef(getSource().getNodeRef(), 65 this.typeQName, 66 getTarget().getNodeRef()); 67 } 68 return nodeAssocRef; 69 } 70 71 public String toString() 72 { 73 StringBuffer sb = new StringBuffer (32); 74 sb.append("NodeAssoc") 75 .append("[ source=").append(source) 76 .append(", target=").append(target) 77 .append(", name=").append(getTypeQName()) 78 .append("]"); 79 return sb.toString(); 80 } 81 82 public boolean equals(Object obj) 83 { 84 if (obj == null) 85 { 86 return false; 87 } 88 else if (obj == this) 89 { 90 return true; 91 } 92 else if (!(obj instanceof NodeAssoc)) 93 { 94 return false; 95 } 96 NodeAssoc that = (NodeAssoc) obj; 97 return (EqualsHelper.nullSafeEquals(this.getTypeQName(), that.getTypeQName()) 98 && EqualsHelper.nullSafeEquals(this.getTarget(), that.getTarget()) 99 && EqualsHelper.nullSafeEquals(this.getSource(), that.getSource())); 100 } 101 102 public int hashCode() 103 { 104 return (typeQName == null ? 0 : typeQName.hashCode()); 105 } 106 107 public long getId() 108 { 109 return id; 110 } 111 112 115 private void setId(long id) 116 { 117 this.id = id; 118 } 119 120 public Node getSource() 121 { 122 return source; 123 } 124 125 128 private void setSource(Node source) 129 { 130 this.source = source; 131 } 132 133 public Node getTarget() 134 { 135 return target; 136 } 137 138 141 private void setTarget(Node target) 142 { 143 this.target = target; 144 } 145 146 public QName getTypeQName() 147 { 148 return typeQName; 149 } 150 151 public void setTypeQName(QName typeQName) 152 { 153 this.typeQName = typeQName; 154 } 155 } 156 | Popular Tags |