org.jSyncManager.Transport

Class CommAPITransport

Implemented Interfaces:
ActionListener, Serializable

public class CommAPITransport
extends SerialTransportInterface
implements ActionListener

Sun Communications API Transport. This class provides a bridge between Sun Microsystem's Java Communications API and the SLP Protocol class.

Field Summary

protected JComboBox
comSelectBox
A combo box to hold the communications port names.
protected DataInputStream
dis
The port data input stream.
protected DataOutputStream
dos
The port data output stream.
protected boolean
noflush
A flag to denote whether or not we should flush the transport during speed change.
protected CommPortIdentifier
port
A handle to hold the communications port identifier object.
protected String
portName
The name of the port selected for I/O.
protected SerialPort
ser
A handle to hold the serial port object.
protected JComboBox
speedSelectBox
A combo box to hold the serial port speeds.

Fields inherited from class org.jSyncManager.API.Transport.SerialTransportInterface

INITIAL_SERIAL_SPEED, serialSpeed

Fields inherited from class org.jSyncManager.API.Transport.SLPTransportInterface

configPanel, connected

Constructor Summary

CommAPITransport()
Create a new instance of the Comm API Transport.

Method Summary

void
actionPerformed(ActionEvent e)
Method that is called whenever an action is performed.
void
close()
Closes the Java COMM API port.
protected JPanel
constructConfigPanel()
Constructs this transports configuration panel.
protected void
finalize()
This method overrides Object.finalize() in order to ensure that the underlying Java Comm API connection to the serial handler is properly shut down.
void
flush()
Flushes the input buffer of any remaining data.
protected static Vector
getPortNames()
Returns an array of Strings representing the names of available ports.
int
getPreferredSyncSpeed()
A method to retreive the users preferred sync speed.
String
getResourceBundleName()
Returns the fully-qualified classname for the resources package to use for this transport.
String
getTransportDescription()
Returns the description for this Transport Interface.
String
getTransportExceptionText(TransportException ex)
Retrieves error information for a given TransportException.
String
getTransportName()
Returns the name of this Transport Interface.
void
initialize()
Initialize the port.
void
initialize(Properties properties, int id)
Initialize the port.
void
open()
Opens a read/write connection to the implemented transport.
byte
readByte()
Read a single byte from the Java COMM API port.
protected void
setSpeed(int speed)
Sets the speed of the underlying Java COMM API port.
String
toString()
Returns settings information on this transport as a String.
void
writeBytes(data[] )
Writes an array of bytes to the Java COMM API port.

Methods inherited from class org.jSyncManager.API.Transport.SerialTransportInterface

getPreferredSyncSpeed, setSpeed, switchSpeed

Methods inherited from class org.jSyncManager.API.Transport.SLPTransportInterface

close, constructConfigPanel, flush, getConfigPanel, getResourceBundle, getResourceBundleName, getTransportDescription, getTransportExceptionText, getTransportName, initialize, initialize, isConnected, loadResourceBundle, open, readByte, setConnected, writeBytes

Field Details

comSelectBox

protected JComboBox comSelectBox
A combo box to hold the communications port names.

dis

protected DataInputStream dis
The port data input stream.

dos

protected DataOutputStream dos
The port data output stream.

noflush

protected boolean noflush
A flag to denote whether or not we should flush the transport during speed change.

port

protected CommPortIdentifier port
A handle to hold the communications port identifier object.

portName

protected String portName
The name of the port selected for I/O.

ser

protected SerialPort ser
A handle to hold the serial port object.

speedSelectBox

protected JComboBox speedSelectBox
A combo box to hold the serial port speeds.

Constructor Details

CommAPITransport

public CommAPITransport()
            throws TransportException
Create a new instance of the Comm API Transport. This constructor creates a new instance of the Comm API Transport.
Throws:
TransportException - thrown if the Java Comm API cannot be found, or if the Java Comm API can't find any serial ports on the users system.

Method Details

actionPerformed

public void actionPerformed(ActionEvent e)
Method that is called whenever an action is performed.
Parameters:
e - the action that was performed.

close

public void close()
            throws TransportException
Closes the Java COMM API port.
Overrides:
close in interface SLPTransportInterface
Throws:
TransportException - any exception encountered is rethrown.

