001: /*---------------------------------------------------------------------------*\
002: $Id: AbstractPersistentDataClient.java 6956 2007-08-11 15:20:31Z bmc $
003: \*---------------------------------------------------------------------------*/
004:
005: package org.clapper.curn;
006:
007: import java.util.Collections;
008: import java.util.HashMap;
009: import java.util.Map;
010:
011: /**
012: * Abstract class that implements the {@link PersistentDataClient}
013: * interface, providing stubs or simple versions of the methods. This class
014: * makes it easier for a class to declare itself as a
015: * <tt>PersistentDataClient</tt>, even if it doesn't need to implement all
016: * the <tt>PersistentDataClient</tt> methods.
017: *
018: * @version <tt>$Revision: 6956 $</tt>
019: */
020: public class AbstractPersistentDataClient implements
021: PersistentDataClient {
022: /*----------------------------------------------------------------------*\
023: Private Constants
024: \*----------------------------------------------------------------------*/
025:
026: private static Map<String, String> NO_METADATA = Collections
027: .unmodifiableMap(new HashMap<String, String>());
028:
029: /*----------------------------------------------------------------------*\
030: Private Instance Data
031: \*----------------------------------------------------------------------*/
032:
033: /*----------------------------------------------------------------------*\
034: Constructor
035: \*----------------------------------------------------------------------*/
036:
037: /**
038: * Creates a new instance of AbstractPersistentDataClient
039: */
040: protected AbstractPersistentDataClient() {
041: }
042:
043: /*----------------------------------------------------------------------*\
044: Public Methods
045: \*----------------------------------------------------------------------*/
046:
047: /**
048: * <p>Process a data item that has been read from the metadata store
049: * and is associated with a feed (or channel). This method is
050: * called when the metadata store is being loaded into memory
051: * at the beginning of a <i>curn</i> run. This method is only called
052: * for data items within this object's name space.</p>
053: *
054: * <p>This stub implementation does nothing.</p>
055: *
056: *
057: * @param name the name associated with the data item
058: * @param value the (string) value of the data
059: * @param feedData the {@link FeedCacheEntry} record for the feed
060: * @see #getMetatdataNamespace
061: * @throws CurnException on error
062: */
063: public void parseFeedMetadata(String name, String value,
064: FeedCacheEntry feedData) throws CurnException {
065: }
066:
067: /**
068: * <p>Process a data item that has been read from the metadata store
069: * and is associated with a cached item. This method is called when
070: * the metadata store is being loaded into memory at the beginning
071: * of a <i>curn</i> run. This method is only called for data items
072: * within this object's name space.</p>
073: *
074: * <p>This stub implementation does nothing.</p>
075: *
076: * @param name the name associated with the data item
077: * @param value the (string) value of the data
078: * @param itemData The {@link FeedCacheEntry} data for the item
079: *
080: * @throws CurnException on error
081: *
082: * @see #getMetatdataNamespace
083: */
084: public void parseItemMetadata(String name, String value,
085: FeedCacheEntry itemData) throws CurnException {
086: }
087:
088: /**
089: * <p>Process an "extra" data item that is not associated with a feed
090: * or an item. This method is called when the metadata store is
091: * being loaded into memory at the beginning of a <i>curn</i> run.
092: * This method is only called for data items within this object's name
093: * space.</p>
094: *
095: *
096: * @param name the name of the data item
097: * @param value its value
098: *
099: * @throws CurnException on error
100: *
101: * @see #getMetatdataNamespace
102: */
103: public void parseExtraMetadata(String name, String value)
104: throws CurnException {
105: }
106:
107: /**
108: * <p>Get the metadata that is to be saved with a particular feed or
109: * channel.</p>
110: *
111: * <p>This stub implementation does nothing and returns an empty map.</p>
112: *
113: * @param feedData the {@link FeedCacheEntry} record for the feed
114: *
115: * @return a <tt>Map</tt> of all the name/value pairs to be associated
116: * with the feed. The names should not be qualified by the
117: * namespace; the caller will handle that. An empty or null
118: * map signifies that this object has no metadata for the feed.
119: *
120: * @throws CurnException on error
121: */
122: public Map<String, String> getMetadataForFeed(
123: FeedCacheEntry feedData) throws CurnException {
124: return NO_METADATA;
125: }
126:
127: /**
128: * <p>Get the metadata that is to be saved with a particular item within a
129: * feed.</p>
130: *
131: * <p>This stub implementation does nothing and returns an empty map.</p>
132: *
133: * @param itemData the {@link FeedCacheEntry} record for the item
134: * @param feedData the {@link FeedCacheEntry} record for the parent feed
135: *
136: * @return a <tt>Map</tt> of all the name/value pairs to be associated
137: * with the item. The names should not be qualified by the
138: * namespace; the caller will handle that. An empty or null
139: * map signifies that this object has no metadata for the item.
140: *
141: * @throws CurnException on error
142: */
143: public Map<String, String> getMetadataForItem(
144: FeedCacheEntry itemData, FeedCacheEntry feedData)
145: throws CurnException {
146: return NO_METADATA;
147: }
148:
149: /**
150: * <p>Get any extra metadata (i.e., data that is not associated with a feed
151: * or an item) that is to be saved.</p>
152: *
153: * <p>This stub implementation does nothing and returns an empty map.</p>
154: *
155: * @return a <tt>Map</tt> of all the name/value pairs to be associated
156: * with the feed. The names should not be qualified by the
157: * namespace; the caller will handle that. An empty or null
158: * map signifies that this object has no extract metadata.
159: *
160: * @throws CurnException on error
161: */
162: public Map<String, String> getExtraFeedMetadata()
163: throws CurnException {
164: return NO_METADATA;
165: }
166:
167: /**
168: * <p>Get the namespace for this object's metadata. The namespace must
169: * be unique. Think of it as a package name for the data. Recommendation:
170: * Use the fully-qualified class name.</p>
171: *
172: * <p>This implementation returns the fully-qualified class name of the
173: * subclass.</p>
174: *
175: * @return the namespace
176: */
177: public String getMetatdataNamespace() {
178: return this .getClass().getName();
179: }
180:
181: /*----------------------------------------------------------------------*\
182: Protected Methods
183: \*----------------------------------------------------------------------*/
184:
185: /*----------------------------------------------------------------------*\
186: Private Methods
187: \*----------------------------------------------------------------------*/
188: }
|