001: //
002: // Informa -- RSS Library for Java
003: // Copyright (c) 2002 by Niko Schmuck
004: //
005: // Niko Schmuck
006: // http://sourceforge.net/projects/informa
007: // mailto:niko_schmuck@users.sourceforge.net
008: //
009: // This library is free software.
010: //
011: // You may redistribute it and/or modify it under the terms of the GNU
012: // Lesser General Public License as published by the Free Software Foundation.
013: //
014: // Version 2.1 of the license should be included with this distribution in
015: // the file LICENSE. If the license is not included with this distribution,
016: // you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
017: // or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
018: // MA 02139 USA.
019: //
020: // This library is distributed in the hope that it will be useful,
021: // but WITHOUT ANY WARRANTY; without even the implied waranty of
022: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
023: // Lesser General Public License for more details.
024: //
025:
026: // $Id: ChannelBuilder.java,v 1.22 2006/01/03 00:30:38 niko_schmuck Exp $
027:
028: package de.nava.informa.impl.basic;
029:
030: import java.net.URL;
031: import java.util.Date;
032: import java.util.Properties;
033:
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: import org.jdom.Element;
038:
039: import de.nava.informa.core.CategoryIF;
040: import de.nava.informa.core.ChannelBuilderException;
041: import de.nava.informa.core.ChannelBuilderIF;
042: import de.nava.informa.core.ChannelGroupIF;
043: import de.nava.informa.core.ChannelIF;
044: import de.nava.informa.core.CloudIF;
045: import de.nava.informa.core.ImageIF;
046: import de.nava.informa.core.ItemEnclosureIF;
047: import de.nava.informa.core.ItemGuidIF;
048: import de.nava.informa.core.ItemIF;
049: import de.nava.informa.core.ItemSourceIF;
050: import de.nava.informa.core.TextInputIF;
051:
052: /**
053: * Factory for the creation of the channel object model with the in-memory
054: * implementation.
055: *
056: * @author Niko Schmuck (niko@nava.de)
057: */
058: public class ChannelBuilder implements ChannelBuilderIF {
059:
060: private static Log logger = LogFactory.getLog(ChannelBuilder.class);
061:
062: public ChannelBuilder() {
063: logger.debug("New channel builder for the in-memory backend");
064: }
065:
066: // --------------------------------------------------------------
067: // implementation of ChannelBuilderIF interface
068: // --------------------------------------------------------------
069:
070: public void init(Properties props) throws ChannelBuilderException {
071: logger
072: .debug("Initialising channel builder for in-memory backend");
073: }
074:
075: public ChannelGroupIF createChannelGroup(String title) {
076: return new ChannelGroup(title);
077: }
078:
079: public ChannelIF createChannel(String title, String location) {
080: // TODO Auto-generated method stub
081: return null;
082: }
083:
084: public ChannelIF createChannel(Element channelElement,
085: String title, String location) {
086: // TODO Auto-generated method stub
087: return null;
088: }
089:
090: public ChannelIF createChannel(String title) {
091: return new Channel(title);
092: }
093:
094: public ChannelIF createChannel(Element channelElement, String title) {
095: return new Channel(channelElement, title);
096: }
097:
098: public ItemIF createItem(ChannelIF channel, String title,
099: String description, URL link) {
100: return createItem(null, channel, title, description, link);
101: }
102:
103: public ItemIF createItem(Element itemElement, ChannelIF channel,
104: String title, String description, URL link) {
105: ItemIF item = new Item(itemElement, channel, title,
106: description, link);
107: if (channel != null) {
108: channel.addItem(item);
109: }
110: return item;
111: }
112:
113: /** Create an item from an existing item.
114: * @param chan - Channel in which the new item will be held
115: * @param oldItem - Old item which will provide the state for the new item
116: * @return -
117: */
118: public ItemIF createItem(ChannelIF chan, ItemIF oldItem) {
119: return createItem(null, chan, oldItem.getTitle(), oldItem
120: .getDescription(), oldItem.getLink());
121: }
122:
123: public ImageIF createImage(String title, URL location, URL link) {
124: return new Image(title, location, link);
125: }
126:
127: public TextInputIF createTextInput(String title,
128: String description, String name, URL link) {
129: return new TextInput(title, description, name, link);
130: }
131:
132: public CloudIF createCloud(String domain, int port, String path,
133: String registerProcedure, String protocol) {
134: logger.info("ChannelBuilder is creating a Basic Cloud");
135: return new Cloud(domain, port, path, registerProcedure,
136: protocol);
137: }
138:
139: public ItemSourceIF createItemSource(ItemIF item, String name,
140: String location, Date timestamp) {
141: return new ItemSource(item, name, location, timestamp);
142: }
143:
144: public ItemEnclosureIF createItemEnclosure(ItemIF item,
145: URL location, String type, int length) {
146: return new ItemEnclosure(item, location, type, length);
147: }
148:
149: public ItemGuidIF createItemGuid(ItemIF item, String location,
150: boolean permaLink) {
151: return new ItemGuid(item, location, permaLink);
152: }
153:
154: public CategoryIF createCategory(CategoryIF parent, String title) {
155: CategoryIF cat = new Category(title);
156: if (parent != null) {
157: parent.addChild(cat);
158: }
159: return cat;
160: }
161:
162: /**
163: *
164: * The following methods are only meaningful for persistent informa back end
165: * implementations such as Hibernate and are no-ops otherwise.
166: */
167: public void close() throws ChannelBuilderException {
168: logger.debug("Closing channel builder for in-memory backend");
169: }
170:
171: public void beginTransaction() throws ChannelBuilderException {
172: logger.debug("No-op beginTransaction for in-memory backend");
173: }
174:
175: public void endTransaction() throws ChannelBuilderException {
176: logger.debug("No-op endTransaction for in-memory backend");
177: }
178:
179: public void update(Object obj) {
180: logger.debug("No-op update for in-memory backend");
181: }
182:
183: }
|