1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.services.registry;
1819import org.apache.jetspeed.services.Registry;
20import org.apache.jetspeed.om.registry.RegistryEntry;
21import java.util.Vector;
22import java.util.Hashtable;
23import java.util.Iterator;
2425/***26 * Bean like implementation of a multi-object registry usable27 * by Castor XML serialization28 *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 */32publicclassRegistryFragmentextends Hashtable implements java.io.Serializable
33 {
3435/*** this flag is used to mark this fragment has some changes that are36 * not yet persisted to disk37 */38privatetransientboolean dirty = false;
3940/*** this flag is used to mark that this fragment needs to updated to41 * incorporated changes from its disk state42 */43privatetransientboolean changed = false;
4445/*** @return true if this fragment has some unpersisted changes46 */47publicboolean isDirty()
48 {
49returnthis.dirty;
50 }
5152/*** Sets the dirty flag indicating wether this fragment has some53 * uncommitted changes54 *55 * @param value the new dirty state for this fragment56 */57publicvoid setDirty(boolean value)
58 {
59this.dirty = value;
60 }
6162/*** @return true if this fragment has some persisted changes that need loading63 */64publicboolean hasChanged()
65 {
66returnthis.changed;
67 }
6869/*** Sets the changed flag indicating wether this fragment has some70 * changes to load71 *72 * @param value the new dirty state for this fragment73 */74publicvoid setChanged(boolean value)
75 {
76this.changed = value;
77 }
7879/*** @return the entries stored in this Fragment that are suitable80 * for the requested registry81 *82 * @param name a valid Registry name.83 */84public Vector getEntries(String name)
85 {
8687if (name != null)
88 {
89 Vector registry = (Vector)get(name);
9091if (registry != null)
92 {
93return registry;
94 }
95 }
9697returnnew Vector();
98 }
99100/*** Add a new entry in the fragment. It does not check for name101 * duplication102 * @param name a valid Registry name.103 * @param entry the entry to add104 */105publicvoid addEntry(String name, RegistryEntry entry)
106 {
107if ( (name != null) && (entry != null) )
108 {
109 Vector registry = (Vector)get(name);
110111if (registry != null)
112 {
113 registry.add(entry);
114 }
115 }
116 }
117118/*** Remove an existing entry in the fragment.119 * @param name a valid Registry name.120 * @param entryName the name of the entry to remove121 */122publicvoid removeEntry(String name, String entryName)
123 {
124if ( (name != null) && (entryName != null) )
125 {
126 Vector registry = (Vector)get(name);
127if (registry != null)
128 {
129 Iterator i = registry.iterator();
130while(i.hasNext())
131 {
132RegistryEntry regEntry = (RegistryEntry)i.next();
133if (entryName.equals(regEntry.getName()))
134 {
135 i.remove();
136 }
137 }
138 }
139 }
140 }
141142/*** Modify an existing entry in the fragment.143 * @param name a valid Registry name.144 * @param entry the entry to add145 */146publicvoid setEntry(String name, RegistryEntry entry)
147 {
148if (entry!=null)
149 {
150 removeEntry(name,entry.getName());
151 addEntry(name,entry);
152 }
153 }
154155// Castor serialization support methods156157public Vector getPortlets()
158 {
159return (Vector)get(Registry.PORTLET);
160 }
161162publicvoid setPortlets(Vector portlets)
163 {
164if (portlets!=null)
165 {
166 put(Registry.PORTLET,portlets);
167 }
168 }
169170public Vector getControls()
171 {
172return (Vector)get(Registry.PORTLET_CONTROL);
173 }
174175publicvoid setControls(Vector controls)
176 {
177if (controls!=null)
178 {
179 put(Registry.PORTLET_CONTROL,controls);
180 }
181 }
182183public Vector getControllers()
184 {
185return (Vector)get(Registry.PORTLET_CONTROLLER);
186 }
187188publicvoid setControllers(Vector controllers)
189 {
190if (controllers!=null)
191 {
192 put(Registry.PORTLET_CONTROLLER,controllers);
193 }
194 }
195196public Vector getMedias()
197 {
198return (Vector)get(Registry.MEDIA_TYPE);
199 }
200201publicvoid setMedias(Vector medias)
202 {
203if (medias!=null)
204 {
205 put(Registry.MEDIA_TYPE,medias);
206 }
207 }
208209public Vector getSkins()
210 {
211return (Vector)get(Registry.SKIN);
212 }
213214publicvoid setSkins(Vector skins)
215 {
216if (skins!=null)
217 {
218 put(Registry.SKIN,skins);
219 }
220 }
221222public Vector getSecurityEntries()
223 {
224return (Vector)get(Registry.SECURITY);
225 }
226227publicvoid setSecurityEntries(Vector securityEntries)
228 {
229if (securityEntries!=null)
230 {
231 put(Registry.SECURITY, securityEntries);
232 }
233 }
234235public Vector getClients()
236 {
237return (Vector)get(Registry.CLIENT);
238 }
239240publicvoid setClients(Vector clients)
241 {
242if (clients!=null)
243 {
244 put(Registry.CLIENT, clients);
245 }
246 }
247 }