KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > impl > basic > ChannelBuilder


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: ChannelBuilder.java,v 1.21 2004/01/09 20:31:19 pitosalas Exp $
28

29 package de.nava.informa.impl.basic;
30
31 import java.net.URL JavaDoc;
32 import java.util.Date JavaDoc;
33 import java.util.Properties JavaDoc;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 import org.jdom.Element;
39
40 import de.nava.informa.core.CategoryIF;
41 import de.nava.informa.core.ChannelBuilderException;
42 import de.nava.informa.core.ChannelBuilderIF;
43 import de.nava.informa.core.ChannelGroupIF;
44 import de.nava.informa.core.ChannelIF;
45 import de.nava.informa.core.CloudIF;
46 import de.nava.informa.core.ImageIF;
47 import de.nava.informa.core.ItemEnclosureIF;
48 import de.nava.informa.core.ItemGuidIF;
49 import de.nava.informa.core.ItemIF;
50 import de.nava.informa.core.ItemSourceIF;
51 import de.nava.informa.core.TextInputIF;
52
53 /**
54  * Factory for the creation of the channel object model with the in-memory
55  * implementation.
56  *
57  * @author Niko Schmuck (niko@nava.de)
58  */

59 public class ChannelBuilder implements ChannelBuilderIF {
60
61   private static Log logger = LogFactory.getLog(ChannelBuilder.class);
62
63   public ChannelBuilder() {
64     logger.debug("New channel builder for the in-memory backend");
65   }
66
67   // --------------------------------------------------------------
68
// implementation of ChannelBuilderIF interface
69
// --------------------------------------------------------------
70

71   public void init(Properties JavaDoc props) throws ChannelBuilderException {
72     logger.debug("Initialising channel builder for in-memory backend");
73   }
74
75   public ChannelGroupIF createChannelGroup(String JavaDoc title) {
76     return new ChannelGroup(title);
77   }
78
79   public ChannelIF createChannel(String JavaDoc title) {
80     return new Channel(title);
81   }
82
83   public ChannelIF createChannel(Element channelElement, String JavaDoc title) {
84     return new Channel(channelElement, title);
85   }
86
87   public ItemIF createItem(ChannelIF channel, String JavaDoc title, String JavaDoc description,
88                            URL JavaDoc link) {
89     return createItem(null, channel, title, description, link);
90   }
91
92   public ItemIF createItem(Element itemElement, ChannelIF channel, String JavaDoc title, String JavaDoc description,
93                            URL JavaDoc link) {
94     ItemIF item = new Item(itemElement, channel, title, description, link);
95     if (channel != null) {
96       channel.addItem(item);
97     }
98     return item;
99   }
100
101 /** Create an item from an existing item.
102  * @param chan - Channel in which the new item will be held
103  * @param oldItem - Old item which will provide the state for the new item
104  * @return -
105  */

106   public ItemIF createItem(ChannelIF chan, ItemIF oldItem)
107   {
108         return createItem(null, chan, oldItem.getTitle(), oldItem.getDescription(), oldItem.getLink());
109   }
110
111   public ImageIF createImage(String JavaDoc title, URL JavaDoc location, URL JavaDoc link) {
112     return new Image(title, location, link);
113   }
114
115   public TextInputIF createTextInput(String JavaDoc title, String JavaDoc description, String JavaDoc name, URL JavaDoc link) {
116     return new TextInput(title, description, name, link);
117   }
118
119   public CloudIF createCloud(String JavaDoc domain, int port, String JavaDoc path, String JavaDoc registerProcedure, String JavaDoc protocol) {
120     logger.info("ChannelBuilder is creating a Basic Cloud");
121     return new Cloud(domain, port, path, registerProcedure, protocol);
122   }
123
124   public ItemSourceIF createItemSource(ItemIF item, String JavaDoc name, String JavaDoc location, Date JavaDoc timestamp) {
125     return new ItemSource(item, name, location, timestamp);
126   }
127
128   public ItemEnclosureIF createItemEnclosure(ItemIF item, URL JavaDoc location, String JavaDoc type, int length) {
129     return new ItemEnclosure(item, location, type, length);
130   }
131
132   public ItemGuidIF createItemGuid(ItemIF item, String JavaDoc location, boolean permaLink) {
133     return new ItemGuid(item, location, permaLink);
134   }
135
136   public CategoryIF createCategory(CategoryIF parent, String JavaDoc title) {
137     CategoryIF cat = new Category(title);
138     if (parent != null) {
139       parent.addChild(cat);
140     }
141     return cat;
142   }
143
144 /**
145  *
146  * The following methods are only meaningful for persistent informa back end
147  * implementations such as Hibernate and are no-ops otherwise.
148  */

149   public void close() throws ChannelBuilderException {
150     logger.debug("Closing channel builder for in-memory backend");
151   }
152
153   public void beginTransaction() throws ChannelBuilderException
154   {
155         logger.debug("No-op beginTransaction for in-memory backend");
156   }
157
158   public void endTransaction() throws ChannelBuilderException
159   {
160         logger.debug("No-op endTransaction for in-memory backend");
161   }
162
163   public void update(Object JavaDoc obj)
164   {
165         logger.debug("No-op update for in-memory backend");
166   }
167 }
168
Popular Tags