jSyncManager

org.jSyncManager.Transport
Class CommAPITransport

java.lang.Object
  |
  +--org.jSyncManager.API.Transport.SLPTransportInterface
        |
        +--org.jSyncManager.API.Transport.SerialTransportInterface
              |
              +--org.jSyncManager.Transport.CommAPITransport
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.io.Serializable

public class CommAPITransport
extends SerialTransportInterface
implements java.awt.event.ActionListener

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

Version:
$Revision: 1.18 $
Author:
Brad BARCLAY <bbarclay@jsyncmanager.org>
Last modified by: $Author: dingodave $ on $Date: 2003/06/18 05:32:16 $.
See Also:
Serialized Form

Field Summary
protected  javax.swing.JComboBox comSelectBox
          A combo box to hold the communications port names.
protected  java.io.DataInputStream dis
          The port data input stream.
protected  java.io.DataOutputStream dos
          The port data output stream.
protected  javax.comm.CommPortIdentifier port
          A handle to hold the communications port identifier object.
protected  java.lang.String portName
          The name of the port selected for I/O.
protected  javax.comm.SerialPort ser
          A handle to hold the serial port object.
protected  javax.swing.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(java.awt.event.ActionEvent e)
          Method that is called whenever an action is performed.
 void close()
          Closes the Java COMM API port.
protected  javax.swing.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.
 int getPreferredSyncSpeed()
          A method to retreive the users preferred sync speed.
 java.lang.String getResourceBundleName()
          Returns the fully-qualified classname for the resources package to use for this transport.
 java.lang.String getTransportDescription()
          Returns the description for this Transport Interface.
 java.lang.String getTransportExceptionText(TransportException ex)
          Retrieves error information for a given TransportException.
 java.lang.String getTransportName()
          Returns the name of this Transport Interface.
 void initialize()
          Initialize the port.
 void initialize(java.util.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.
 java.lang.String toString()
          Returns settings information on this transport as a String.
 void writeBytes(byte[] data)
          Writes an array of bytes to the Java COMM API port.
 
Methods inherited from class org.jSyncManager.API.Transport.SerialTransportInterface
switchSpeed
 
Methods inherited from class org.jSyncManager.API.Transport.SLPTransportInterface
getConfigPanel, getResourceBundle, isConnected, loadResourceBundle, setConnected
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

port

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

ser

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

dis

protected transient java.io.DataInputStream dis
The port data input stream.

dos

protected transient java.io.DataOutputStream dos
The port data output stream.

comSelectBox

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

speedSelectBox

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

portName

protected java.lang.String portName
The name of the port selected for I/O.
Constructor Detail

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.
Parameters:
portName - A string representing the Comm Port to be used.
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 Detail

close

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

finalize

protected void finalize()
                 throws java.lang.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.
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - a Throwable as per Object.finalize().
See Also:
Object.finalize()

flush

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

getTransportName

public java.lang.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 class SLPTransportInterface
Returns:
the name of this transport interface.

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 class SLPTransportInterface
Throws:
TransportException - thrown when a problem occurs with flushing the stream.

readByte

public byte readByte()
Read a single byte from the Java COMM API port.
Overrides:
readByte in class SLPTransportInterface

setSpeed

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

writeBytes

public void writeBytes(byte[] data)
Writes an array of bytes to the Java COMM API port.
Overrides:
writeBytes in class SLPTransportInterface
Parameters:
data - the bytes to be written to the serial port.

constructConfigPanel

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

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Method that is called whenever an action is performed.
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
the - action that was performed.

initialize

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

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 class SerialTransportInterface
Returns:
the maximum serial rate the user has selected to sync at.

initialize

public void initialize(java.util.Properties properties,
                       int id)
                throws TransportException
Initialize the port.
Overrides:
initialize in class 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.

getTransportExceptionText

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

getResourceBundleName

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

toString

public java.lang.String toString()
Returns settings information on this transport as a String.
Overrides:
toString in class java.lang.Object
Returns:
settings information on this transport as a String.

getTransportDescription

public java.lang.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 class SLPTransportInterface
Returns:
the description for this transport interface.

jSyncManager

Copyright (c) 1999 - 2003 Brad BARCLAY and others. All Rights Reserved.