001: /*---------------------------------------------------------------------------*\
002: $Id: PersistentFeedData.java 6547 2006-11-03 03:38:55Z bmc $
003: \*---------------------------------------------------------------------------*/
004:
005: package org.clapper.curn;
006:
007: import java.util.Collection;
008: import java.util.Collections;
009: import java.util.HashSet;
010: import java.util.Set;
011:
012: /**
013: * <p>A <tt>PersistentFeedData</tt> object contains feed cache data and related
014: * metadata for a single feed (or channel), in a form suitable for saving to
015: * and restoring from an external store. The data are organized to make
016: * persistence operations easier. At runtime, the data are reorganized: The
017: * cache-specific data is stored in the feed cache (see {@link FeedCache}) and
018: * other metadata items are parceled out to various plug-ins.</p>
019: *
020: * <p>There are three categories of persistent feed data:</p>
021: *
022: * <ul>
023: * <li> The feed cache data for the feed itself, stored in a
024: * {@link FeedCacheEntry} object
025: * <li> The feed cache data for the items within the feed, stored in
026: * individual {@link FeedCacheEntry} objects.
027: * <li> Any additional metadata (typically generated by plug-ins)
028: * associated with the feed, stored in name/value pairs within
029: * individual namespaces. (e.g., Each plug-in typically stores its
030: * data in a separate namespace.)
031: * </ul>
032: *
033: * <p><b>WARNING:</b> This class is <b>not</b> thread-safe.</p>
034: *
035: * @see FeedCache
036: * @see DataPersister
037: * @see PersistentFeedItemData
038: *
039: * @version <tt>$Revision: 6547 $</tt>
040: */
041: public class PersistentFeedData {
042: /*----------------------------------------------------------------------*\
043: Private Constants
044: \*----------------------------------------------------------------------*/
045:
046: /*----------------------------------------------------------------------*\
047: Private Instance Data
048: \*----------------------------------------------------------------------*/
049:
050: /**
051: * The FeedCacheEntry for this feed
052: */
053: private FeedCacheEntry feedCacheEntry = null;
054:
055: /**
056: * The PersistentFeedItemData contained within this feed.
057: */
058: private Set<PersistentFeedItemData> feedItemData = new HashSet<PersistentFeedItemData>();
059:
060: /**
061: * Extra metadata associated with the feed.
062: */
063: private Set<PersistentMetadataGroup> feedMetadata = new HashSet<PersistentMetadataGroup>();
064:
065: /*----------------------------------------------------------------------*\
066: Constructor
067: \*----------------------------------------------------------------------*/
068:
069: /**
070: * Creates a new instance of <tt>PersistentFeedData</tt>.
071: *
072: * @param feedCacheEntry the {@link FeedCacheEntry} for the channel/feed
073: */
074: public PersistentFeedData(FeedCacheEntry feedCacheEntry) {
075: setFeedCacheEntry(feedCacheEntry);
076: }
077:
078: /**
079: * Allocate a new empty <tt>PersistentFeedData</tt> object.
080: */
081: public PersistentFeedData() {
082: }
083:
084: /*----------------------------------------------------------------------*\
085: Public Methods
086: \*----------------------------------------------------------------------*/
087:
088: /**
089: * Get the {@link FeedCacheEntry} for the feed
090: *
091: * @return the {@link FeedCacheEntry}
092: */
093: public FeedCacheEntry getFeedCacheEntry() {
094: return feedCacheEntry;
095: }
096:
097: /**
098: * Set the {@link FeedCacheEntry} field.
099: *
100: * @param feedCacheEntry the {@link FeedCacheEntry} object for the
101: * channel/feed
102: */
103: public final void setFeedCacheEntry(
104: final FeedCacheEntry feedCacheEntry) {
105: this .feedCacheEntry = feedCacheEntry;
106:
107: // An entry for a channel will have the same entry URL as channel URL.
108:
109: assert (feedCacheEntry.isChannelEntry());
110: }
111:
112: /**
113: * Add persistent data for a feed item to this object.
114: *
115: * @param itemData the {@link PersistentFeedItemData} object to add
116: */
117: public void addPersistentFeedItem(PersistentFeedItemData itemData) {
118: feedItemData.add(itemData);
119: }
120:
121: /**
122: * Get the list of {@link PersistentFeedItemData} entries associated with
123: * this feed.
124: *
125: * @return a read-only collection of {@link PersistentFeedItemData}
126: * objects and empty collection if there are none.
127: *
128: * @see #addPersistentFeedItem
129: */
130: public Collection<PersistentFeedItemData> getPersistentFeedItems() {
131: return Collections.unmodifiableSet(feedItemData);
132: }
133:
134: /**
135: * Add a metadata group (i.e., all the metadata within a given
136: * namespace) to this object.
137: *
138: * @param metadataGroup the group of metadata
139: */
140: public void addFeedMetadataGroup(
141: PersistentMetadataGroup metadataGroup) {
142: feedMetadata.add(metadataGroup);
143: }
144:
145: /**
146: * Add a metadata group (i.e., all the metadata within a given
147: * namespace) to this object.
148: *
149: * @param metadata the metadata
150: */
151: public void addFeedMetadata(
152: Collection<PersistentMetadataGroup> metadata) {
153: for (PersistentMetadataGroup metadataGroup : metadata)
154: addFeedMetadataGroup(metadataGroup);
155: }
156:
157: /**
158: * Get the extra metadata associated with the feed. The returned data
159: * is aggregated into individual namespaces.
160: *
161: * @return a <tt>Collection</tt> of {@link PersistentMetadataGroup}
162: * objects, each one containing the data for one namespace.
163: * The collection will be empty if there is no feed metadata.
164: */
165: public Collection<PersistentMetadataGroup> getFeedMetadata() {
166: return Collections.unmodifiableCollection(feedMetadata);
167: }
168:
169: /*----------------------------------------------------------------------*\
170: Protected Methods
171: \*----------------------------------------------------------------------*/
172:
173: /*----------------------------------------------------------------------*\
174: Private Methods
175: \*----------------------------------------------------------------------*/
176: }
|