KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > service > cmr > repository > AssociationRef


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.service.cmr.repository;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.alfresco.service.namespace.QName;
22 import org.alfresco.util.EqualsHelper;
23
24 /**
25  * This class represents a regular, named node relationship between two nodes.
26  *
27  * @author Derek Hulley
28  */

29 public class AssociationRef implements EntityRef, Serializable JavaDoc
30 {
31     private static final long serialVersionUID = 3977867284482439475L;
32
33     private NodeRef sourceRef;
34     private QName assocTypeQName;
35     private NodeRef targetRef;
36
37     /**
38      * Construct a representation of a source --- name ----> target
39      * relationship.
40      *
41      * @param sourceRef
42      * the source reference - never null
43      * @param assocTypeQName
44      * the qualified name of the association type - never null
45      * @param targetRef
46      * the target node reference - never null.
47      */

48     public AssociationRef(NodeRef sourceRef, QName assocTypeQName, NodeRef targetRef)
49     {
50         this.sourceRef = sourceRef;
51         this.assocTypeQName = assocTypeQName;
52         this.targetRef = targetRef;
53
54         // check
55
if (sourceRef == null)
56         {
57             throw new IllegalArgumentException JavaDoc("Source reference may not be null");
58         }
59         if (assocTypeQName == null)
60         {
61             throw new IllegalArgumentException JavaDoc("QName may not be null");
62         }
63         if (targetRef == null)
64         {
65             throw new IllegalArgumentException JavaDoc("Target reference may not be null");
66         }
67     }
68
69     /**
70      * Get the qualified name of the source-target association
71      *
72      * @return Returns the qualified name of the source-target association.
73      */

74     public QName getTypeQName()
75     {
76         return assocTypeQName;
77     }
78
79     /**
80      * @return Returns the child node reference - never null
81      */

82     public NodeRef getTargetRef()
83     {
84         return targetRef;
85     }
86
87     /**
88      * @return Returns the parent node reference, which may be null if this
89      * represents the imaginary reference to the root node
90      */

91     public NodeRef getSourceRef()
92     {
93         return sourceRef;
94     }
95
96     /**
97      * Compares:
98      * <ul>
99      * <li>{@link #sourceRef}</li>
100      * <li>{@link #targetRef}</li>
101      * <li>{@link #assocTypeQName}</li>
102      * </ul>
103      */

104     public boolean equals(Object JavaDoc 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 JavaDoc toString()
130     {
131         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
132         buffer.append(getSourceRef());
133         buffer.append(" --- ").append(getTypeQName()).append(" ---> ");
134         buffer.append(getTargetRef());
135         return buffer.toString();
136     }
137 }
138
Popular Tags