| java.lang.Object com.sun.midp.io.j2me.ProtocolBase com.sun.midp.io.j2me.sms.Protocol
Protocol | public class Protocol extends ProtocolBase (Code) | | SMS message connection implementation.
Protocol itself is not instantiated. Instead, the application
calls Connector.open with an SMS URL string and obtains a
javax.wireless.messaging.MessageConnection MessageConnection object. It is an instance of MessageConnection
that is instantiated. The Generic Connection Framework mechanism
in CLDC will return a Protocol object, which is the
implementation of MessageConnection . The
Protocol object represents a connection to a low-level transport
mechanism.
Optional packages, such as Protocol , cannot reside in
small devices.
The Generic Connection Framework allows an application to reach the
optional packages and classes indirectly. For example, an application
can be written with a string that is used to open a connection. Inside
the implementation of Connector , the string is mapped to a
particular implementation: Protocol , in this case. This allows
the implementation to be optional even though
the interface, MessageConnection , is required.
Closing the connection frees an instance of MessageConnection .
The Protocol class contains methods
to open and close the connection to the low-level transport mechanism. The
messages passed on the transport mechanism are defined by the
MessageObject MessageObject class.
Connections can be made in either client mode or server mode.
- Client mode connections are for sending messages only. They are
created by passing a string identifying a destination address to the
Connector.open() method.
- Server mode connections are for receiving and sending messages. They
are created by passing a string that identifies a port, or equivalent,
on the local host to the
Connector.open() method.
The class also contains methods to send, receive, and construct
Message objects.
This class declares that it implements StreamConnection
so it can intercept calls to Connector.open*Stream()
to throw an IllegalArgumentException .
|
Constructor Summary | |
public | Protocol() Creates a message connection protocol handler. |
Method Summary | |
protected void | checkReceivePermission() Checks internal setting of receive permission. | public void | close() Closes the connection. | protected int | close00(int connHandle, int deRegister) Close connection.
Parameters: connHandle - handle returned by open0 Parameters: deRegister - Deregistration appID when parameter is 1. | protected String | getAppID() Gets the connection parameter in string mode. | public Message | newMessage(String type) Constructs a new message object of a text or binary type.
If the TEXT_MESSAGE constant is passed in, the
TextMessage interface is implemented by the created object.
If the BINARY_MESSAGE constant is passed in, the
BinaryMessage interface is implemented by the created
object.
If this method is called in a sending mode, a new Message
object is requested from the connection. | public Message | newMessage(String type, String addr) Constructs a new message object of a text or binary type and specifies
a destination address.
If the TEXT_MESSAGE constant is passed in, the
TextMessage interface is implemented by the created object.
If the BINARY_MESSAGE constant is passed in, the
BinaryMessage interface is implemented by the created
object.
The destination address addr has the following format:
sms:// phone_number:port
Parameters: type - TEXT_MESSAGE orBINARY_MESSAGE . Parameters: addr - the destination address of the message. | public int | numberOfSegments(Message msg) Returns how many segments in the underlying protocol would
be needed for sending the Message given as the parameter.
Note that this method does not actually send the message;
it will only calculate the number of protocol segments
needed for sending it.
This method calculates the number of segments required
when this message is split into the protocol segments
utilizing the underlying protocol's features.
Possible implementation's limitations that may limit the number of
segments that can be sent using it are not taken into account. | public DataInputStream | openDataInputStream() Open and return a data input stream for a connection. | public DataOutputStream | openDataOutputStream() Open and return a data output stream for a connection. | public InputStream | openInputStream() Open and return an input stream for a connection. | public OutputStream | openOutputStream() Open and return an output stream for a connection. | public Connection | openPrim(String name, int mode, boolean timeouts) Opens a connection. | public synchronized Connection | openPrimInternal(String name, int mode, boolean timeouts) Opens a connection. | public synchronized Message | receive() Receives the bytes that have been sent over the connection, constructs a
Message object, and returns it. | public void | send(Message dmsg) Sends a message over the connection. | protected void | setAppID(String newValue) Sets the connection parameter in string mode. | protected int | unblock00(int msid) Unblock the receive thread.
Parameters: msid - The MIDlet suite ID. | protected int | waitUntilMessageAvailable00(int handle) |
GSM_BINARY | final protected static int GSM_BINARY(Code) | | DCS: Binary
|
GSM_TEXT | final protected static int GSM_TEXT(Code) | | DCS: GSM Alphabet
|
GSM_UCS2 | final protected static int GSM_UCS2(Code) | | DCS: Unicode UCS-2
|
open_count | protected static int open_count(Code) | | Count of simultaneous opened conenctions.
|
openconnections | protected static Vector openconnections(Code) | | Currently opened connections.
|
restrictedPorts | int restrictedPorts(Code) | | Ports barred from use int the specification.
|
Protocol | public Protocol()(Code) | | Creates a message connection protocol handler.
|
checkReceivePermission | protected void checkReceivePermission() throws InterruptedIOException(Code) | | Checks internal setting of receive permission.
Called from receive and setMessageListener methods.
exception: InterruptedIOException - if permission dialogwas preempted |
close | public void close() throws IOException(Code) | | Closes the connection. Resets the connection open flag
to false . Subsequent operations on a
closed connection should throw an appropriate exception.
exception: IOException - if an I/O error occurs |
close00 | protected int close00(int connHandle, int deRegister)(Code) | | Close connection.
Parameters: connHandle - handle returned by open0 Parameters: deRegister - Deregistration appID when parameter is 1. 0 on success, -1 on failure |
getAppID | protected String getAppID()(Code) | | Gets the connection parameter in string mode.
string that contains a parameter |
newMessage | public Message newMessage(String type)(Code) | | Constructs a new message object of a text or binary type.
If the TEXT_MESSAGE constant is passed in, the
TextMessage interface is implemented by the created object.
If the BINARY_MESSAGE constant is passed in, the
BinaryMessage interface is implemented by the created
object.
If this method is called in a sending mode, a new Message
object is requested from the connection. For example:
Message msg = conn.newMessage(TEXT_MESSAGE);
The Message object that was created doesn't have the
destination address set. It's the application's responsibility to set it
before the message is sent.
If this method is called in receiving mode, the
Message object does have
its address set. The application can act on the object to extract
the address and message data.
Parameters: type - TEXT_MESSAGE orBINARY_MESSAGE . a new message. |
newMessage | public Message newMessage(String type, String addr)(Code) | | Constructs a new message object of a text or binary type and specifies
a destination address.
If the TEXT_MESSAGE constant is passed in, the
TextMessage interface is implemented by the created object.
If the BINARY_MESSAGE constant is passed in, the
BinaryMessage interface is implemented by the created
object.
The destination address addr has the following format:
sms:// phone_number:port
Parameters: type - TEXT_MESSAGE orBINARY_MESSAGE . Parameters: addr - the destination address of the message. a new Message object. |
numberOfSegments | public int numberOfSegments(Message msg)(Code) | | Returns how many segments in the underlying protocol would
be needed for sending the Message given as the parameter.
Note that this method does not actually send the message;
it will only calculate the number of protocol segments
needed for sending it.
This method calculates the number of segments required
when this message is split into the protocol segments
utilizing the underlying protocol's features.
Possible implementation's limitations that may limit the number of
segments that can be sent using it are not taken into account. These
limitations are protocol specific. They are documented
with that protocol's adapter definition.
Parameters: msg - the message to be used for the calculation number of protocol segments required to send the message.If the Message object can't be sent usingthe underlying protocol, 0 is returned. |
openPrim | public Connection openPrim(String name, int mode, boolean timeouts) throws IOException(Code) | | Opens a connection. This method is called from the
Connector.open() method to obtain the destination
address given in the name parameter.
The format for the name string for this method is:
sms://[phone_number:][port_number]
where the phone_number: is optional.
If the phone_number
parameter is present, the connection is being opened in
client mode. This means that messages can be sent.
If the parameter is absent, the connection is being opened in
server mode. This means that messages can be sent and received.
The connection that is opened is to a low-level transport mechanism
which can be any of the following:
- a datagram Short Message Peer-to-Peer (SMPP)
to a service center
- a
comm connection to a phone device with
AT-commands
- a native SMS stack
Currently, the mode and timeouts parameters are
ignored.
Parameters: name - the target of the connection Parameters: mode - indicates whether the callerintends to write to the connection. Currently,this parameter is ignored. Parameters: timeouts - indicates whether the callerwants timeout exceptions. Currently,this parameter is ignored. this connection exception: IOException - if the connection is closed or unavailable |
openPrimInternal | public synchronized Connection openPrimInternal(String name, int mode, boolean timeouts) throws IOException(Code) | | Opens a connection. This is the internal entry point that
allows the CBS protocol handler to use the reserved port for
CBS emulated messages.
Parameters: name - the target of the connection Parameters: mode - indicates whether the callerintends to write to the connection. Currently,this parameter is ignored. Parameters: timeouts - indicates whether the callerwants timeout exceptions. Currently,this parameter is ignored. this connection exception: IOException - if the connection is closed or unavailable |
receive | public synchronized Message receive() throws IOException(Code) | | Receives the bytes that have been sent over the connection, constructs a
Message object, and returns it.
If there are no Message s waiting on the connection, this
method will block until a message is received, or the
MessageConnection is closed.
a Message object. exception: java.io.IOException - if an error occurs while receiving amessage. exception: java.io.InterruptedIOException - if thisMessageConnection object is closed during this receivemethod call. exception: java.lang.SecurityException - if the application does not havepermission to receive messages using the given port number. |
send | public void send(Message dmsg) throws IOException(Code) | | Sends a message over the connection. This method extracts the data
payload from the Message object so that it can be sent as a
datagram.
Parameters: dmsg - a Message object exception: java.io.IOException - if the message could not be sent orbecause of network failure exception: java.lang.IllegalArgumentException - if the message isincomplete or contains invalid information. This exception is alsothrown if the payload of the message exceeds the maximum length forthe given messaging protocol. exception: java.io.InterruptedIOException - if a timeout occurs whileeither trying to send the message or if this Connection object is closed during this send operation. exception: java.lang.NullPointerException - if the parameter isnull . exception: java.lang.SecurityException - if the application does not havepermission to send the message. |
setAppID | protected void setAppID(String newValue)(Code) | | Sets the connection parameter in string mode.
Parameters: newValue - new value of connection parameter |
unblock00 | protected int unblock00(int msid) throws IOException(Code) | | Unblock the receive thread.
Parameters: msid - The MIDlet suite ID. returns handle to the connection. |
waitUntilMessageAvailable00 | protected int waitUntilMessageAvailable00(int handle) throws IOException(Code) | | Waits until message available
Parameters: handle - handle to connection 0 on success, -1 on failure exception: IOException - if an I/O error occurs |
|
|