use of org.eclipse.ecf.datashare.mergeable.IMergeableChannel in project ecf by eclipse.
the class RssClientSOContainer method main.
public static final void main(String[] args) throws Exception {
// Get server identity
// String targetURL =
// "http://"+java.net.InetAddress.getLocalHost().getHostName();
String targetURL = "http://feeds.feedburner.com";
if (args.length > 0) {
targetURL = args[0];
}
final ContainerTypeDescription contd = new ContainerTypeDescription(RssContainerInstantiator.class.getName(), RssContainerInstantiator.class.getName(), null);
ContainerFactory.getDefault().addDescription(contd);
final RssClientSOContainer container = new RssClientSOContainer();
// now connect to rss service
final ID serverID = IDFactory.getDefault().createStringID(targetURL);
container.connect(serverID, null);
// get IMergeableChannelContainer adapter
final IMergeableChannelContainerAdapter channelContainer = (IMergeableChannelContainerAdapter) container.getAdapter(IMergeableChannelContainerAdapter.class);
// create channel listener
final IChannelListener listener = new IChannelListener() {
public void handleChannelEvent(IChannelEvent event) {
System.out.println("listener.handleChannelEvent(" + event + ")");
}
};
// create a new channel
final ID channelID = IDFactory.getDefault().createStringID("/reuters/worldNews/");
// ID channelID = IDFactory.getDefault().createStringID("/feed.xml");
final IMergeableChannel channel = channelContainer.createMergeableChannel(channelID, listener, new HashMap());
if (channel instanceof FeedSharedObject) {
// get remote feed (subscribed)
final RssFeed remoteFeed = ((FeedSharedObject) channel).getFeed();
// get local feed (published)
final File feedFile = new File("feed.xml");
RssFeed localFeed = RssFeed.load(feedFile);
if (localFeed == null) {
localFeed = new RssFeed(remoteFeed.getTitle(), remoteFeed.getLink(), remoteFeed.getDescription());
localFeed.setVersion(RssVersion.RSS_2_0);
}
// merge remote feed with local one
localFeed.merge(remoteFeed);
// add a new item to feed
localFeed.addItem(new RssItem("New Google Item", "This is a new item", "http://www.google.com"));
// publish updated feed
localFeed.save(feedFile);
// print item titles
final java.util.List items = localFeed.getItems();
for (int i = 0; i < items.size(); i++) {
System.out.println(" " + i + " " + ((RssItem) items.get(i)).getTitle());
}
}
// remove the channel
channelContainer.removeChannel(channelID);
// disconnect the service
container.disconnect();
container.dispose();
System.out.println("Exiting.");
}
use of org.eclipse.ecf.datashare.mergeable.IMergeableChannel in project ecf by eclipse.
the class RssClientSOContainer method createChannel.
public IMergeableChannel createChannel(IChannelConfig newChannelConfig) throws ECFException {
final IChannelListener listener = newChannelConfig.getListener();
final SharedObjectDescription sodesc = new SharedObjectDescription(FeedSharedObject.class, IDFactory.getDefault().createGUID(), new HashMap());
final SharedObjectTypeDescription sotypedesc = sodesc.getTypeDescription();
ISharedObject sharedObject = null;
if (sotypedesc.getName() != null) {
sharedObject = SharedObjectFactory.getDefault().createSharedObject(sotypedesc, new Object[] { listener });
} else {
sharedObject = createSharedObject(sotypedesc, listener);
}
final IMergeableChannel channel = (IMergeableChannel) sharedObject.getAdapter(IMergeableChannel.class);
if (channel == null) {
throw new SharedObjectCreateException("Cannot coerce object " + channel + " to be of type IChannel");
}
ID newID = sodesc.getID();
if (newID == null) {
newID = IDFactory.getDefault().createGUID();
}
Map properties = sodesc.getProperties();
if (properties == null) {
properties = new HashMap();
}
// Now add channel to container...this will block
getSharedObjectManager().addSharedObject(newID, sharedObject, properties);
return channel;
}
Aggregations