Article View: borland.public.jbuilder.java.language
Article #18277Re: InfoBus Examples
From: William Yu
Date: Tue, 14 Jul 1998 00:00
Date: Tue, 14 Jul 1998 00:00
113 lines
4939 bytes
4939 bytes
Greg Tomalesky wrote:
>
> Does anyone have (or know where I can get) examples of applets
> written to use the InfoBus (Lotus/Sun) api? The examples that come
> with the distribution are OK but require that the data item be a part
> of the applet.
Finding some good documentation on InfoBus is near impossible. I must
have read both the API HTML documentation and the PDF specifications
left and right and up and down before I even understood the basic
concepts. Let me see if I can explain some hard fought insights.
Step 1. Classes participating in an InfoBus must implement the
InfoBusMember interface.
public class InfoBusMemberImpl implements InfoBusMember {...}
The methods you must define are:
public void addInfoBusPropertyListener(PropertyChangeListener pcl)
public void removeInfoBusPropertyListener(PropertyChangeListener pcl)
public void addInfoBusVetoableListener(VetoableChangeListener vcl)
public void removeInfoBusVetoableListener(VetoableChangeListener vcl)
public InfoBus getInfoBus()
public void setInfoBus(InfoBus ib) throws PropertyVetoException
This looks like a ton of work...and how the hell do we actually
implement them? Luckily, we have the InfoBusMemberSupport class to give
us a hand to which we pass the corresponding method/parameters, like so:
public class InfoBusMemberImpl implements InfoBusMember {
private InfoBusMemberSupport ibms = new InfoBusMemberSupport(this);
public void addInfoBusPropertyListener(PropertyChangeListener pcl) {
ibms.addInfoBusPropertyListener(pcl);
}
...
}
We can also throw in some code to automatically join/leave the InfoBus
(error handling not included):
public class InfoBusMemberImpl implements InfoBusMember {
private InfoBusMemberSupport ibms = new InfoBusMemberSupport(this);
public InfoBusMemberImpl() {
ibms.joinInfoBus("MY_INFOBUS");
}
public void close() {
ibms.leaveInfoBus();
ibms = null;
}
...
}
Now that we have the basics for joining an InfoBus, we can create
classes to read from and write to an InfoBus. The process is a bit
convoluted but we start with a writer class that implements both
InfoBusMember and InfoBusDataProducer. (To make it easier though, you
can inherit from the InfoBusMemberImpl defined above and just implement
the InfoBusDataProducer methods.)
public class InfoBusWriter extends InfoBusMemberImpl implements
InfoBusDataProducer {
public void dataItemRequested(InfoBusItemRequestedEvent e)
public void propertyChange(PropertyChangeEvent e)
}
Reader class implements InfoBusDataConsumer:
public class InfoBusReader extends InfoBusMemberImpl implements
InfoBusDataConsumer {
public void dataItemRevoked(InfoBusItemRevokedEvent e)
public void dataItemAvailable(InfoBusItemAvailableEvent e)
public void propertyChange(PropertyChangeEvent e)
}
Finally, we need a class that implements DataItem (or related interfaces
like ImmediateAccess) to store data being passed on the InfoBus.
public class InfoBusImmediateItem implements ImmediateAccess {
public String getPresentationString(Locale l)
public Object getValueAsObject()
public String getValueAsString()
public void setValue(Object)
}
With the above,The data flow logic goes something like:
1. The write() method calls the fireItemAvailable() method announcing
the availability of a data item. Syntax is roughly:
ibms.getInfoBus().fireItemAvailable("FOR_IB_READER2", this);
2. fireItemAvailable() notifies the implemented dataItemAvailable() in
all InfoBusReaders instantiated. In this method, we use the
e.getDataItemName() to see if this is a data item we are looking for. If
so, we can then use the Infobus's findDataItem() to actually get the
data. Quick example:
if (e.getDataItemName().equals("FOR_IB_READER2"))
answer = ibms.getInfoBus().findDataItem("FOR_IB_READER2", this);
3. findDataItem() then notifies dataItemRequested in all
InfoBusWriters instantiated. Like in step 2, we check to see if the data
label matches. If so, we wrap the data in InfoBusImmediateItem and we
can finally send the data to the reader.
if (e.getDataItemName().equals("FOR_IB_READER2"))
e.setDataItem(new InfoBusImmediateItem("Hello Reader 2"));
Technical Details
Message-ID:
<35AC1BDB.443DE28@Bigfoot.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<35a9e8c5.1376917@forums.inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,5e122ff4a98c4e9e X-Google-Attributes: gidf74b3,public From: William Yu <William_Yu@Bigfoot.com> Subject: Re: InfoBus Examples Date: 1998/07/14 Message-ID: <35AC1BDB.443DE28@Bigfoot.com> X-Deja-AN: 371553259 Content-Transfer-Encoding: 7bit References: <35a9e8c5.1376917@forums.inprise.com> Content-Type: text/plain; charset=us-ascii Organization: American All-Risk Group (AARG) Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language