1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.registry;
18
19 import org.apache.jetspeed.services.Registry;
20 import org.apache.jetspeed.om.registry.RegistryEntry;
21 import java.util.Vector;
22 import java.util.Hashtable;
23 import java.util.Iterator;
24
25 /***
26 * Bean like implementation of a multi-object registry usable
27 * by Castor XML serialization
28 *
29 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
30 * @version $Id: RegistryFragment.java,v 1.10 2004/02/23 03:31:50 jford Exp $
31 */
32 public class RegistryFragment extends Hashtable implements java.io.Serializable
33 {
34
35 /*** this flag is used to mark this fragment has some changes that are
36 * not yet persisted to disk
37 */
38 private transient boolean dirty = false;
39
40 /*** this flag is used to mark that this fragment needs to updated to
41 * incorporated changes from its disk state
42 */
43 private transient boolean changed = false;
44
45 /*** @return true if this fragment has some unpersisted changes
46 */
47 public boolean isDirty()
48 {
49 return this.dirty;
50 }
51
52 /*** Sets the dirty flag indicating wether this fragment has some
53 * uncommitted changes
54 *
55 * @param value the new dirty state for this fragment
56 */
57 public void setDirty(boolean value)
58 {
59 this.dirty = value;
60 }
61
62 /*** @return true if this fragment has some persisted changes that need loading
63 */
64 public boolean hasChanged()
65 {
66 return this.changed;
67 }
68
69 /*** Sets the changed flag indicating wether this fragment has some
70 * changes to load
71 *
72 * @param value the new dirty state for this fragment
73 */
74 public void setChanged(boolean value)
75 {
76 this.changed = value;
77 }
78
79 /*** @return the entries stored in this Fragment that are suitable
80 * for the requested registry
81 *
82 * @param name a valid Registry name.
83 */
84 public Vector getEntries(String name)
85 {
86
87 if (name != null)
88 {
89 Vector registry = (Vector)get(name);
90
91 if (registry != null)
92 {
93 return registry;
94 }
95 }
96
97 return new Vector();
98 }
99
100 /*** Add a new entry in the fragment. It does not check for name
101 * duplication
102 * @param name a valid Registry name.
103 * @param entry the entry to add
104 */
105 public void addEntry(String name, RegistryEntry entry)
106 {
107 if ( (name != null) && (entry != null) )
108 {
109 Vector registry = (Vector)get(name);
110
111 if (registry != null)
112 {
113 registry.add(entry);
114 }
115 }
116 }
117
118 /*** Remove an existing entry in the fragment.
119 * @param name a valid Registry name.
120 * @param entryName the name of the entry to remove
121 */
122 public void removeEntry(String name, String entryName)
123 {
124 if ( (name != null) && (entryName != null) )
125 {
126 Vector registry = (Vector)get(name);
127 if (registry != null)
128 {
129 Iterator i = registry.iterator();
130 while(i.hasNext())
131 {
132 RegistryEntry regEntry = (RegistryEntry)i.next();
133 if (entryName.equals(regEntry.getName()))
134 {
135 i.remove();
136 }
137 }
138 }
139 }
140 }
141
142 /*** Modify an existing entry in the fragment.
143 * @param name a valid Registry name.
144 * @param entry the entry to add
145 */
146 public void setEntry(String name, RegistryEntry entry)
147 {
148 if (entry!=null)
149 {
150 removeEntry(name,entry.getName());
151 addEntry(name,entry);
152 }
153 }
154
155
156
157 public Vector getPortlets()
158 {
159 return (Vector)get(Registry.PORTLET);
160 }
161
162 public void setPortlets(Vector portlets)
163 {
164 if (portlets!=null)
165 {
166 put(Registry.PORTLET,portlets);
167 }
168 }
169
170 public Vector getControls()
171 {
172 return (Vector)get(Registry.PORTLET_CONTROL);
173 }
174
175 public void setControls(Vector controls)
176 {
177 if (controls!=null)
178 {
179 put(Registry.PORTLET_CONTROL,controls);
180 }
181 }
182
183 public Vector getControllers()
184 {
185 return (Vector)get(Registry.PORTLET_CONTROLLER);
186 }
187
188 public void setControllers(Vector controllers)
189 {
190 if (controllers!=null)
191 {
192 put(Registry.PORTLET_CONTROLLER,controllers);
193 }
194 }
195
196 public Vector getMedias()
197 {
198 return (Vector)get(Registry.MEDIA_TYPE);
199 }
200
201 public void setMedias(Vector medias)
202 {
203 if (medias!=null)
204 {
205 put(Registry.MEDIA_TYPE,medias);
206 }
207 }
208
209 public Vector getSkins()
210 {
211 return (Vector)get(Registry.SKIN);
212 }
213
214 public void setSkins(Vector skins)
215 {
216 if (skins!=null)
217 {
218 put(Registry.SKIN,skins);
219 }
220 }
221
222 public Vector getSecurityEntries()
223 {
224 return (Vector)get(Registry.SECURITY);
225 }
226
227 public void setSecurityEntries(Vector securityEntries)
228 {
229 if (securityEntries!=null)
230 {
231 put(Registry.SECURITY, securityEntries);
232 }
233 }
234
235 public Vector getClients()
236 {
237 return (Vector)get(Registry.CLIENT);
238 }
239
240 public void setClients(Vector clients)
241 {
242 if (clients!=null)
243 {
244 put(Registry.CLIENT, clients);
245 }
246 }
247 }