KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > syndication > feed > synd > SyndEntryImpl


1 /*
2  * Copyright 2004 Sun Microsystems, Inc.
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 com.sun.syndication.feed.synd;
18
19 import com.sun.syndication.feed.impl.ObjectBean;
20 import com.sun.syndication.feed.module.*;
21 import com.sun.syndication.feed.module.impl.ModuleUtils;
22 import com.sun.syndication.feed.synd.impl.URINormalizer;
23 import com.sun.syndication.feed.impl.CopyFromHelper;
24
25 import java.util.*;
26 import java.io.Serializable JavaDoc;
27
28 /**
29  * Bean for entries of SyndFeedImpl feeds.
30  * <p>
31  * @author Alejandro Abdelnur
32  *
33  */

34 public class SyndEntryImpl implements Serializable JavaDoc,SyndEntry {
35     private ObjectBean _objBean;
36     private String JavaDoc _uri;
37     private String JavaDoc _title;
38     private String JavaDoc _link;
39     private SyndContent _description;
40     private List _contents;
41     private List _modules;
42
43     private static final Set IGNORE_PROPERTIES = new HashSet();
44
45     /**
46      * Unmodifiable Set containing the convenience properties of this class.
47      * <p>
48      * Convenience properties are mapped to Modules, for cloning the convenience properties
49      * can be ignored as the will be copied as part of the module cloning.
50      */

51     public static final Set CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES);
52
53     static {
54         IGNORE_PROPERTIES.add("publishedDate");
55         IGNORE_PROPERTIES.add("author");
56         IGNORE_PROPERTIES.add("categories");
57     }
58
59     /**
60      * For implementations extending SyndEntryImpl to be able to use the ObjectBean functionality
61      * with extended interfaces.
62      * <p>
63      * @param beanClass
64      * @param convenienceProperties set containing the convenience properties of the SyndEntryImpl
65      * (the are ignored during cloning, check CloneableBean for details).
66      *
67      */

68     protected SyndEntryImpl(Class JavaDoc beanClass,Set convenienceProperties) {
69         _objBean = new ObjectBean(beanClass,this,convenienceProperties);
70     }
71
72     /**
73      * Default constructor. All properties are set to <b>null</b>.
74      * <p>
75      *
76      */

77     public SyndEntryImpl() {
78         this(SyndEntry.class,IGNORE_PROPERTIES);
79     }
80
81     /**
82      * Creates a deep 'bean' clone of the object.
83      * <p>
84      * @return a clone of the object.
85      * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
86      *
87      */

88     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
89         return _objBean.clone();
90     }
91
92     /**
93      * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
94      * <p>
95      * @param other he reference object with which to compare.
96      * @return <b>true</b> if 'this' object is equal to the 'other' object.
97      *
98      */

99     public boolean equals(Object JavaDoc other) {
100         return _objBean.equals(other);
101     }
102
103     /**
104      * Returns a hashcode value for the object.
105      * <p>
106      * It follows the contract defined by the Object hashCode() method.
107      * <p>
108      * @return the hashcode of the bean object.
109      *
110      */

111     public int hashCode() {
112         return _objBean.hashCode();
113     }
114
115     /**
116      * Returns the String representation for the object.
117      * <p>
118      * @return String representation for the object.
119      *
120      */

121     public String JavaDoc toString() {
122         return _objBean.toString();
123     }
124
125
126     /**
127      * Returns the entry URI.
128      * <p>
129      * How the entry URI maps to a concrete feed type (RSS or Atom) depends on
130      * the concrete feed type. This is explained in detail in Rome documentation,
131      * <a HREF="http://wiki.java.net/bin/edit/Javawsxml/Rome04URIMapping">Feed and entry URI mapping</a>.
132      * <p>
133      * The returned URI is a normalized URI as specified in RFC 2396bis.
134      * <p>
135      * @return the entry URI, <b>null</b> if none.
136      *
137      */

138     public String JavaDoc getUri() {
139         return _uri;
140     }
141
142     /**
143      * Sets the entry URI.
144      * <p>
145      * How the entry URI maps to a concrete feed type (RSS or Atom) depends on
146      * the concrete feed type. This is explained in detail in Rome documentation,
147      * <a HREF="http://wiki.java.net/bin/edit/Javawsxml/Rome04URIMapping">Feed and entry URI mapping</a>.
148      * <p>
149      * @param uri the entry URI to set, <b>null</b> if none.
150      *
151      */

152     public void setUri(String JavaDoc uri) {
153         _uri = URINormalizer.normalize(uri);
154     }
155
156     /**
157      * Returns the entry title.
158      * <p>
159      * @return the entry title, <b>null</b> if none.
160      *
161      */

162     public String JavaDoc getTitle() {
163         return _title;
164     }
165
166     /**
167      * Sets the entry title.
168      * <p>
169      * @param title the entry title to set, <b>null</b> if none.
170      *
171      */

172     public void setTitle(String JavaDoc title) {
173         _title = title;
174     }
175
176     /**
177      * Returns the entry link.
178      * <p>
179      * @return the entry link, <b>null</b> if none.
180      *
181      */

182     public String JavaDoc getLink() {
183         return _link;
184     }
185
186     /**
187      * Sets the entry link.
188      * <p>
189      * @param link the entry link to set, <b>null</b> if none.
190      *
191      */

192     public void setLink(String JavaDoc link) {
193         _link = link;
194     }
195
196     /**
197      * Returns the entry description.
198      * <p>
199      * @return the entry description, <b>null</b> if none.
200      *
201      */

