KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > registry > base > BaseRegistryEntry


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.om.registry.base;
18
19 // Jetspeed imports
20
import org.apache.jetspeed.om.SecurityReference;
21 import org.apache.jetspeed.om.registry.MetaInfo;
22 import org.apache.jetspeed.om.registry.Security;
23 import org.apache.jetspeed.om.registry.RegistryEntry;
24
25 /**
26  * Base simple bean-like implementation of the RegistryEntry interface
27  * suitable for Castor XML serialization.
28  *
29  * @author <a HREF="mailto:raphael@apache.org">Raphaël Luta</a>
30  * @version $Id: BaseRegistryEntry.java,v 1.10 2004/02/23 03:08:26 jford Exp $
31  */

32 public class BaseRegistryEntry implements RegistryEntry, java.io.Serializable JavaDoc
33 {
34     protected long id = 0;
35
36     protected String JavaDoc name;
37
38     protected MetaInfo metaInfo = null;
39
40     protected Security security = null;
41
42     protected boolean hidden;
43
44     protected int _hidden;
45
46     /** Holds value of property securityRef. */
47     protected SecurityReference securityRef = null;
48
49     public BaseRegistryEntry()
50     {}
51
52     public BaseRegistryEntry(long id,
53                              String JavaDoc name,
54                              int _hidden,
55                              String JavaDoc title,
56                              String JavaDoc description,
57                              String JavaDoc image,
58                              String JavaDoc role)
59     {
60         this.id = id;
61         this.name = name;
62         this._hidden = _hidden;
63         this.hidden = (_hidden == 1);
64         BaseMetaInfo meta = new BaseMetaInfo(title, description, image);
65         this.setMetaInfo(meta);
66         BaseSecurity security = new BaseSecurity(role);
67         this.setSecurity(security);
68     }
69
70     /**
71      * Implements the equals operation so that 2 elements are equal if
72      * all their member values are equal.
73      */

74     public boolean equals(Object JavaDoc entry)
75     {
76         if (entry==null)
77         {
78             return false;
79         }
80
81         BaseRegistryEntry e = (BaseRegistryEntry)entry;
82
83         if (e.getId()!=getId())
84         {
85             return false;
86         }
87
88         if (e.isHidden()!=isHidden())
89         {
90             return false;
91         }
92
93         if (name!=null)
94         {
95             if (!e.name.equals(name))
96             {
97                 return false;
98             }
99         }
100         else
101         {
102             if (e.name!=null)
103             {
104                 return false;
105             }
106         }
107
108         if (metaInfo != null)
109         {
110             if (!metaInfo.equals(e.metaInfo))
111             {
112                 return false;
113             }
114         }
115         else
116         {
117             if (e.metaInfo!=null)
118             {
119                 return false;
120             }
121         }
122
123         if (security!=null)
124         {
125             if (!security.equals(e.security))
126             {
127                 return false;
128             }
129         }
130         else
131         {
132             if (e.security!=null)
133             {
134                 return false;
135             }
136         }
137
138         return true;
139     }
140
141     /** @see RegistryEntry#getName */
142     public long getId()
143     {
144         return this.id;
145     }
146
147     /** @see RegistryEntry#getName */
148     public String JavaDoc getName()
149     {
150         return this.name;
151     }
152
153     /** @see RegistryEntry#setName */
154     public void setName( String JavaDoc name )
155     {
156         this.name = name;
157     }
158
159     /** @see RegistryEntry#getTitle */
160     public String JavaDoc getTitle()
161     {
162         if (this.metaInfo != null)
163         {
164             String JavaDoc title = this.metaInfo.getTitle();
165             if (null != title)
166             {
167                 return title;
168             }
169         }
170
171         return null;
172     }
173
174     /** @see RegistryEntry#setTitle */
175     public void setTitle(String JavaDoc title)
176     {
177         if (this.metaInfo == null)
178         {
179             this.metaInfo = new BaseMetaInfo();
180         }
181
182         this.metaInfo.setTitle(title);
183     }
184
185     /** @see RegistryEntry#getDescription */
186     public String JavaDoc getDescription()
187     {
188         if (this.metaInfo != null)
189         {
190             String JavaDoc desc = this.metaInfo.getDescription();
191             if (null != desc)
192                 return desc;
193         }
194
195         return null;
196     }
197
198     /** @see RegistryEntry#setDescription */
199     public void setDescription(String JavaDoc description)
200     {
201         if (this.metaInfo == null)
202         {
203             this.metaInfo = new BaseMetaInfo();
204         }
205
206         this.metaInfo.setDescription(description);
207         this.description = description;
208     }
209
210     /** @see RegistryEntry#getSecurity */
211     public Security getSecurity()
212     {
213         return this.security;
214     }
215
216     /** @see RegistryEntry#setSecurity */
217     public void setSecurity( Security security )
218     {
219         this.security = security;
220         this.role = this.security.getRole();
221     }
222
223     /** @see RegistryEntry#isHidden */
224     public boolean isHidden()
225     {
226         return this.hidden;
227     }
228
229     /** @see RegistryEntry#setHidden */
230     public void setHidden( boolean hidden )
231     {
232         this.hidden = hidden;
233         this._hidden = (hidden) ? 1 : 0;
234     }
235
236     // Castor serialization methods
237

238     /** Required by Castor 0.8.11 XML serialization for retrieving the visibility
239       * status
240       */

241     public boolean getHidden()
242     {
243         return this.hidden;
244     }
245
246     /** Required by Castor 0.8.11 XML serialization for retrieving the security
247       * object
248       */

249     public BaseSecurity getBaseSecurity()
250     {
251         return (BaseSecurity)this.security;
252     }
253
254     /** Required by Castor 0.8.11 XML serialization for setting the security
255       * status
256       */

257     public void setBaseSecurity( BaseSecurity security )
258     {
259         this.security = security;
260         this.role = this.security.getRole();
261     }
262
263     public MetaInfo getMetaInfo()
264     {
265         return this.metaInfo;
266     }
267
268     /** Required by Castor 0.8.11 XML serialization for setting the entry
269       * metainfo
270       */

271     public void setMetaInfo( MetaInfo metaInfo )
272     {
273         this.metaInfo = metaInfo;
274         this.title = metaInfo.getTitle();
275         this.description = metaInfo.getDescription();
276         this.image = metaInfo.getImage();
277     }
278
279     /** Required by Castor 0.8.11 XML serialization for retrieving the metainfo
280       */

281     public BaseMetaInfo getBaseMetaInfo()
282     {
283         return (BaseMetaInfo)this.metaInfo;
284     }
285
286     /** Required by Castor 0.8.11 XML serialization for setting the entry
287       * metainfo
288       */

289     public void setBaseMetaInfo( BaseMetaInfo metaInfo )
290     {
291         this.metaInfo = metaInfo;
292         this.title = metaInfo.getTitle();
293         this.description = metaInfo.getDescription();
294         this.image = metaInfo.getImage();
295     }
296
297     /** Getter for property securityId.
298      * @return Value of property securityId.
299      */

300     public SecurityReference getSecurityRef()
301     {
302         return securityRef;
303     }
304
305     /** Setter for property securityId.
306      * @param securityId New value of property securityId.
307      */

308     public void setSecurityRef(SecurityReference securityRef)
309     {
310         this.securityRef = securityRef;
311     }
312
313     // OJB - can't seem to get embedded objects to work without this hack
314
String JavaDoc title;
315     String JavaDoc description;
316     String JavaDoc image;
317     String JavaDoc role;
318
319 }
320
Popular Tags