KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > domain > hibernate > NodeImpl


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.repo.domain.hibernate;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import org.alfresco.repo.domain.ChildAssoc;
27 import org.alfresco.repo.domain.Node;
28 import org.alfresco.repo.domain.NodeAssoc;
29 import org.alfresco.repo.domain.NodeKey;
30 import org.alfresco.repo.domain.NodeStatus;
31 import org.alfresco.repo.domain.PropertyValue;
32 import org.alfresco.repo.domain.Store;
33 import org.alfresco.service.cmr.repository.NodeRef;
34 import org.alfresco.service.namespace.QName;
35
36 /**
37  * Bean containing all the persistence data representing a <b>node</b>.
38  * <p>
39  * This implementation of the {@link org.alfresco.repo.domain.Node Node} interface is
40  * Hibernate specific.
41  *
42  * @author Derek Hulley
43  */

44 public class NodeImpl implements Node
45 {
46     private NodeKey key;
47     private Store store;
48     private QName typeQName;
49     private NodeStatus status;
50     private Set JavaDoc<QName> aspects;
51     private Collection JavaDoc<NodeAssoc> sourceNodeAssocs;
52     private Collection JavaDoc<NodeAssoc> targetNodeAssocs;
53     private Collection JavaDoc<ChildAssoc> parentAssocs;
54     private Collection JavaDoc<ChildAssoc> childAssocs;
55     private Map JavaDoc<QName, PropertyValue> properties;
56     private transient NodeRef nodeRef;
57
58     public NodeImpl()
59     {
60         aspects = new HashSet JavaDoc<QName>(5);
61         sourceNodeAssocs = new ArrayList JavaDoc<NodeAssoc>(3);
62         targetNodeAssocs = new ArrayList JavaDoc<NodeAssoc>(3);
63         parentAssocs = new ArrayList JavaDoc<ChildAssoc>(3);
64         childAssocs = new ArrayList JavaDoc<ChildAssoc>(3);
65         properties = new HashMap JavaDoc<QName, PropertyValue>(5);
66     }
67     
68     public boolean equals(Object JavaDoc obj)
69     {
70         if (obj == null)
71         {
72             return false;
73         }
74         else if (obj == this)
75         {
76             return true;
77         }
78         else if (!(obj instanceof Node))
79         {
80             return false;
81         }
82         Node that = (Node) obj;
83         return (this.getKey().equals(that.getKey()));
84     }
85     
86     public int hashCode()
87     {
88         return getKey().hashCode();
89     }
90
91     public NodeKey getKey() {
92         return key;
93     }
94
95     public void setKey(NodeKey key) {
96         this.key = key;
97     }
98     
99     public Store getStore()
100     {
101         return store;
102     }
103
104     public synchronized void setStore(Store store)
105     {
106         this.store = store;
107         this.nodeRef = null;
108     }
109
110     public QName getTypeQName()
111     {
112         return typeQName;
113     }
114
115     public void setTypeQName(QName typeQName)
116     {
117         this.typeQName = typeQName;
118     }
119
120     public NodeStatus getStatus()
121     {
122         return status;
123     }
124
125     public void setStatus(NodeStatus status)
126     {
127         this.status = status;
128     }
129
130     public Set JavaDoc<QName> getAspects()
131     {
132         return aspects;
133     }
134     
135     /**
136      * For Hibernate use
137      */

138     @SuppressWarnings JavaDoc("unused")
139     private void setAspects(Set JavaDoc<QName> aspects)
140     {
141         this.aspects = aspects;
142     }
143
144     public Collection JavaDoc<NodeAssoc> getSourceNodeAssocs()
145     {
146         return sourceNodeAssocs;
147     }
148
149     /**
150      * For Hibernate use
151      */

152     @SuppressWarnings JavaDoc("unused")
153     private void setSourceNodeAssocs(Collection JavaDoc<NodeAssoc> sourceNodeAssocs)
154     {
155         this.sourceNodeAssocs = sourceNodeAssocs;
156     }
157
158     public Collection JavaDoc<NodeAssoc> getTargetNodeAssocs()
159     {
160         return targetNodeAssocs;
161     }
162
163     /**
164      * For Hibernate use
165      */

166     @SuppressWarnings JavaDoc("unused")
167     private void setTargetNodeAssocs(Collection JavaDoc<NodeAssoc> targetNodeAssocs)
168     {
169         this.targetNodeAssocs = targetNodeAssocs;
170     }
171     
172     public Collection JavaDoc<ChildAssoc> getParentAssocs()
173     {
174         return parentAssocs;
175     }
176
177     /**
178      * For Hibernate use
179      */

180     @SuppressWarnings JavaDoc("unused")
181     private void setParentAssocs(Collection JavaDoc<ChildAssoc> parentAssocs)
182     {
183         this.parentAssocs = parentAssocs;
184     }
185
186     public Collection JavaDoc<ChildAssoc> getChildAssocs()
187     {
188         return childAssocs;
189     }
190
191     /**
192      * For Hibernate use
193      */

194     @SuppressWarnings JavaDoc("unused")
195     private void setChildAssocs(Collection JavaDoc<ChildAssoc> childAssocs)
196     {
197         this.childAssocs = childAssocs;
198     }
199
200     public Map JavaDoc<QName, PropertyValue> getProperties()
201     {
202         return properties;
203     }
204
205     /**
206      * For Hibernate use
207      */

208     @SuppressWarnings JavaDoc("unused")
209     private void setProperties(Map JavaDoc<QName, PropertyValue> properties)
210     {
211         this.properties = properties;
212     }
213
214     /**
215      * Thread-safe caching of the reference is provided
216      */

217     public synchronized NodeRef getNodeRef()
218     {
219         if (nodeRef == null && key != null)
220         {
221             nodeRef = new NodeRef(getStore().getStoreRef(), getKey().getGuid());
222         }
223         return nodeRef;
224     }
225     
226     /**
227      * @see #getNodeRef()
228      */

229     public String JavaDoc toString()
230     {
231         return getNodeRef().toString();
232     }
233 }
234
Popular Tags