202     public SyndContent getDescription() {
203         return _description;
204     }
205
206     /**
207      * Sets the entry description.
208      * <p>
209      * @param description the entry description to set, <b>null</b> if none.
210      *
211      */

212     public void setDescription(SyndContent description) {
213         _description = description;
214     }
215
216     /**
217      * Returns the entry contents.
218      * <p>
219      * @return a list of SyndContentImpl elements with the entry contents,
220      * an empty list if none.
221      *
222      */

223     public List getContents() {
224         return (_contents==null) ? (_contents=new ArrayList()) : _contents;
225     }
226
227     /**
228      * Sets the entry contents.
229      * <p>
230      * @param contents the list of SyndContentImpl elements with the entry contents to set,
231      * an empty list or <b>null</b> if none.
232      *
233      */

234     public void setContents(List contents) {
235         _contents = contents;
236     }
237
238
239     /**
240      * Returns the entry published date.
241      * <p>
242      * This method is a convenience method, it maps to the Dublin Core module date.
243      * <p>
244      * @return the entry published date, <b>null</b> if none.
245      *
246      */

247     public Date getPublishedDate() {
248         return getDCModule().getDate();
249     }
250
251     /**
252      * Sets the entry published date.
253      * <p>
254      * This method is a convenience method, it maps to the Dublin Core module date.
255      * <p>
256      * @param publishedDate the entry published date to set, <b>null</b> if none.
257      *
258      */

259     public void setPublishedDate(Date publishedDate) {
260         getDCModule().setDate(publishedDate);
261     }
262
263     /**
264      * Returns the entry author.
265      * <p>
266      * This method is a convenience method, it maps to the Dublin Core module creator.
267      * <p>
268      * @return the entry author, <b>null</b> if none.
269      *
270      */

271     public String JavaDoc getAuthor() {
272         return getDCModule().getCreator();
273     }
274
275     /**
276      * Sets the entry author.
277      * <p>
278      * This method is a convenience method, it maps to the Dublin Core module creator.
279      * <p>
280      * @param author the entry author to set, <b>null</b> if none.
281      *
282      */

283     public void setAuthor(String JavaDoc author) {
284         getDCModule().setCreator(author);
285     }
286
287     /**
288      * Returns the entry categories.
289      * <p>
290      * This method is a convenience method, it maps to the Dublin Core module subjects.
291      * <p>
292      * @return a list of SyndCategoryImpl elements with the entry categories,
293      * an empty list if none.
294      *
295      */

296     public List getCategories() {
297        return new SyndCategoryListFacade(getDCModule().getSubjects());
298     }
299
300     /**
301      * Sets the entry categories.
302      * <p>
303      * This method is a convenience method, it maps to the Dublin Core module subjects.
304      * <p>
305      * @param categories the list of SyndCategoryImpl elements with the entry categories to set,
306      * an empty list or <b>null</b> if none.
307      *
308      */

309     public void setCategories(List categories) {
310         getDCModule().setSubjects(SyndCategoryListFacade.convertElementsSyndCategoryToSubject(categories));
311     }
312
313     /**
314      * Returns the entry modules.
315      * <p>
316      * @return a list of ModuleImpl elements with the entry modules,
317      * an empty list if none.
318      *
319      */

320     public List getModules() {
321         if (_modules==null) {
322             _modules=new ArrayList();
323         }
324         if (ModuleUtils.getModule(_modules,DCModule.URI)==null) {
325             _modules.add(new DCModuleImpl());
326         }
327         return _modules;
328     }
329
330     /**
331      * Sets the entry modules.
332      * <p>
333      * @param modules the list of ModuleImpl elements with the entry modules to set,
334      * an empty list or <b>null</b> if none.
335      *
336      */

337     public void setModules(List modules) {
338         _modules = modules;
339     }
340
341     /**
342      * Returns the module identified by a given URI.
343      * <p>
344      * @param uri the URI of the ModuleImpl.
345      * @return The module with the given URI, <b>null</b> if none.
346      */

347     public Module getModule(String JavaDoc uri) {
348         return ModuleUtils.getModule(getModules(),uri);
349     }
350
351     /**
352      * Returns the Dublin Core module of the feed.
353      * @return the DC module, it's never <b>null</b>
354      *
355      */

356     private DCModule getDCModule() {
357         return (DCModule) getModule(DCModule.URI);
358     }
359
360     public Class JavaDoc getInterface() {
361         return SyndEntry.class;
362     }
363
364     public void copyFrom(Object JavaDoc obj) {
365         COPY_FROM_HELPER.copy(this,obj);
366     }
367
368     private static final CopyFromHelper COPY_FROM_HELPER;
369
370     static {
371         Map basePropInterfaceMap = new HashMap();
372         basePropInterfaceMap.put("uri",String JavaDoc.class);
373         basePropInterfaceMap.put("title",String JavaDoc.class);
374         basePropInterfaceMap.put("link",String JavaDoc.class);
375         basePropInterfaceMap.put("description",SyndContent.class);
376         basePropInterfaceMap.put("contents",SyndContent.class);
377         basePropInterfaceMap.put("modules",Module.class);
378
379         Map basePropClassImplMap = new HashMap();
380         basePropClassImplMap.put(SyndContent.class,SyndContentImpl.class);
381         basePropClassImplMap.put(DCModule.class,DCModuleImpl.class);
382         basePropClassImplMap.put(SyModule.class,SyModuleImpl.class);
383
384         COPY_FROM_HELPER = new CopyFromHelper(SyndEntry.class,basePropInterfaceMap,basePropClassImplMap);
385     }
386
387 }
388
Popular Tags