Jeffrey Ricker is an experienced technology development executive with 15 years of leadership in defense and the private sector. He is the principal of Jeffrey Ricker LLC, providing expertise in Eclipse, RCP and OSGi to Fortune 500 and start-up clients. Previously, he was the founder of Distributed Instruments and XML Solutions Corp. Jeffrey has posted 5 posts at DZone. You can read more from them at their website. View Full User Profile

Eclipse Adapters - A Hands-On, Hand-Holding Explanation

  • submit to reddit

Real world example

The Eclipse Communication Framework (ECF) began as a means of putting instant messaging in the Eclipse platform, but it has since expanded in scope to enable multiple means of data sharing in the Eclipse Rich Client Platform (RCP).
ECF begins with a simple interface called a container and uses the IAdaptable pattern of Eclipse to achieve specific functionality. If we were using ECF for instant messaging, then we would focus on adapting the container for presence and other interfaces.

Listing 10 shows how to create an ECF container. The container provides a generic means for handling any type of session level protocol. Listing 11 shows how to adapt a container for managing presence, a common feature of instant messaging. The container-adapter pattern decouples the session level protocols from the services provided over those protocols.

// make container instance
IContainer container = ContainerFactory.getDefault()
// make targetID
ID newID = IDFactory.getDefault()
// then connect to targetID with null authentication data

Listing 10 Creating an ECF connection

IPresenceContainer presence = (IPresenceContainer)container
if (presence != null) {
// The container DOES expose IPresenceContainer capabilities
} else {
// The container does NOT expose IPresenceContainer capabilities

Listing 11 Adapting a container for functionality

The possibilities are sweeping. For instance, we can create our own adapter called IMarketDataContainer that provides streaming market data. We would create it the same way as IPresenceContainer. As shown in Listing 12, different market data providers might have different session level protocols, even proprietary protocols, but the containeradapter pattern would allow us to plug all of them in to our Eclipse RCP the same way.

IContainer container = ContainerFactory.getDefault()
ID newID = IDFactory.getDefault().createID("md.nyse","");
IMarketDataContainer marketData = (IMarketDataContainer)container

Listing 12 New container types for ECF

The adaptor pattern is a powerful tool which you will find used throughout the Eclipse platform. I hope with the hands-on, hand holding explanation in this article that you can now unleash that power in your own RCP applications.

Published at DZone with permission of its author, Jeffrey Ricker.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)