Java client beans

    The question is about writing a java bean, that will reside on the clinet.

I've gotten a task of writing a java bean, that will be "installed" on the client machine and will be called by an Oracle forms application. The bean should be able to comunicate with the RS232 (serial) port.

I've got no idea which kind of bean to use and how the structure of this should look like. Can anybody give me an example or at least a few pointers on how to find this information?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Dejan PažinConnect With a Mentor Head of SW DevelopmentCommented:

OK. I understand much better now.

First about beans: plain Java Bean is a Java class that you create by specific rules. That means stuff like: implementing getter and setter methods according to rules, create event handlers, firing events,...

Besides those beans there are also Enterprise Java Beans (EJB), which reside on the server. But you are not gonna use those for your task. You just need a plain Bean.

These beans are used a lot as GUI components, so a lot of the stuff there is used for the purpose of visual GUI builders. You are most probably  not gonna need a lot of that stuff, since your bean will not be a visual bean (or will it be?). Anyway, this part is not so complicated, and besides you can get a lot of good documentation here:

BTW: Since you are using jDeveloper, I am sure there is a wizzard for beans, which does a lot of the hard work for you, but its better to understand what the generated code is all about.

As for the RS232 communication, I would check this out first:

I quote: ... The Java Communications API contains support for RS232 serial ports ...

Dejan PažinHead of SW DevelopmentCommented:

It would be good if you gave us some more specific info on your problem.

1. What is the application you have to make?
2. Will this be some kind of a server (since you state that another application will call it)?  Or is it just a client application?
3. What exactly will the bean do?
TheBoogieAuthor Commented:
The bean is supposed to implement "pos printer" (RS232 protocol) interactions. It will be instanciated by an Oracle Forms application. I don't actauly know the Forms appliaction. All I have to do is to implement an interface, so the Oracle forms applets will be able to call the standarized methods.

The bean has to use the computers serial port. Not a spacific one, since the printer can be attached to either one of serial ports. The printer is a RS232 Protocol terminal printer.

One suggestion was, to make this via Windows dll libraries, that already implement this functionality. but this would make the bean OS dependent. So we decided to implement the solution intirely in Java since there is a posibility, that the clients would be using linux.

So far, I have found this; I'm using jDeveloper So I created a Bean from "Client tier". The bean is probably just another Java class if I understood this correctly. As I was exploring the javax.comm package I found javax.comm.SerialPort which extends javax.comm.CommPort. I extended the SerialPort. Both are abstract classes, so I had to implement all the abstact methods from both classes. Now, the dilema is how to actualy implement. Am I going in the right direction?

I have no previous expirience in writing client Java Beans and have only a little idea how this works.
TheBoogieAuthor Commented:
Thanks, dejanpazin.

I actualy understand the rules upon which the java beans must be created. The problem was, that so far I've only been working with server side beans, like session bean and such. So, I found a lot of usefull information on sun links you provided.

I also read parts of the book "OReilly - Java Cookbook" - chapter 11 about serial and parallel ports. Great stuff. In case someone else is working with communication ports.

So far I've written a class CommBean, which implements the and follows the java beans protocol. It contains methods for retriving all ports, available on the machine, opening and closing ports and opening input and output streams. The second class - CommPrinterBean extends the CommBean and contains methods for writing onto the output stream (PrintStream) and reading from input stream (BufferedReader). The OReilly book suggests the use of class DataInputStream.readLine() method for reading, but the method has been depricated (uncorrect character reproduction), so BufferedReader is used.

In order for javax.comm api to work correctly the jre (not jdk) must contain the folowing files from javax.comm package:
<LI>/bin: "win32com.dll"
<LI>/lib: "" and "comm.jar"

If these files are not properly copied, the java files will compile OK, but no ports will be found. In case someone has a problem with finding ports. The info on this is also found on forums.

Now, I've got two problems:

1.) When trying to write some string to a lets say COM1 (there is nothing attached to the port) the write wents through OK. Then I try to read somethign from the input stream and this takes literaly forever. I havent been able to find any information on this, but is there some way to know when to read and how many lines / bytes to read? Is it possible to tell java to try to read only for a period of time? I'm looking form something similar to try - catch statement. Which method to use with RS232 protocol?
<LI>Lock Step,
<LI>Event-Driven or

2.) The bean or better said beans will be packaged into a jar. The jar will have to be signed with a certificate (generated with keytool). Every client machine will contain an instalation of jInitiator (supported by Oracle Forms). In order for IE to use jInitiator JRE the HTML form must use &lt;OBJECT&gt; tag insted of &lt;APPLET&gt;. I've got the folowing:

&lt;OBJECT classid="clsid:CAFECAFE-0013-0001-0018-ABCDEFABCDEF"
      width="200" height="200" align="baseline"
      &lt;PARAM NAME="code" VALUE="PortChooser.class"&gt;
      &lt;PARAM NAME="codebase" VALUE="WEB-INF/classes/"&gt;
      &lt;PARAM NAME="type" VALUE="application/x-jinit-applet;version="&gt;
      No JDK 1.3 support for APPLET!!

The only problem is that when I run the html test form it seems to get stuck in some kind of a loop. It only displays the HTML before the OBJECT tag, but not the applet frame. The PortChooser class is a simple AWT form that displays found ports in drop-downs. It works OK, when ran from jDeveloper.
For test form, I'm using Apache Tomcat 5.5. The class is nested into WEB-INF/classes directory. Could this be the problem? Tomcat disables directory listing for WEB-INF dir, since this is the operating directory.

Thanks in advance.
Dejan PažinHead of SW DevelopmentCommented:

1.) I would do it very much like the Simple Reading Example looks like, using threads:

2.) Dont know much about jInitiator here, sorry. But if this should work as an applet I would sure test it straight from IE, to make sure it works. Then I would first create a very simple applet and make it work in the jInitiator.

After that I would have all I need under control and there should be no problem running my applet inside jInitiator.
All Courses

From novice to tech pro — start learning today.