Java Doc for ContentHandlerServer.java in  » 6.0-JDK-Modules » j2me » javax » microedition » content » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.content 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.microedition.content.ContentHandlerServer

All known Subclasses:   javax.microedition.content.ContentHandlerServerImpl,
ContentHandlerServer
public interface ContentHandlerServer extends ContentHandler(Code)
ContentHandlerServer provides methods to get new Invocation requests, to finish the processing of requests and to get the access control information. This server interface extends ContentHandler to make available the registration information for types, suffixes, actions, ID, etc. Instances are thread safe.

Responding to an Invocation

Content handler applications process requests using either blocking calls to ContentHandlerServer.getRequest getRequest or can be notified of new requests with the ContentHandlerServer.setListener setListener method. A content handler receives an Invocation by calling ContentHandlerServer.getRequest getRequest . The content handler should use the Invocation.getAction Invocation.getAction method to determine the requested action and act on the content appropriately. The content handler will typically call the Invocation.open Invocation.open method to read the content. The open method returns a Connection from the Generic Connection framework that provides access to the content. When the content handler is finished processing the Invocation, it must call the ContentHandlerServer.finish finish method to report the status. If a response was required the status and parameters are returned to the invoking application.

Required Response to the Invoking Application

The invoking application decides whether it needs a response and sets the request state before calling Registry.invoke Registry.invoke . When an Invocation is completed either by using the ContentHandlerServer.finish finish method or when the AMS is handling an error condition, the Invocation.getResponseRequired Invocation.getResponseRequired method is checked. If it is true, then the values from the Invocation are queued to the invoking application with the status set by the ContentHandler or AMS. When a response is queued, it will be dispatched to the invoking application. If a response is not required, it is not delivered to the invoking application and the invoking application is not started.

Chaining Content Handlers

Content handlers link Invocations that are part of a user-driven task and depend on each other as part of a transaction. Suppose an application A creates an invocation a. When invoked, it is dispatched to content handler B which in-turn creates an invocation b and it is dispatched to content handler C. C displays the content and returns a response b' to B, B in turn completes processing and returns a response a' to A.

The implementation MUST have the capacity and mechanisms to support the chaining of requests required for an application to invoke a content handler, and the content handler invoking another content handler, and for each content handler to return a response. This chain length of two active invocations is the minimum requirement. The implementation should not artificially limit the number of invocations and responses that are supported except as constrained by the resources of the device.

To maintain continuity across the applications, chained invocations are part of the same transaction. Invoking an Invocation places it in a transaction. The transaction maintains the sequence of invocations across all of the applications involved. The transaction maintains the invocations regardless of whether a single application can run at a time or the applications execute in parallel in different runtime environments. The transaction is used to record and manage the steps in processing and dispatching to applications.

For simple non-chaining use cases that involve only two applications with a single invocation and response, only the methods ContentHandlerServer.getRequest getRequest , ContentHandlerServer.finish finish , Registry.invoke Registry.invoke , and Registry.getResponse Registry.getResponse are needed.

For chained use cases, the methods Registry.invoke Registry.invoke and Invocation.getPrevious Invocation.getPrevious are used to establish the sequence and to retrieve the previous Invocation. The Registry.invoke Registry.invoke method places the new Invocation in the same transaction as a previous Invocation. The previous Invocation will be held in the transaction until the new Invocation is completed. When the response to the new Invocation is returned, the previously active Invocation can be retrieved with Invocation.getPrevious Invocation.getPrevious so the content handler can complete its processing.

An Invocation can be delegated to another handler with the Registry.reinvoke Registry.reinvoke method. Responses to the reinvocation will be queued to the original invoking application.

Handling Faults

If the content handler cannot or does not correctly handle the Invocation, then the AMS MUST handle it correctly. These actions prevent an incorrectly written content handler from being unresponsive or being run repeatedly but never processing queued invocations.
  • If an Invocation with a status of ACTIVE is dequeued by the content handler, but the handler does not call ContentHandlerServer.finish finish or make a request to chain a new Invocation to the ACTIVE invocation before the content handler exits, then the AMS MUST complete the request with an ERROR status. This ensures that the invoking application will always get a response, if required, for each invocation regardless of whether the content handler correctly handles it.
  • If the content handler is not running, or exits before processing all queued requests or responses, then it MUST be started. The content handler is expected to dequeue at least one invocation that was queued before it was started. If it does not dequeue any pending Invocations or can not be started, then Invocations that were in the queue for the content handler before it was started MUST be handled as follows:
    • Invocation requests with a status of ACTIVE are completed with the ERROR status.
    • Invocation responses are discarded.
    • Invocations queued after the content handler was started are retained and will require it to be restarted.
    This serialization of queued requests and starting the content handler addresses a race condition. This condition may occur when the content handler is active but exits before processing Invocations that were queued after it was started or it last called ContentHandlerServer.getRequest getRequest or Registry.getResponse Registry.getResponse .

