| java.lang.Object com.sun.midp.io.j2me.ProtocolBase com.sun.midp.io.j2me.mms.Protocol
Protocol | public class Protocol extends ProtocolBase (Code) | | MMS message connection implementation.
Protocol itself is not instantiated. Instead, the application
calls Connector.open with an MMS 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. |
Protocol | public Protocol()(Code) | | Creates a message connection protocol handler.
|
checkReceivePermission | protected void checkReceivePermission() throws InterruptedIOException(Code) | | Checks the internal setting of the receive permission. Called from
the receive and setMessageListener methods.
exception: InterruptedIOException - if permission dialog was pre-empted. |
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) | | Construct a new message object of a text, binary or multipart message
type and specify a destination address. When a
MULTIPART_MESSAGE constant is passed in, the created object
implements the MultipartMessage interface.
If this method is called in a sending mode, a new Message
object is requested from the connection. For example:
Message msg = conn.newMessage(MULTIPART_MESSAGE);
The Message does not have the destination address set. It
must be set by the application 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 - MULTIPART_MESSAGE is the only type permitted. A new MMS Message object. |
newMessage | public Message newMessage(String type, String addr)(Code) | | Construct a new MULTIPART_MESSAGE message object and specify
a destination address. The MULTIPART_MESSAGE constant must
be passed in. The created object implements the
MultipartMessage interface.
The destination address addr has the following format:
mms://phone_number:application_id
Parameters: type - MULTIPART_MESSAGE is the only type permitted. Parameters: addr - The destination address of the message. A new MMS Message object. |
numberOfSegments | public int numberOfSegments(Message msg)(Code) | | Returns the number of segments required to send the given
Message .
Note: The message is not actually sent. This method will compute the
number of segments needed when this message is split into the protocol
segments using the appropriate features of the underlying protocol. This
method does not take the possible limitations of the implementation into
account, which may limit the number of segments that can be sent, using
this feature. These limitations are protocol-specific and are documented
with the adapter definition for that protocol.
Parameters: msg - The MultipartObject message to be used forthe computation. The number of protocol segments needed for sending the message.Returns 0 if the Message object cannot besent using the underlying protocol. |
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:
mms://[phone_number]:[application_id]
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 MMS stack.
Currently, the mode and timeouts parameters are
ignored.
Parameters: name - The target of the connection. Parameters: mode - Indicates whether the caller intends to write to theconnection. Currently, this parameter is ignored. Parameters: timeouts - Indicates whether the caller wants 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 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:
mms://[phone_number]:[application_id]
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 MMS stack.
Currently, the mode and timeouts parameters are
ignored.
Parameters: name - The target of the connection. Parameters: mode - Indicates whether the caller intends to write to theconnection. Currently, this parameter is ignored. Parameters: timeouts - Indicates whether the caller wants timeout exceptions.Currently, this parameter is ignored. This connection. exception: IOException - if the connection is closed or unavailable. exception: IllegalArgumentException - if the parameters are invalid |
receive | public synchronized Message receive() throws IOException(Code) | | Receives the bytes that have been sent over the connection, constructs a
MultipartMessage object, and returns the message.
If there are no MultipartMessage s waiting on the connection,
this method will block until a message is received, or the
MessageConnection is closed.
A MultipartMessage object. exception: java.io.IOException - if an error occurs while receiving amessage. exception: java.io.InterruptedIOException - if thisMessageConnection object is closed during thisreceive method call. exception: java.lang.SecurityException - if the application does not havepermission to receive messages using the given application ID. |
send | public void send(Message msg) throws IOException(Code) | | Send an MMS message over the connection. The data are extracted from the
Message object payload for use by the underlying transport
layer.
Parameters: msg - A Message object. exception: java.io.IOException - if the message could not be sentor because of network failure. exception: java.lang.IllegalArgumentException - if the message isincomplete or contains invalid information. This exceptionis also thrown if the payload of the message exceedsthe maximum length for the given messaging protocol. exception: java.io.InterruptedIOException - if a timeout occurs whileeither trying to send the message or if thisConnection object is closed during thissend operation. exception: java.lang.NullPointerException - if the parameter is null. exception: java.lang.SecurityException - if the application does nothave permission 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 |
|
|