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.data;
020:
021: /**
022: * Method to execute when handling a call.
023: *
024: * @author Jerome Louvel (contact@noelios.com)
025: */
026: public final class Method extends Metadata {
027: private static final String BASE_HTTP = "http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html";
028:
029: private static final String BASE_WEBDAV = "http://www.webdav.org/specs/rfc2518.html";
030:
031: /**
032: * Used with a proxy that can dynamically switch to being a tunnel.
033: *
034: * @see <a
035: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.9">HTTP
036: * RFC - 9.9 CONNECT</a>
037: */
038: public static final Method CONNECT = new Method(
039: "CONNECT",
040: "Used with a proxy that can dynamically switch to being a tunnel",
041: BASE_HTTP + "#sec9.9");
042:
043: /**
044: * Creates a duplicate of the source resource, identified by the
045: * Request-URI, in the destination resource, identified by the URI in the
046: * Destination header.
047: *
048: * @see <a
049: * href="http://www.webdav.org/specs/rfc2518.html#METHOD_COPY">WEBDAV
050: * RFC - 8.8 COPY Method</a>
051: */
052: public static final Method COPY = new Method(
053: "COPY",
054: "Creates a duplicate of the source resource, identified by the Request-URI, in the destination resource, identified by the URI in the Destination header",
055: BASE_WEBDAV + "#METHOD_COPY");
056:
057: /**
058: * Requests that the origin server deletes the resource identified by the
059: * request URI.
060: *
061: * @see <a
062: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7">HTTP
063: * RFC - 9.7 DELETE</a>
064: */
065: public static final Method DELETE = new Method(
066: "DELETE",
067: "Requests that the origin server deletes the resource identified by the request URI",
068: BASE_HTTP + "#sec9.7");
069:
070: /**
071: * Retrieves whatever information (in the form of an entity) that is
072: * identified by the request URI.
073: *
074: * @see <a
075: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3">HTTP
076: * RFC - 9.3 GET</a>
077: */
078: public static final Method GET = new Method(
079: "GET",
080: "Retrieves whatever information (in the form of an entity) that is identified by the request URI",
081: BASE_HTTP + "#sec9.3");
082:
083: /**
084: * Identical to GET except that the server must not return a message body in
085: * the response but only the message header.
086: *
087: * @see <a
088: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4">HTTP
089: * RFC - 9.4 GET</a>
090: */
091: public static final Method HEAD = new Method(
092: "HEAD",
093: "Identical to GET except that the server must not return a message body in the response",
094: BASE_HTTP + "#sec9.4");
095:
096: /**
097: * Used to take out a lock of any access type on the resource identified by
098: * the request URI.
099: *
100: * @see <a
101: * href="http://www.webdav.org/specs/rfc2518.html#METHOD_LOCK">WEBDAV
102: * RFC - 8.10 LOCK Method</a>
103: */
104: public static final Method LOCK = new Method("LOCK",
105: "Used to take out a lock of any access type (WebDAV)",
106: BASE_WEBDAV + "#METHOD_LOCK");
107:
108: /**
109: * MKCOL creates a new collection resource at the location specified by the
110: * Request URI.
111: *
112: * @see <a
113: * href="http://www.webdav.org/specs/rfc2518.html#METHOD_MKCOL">WEBDAV
114: * RFC - 8.3 MKCOL Method</a>
115: */
116: public static final Method MKCOL = new Method("MKCOL",
117: "Used to create a new collection (WebDAV)", BASE_WEBDAV
118: + "#METHOD_MKCOL");
119:
120: /**
121: * Logical equivalent of a copy, followed by consistency maintenance
122: * processing, followed by a delete of the source where all three actions
123: * are performed atomically.
124: *
125: * @see <a
126: * href="http://www.webdav.org/specs/rfc2518.html#METHOD_MOVE">WEBDAV
127: * RFC - 8.3 MKCOL Method</a>
128: */
129: public static final Method MOVE = new Method(
130: "MOVE",
131: "Logical equivalent of a copy, followed by consistency maintenance processing, followed by a delete of the source (WebDAV)",
132: BASE_WEBDAV + "#METHOD_MOVE");
133:
134: /**
135: * Requests for information about the communication options available on the
136: * request/response chain identified by the URI.
137: *
138: * @see <a
139: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2">HTTP
140: * RFC - 9.2 OPTIONS</a>
141: */
142: public static final Method OPTIONS = new Method(
143: "OPTIONS",
144: "Requests for information about the communication options available on the request/response chain identified by the URI",
145: BASE_HTTP + "#sec9.2");
146:
147: /**
148: * Requests that the origin server accepts the entity enclosed in the
149: * request as a new subordinate of the resource identified by the request
150: * URI.
151: *
152: * @see <a
153: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5">HTTP
154: * RFC - 9.5 POST</a>
155: */
156: public static final Method POST = new Method(
157: "POST",
158: "Requests that the origin server accepts the entity enclosed in the request as a new subordinate of the resource identified by the request URI",
159: BASE_HTTP + "#sec9.5");
160:
161: /**
162: * Retrieves properties defined on the resource identified by the request
163: * URI.
164: *
165: * @see <a
166: * href="http://www.webdav.org/specs/rfc2518.html#METHOD_PROPFIND">WEBDAV
167: * RFC - 8.1 PROPFIND</a>
168: */
169: public static final Method PROPFIND = new Method(
170: "PROPFIND",
171: "Retrieves properties defined on the resource identified by the request URI",
172: BASE_WEBDAV + "#METHOD_PROPFIND");
173:
174: /**
175: * Processes instructions specified in the request body to set and/or remove
176: * properties defined on the resource identified by the request URI.
177: *
178: * @see <a
179: * href="http://www.webdav.org/specs/rfc2518.html#METHOD_PROPPATCH">WEBDAV
180: * RFC - 8.2 PROPPATCH</a>
181: */
182: public static final Method PROPPATCH = new Method(
183: "PROPPATCH",
184: "Processes instructions specified in the request body to set and/or remove properties defined on the resource identified by the request URI",
185: BASE_WEBDAV + "#METHOD_PROPPATCH");
186:
187: /**
188: * Requests that the enclosed entity be stored under the supplied request
189: * URI.
190: *
191: * @see <a
192: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6">HTTP
193: * RFC - 9.6 PUT</a>
194: */
195: public static final Method PUT = new Method(
196: "PUT",
197: "Requests that the enclosed entity be stored under the supplied request URI",
198: BASE_HTTP + "#sec9.6");
199:
200: /**
201: * Used to invoke a remote, application-layer loop-back of the request
202: * message.
203: *
204: * @see <a
205: * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.8">HTTP
206: * RFC - 9.8 TRACE</a>
207: */
208: public static final Method TRACE = new Method(
209: "TRACE",
210: "Used to invoke a remote, application-layer loop-back of the request message",
211: BASE_HTTP + "#sec9.8");
212:
213: /**
214: * Removes the lock identified by the lock token from the request URI, and
215: * all other resources included in the lock.
216: *
217: * @see <a
218: * href="http://www.webdav.org/specs/rfc2518.html#METHOD_UNLOCK">WEBDAV
219: * RFC - 8.11 UNLOCK Method</a>
220: */
221: public static final Method UNLOCK = new Method(
222: "UNLOCK",
223: "Removes the lock identified by the lock token from the request URI, and all other resources included in the lock",
224: BASE_WEBDAV + "#METHOD_UNLOCK");
225:
226: /**
227: * Returns the method associated to a given method name. If an existing
228: * constant exists then it is returned, otherwise a new instance is created.
229: *
230: * @param methodName
231: * The method name.
232: * @return The associated method.
233: */
234: public static Method valueOf(final String methodName) {
235: Method result = null;
236:
237: if (methodName != null) {
238: if (methodName.equalsIgnoreCase(GET.getName()))
239: result = GET;
240: else if (methodName.equalsIgnoreCase(POST.getName()))
241: result = POST;
242: else if (methodName.equalsIgnoreCase(HEAD.getName()))
243: result = HEAD;
244: else if (methodName.equalsIgnoreCase(OPTIONS.getName()))
245: result = OPTIONS;
246: else if (methodName.equalsIgnoreCase(PUT.getName()))
247: result = PUT;
248: else if (methodName.equalsIgnoreCase(DELETE.getName()))
249: result = DELETE;
250: else if (methodName.equalsIgnoreCase(CONNECT.getName()))
251: result = CONNECT;
252: else if (methodName.equalsIgnoreCase(COPY.getName()))
253: result = COPY;
254: else if (methodName.equalsIgnoreCase(LOCK.getName()))
255: result = LOCK;
256: else if (methodName.equalsIgnoreCase(MKCOL.getName()))
257: result = MKCOL;
258: else if (methodName.equalsIgnoreCase(MOVE.getName()))
259: result = MOVE;
260: else if (methodName.equalsIgnoreCase(PROPFIND.getName()))
261: result = PROPFIND;
262: else if (methodName.equalsIgnoreCase(PROPPATCH.getName()))
263: result = PROPPATCH;
264: else if (methodName.equalsIgnoreCase(TRACE.getName()))
265: result = TRACE;
266: else if (methodName.equalsIgnoreCase(UNLOCK.getName()))
267: result = UNLOCK;
268: else
269: result = new Method(methodName);
270: }
271:
272: return result;
273: }
274:
275: /** The URI of the specification describing the method. */
276: private String uri;
277:
278: /**
279: * Constructor.
280: *
281: * @param name
282: * The technical name of the method.
283: * @see org.restlet.data.Method#valueOf(String)
284: */
285: public Method(final String name) {
286: this (name, null, null);
287: }
288:
289: /**
290: * Constructor.
291: *
292: * @param name
293: * The technical name of the method.
294: * @param description
295: * The description.
296: * @see org.restlet.data.Method#valueOf(String)
297: */
298: public Method(final String name, final String description) {
299: this (name, description, null);
300: }
301:
302: /**
303: * Constructor.
304: *
305: * @param name
306: * The technical name.
307: * @param description
308: * The description.
309: * @param uri
310: * The URI of the specification describing the method.
311: * @see org.restlet.data.Method#valueOf(String)
312: */
313: public Method(final String name, final String description,
314: final String uri) {
315: super (name, description);
316: this .uri = uri;
317: }
318:
319: /** {@inheritDoc} */
320: @Override
321: public boolean equals(final Object object) {
322: return (object instanceof Method)
323: && ((Method) object).getName().equals(getName());
324: }
325:
326: /**
327: * Returns the URI of the specification describing the method.
328: *
329: * @return The URI of the specification describing the method.
330: */
331: public String getUri() {
332: return this .uri;
333: }
334:
335: /** {@inheritDoc} */
336: @Override
337: public int hashCode() {
338: return (getName() == null) ? 0 : getName().hashCode();
339: }
340: }
|