Invocations and invocation state MUST NOT be preserved across soft and hard restarts of the device software including unexpected power interruptions.





Method Summary
public  intaccessAllowedCount()
     Gets the number of IDs allowed access by the content handler.
public  voidcancelGetRequest()
     Cancels a pending getRequest.
public  booleanfinish(Invocation invocation, int status)
     Finishes the Invocation and sets the status for the response.
public  StringgetAccessAllowed(int index)
     Gets the ID at the specified index of an application or content handler allowed access to this content handler. The ID returned for each index must be the equal to the ID at the same index in the accessAllowed array passed to Registry.register Registry.register .
public  InvocationgetRequest(boolean wait)
     Gets the next Invocation request pending for this ContentHandlerServer.
public  booleanisAccessAllowed(String ID)
     Determines if an ID MUST be allowed access by the content handler.
public  voidsetListener(RequestListener listener)
     Sets the listener to be notified when a new request is available for this content handler.



Method Detail
accessAllowedCount
public int accessAllowedCount()(Code)
Gets the number of IDs allowed access by the content handler. The number of IDs MUST be equal to the length of the array of accessAllowed passed to Registry.register Registry.register . If the number of IDs is zero then all applications and content handlers are allowed access. the number of IDs allowed access



cancelGetRequest
public void cancelGetRequest()(Code)
Cancels a pending getRequest. This method will force all threads blocked in a call to the getRequest method for this ContentHandlerServer to return. If no threads are blocked; this call has no effect.



finish
public boolean finish(Invocation invocation, int status)(Code)
Finishes the Invocation and sets the status for the response. The finish method can only be called when the Invocation has a status of ACTIVE or HOLD.

The content handler may modify the URL, type, action, or arguments before invoking finish. If the method Invocation.getResponseRequired Invocation.getResponseRequired returns true, then the modified values MUST be returned to the invoking application.
Parameters:
  invocation - the Invocation to finish
Parameters:
  status - the new status of the Invocation;MUST be either OK, CANCELLEDor INITIATED true if the application MUSTvoluntarily exit to allow pending responses or requeststo be handled;false otherwise
exception:
  IllegalArgumentException - if the newstatus of the Invocationis not OK, CANCELLED,or INITIATED
exception:
  IllegalStateException - if the currentstatus of theInvocation is not ACTIVE or HOLD
exception:
  NullPointerException - if the invocation is null




getAccessAllowed
public String getAccessAllowed(int index)(Code)
Gets the ID at the specified index of an application or content handler allowed access to this content handler. The ID returned for each index must be the equal to the ID at the same index in the accessAllowed array passed to Registry.register Registry.register .
Parameters:
  index - the index of the ID the ID at the specified index
exception:
  IndexOutOfBoundsException - if index is less than zero orgreater than or equal to the value of theContentHandlerServer.accessAllowedCount accessAllowedCount method.



getRequest
public Invocation getRequest(boolean wait)(Code)
Gets the next Invocation request pending for this ContentHandlerServer. The method can be unblocked with a call to ContentHandlerServer.cancelGetRequest cancelGetRequest . The application should process the Invocation as a request to perform the action on the content.
Parameters:
  wait - true if the method must waitfor an Invocation if one is not available;false if the method MUST NOT wait. the next pending Invocation or nullif no Invocation is available; nullif cancelled with ContentHandlerServer.cancelGetRequest cancelGetRequest
See Also:   Registry.invoke
See Also:   ContentHandlerServer.finish



isAccessAllowed
public boolean isAccessAllowed(String ID)(Code)
Determines if an ID MUST be allowed access by the content handler. Access MUST be allowed if the ID has a prefix that exactly matches any of the IDs returned by ContentHandlerServer.getAccessAllowed . The prefix comparison is equivalent to java.lang.String.startsWith.
Parameters:
  ID - the ID for which to check access true if access MUST be allowed by thecontent handler;false otherwise
exception:
  NullPointerException - if IDis null



setListener
public void setListener(RequestListener listener)(Code)
Sets the listener to be notified when a new request is available for this content handler. The request is retrieved using ContentHandlerServer.getRequest getRequest . If the listener is non-null and a request is available, the listener MUST be notified.
Parameters:
  listener - the listener to register;null to remove the listener.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.