Invocationpublic final class Invocation extends Object An Invocation contains the parameters that
are passed from an invoking application to a content handler and
the results that are returned to the application.
The parameters are the type, URL, action,
content handler ID, and responseRequired.
The string and data arguments can be set using
{@link #setArgs setArgs} and {@link #setData setData} methods.
All of the parameters are provided to the content handler and
are returned with the handlers response, if any.
Invocation instances are not thread safe, the application
must handle any synchronization necessary.
The values of content handler ID, type, URL, and action are used to
identify the content handler when invoked by
{@link Registry#invoke Registry.invoke}.
If an Invocation contains an ID then it is used to identify the
content handler to be invoked. The other parameters are input to
the content handler.
If a type is present, it is used to find handlers that support
that type. The application should supply the type if it is known.
If the type is not set, then calling the
{@link #findType findType} will find the type using the URL to the
content.
Invocation Status
The status value indicates the next processing step of
the invocation by the content handler.
The status of an Invocation can be any of the following:
- {@link #INIT}indicates the Invocation is still being
initialized
- {@link #WAITING}indicates that this Invocation is waiting
to complete
- {@link #ACTIVE}indicates the Invocation is currently
being processed
- {@link #HOLD}indicates the Invocation is currently
waiting for a chained Invocation to complete
- {@link #ERROR}, {@link #OK}, {@link #CANCELLED}
indicate that the Invocation is complete
- {@link #INITIATED}
indicate that the Invocation has been initiated but the content
handler cannot provide a response when it is finished.
All status transitions occur only during method calls that involve
the Invocation instance. The transitions that occur are specified
in the methods that make the change visible.
For example, when an invoking application creates a new Invocation, the
status is {@link #INIT INIT}.
When the application calls
{@link Registry#invoke Registry.invoke}
the status changes to {@link #WAITING WAITING}.
When the Registry.getResponse method is invoked, the
status will be updated to the appropriate {@link #OK OK},
{@link #CANCELLED CANCELLED},
{@link #INITIATED INITIATED}, or {@link #ERROR ERROR} status from
the content handler.
A content handler calls
{@link ContentHandlerServer#getRequest ContentHandlerServer.getRequest}
to get the next request.
The request always has the {@link #ACTIVE ACTIVE} status.
When the handler is finished acting on the content, the status
is set to either {@link #OK OK}, {@link #CANCELLED CANCELLED}, or
{@link #INITIATED INITIATED} by
the {@link ContentHandlerServer#finish ContentHandlerServer.finish} method.
If the handler is chaining, then the new Invocation follows the status
transitions of invoke as described above. The status of the
previous invocation being chained from is set to {@link #HOLD HOLD}
by the Registry.invoke method. The status of the previous
Invocation is restored to {@link #ACTIVE ACTIVE} by the
{@link Registry#getResponse Registry.getResponse}
method that returns the status for the new Invocation.
If the content handler application causes faults because it
does not properly dequeue and respond to invocations as described
in the {@link ContentHandler} class, then the
status is set to {@link #ERROR ERROR} in the response queued back
to the invoking application.
Access to Content
The implementation of the invocation mechanism may save or cache
information about the request, the URL, the content type, or content
during the invocation. The information may be
utilized when the application accesses the content with the
{@link #open open} method.
The {@link #getURL} method MUST return the original URL unmodified
by any implementation specific information. |
Fields Summary |
---|
private com.sun.midp.content.InvocationImpl | invocImplThe InvocationImpl to delegate to. | public static final int | INITThis Invocation was just constructed and is being initialized. | public static final int | ACTIVEThis Invocation is a new request and is being handled
by the content handler. | public static final int | WAITINGThis Invocation has been invoked and is waiting to be
complete. | public static final int | HOLDThis Invocation is on hold until a chained
Invocation is completed. | public static final int | OKThe content handler successfully completed processing
the Invocation.
Invocations queued with
{@link ContentHandlerServer#finish ContentHandlerServer.finish}
will have this status. | public static final int | CANCELLEDThe processing of the Invocation was cancelled by
the ContentHandler.
Invocations queued with
{@link ContentHandlerServer#finish ContentHandlerServer.finish}
will have this status. | public static final int | ERRORThe content handler failed to correctly process the Invocation
request. | public static final int | INITIATEDThe processing of the Invocation has been initiated and will
continue. This status is only appropriate when the content
handler can not provide a response when it is finished. |
Constructors Summary |
---|
public Invocation()Creates a new Invocation.
The status of the new Invocation object is INIT .
The URL, type, ID, action, arguments, and data are set to
empty arrays, and initialized to require a response.
invocImpl = new InvocationImpl(this);
| public Invocation(String url, String type, String ID)Convenient alternative constructor with URL, type, and ID.
The behavior is identical to
new Invocation(url, type, ID, true, null) .
this(url, type, ID, true, null);
| public Invocation(String url, String type)Convenient alternative constructor with URL and type.
The behavior is identical to
new Invocation(url, type, null, true, null) .
this(url, type, null, true, null);
| public Invocation(String url)Convenient alternative constructor with a URL.
The behavior is identical to
new Invocation(url, null, null, true, null) .
this(url, null, null, true, null);
| public Invocation(String url, String type, String ID, boolean responseRequired, String action)Creates a new instance and initializes it from the
specified parameters.
The status of the new Invocation is INIT .
None of the values are checked until the
{@link Registry#invoke Registry.invoke}
method is called.
String arguments or data can be set with
{@link #setArgs setArgs} or {@link #setData setData}.
this();
invocImpl.setURL(url);
invocImpl.setType(type);
invocImpl.setID(ID);
invocImpl.setResponseRequired(responseRequired);
invocImpl.setAction(action);
| Invocation(com.sun.midp.content.InvocationImpl impl)Creates a new Invocation to refer to an InvocationImpl.
And makes the InvocationImpl refer to the new Invocation.
invocImpl = impl;
if (impl != null) {
impl.invocation = this;
}
|
Methods Summary |
---|
public java.lang.String | findType()Finds the type of the content in this Invocation.
If the getType method return value is
non-null , then the type is returned.
If the type is null and the URL is non-null ,
then the content type will be found by accessing the content
through the URL.
When found, the type is set as if the setType method
was called; subsequent calls to
{@link #getType getType} and {@link #findType findType}
will return the type.
If an exception is thrown, the getType method will
return null .
The calling thread blocks while the type is being determined.
If a network access is needed there may be an associated delay.
// Delegated to the implementation class
return invocImpl.findType();
| public java.lang.String | getAction()Gets the action to be performed on the content.
return invocImpl.getAction();
| public java.lang.String[] | getArgs()Gets the argument list as an array of Strings. These values
are passed to the content handler and are returned from
the content handler.
The array is not copied; modifications to array elements
will be visible.
return invocImpl.getArgs();
| public byte[] | getData()Gets the data for the Invocation. The data
is passed to the content handler.
The content handler may modify and return the data
if it returns a response.
return invocImpl.getData();
| public java.lang.String | getID()Gets the content handler ID for this Invocation.
// Delegated to the implementation class
return invocImpl.getID();
| com.sun.midp.content.InvocationImpl | getInvocImpl()Gets the InvocationImpl for this Invocation.
return invocImpl;
| public java.lang.String | getInvokingAppName()Get the user-friendly name of the application that invoked
the content handler. This information is available only if the status is
ACTIVE or HOLD .
This information has been authenticated only if
getInvokingAuthority is non-null.
// Delegated to the implementation class
return invocImpl.getInvokingAppName();
| public java.lang.String | getInvokingAuthority()Gets the authority, if any, used to authenticate the
application that invoked this request.
This value MUST be null unless the device has been
able to authenticate this application.
If non-null , it is the string identifying the
authority.
// Delegated to the implementation class
return invocImpl.getInvokingAuthority();
| public java.lang.String | getInvokingID()Gets the ID of the application that invoked the content
handler. This information is available only if the status is
ACTIVE or HOLD .
This information has been authenticated only if
getInvokingAuthority is non-null.
// Delegated to the implementation class
return invocImpl.getInvokingID();
| public javax.microedition.content.Invocation | getPrevious()Gets the previous Invocation saved in this
Invocation by
{@link Registry#invoke Registry.invoke} or
{@link Registry#getResponse Registry.getResponse}.
Invocations returned by
{@link ContentHandlerServer#getRequest ContentHandlerServer.getRequest}
MUST return null .
InvocationImpl prev = invocImpl.getPrevious();
if (prev != null) {
if (prev.invocation == null) {
/*
* An InvocationImpl created by the implementation needs
* a Invocation to return to the application.
*/
prev.invocation = new Invocation(prev);
}
return prev.invocation;
} else {
return null;
}
| public boolean | getResponseRequired()Gets the responseRequired mode for
this Invocation.
If true , then the invoking application requires a
response to the Invocation.
return invocImpl.getResponseRequired();
| public int | getStatus()Gets the status of this Invocation, which can be
INIT , WAITING , HOLD ,
ACTIVE , OK ,
CANCELLED ,
INITIATED , or ERROR .
// Delegated to the implementation class
return invocImpl.getStatus();
| public java.lang.String | getType()Gets the content type for the Invocation.
The type for this Invocation may be set by the application using
{@link #setType setType}.
The {@link #findType findType} method can be used by an application
to find the type by accessing the content via the URL.
When found, findType sets the type returned
by getType .
return invocImpl.getType();
| public java.lang.String | getURL()Gets the URL for the invocation.
The URL must be equal to the value set with {@link #setURL setURL}.
return invocImpl.getURL();
| public javax.microedition.io.Connection | open(boolean timeouts)Creates and opens a Connection to the content addressed by
the URL in {@link #getURL getURL}. This method is
similar to Connector.open(getURL(), READ, timeouts)
but may deliver the content from a cache.
The application should use this method to access the
content of the URL
so that any type or content information cached by the
implementation can be utilized. The content is opened
in read only mode.
Regardless of whether or not the content is cached, the
application or content handler must have permission to access
the content via the URL.
String url = getURL();
url.length(); // Throw NPE if null
Connection conn = Connector.open(url, Connector.READ, timeouts);
return conn;
| public void | setAction(java.lang.String action)Sets the action to be performed on the content.
invocImpl.setAction(action);
| public void | setArgs(java.lang.String[] args)Sets the argument list to a new array of Strings. The arguments
are used by the application to communicate to the content
handler and return results from the content handler.
The values of the arguments are not checked when they are set.
Instead, they are checked during
{@link Registry#invoke Registry.invoke} to
check that none of the values are null .
invocImpl.setArgs(args);
| public void | setCredentials(java.lang.String username, char[] password)Provide the credentials needed to access the content.
Use of the credential is protocol specific.
invocImpl.setCredentials(username, password);
| public void | setData(byte[] data)Sets the data used for the Invocation. The data
is used by the application to communicate to the content
handler and return data from the content handler.
The array is not copied until the Invocation is invoked
or finish ed;
modifications to array elements will otherwise be visible.
invocImpl.setData(data);
| public void | setID(java.lang.String ID)Sets the ID of the content handler for this Invocation.
// Delegated to the implementation class
invocImpl.setID(ID);
| void | setInvocImpl(com.sun.midp.content.InvocationImpl invocImpl)Sets the InvocationImpl for this Invocation.
this.invocImpl = invocImpl;
| public void | setResponseRequired(boolean responseRequired)Sets the responseRequired mode for
this Invocation.
If true , then the invoking application requires a
response to the Invocation.
The value in the request can be changed only if the status is
INIT .
invocImpl.setResponseRequired(responseRequired);
| public void | setType(java.lang.String type)Sets the type for the Invocation.
invocImpl.setType(type);
| public void | setURL(java.lang.String url)Sets the URL for the invocation.
invocImpl.setURL(url);
|
|