Java Doc for Resource.java in  » Web-Services » restlet-1.0.8 » org » restlet » resource » 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 » Web Services » restlet 1.0.8 » org.restlet.resource 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.restlet.resource.Resource

All known Subclasses:   com.noelios.restlet.local.DirectoryResource,  org.restlet.example.book.rest.ch7.UserResource,  org.restlet.example.tutorial.UserResource,
Resource
public class Resource (Code)
Intended conceptual target of a hypertext reference. "Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource. The only thing that is required to be static for a resource is the semantics of the mapping, since the semantics is what distinguishes one resource from another." Roy T. Fielding

Another definition adapted from the URI standard (RFC 3986): a resource is the conceptual mapping to a representation (also known as entity) or set of representations, not necessarily the representation which corresponds to that mapping at any particular instance in time. Thus, a resource can remain constant even when its content (the representations to which it currently corresponds) changes over time, provided that the conceptual mapping is not changed in the process. In addition, a resource is always identified by a URI.

Typically created by Finders, Resource instances are the final handlers of calls received by server connectors. Unlike the other handlers in the processing chain, a Resource is generally not shared between calls and doesn't have to be thread-safe. This is the point where the RESTful view of your Web application can be integrated with your domain objects. Those domain objects can be implemented using any technology, relational databases, object databases, transactional components like EJB, etc. You just have to extend this class to override the REST methods you want to support like post(), put() or delete(). The common GET method is supported by the modifiable "variants" list property and the Resource.getRepresentation(Variant) method. This allows an easy and cheap declaration of the available variants in the constructor for example, then the on-demand creation of costly representations via the Resource.getRepresentation(Variant) method.

At a lower level, you have a handle*(Request,Response) method for each REST method that is supported by the Resource, where the '*' is replaced by the method name. The Finder handler for example, will be able to dynamically dispatch a call to the appropriate handle*() method. Most common REST methods like GET, POST, PUT and DELETE have default implementations that pre-handle calls to do content negotiation for example, based on the higher-level methods that we discussed previously. For example if you want to support a MOVE method, just add an handleMove(Request,Response) method and it will be detected automatically by a Finder handler.

Finally, you need to declare which REST methods are allowed by your Resource by overiding the matching allow*() method. By default, allowGet() returns true, but all other allow*() methods will return false. Therefore, if you want to support the DELETE method, just override allowDelete() and return true. Again, a previous Finder handler will be able to detect this method and know whether or not your Resource should be invoked. It is also used by the handleOptions() method to return the list of allowed methods.
See Also:    Source * dissertation
See Also:    Tutorial: Reaching * target Resources
See Also:   org.restlet.resource.Representation
See Also:   org.restlet.Finder
author:
   Jerome Louvel (contact@noelios.com)
author:
   Thierry Boileau (thboileau@gmail.com)



Constructor Summary
public  Resource()
     Default constructor.
public  Resource(Context context, Request request, Response response)
     Constructor.

Method Summary
public  booleanallowDelete()
     Indicates if it is allowed to delete the resource.
public  booleanallowGet()
     Indicates if it is allowed to get the variants.
public  booleanallowPost()
     Indicates if it is allowed to post to the resource.
public  booleanallowPut()
     Indicates if it is allowed to put to the resource.
public  voiddelete()
     Asks the resource to delete itself and all its representations.
public  ReferencegenerateRef(String uriTemplate)
     Generates a reference based on a template URI.
public  ContextgetContext()
     Returns the context.
public  LoggergetLogger()
     Returns the logger to use.
public  RepresentationgetPreferredRepresentation()
     Returns the preferred representation according to the client preferences specified in the associated request.
public  VariantgetPreferredVariant()
     Returns the preferred variant according to the client preferences specified in the associated request.
public  RepresentationgetRepresentation(Variant variant)
     Returns a full representation for a given variant previously returned via the getVariants() method.
public  RequestgetRequest()
     Returns the request.
public  ResponsegetResponse()
     Returns the response.
public  List<Variant>getVariants()
     Returns the modifiable list of variants.
public  voidhandleDelete()
     Handles a DELETE call invoking the 'delete' method of the target resource (as provided by the 'findTarget' method).
public  voidhandleGet()
     Handles a GET call by automatically returning the best entity available from the target resource (as provided by the 'findTarget' method).
public  voidhandleHead()
     Handles a HEAD call, using a logic similar to the handleGet method.
public  voidhandleOptions()
     Handles an OPTIONS call introspecting the target resource (as provided by the 'findTarget' method).
public  voidhandlePost()
     Handles a POST call invoking the 'post' method of the target resource (as provided by the 'findTarget' method).
public  voidhandlePut()
     Handles a PUT call invoking the 'put' method of the target resource (as provided by the 'findTarget' method).
public  voidinit(Context context, Request request, Response response)
     Initialize the resource with its context.
public  booleanisNegotiateContent()
     Indicates if the best content is automatically negotiated.
public  voidpost(Representation entity)
     Posts a representation to the resource.
public  voidput(Representation entity)
     Puts a representation in the resource.
public  voidsetContext(Context context)
     Sets the parent context.
public  voidsetNegotiateContent(boolean negotiateContent)
     Indicates if the best content is automatically negotiated.
public  voidsetRequest(Request request)
     Sets the request to handle.
public  voidsetResponse(Response response)
     Sets the response to update.


