KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > registry > RegistryFragment


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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * 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 and
14  * limitations under the License.
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 JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import java.util.Iterator JavaDoc;
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 JavaDoc implements java.io.Serializable JavaDoc
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 JavaDoc getEntries(String JavaDoc name)
85     {
86
87         if (name != null)
88         {
89             Vector JavaDoc registry = (Vector JavaDoc)get(name);
90
91             if (registry != null)
92             {
93                 return registry;
94             }
95         }
96
97         return new Vector JavaDoc();
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 JavaDoc name, RegistryEntry entry)
106     {
107         if ( (name != null) && (entry != null) )
108         {
109             Vector JavaDoc registry = (Vector JavaDoc)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 JavaDoc name, String JavaDoc entryName)
123     {
124         if ( (name != null) && (entryName != null) )
125         {
126             Vector JavaDoc registry = (Vector JavaDoc)get(name);
127             if (registry != null)
128             {
129                 Iterator JavaDoc 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 JavaDoc name, RegistryEntry entry)
147     {
148         if (entry!=null)
149         {
150             removeEntry(name,entry.getName());
151             addEntry(name,entry);
152         }
153     }
154
155     // Castor serialization support methods
156

157     public Vector JavaDoc getPortlets()
158     {
159         return (Vector JavaDoc)get(Registry.PORTLET);
160     }
161
162     public void setPortlets(Vector JavaDoc portlets)
163     {
164         if (portlets!=null)
165         {
166             put(Registry.PORTLET,portlets);
167         }
168     }
169
170     public Vector JavaDoc getControls()
171     {
172         return (Vector JavaDoc)get(Registry.PORTLET_CONTROL);
173     }
174
175     public void setControls(Vector JavaDoc controls)
176     {
177         if (controls!=null)
178         {
179             put(Registry.PORTLET_CONTROL,controls);
180         }
181     }
182
183     public Vector JavaDoc getControllers()
184     {
185         return (Vector JavaDoc)get(Registry.PORTLET_CONTROLLER);
186     }
187
188     public void setControllers(Vector JavaDoc controllers)
189     {
190         if (controllers!=null)
191         {
192             put(Registry.PORTLET_CONTROLLER,controllers);
193         }
194     }
195
196     public Vector JavaDoc getMedias()
197     {
198         return (Vector JavaDoc)get(Registry.MEDIA_TYPE);
199     }
200
201     public void setMedias(Vector JavaDoc medias)
202     {
203         if (medias!=null)
204         {
205             put(Registry.MEDIA_TYPE,medias);
206         }
207     }
208
209     public Vector JavaDoc getSkins()
210     {
211         return (Vector JavaDoc)get(Registry.SKIN);
212     }
213
214     public void setSkins(Vector JavaDoc skins)
215     {
216         if (skins!=null)
217         {
218             put(Registry.SKIN,skins);
219         }
220     }
221
222     public Vector JavaDoc getSecurityEntries()
223     {
224         return (Vector JavaDoc)get(Registry.SECURITY);
225     }
226
227     public void setSecurityEntries(Vector JavaDoc securityEntries)
228     {
229         if (securityEntries!=null)
230         {
231             put(Registry.SECURITY, securityEntries);
232         }
233     }
234
235     public Vector JavaDoc getClients()
236     {
237         return (Vector JavaDoc)get(Registry.CLIENT);
238     }
239
240     public void setClients(Vector JavaDoc clients)
241     {
242         if (clients!=null)
243         {
244             put(Registry.CLIENT, clients);
245         }
246     }
247 }
248
Popular Tags