SipConnectorpublic class SipConnector extends Object This class is factory for creating new Connection objects.
The creation of Connections is performed dynamically by looking
up a protocol implementation class whose name is formed from the
platform name (read from a system property) and the protocol name
of the requested connection (extracted from the parameter string
supplied by the application programmer.)
The parameter string that describes the target should conform
to the URL format as described in RFC 2396.
This takes the general form:
{scheme}:[{target}][{params}]
where {scheme} is the name of a protocol such as
http}.
The {target} is normally some kind of network
address.
Any {params} are formed as a series of equates
of the form ";x=y". Example: ";type=a".
An optional second parameter may be specified to the open
function. This is a mode flag that indicates to the protocol
handler the intentions of the calling code. The options here
specify if the connection is going to be read (READ), written
(WRITE), or both (READ_WRITE). The validity of these flag
settings is protocol dependent. For instance, a connection
for a printer would not allow read access, and would throw
an IllegalArgumentException. If the mode parameter is not
specified, READ_WRITE is used by default.
An optional third parameter is a boolean flag that indicates
if the calling code can handle timeout exceptions. If this
flag is set, the protocol implementation may throw an
InterruptedIOException when it detects a timeout condition.
This flag is only a hint to the protocol handler, and it
does not guarantee that such exceptions will actually be thrown.
If this parameter is not set, no timeout exceptions will be
thrown.
Because connections are frequently opened just to gain access
to a specific input or output stream, four convenience
functions are provided for this purpose.
See also: {@link DatagramConnection DatagramConnection}
for information relating to datagram addressing |
Fields Summary |
---|
public static final int | READAccess mode READ. | public static final int | WRITEAccess mode WRITE. | public static final int | READ_WRITEAccess mode READ_WRITE. | private static String | platformThe platform name. | private static boolean | j2meTrue if we are running on a J2ME system | private static String | classRootThe root of the classes. |
Constructors Summary |
---|
private SipConnector()Prevent instantiation of this class.
/* Find out if we are running on a J2ME system */
if (System.getProperty("microedition.configuration") != null) {
j2me = true;
}
/* Set up the platform name */
platform = System.getProperty("microedition.platform");
/* Set up the library class root path */
/* This may vary from one CLDC implementation to another */
classRoot =
System.getProperty("javax.microedition.io.Connector.protocolpath");
if (classRoot == null) {
classRoot = "com.sun.cldc.io";
}
classRoot = "gov.nist.microedition.io";
|
Methods Summary |
---|
public static javax.microedition.io.Connection | open(java.lang.String name)Create and open a Connection.
return open(name, READ_WRITE);
| public static javax.microedition.io.Connection | open(java.lang.String name, int mode)Create and open a Connection.
return open(name, mode, false);
| public static javax.microedition.io.Connection | open(java.lang.String name, int mode, boolean timeouts)Create and open a Connection.
/* If the "microedition.platform" property is defined, */
/* use that as the platform name for opening a connection */
if (platform != null) {
try {
return openPrim(name, mode, timeouts, platform);
} catch (ClassNotFoundException x) {
}
}
/* If the "microedition.platform" property is not defined, */
/* use one of the default values */
try {
return openPrim(name, mode, timeouts, j2me ? "j2me" : "j2se");
} catch (ClassNotFoundException x) {
}
throw new
ConnectionNotFoundException("The requested protocol does not exist "
+ name);
| public static java.io.DataInputStream | openDataInputStream(java.lang.String name)Create and open a connection input stream.
/* Look for : as in "http:", "file:", or whatever */
int colon = name.indexOf(':");
/* Test for null argument */
if (colon < 1) {
throw new
IOException("This method is not authorized for this protocol");
}
String protocol = name.substring(0, colon);
if (protocol.equals("sip"))
throw new
IOException("This method is not authorized for this protocol");
InputConnection con =
(InputConnection)SipConnector.open(name, SipConnector.READ);
try {
return con.openDataInputStream();
} finally {
con.close();
}
| public static java.io.DataOutputStream | openDataOutputStream(java.lang.String name)Create and open a connection output stream.
/* Look for : as in "http:", "file:", or whatever */
int colon = name.indexOf(':");
/* Test for null argument */
if (colon < 1) {
throw new
IOException("This method is not authorized for this protocol");
}
String protocol = name.substring(0, colon);
if (protocol.equals("sip"))
throw new
IOException("This method is not authorized for this protocol");
OutputConnection con =
(OutputConnection)SipConnector.open(name, SipConnector.WRITE);
try {
return con.openDataOutputStream();
} finally {
con.close();
}
| public static java.io.InputStream | openInputStream(java.lang.String name)Create and open a connection input stream.
/* Look for : as in "http:", "file:", or whatever */
int colon = name.indexOf(':");
/* Test for null argument */
if (colon < 1) {
throw new
IOException("This method is not authorized for this protocol");
}
String protocol = name.substring(0, colon);
if (protocol.equals("sip"))
throw new
IOException("This method is not authorized for this protocol");
return openDataInputStream(name);
| public static java.io.OutputStream | openOutputStream(java.lang.String name)Create and open a connection output stream.
/* Look for : as in "http:", "file:", or whatever */
int colon = name.indexOf(':");
/* Test for null argument */
if (colon < 1) {
throw new
IOException("This method is not authorized for this protocol");
}
String protocol = name.substring(0, colon);
if (protocol.equals("sip"))
throw new
IOException("This method is not authorized for this protocol");
return openDataOutputStream(name);
| private static javax.microedition.io.Connection | openPrim(java.lang.String name, int mode, boolean timeouts, java.lang.String platform)Create and open a Connection.
/* Test for null argument */
if (name == null) {
throw new IllegalArgumentException("Null URL");
}
/* Look for : as in "http:", "file:", or whatever */
int colon = name.indexOf(':");
/* Test for null argument */
if (colon < 1) {
throw new IllegalArgumentException("no ':' in URL");
}
try {
String protocol;
/* Strip off the protocol name */
protocol = name.substring(0, colon);
/* Strip off the rest of the string */
name = name.substring(colon+1);
/* Convert all the '-' characters in the protocol */
/* name to '_' characters (dashes are not allowed */
/* in class names). This operation creates garbage */
/* only if the protocol name actually contains dashes */
protocol = protocol.replace('-", '_");
/* Use the platform and protocol names to look up */
/* a class to implement the connection */
Class clazz =
Class.forName(classRoot +
"." + platform +
"." + protocol + ".Protocol");
/* Construct a new instance of the protocol */
ConnectionBaseInterface uc =
(ConnectionBaseInterface)clazz.newInstance();
/* Open the connection, and return it */
return uc.openPrim(name, mode, timeouts);
} catch (InstantiationException x) {
throw new IOException(x.toString());
} catch (IllegalAccessException x) {
throw new IOException(x.toString());
} catch (ClassCastException x) {
throw new IOException(x.toString());
}
|
|