Constructor Detail
Resource
public Resource()(Code)
Default constructor. Note that the init() method must be invoked right after the creation of the resource.



Resource
public Resource(Context context, Request request, Response response)(Code)
Constructor. This constructor will invoke the init() method by default.
Parameters:
  context - The parent context.
Parameters:
  request - The request to handle.
Parameters:
  response - The response to return.




Method Detail
allowDelete
public boolean allowDelete()(Code)
Indicates if it is allowed to delete the resource. The default value is false. True if the method is allowed.



allowGet
public boolean allowGet()(Code)
Indicates if it is allowed to get the variants. The default value is true. True if the method is allowed.



allowPost
public boolean allowPost()(Code)
Indicates if it is allowed to post to the resource. The default value is false. True if the method is allowed.



allowPut
public boolean allowPut()(Code)
Indicates if it is allowed to put to the resource. The default value is false. True if the method is allowed.



delete
public void delete()(Code)
Asks the resource to delete itself and all its representations.



generateRef
public Reference generateRef(String uriTemplate)(Code)
Generates a reference based on a template URI. Note that you can leverage all the variables defined in the Template class as they will be resolved using the resource's request and response properties.
Parameters:
  uriTemplate - The URI template to use for generation. The generated reference.



getContext
public Context getContext()(Code)
Returns the context. The context.



getLogger
public Logger getLogger()(Code)
Returns the logger to use. The logger to use.



getPreferredRepresentation
public Representation getPreferredRepresentation()(Code)
Returns the preferred representation according to the client preferences specified in the associated request. The preferred representation.



getPreferredVariant
public Variant getPreferredVariant()(Code)
Returns the preferred variant according to the client preferences specified in the associated request. The preferred variant.



getRepresentation
public Representation getRepresentation(Variant variant)(Code)
Returns a full representation for a given variant previously returned via the getVariants() method. The default implementation directly returns the variant in case the variants are already full representations. In all other cases, you will need to override this method in order to provide your own implementation.

This method is very useful for content negotiation when it is too costly to initilize all the potential representations. It allows a resource to simply expose the available variants via the getVariants() method and to actually server the one selected via this method.
Parameters:
  variant - The variant whose full representation must be returned. The full representation for the variant.
See Also:   Resource.getVariants()



getRequest
public Request getRequest()(Code)
Returns the request. the request.



getResponse
public Response getResponse()(Code)
Returns the response. the response.



getVariants
public List<Variant> getVariants()(Code)
Returns the modifiable list of variants. A variant can be a purely descriptive representation, with no actual content that can be served. It can also be a full representation in case a resource has only one variant or if the initialization cost is very low.

Note that the order in which the variants are inserted in the list matters. For example, if the client has no preference defined, or if the acceptable variants have the same quality level for the client, the first acceptable variant in the list will be returned.

It is recommended to not override this method and to simply use it at construction time to initialize the list of available variants. Overriding it will force you to reconstruct the list for each call which is expensive. The list of variants.
See Also:   Resource.getRepresentation(Variant)



handleDelete
public void handleDelete()(Code)
Handles a DELETE call invoking the 'delete' method of the target resource (as provided by the 'findTarget' method).



handleGet
public void handleGet()(Code)
Handles a GET call by automatically returning the best entity available from the target resource (as provided by the 'findTarget' method). The content negotiation is based on the client's preferences available in the handled call and can be turned off using the "negotiateContent" property. If it is disabled and multiple variants are available for the target resource, then a 300 (Multiple Choices) status will be returned with the list of variants URI if available.



handleHead
public void handleHead()(Code)
Handles a HEAD call, using a logic similar to the handleGet method.



handleOptions
public void handleOptions()(Code)
Handles an OPTIONS call introspecting the target resource (as provided by the 'findTarget' method).



handlePost
public void handlePost()(Code)
Handles a POST call invoking the 'post' method of the target resource (as provided by the 'findTarget' method).



handlePut
public void handlePut()(Code)
Handles a PUT call invoking the 'put' method of the target resource (as provided by the 'findTarget' method).



init
public void init(Context context, Request request, Response response)(Code)
Initialize the resource with its context. If you override this method, make sure that you don't forget to call super.init() first, otherwise your Resource won't behave properly.
Parameters:
  context - The parent context.
Parameters:
  request - The request to handle.
Parameters:
  response - The response to return.



isNegotiateContent
public boolean isNegotiateContent()(Code)
Indicates if the best content is automatically negotiated. Default value is true. True if the best content is automatically negotiated.



post
public void post(Representation entity)(Code)
Posts a representation to the resource.
Parameters:
  entity - The posted entity.



put
public void put(Representation entity)(Code)
Puts a representation in the resource.
Parameters:
  entity - A new or updated representation.



setContext
public void setContext(Context context)(Code)
Sets the parent context.
Parameters:
  context - The parent context.



setNegotiateContent
public void setNegotiateContent(boolean negotiateContent)(Code)
Indicates if the best content is automatically negotiated. Default value is true.
Parameters:
  negotiateContent - True if the best content is automatically negotiated.



setRequest
public void setRequest(Request request)(Code)
Sets the request to handle.
Parameters:
  request - The request to handle.



setResponse
public void setResponse(Response response)(Code)
Sets the response to update.
Parameters:
  response - The response to update.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

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