001: /*
002: * Copyright 2005-2007 Noelios Consulting.
003: *
004: * The contents of this file are subject to the terms of the Common Development
005: * and Distribution License (the "License"). You may not use this file except in
006: * compliance with the License.
007: *
008: * You can obtain a copy of the license at
009: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010: * language governing permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL HEADER in each file and
013: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014: * applicable, add the following below this CDDL HEADER, with the fields
015: * enclosed by brackets "[]" replaced with your own identifying information:
016: * Portions Copyright [yyyy] [name of copyright owner]
017: */
018:
019: package org.restlet;
020:
021: import org.restlet.data.Method;
022: import org.restlet.data.Reference;
023: import org.restlet.data.Request;
024: import org.restlet.data.Response;
025: import org.restlet.resource.Representation;
026:
027: /**
028: * Base class exposing the uniform REST interface.
029: *
030: * "The central feature that distinguishes the REST architectural style from
031: * other network-based styles is its emphasis on a uniform interface between
032: * components. By applying the software engineering principle of generality to
033: * the component interface, the overall system architecture is simplified and
034: * the visibility of interactions is improved. Implementations are decoupled
035: * from the services they provide, which encourages independent evolvability."
036: * Roy T. Fielding<br/> <br/>
037: *
038: * @see <a
039: * href="http://roy.gbiv.com/pubs/dissertation/rest_arch_style.htm#sec_5_1_5">Source
040: * dissertation</a>
041: * @author Jerome Louvel (contact@noelios.com)
042: */
043: public abstract class Uniform {
044: /**
045: * Deletes the identified resource.
046: *
047: * @param resourceUri
048: * The URI of the resource to delete.
049: * @return The response.
050: */
051: public final Response delete(String resourceUri) {
052: return handle(new Request(Method.DELETE, resourceUri));
053: }
054:
055: /**
056: * Deletes the identified resource.
057: *
058: * @param resourceRef
059: * The reference of the resource to delete.
060: * @return The response.
061: */
062: public final Response delete(Reference resourceRef) {
063: return handle(new Request(Method.DELETE, resourceRef));
064: }
065:
066: /**
067: * Gets the identified resource.
068: *
069: * @param resourceUri
070: * The URI of the resource to get.
071: * @return The response.
072: */
073: public final Response get(String resourceUri) {
074: return handle(new Request(Method.GET, resourceUri));
075: }
076:
077: /**
078: * Gets the identified resource.
079: *
080: * @param resourceRef
081: * The reference of the resource to get.
082: * @return The response.
083: */
084: public final Response get(Reference resourceRef) {
085: return handle(new Request(Method.GET, resourceRef));
086: }
087:
088: /**
089: * Handles a call.
090: *
091: * @param request
092: * The request to handle.
093: * @return The returned response.
094: */
095: public final Response handle(Request request) {
096: Response response = new Response(request);
097: handle(request, response);
098: return response;
099: }
100:
101: /**
102: * Handles a call.
103: *
104: * @param request
105: * The request to handle.
106: * @param response
107: * The response to update.
108: */
109: public abstract void handle(Request request, Response response);
110:
111: /**
112: * Gets the identified resource without its representation's content.
113: *
114: * @param resourceUri
115: * The URI of the resource to get.
116: * @return The response.
117: */
118: public final Response head(String resourceUri) {
119: return handle(new Request(Method.HEAD, resourceUri));
120: }
121:
122: /**
123: * Gets the identified resource without its representation's content.
124: *
125: * @param resourceRef
126: * The reference of the resource to get.
127: * @return The response.
128: */
129: public final Response head(Reference resourceRef) {
130: return handle(new Request(Method.HEAD, resourceRef));
131: }
132:
133: /**
134: * Gets the options for the identified resource.
135: *
136: * @param resourceUri
137: * The URI of the resource to get.
138: * @return The response.
139: */
140: public final Response options(String resourceUri) {
141: return handle(new Request(Method.OPTIONS, resourceUri));
142: }
143:
144: /**
145: * Gets the options for the identified resource.
146: *
147: * @param resourceRef
148: * The reference of the resource to get.
149: * @return The response.
150: */
151: public final Response options(Reference resourceRef) {
152: return handle(new Request(Method.OPTIONS, resourceRef));
153: }
154:
155: /**
156: * Posts a representation to the identified resource.
157: *
158: * @param resourceUri
159: * The URI of the resource to post to.
160: * @param entity
161: * The entity to post.
162: * @return The response.
163: */
164: public final Response post(String resourceUri, Representation entity) {
165: return handle(new Request(Method.POST, resourceUri, entity));
166: }
167:
168: /**
169: * Posts a representation to the identified resource.
170: *
171: * @param resourceRef
172: * The reference of the resource to post to.
173: * @param entity
174: * The entity to post.
175: * @return The response.
176: */
177: public final Response post(Reference resourceRef,
178: Representation entity) {
179: return handle(new Request(Method.POST, resourceRef, entity));
180: }
181:
182: /**
183: * Puts a representation in the identified resource.
184: *
185: * @param resourceUri
186: * The URI of the resource to modify.
187: * @param entity
188: * The entity to put.
189: * @return The response.
190: */
191: public final Response put(String resourceUri, Representation entity) {
192: return handle(new Request(Method.PUT, resourceUri, entity));
193: }
194:
195: /**
196: * Puts a representation in the identified resource.
197: *
198: * @param resourceRef
199: * The reference of the resource to modify.
200: * @param entity
201: * The entity to put.
202: * @return The response.
203: */
204: public final Response put(Reference resourceRef,
205: Representation entity) {
206: return handle(new Request(Method.PUT, resourceRef, entity));
207: }
208:
209: }
|