KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > bean > repository > MapNode


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.web.bean.repository;
18
19 import java.util.Collection JavaDoc;
20 import java.util.Map JavaDoc;
21 import java.util.Set JavaDoc;
22
23 import org.alfresco.service.cmr.repository.NodeRef;
24 import org.alfresco.service.cmr.repository.NodeService;
25
26 /**
27  * Lighweight client side representation of a node held in the repository, which
28  * is modelled as a map for use in the data tables.
29  *
30  * @author gavinc
31  */

32 public class MapNode extends Node implements Map JavaDoc<String JavaDoc, Object JavaDoc>
33 {
34    private static final long serialVersionUID = 4051322327734433079L;
35    
36    private boolean propsInitialised = false;
37    
38    
39    /**
40     * Constructor
41     *
42     * @param nodeRef The NodeRef this Node wrapper represents
43     */

44    public MapNode(NodeRef nodeRef)
45    {
46       super(nodeRef);
47    }
48    
49    /**
50     * Constructor
51     *
52     * @param nodeRef The NodeRef this Node wrapper represents
53     * @param nodeService The node service to use to retrieve data for this node
54     * @param initProps True to immediately init the properties of the node, false to do nothing
55     */

56    public MapNode(NodeRef nodeRef, NodeService nodeService, boolean initProps)
57    {
58       super(nodeRef);
59       if (initProps == true)
60       {
61          getProperties();
62       }
63    }
64    
65    
66    // ------------------------------------------------------------------------------
67
// Map implementation - allows the Node bean to be accessed using JSF expression syntax
68

69    /**
70     * @see java.util.Map#clear()
71     */

72    public void clear()
73    {
74       getProperties().clear();
75    }
76
77    /**
78     * @see java.util.Map#containsKey(java.lang.Object)
79     */

80    public boolean containsKey(Object JavaDoc key)
81    {
82       return getProperties().containsKey(key);
83    }
84
85    /**
86     * @see java.util.Map#containsValue(java.lang.Object)
87     */

88    public boolean containsValue(Object JavaDoc value)
89    {
90       return getProperties().containsKey(value);
91    }
92
93    /**
94     * @see java.util.Map#entrySet()
95     */

96    public Set JavaDoc entrySet()
97    {
98       return getProperties().entrySet();
99    }
100
101    /**
102     * @see java.util.Map#get(java.lang.Object)
103     */

104    public Object JavaDoc get(Object JavaDoc key)
105    {
106       Object JavaDoc obj = null;
107       
108       // there are some things that aren't available as properties
109
// but from method calls, so for these handle them individually
110
Map JavaDoc<String JavaDoc, Object JavaDoc> props = getProperties();
111       if (propsInitialised == false)
112       {
113          // well known properties required as publically accessable map attributes
114
props.put("id", this.getId());
115          props.put("name", this.getName()); // TODO: perf test pulling back single prop here instead of all!
116
props.put("nodeRef", this.getNodeRef());
117          
118          propsInitialised = true;
119       }
120       
121       return props.get(key);
122    }
123
124    /**
125     * @see java.util.Map#isEmpty()
126     */

127    public boolean isEmpty()
128    {
129       return getProperties().isEmpty();
130    }
131
132    /**
133     * @see java.util.Map#keySet()
134     */

135    public Set JavaDoc keySet()
136    {
137       return getProperties().keySet();
138    }
139
140    /**
141     * @see java.util.Map#put(K, V)
142     */

143    public Object JavaDoc put(String JavaDoc key, Object JavaDoc value)
144    {
145       return getProperties().put(key, value);
146    }
147
148    /**
149     * @see java.util.Map#putAll(java.util.Map)
150     */

151    public void putAll(Map JavaDoc t)
152    {
153       getProperties().putAll(t);
154    }
155
156    /**
157     * @see java.util.Map#remove(java.lang.Object)
158     */

159    public Object JavaDoc remove(Object JavaDoc key)
160    {
161       return getProperties().remove(key);
162    }
163
164    /**
165     * @see java.util.Map#size()
166     */

167    public int size()
168    {
169       return getProperties().size();
170    }
171
172    /**
173     * @see java.util.Map#values()
174     */

175    public Collection JavaDoc values()
176    {
177       return getProperties().values();
178    }
179 }
180
Popular Tags