01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package org.restlet.example.book.rest.ch3;
20:
21: import org.restlet.data.Reference;
22: import org.restlet.data.Status;
23: import org.restlet.resource.Representation;
24: import org.restlet.resource.Variant;
25:
26: /**
27: * Amazon S3 object.
28: *
29: * @author Jerome Louvel (contact@noelios.com)
30: */
31: public class S3Object extends S3Authorized {
32:
33: private S3Bucket bucket;
34:
35: private Variant metadata;
36:
37: private String name;
38:
39: public S3Object(S3Bucket bucket, String name) {
40: this .bucket = bucket;
41: this .name = name;
42: }
43:
44: /**
45: * Retrieves the metadata hash for this object, possibly fetchingit from S3.
46: *
47: * @return The metadata hash for this object, possibly fetchingit from S3.
48: */
49: public Variant getMetadata() {
50: if (this .metadata == null)
51: this .metadata = authorizedHead(getUri()).getEntity();
52: return this .metadata;
53: }
54:
55: /**
56: * Retrieves the value of this object, always fetching it (along with the
57: * metadata) from S3.
58: *
59: * @return The value of this object.
60: */
61: public Representation getValue() {
62: return authorizedGet(getUri()).getEntity();
63: }
64:
65: /**
66: * Store this object on S3 with a given value.
67: *
68: * @param value
69: * The value of the object to store.
70: */
71: public Status save(Representation value) {
72: this .metadata = value;
73: return authorizedPut(getUri(), value).getStatus();
74: }
75:
76: /**
77: * Deletes this bucket.
78: */
79: public Status delete() {
80: return authorizedDelete(getUri()).getStatus();
81: }
82:
83: public String getUri() {
84: return getBucket().getUri() + "/" + Reference.encode(getName());
85: }
86:
87: public S3Bucket getBucket() {
88: return this .bucket;
89: }
90:
91: public String getName() {
92: return this .name;
93: }
94:
95: public void setName(String name) {
96: this.name = name;
97: }
98:
99: }
|