View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.prefs.om.impl;
18  
19  import java.sql.Timestamp;
20  import java.util.ArrayList;
21  import java.util.Collection;
22  
23  import org.apache.jetspeed.prefs.om.Node;
24  
25  /***
26   * <p>
27   * {@link Node}interface implementation.
28   * </p>
29   * <p>
30   * Represents a preferences node.
31   * </p>
32   * 
33   * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
34   */
35  public class NodeImpl implements Node
36  {
37      /*** The serial version uid. */
38      private static final long serialVersionUID = -5367800007757021163L;
39  
40      private long nodeId;
41  
42      private Long parentNodeId;
43  
44      private Collection nodeProperties;
45  
46      private Collection nodeKeys;
47  
48      private String nodeName;
49  
50      private int nodeType;
51  
52      private String fullPath;
53  
54      private Timestamp creationDate;
55  
56      /***
57       * <p>
58       * Preferences node implementation default constructor.
59       * </p>
60       */
61      public NodeImpl()
62      {
63      }
64  
65      /***
66       * <p>
67       * Node constructor given:
68       * </p>
69       * <ul>
70       * <li>Parent node id,</li>
71       * <li>Property set definition id: Long so that we can pass null value if
72       * the node does not have any properties associated to it,</li>
73       * <li>Node name,</li>
74       * <li>Node type,</li>
75       * <li>Full path.</li>
76       * </ul>
77       * 
78       * @param parentNodeId The parent node id.
79       * @param nodeName The node name.
80       * @param nodeType The node type.
81       * @param fullPath The full path.
82       */
83      public NodeImpl(Long parentNodeId, String nodeName, int nodeType, String fullPath)
84      {
85          this.parentNodeId = parentNodeId;
86          this.nodeName = nodeName;
87          this.nodeType = nodeType;
88          this.fullPath = fullPath;
89          this.nodeKeys = new ArrayList(0);
90          this.nodeProperties = new ArrayList(0);
91          this.creationDate = new Timestamp(System.currentTimeMillis());
92          this.modifiedDate = this.creationDate;
93      }
94  
95      /***
96       * @see org.apache.jetspeed.prefs.om.Node#getNodeId()
97       */
98      public long getNodeId()
99      {
100         return this.nodeId;
101     }
102 
103     /***
104      * @see org.apache.jetspeed.prefs.om.Node#setNodeId(int)
105      */
106     public void setNodeId(long nodeId)
107     {
108         this.nodeId = nodeId;
109     }
110 
111     /***
112      * @see org.apache.jetspeed.prefs.om.Node#getParentNodeId()
113      */
114     public Long getParentNodeId()
115     {
116         return this.parentNodeId;
117     }
118 
119     /***
120      * @see org.apache.jetspeed.prefs.om.Node#setParentNodeId(java.lang.Long)
121      */
122     public void setParentNodeId(Long parentNodeId)
123     {
124         this.parentNodeId = parentNodeId;
125     }
126 
127     /***
128      * @see org.apache.jetspeed.prefs.om.Node#getNodeProperties()
129      */
130     public Collection getNodeProperties()
131     {
132         return this.nodeProperties;
133     }
134 
135     /***
136      * @see org.apache.jetspeed.prefs.om.Node#setNodeProperties(java.util.Collection)
137      */
138     public void setNodeProperties(Collection nodeProperties)
139     {
140         this.nodeProperties = nodeProperties;
141     }
142 
143     /***
144      * @see org.apache.jetspeed.prefs.om.Node#getNodeKeys()
145      */
146     public Collection getNodeKeys()
147     {
148         return this.nodeKeys;
149     }
150 
151     /***
152      * @see org.apache.jetspeed.prefs.om.Node#setNodeKeys(java.util.Collection)
153      */
154     public void setNodeKeys(Collection nodeKeys)
155     {
156         this.nodeKeys = nodeKeys;
157     }
158 
159     /***
160      * @see org.apache.jetspeed.prefs.om.Node#getNodeName()
161      */
162     public String getNodeName()
163     {
164         return this.nodeName;
165     }
166 
167     /***
168      * @see org.apache.jetspeed.prefs.om.Node#setNodeName(java.lang.String)
169      */
170     public void setNodeName(String nodeName)
171     {
172         this.nodeName = nodeName;
173     }
174 
175     /***
176      * @see org.apache.jetspeed.prefs.om.Node#getNodeType()
177      */
178     public int getNodeType()
179     {
180         return this.nodeType;
181     }
182 
183     /***
184      * @see org.apache.jetspeed.prefs.om.Node#setNodeType(int)
185      */
186     public void setNodeType(int nodeType)
187     {
188         this.nodeType = nodeType;
189     }
190 
191     /***
192      * @see org.apache.jetspeed.prefs.om.Node#getFullPath()
193      */
194     public String getFullPath()
195     {
196         return this.fullPath;
197     }
198 
199     /***
200      * @see org.apache.jetspeed.prefs.om.Node#setFullPath(java.lang.String)
201      */
202     public void setFullPath(String fullPath)
203     {
204         this.fullPath = fullPath;
205     }
206 
207     /***
208      * @see org.apache.jetspeed.prefs.om.Node#getCreationDate()
209      */
210     public Timestamp getCreationDate()
211     {
212         return this.creationDate;
213     }
214 
215     /***
216      * @see org.apache.jetspeed.prefs.om.Node#setCreationDate(java.sql.Timestamp)
217      */
218     public void setCreationDate(Timestamp creationDate)
219     {
220         this.creationDate = creationDate;
221     }
222 
223     private Timestamp modifiedDate;
224 
225     /***
226      * @see org.apache.jetspeed.prefs.om.Node#getModifiedDate()
227      */
228     public Timestamp getModifiedDate()
229     {
230         return this.modifiedDate;
231     }
232 
233     /***
234      * @see org.apache.jetspeed.prefs.om.Node#setModifiedDate(java.sql.Timestamp)
235      */
236     public void setModifiedDate(Timestamp modifiedDate)
237     {
238         this.modifiedDate = modifiedDate;
239     }
240 
241     public boolean equals(Object o)
242     {
243         return fullPath != null && o != null && o instanceof NodeImpl && ((NodeImpl) o).fullPath != null
244                 && fullPath.equals(((NodeImpl) o).fullPath);
245     }
246 
247     /***
248      * <p>
249      * Convert <code>Node</code> to string.
250      * </p>
251      * 
252      * @return The Node string value.
253      */
254     public String toString()
255     {
256         String toStringNode = "[[parentNodeId, " + this.parentNodeId + "], " + "[nodeName, " + this.nodeName + "], "
257                 + "[fullPath, " + this.fullPath + "], " + "[nodeType, " + this.nodeType + "], " + "[nodeKeys, "
258                 + this.nodeKeys + "], " + "[nodeProperties, " + this.nodeProperties + "], " + "[creationDate, "
259                 + this.creationDate + "], " + "[modifiedDate, " + this.modifiedDate + "]]";
260         return toStringNode;
261     }
262 
263 }