1 17 package org.alfresco.service.cmr.repository; 18 19 import java.io.Serializable ; 20 21 import org.alfresco.service.namespace.QName; 22 import org.alfresco.util.EqualsHelper; 23 24 29 public class AssociationRef implements EntityRef, Serializable 30 { 31 private static final long serialVersionUID = 3977867284482439475L; 32 33 private NodeRef sourceRef; 34 private QName assocTypeQName; 35 private NodeRef targetRef; 36 37 48 public AssociationRef(NodeRef sourceRef, QName assocTypeQName, NodeRef targetRef) 49 { 50 this.sourceRef = sourceRef; 51 this.assocTypeQName = assocTypeQName; 52 this.targetRef = targetRef; 53 54 if (sourceRef == null) 56 { 57 throw new IllegalArgumentException ("Source reference may not be null"); 58 } 59 if (assocTypeQName == null) 60 { 61 throw new IllegalArgumentException ("QName may not be null"); 62 } 63 if (targetRef == null) 64 { 65 throw new IllegalArgumentException ("Target reference may not be null"); 66 } 67 } 68 69 74 public QName getTypeQName() 75 { 76 return assocTypeQName; 77 } 78 79 82 public NodeRef getTargetRef() 83 { 84 return targetRef; 85 } 86 87 91 public NodeRef getSourceRef() 92 { 93 return sourceRef; 94 } 95 96 104 public boolean equals(Object o) 105 { 106 if (this == o) 107 { 108 return true; 109 } 110 if (!(o instanceof ChildAssociationRef)) 111 { 112 return false; 113 } 114 AssociationRef other = (AssociationRef) o; 115 116 return (EqualsHelper.nullSafeEquals(this.sourceRef, other.sourceRef) 117 && EqualsHelper.nullSafeEquals(this.assocTypeQName, other.assocTypeQName) 118 && EqualsHelper.nullSafeEquals(this.targetRef, other.targetRef)); 119 } 120 121 public int hashCode() 122 { 123 int hashCode = (getSourceRef() == null) ? 0 : getSourceRef().hashCode(); 124 hashCode = 37 * hashCode + ((getTypeQName() == null) ? 0 : getTypeQName().hashCode()); 125 hashCode = 37 * hashCode + getTargetRef().hashCode(); 126 return hashCode; 127 } 128 129 public String toString() 130 { 131 StringBuffer buffer = new StringBuffer (); 132 buffer.append(getSourceRef()); 133 buffer.append(" --- ").append(getTypeQName()).append(" ---> "); 134 buffer.append(getTargetRef()); 135 return buffer.toString(); 136 } 137 } 138 | Popular Tags |