EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.s3.options]

COVERAGE SUMMARY FOR SOURCE FILE [PutObjectOptions.java]

nameclass, %method, %block, %line, %
PutObjectOptions.java100% (2/2)88%  (7/8)95%  (80/84)98%  (17.6/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PutObjectOptions$Builder100% (1/1)50%  (1/2)73%  (8/11)67%  (2/3)
PutObjectOptions$Builder (): void 0%   (0/1)0%   (0/3)0%   (0/1)
withAcl (CannedAccessPolicy): PutObjectOptions 100% (1/1)100% (8/8)100% (2/2)
     
class PutObjectOptions100% (1/1)100% (6/6)99%  (72/73)100% (15.9/16)
buildRequestHeaders (): Multimap 100% (1/1)97%  (37/38)99%  (4.9/5)
<static initializer> 100% (1/1)100% (5/5)100% (1/1)
PutObjectOptions (): void 100% (1/1)100% (6/6)100% (3/3)
getAcl (): CannedAccessPolicy 100% (1/1)100% (3/3)100% (1/1)
setHeaderTag (String): void 100% (1/1)100% (4/4)100% (2/2)
withAcl (CannedAccessPolicy): PutObjectOptions 100% (1/1)100% (17/17)100% (4/4)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.s3.options;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Preconditions.checkState;
23import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
24import static org.jclouds.s3.reference.S3Headers.CANNED_ACL;
25import static org.jclouds.s3.reference.S3Headers.DEFAULT_AMAZON_HEADERTAG;
26 
27import java.util.Map.Entry;
28 
29import javax.inject.Inject;
30import javax.inject.Named;
31 
32import org.jclouds.http.options.BaseHttpRequestOptions;
33import org.jclouds.s3.domain.CannedAccessPolicy;
34 
35import com.google.common.collect.ImmutableMultimap;
36import com.google.common.collect.Multimap;
37 
38/**
39 * Contains options supported in the REST API for the PUT object operation.
40 * <p/>
41 * <h2>
42 * Usage</h2> The recommended way to instantiate a PutObjectOptions object is to statically import
43 * PutObjectOptions.Builder.* and invoke a static creation method followed by an instance mutator
44 * (if needed):
45 * <p/>
46 * <code>
47 * import static org.jclouds.s3.commands.options.PutObjectOptions.Builder.*
48 * import org.jclouds.s3.S3Client;
49 * 
50 * S3Client connection = // get connection
51 * Future<Boolean> publicly readable = connection.putObject("bucketName",new S3Object("key","value"), withAcl(CannedAccessPolicy.PUBLIC_READ));
52 * <code>
53 * 
54 * @see <a
55 *      href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectPUT.html?"
56 *      />
57 * 
58 * @author Adrian Cole
59 * 
60 */
61public class PutObjectOptions extends BaseHttpRequestOptions {
62   public static final PutObjectOptions NONE = new PutObjectOptions();
63 
64   private CannedAccessPolicy acl = CannedAccessPolicy.PRIVATE;
65 
66   private String headerTag;
67 
68   @Inject
69   public void setHeaderTag(@Named(PROPERTY_HEADER_TAG) String headerTag) {
70      this.headerTag = headerTag;
71   }
72 
73   @Override
74   public Multimap<String, String> buildRequestHeaders() {
75      checkState(headerTag != null, "headerTag should have been injected!");
76      ImmutableMultimap.Builder<String, String> returnVal = ImmutableMultimap.<String, String> builder();
77      for (Entry<String, String> entry : headers.entries()) {
78         returnVal.put(entry.getKey().replace(DEFAULT_AMAZON_HEADERTAG, headerTag), entry.getValue());
79      }
80      return returnVal.build();
81   }
82 
83   /**
84    * Override the default ACL (private) with the specified one.
85    * 
86    * @see CannedAccessPolicy
87    */
88   public PutObjectOptions withAcl(CannedAccessPolicy acl) {
89      this.acl = checkNotNull(acl, "acl");
90      if (!acl.equals(CannedAccessPolicy.PRIVATE))
91         this.replaceHeader(CANNED_ACL, acl.toString());
92      return this;
93   }
94 
95   /**
96    * @see PutObjectOptions#withAcl(CannedAccessPolicy)
97    */
98   public CannedAccessPolicy getAcl() {
99      return acl;
100   }
101 
102   public static class Builder {
103 
104      /**
105       * @see PutObjectOptions#withAcl(CannedAccessPolicy)
106       */
107      public static PutObjectOptions withAcl(CannedAccessPolicy acl) {
108         PutObjectOptions options = new PutObjectOptions();
109         return options.withAcl(acl);
110      }
111   }
112}

[all classes][org.jclouds.s3.options]
EMMA 2.0.5312 (C) Vladimir Roubtsov