constructConfigPanel

protected JPanel constructConfigPanel()
Constructs this transports configuration panel.
Overrides:
constructConfigPanel in interface SLPTransportInterface
Returns:
a javax.swing.JPanel containing the transports settings panel.

finalize

protected void finalize()
            throws Throwable
This method overrides Object.finalize() in order to ensure that the underlying Java Comm API connection to the serial handler is properly shut down.
See Also:
Object.finalize

flush

public void flush()
            throws TransportException
Flushes the input buffer of any remaining data.
Overrides:
flush in interface SLPTransportInterface
Throws:
TransportException - thrown when a problem occurs with flushing the stream.

getPortNames

protected static Vector getPortNames()
            throws NoClassDefFoundError
Returns an array of Strings representing the names of available ports. This method will return to the caller an array of strings representing the serial ports available on this system.
Returns:
an array of String representing the names of the available ports.

getPreferredSyncSpeed

public int getPreferredSyncSpeed()
A method to retreive the users preferred sync speed. As the transport takes care of storing user selections on its own, and as the CMP layer negotiates the speed for the transfer after connecting, it needs a way to determine at what speed the user prefers to sync at.
Overrides:
getPreferredSyncSpeed in interface SerialTransportInterface
Returns:
the maximum serial rate the user has selected to sync at.

getResourceBundleName

public String getResourceBundleName()
Returns the fully-qualified classname for the resources package to use for this transport.
Overrides:
getResourceBundleName in interface SLPTransportInterface
Returns:
a String object containing the fully qualified classname for the ResoureBundle class to use for this transport.

getTransportDescription

public String getTransportDescription()
Returns the description for this Transport Interface. This method will return a string containing the description for this transport interface.
Overrides:
getTransportDescription in interface SLPTransportInterface
Returns:
the description for this transport interface.

getTransportExceptionText

public String getTransportExceptionText(TransportException ex)
Retrieves error information for a given TransportException.
Overrides:
getTransportExceptionText in interface SLPTransportInterface
Parameters:
ex - the TransportException to be inspected.
Returns:
a String object containing a text explaination for the exception.

getTransportName

public String getTransportName()
Returns the name of this Transport Interface. This method will return a string containing the name of this transport interface. This is used when searching for and selecting from one of many available transport interfaces that are installed on the system.
Overrides:
getTransportName in interface SLPTransportInterface
Returns:
the name of this transport interface.

initialize

public void initialize()
            throws TransportException
Initialize the port.
Overrides:
initialize in interface SLPTransportInterface
Throws:
TransportException - thrown if there isn't sufficient info to setup the transport, or if another exception has occurred.

initialize

public void initialize(Properties properties,
                       int id)
            throws TransportException
Initialize the port.
Overrides:
initialize in interface SLPTransportInterface
Parameters:
properties - a reference to the properties file containing configuration information.
id - the transport ID number to load data for.
Throws:
TransportException - if there is a problem initializing the transport.

open

public void open()
            throws TransportException
Opens a read/write connection to the implemented transport. This method should open the transport device being implemented using default parameters.
Overrides:
open in interface SLPTransportInterface
Throws:
TransportException - thrown when a problem occurs with flushing the stream.

readByte

public byte readByte()
            throws TransportException
Read a single byte from the Java COMM API port.
Overrides:
readByte in interface SLPTransportInterface
Throws:
TransportException - this class won't throw any exceptions, but maintains the superclasses exception signature.

setSpeed

protected void setSpeed(int speed)
            throws TransportException
Sets the speed of the underlying Java COMM API port.
Overrides:
setSpeed in interface SerialTransportInterface
Parameters:
speed - The speed to set the transport to.
Throws:
TransportException - thrown when a problem occurs with flushing the stream.

toString

public String toString()
Returns settings information on this transport as a String.
Returns:
settings information on this transport as a String.

writeBytes

public void writeBytes(data[] )
            throws TransportException
Writes an array of bytes to the Java COMM API port.
Overrides:
writeBytes in interface SLPTransportInterface
Parameters:
Throws:
TransportException - this class won't throw any exceptions, but maintains the superclasses exception signature.