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

COVERAGE SUMMARY FOR SOURCE FILE [BlobToObjectMetadata.java]

nameclass, %method, %block, %line, %
BlobToObjectMetadata.java100% (1/1)50%  (2/4)74%  (62/84)72%  (13/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BlobToObjectMetadata100% (1/1)50%  (2/4)74%  (62/84)72%  (13/18)
setBucket (String): BlobToObjectMetadata 0%   (0/1)0%   (0/5)0%   (0/2)
setContext (HttpRequest): BlobToObjectMetadata 0%   (0/1)0%   (0/15)0%   (0/2)
apply (BlobMetadata): MutableObjectMetadata 100% (1/1)97%  (59/61)92%  (12/13)
BlobToObjectMetadata (): void 100% (1/1)100% (3/3)100% (1/1)

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.blobstore.functions;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22 
23import java.util.Map.Entry;
24 
25import org.jclouds.blobstore.domain.BlobMetadata;
26import org.jclouds.http.HttpRequest;
27import org.jclouds.http.HttpUtils;
28import org.jclouds.rest.InvocationContext;
29import org.jclouds.rest.internal.GeneratedHttpRequest;
30import org.jclouds.s3.domain.MutableObjectMetadata;
31import org.jclouds.s3.domain.internal.MutableObjectMetadataImpl;
32 
33import com.google.common.base.Function;
34 
35/**
36 * @author Adrian Cole
37 */
38public class BlobToObjectMetadata implements Function<BlobMetadata, MutableObjectMetadata>,
39         InvocationContext<BlobToObjectMetadata> {
40   private String bucket;
41 
42   public MutableObjectMetadata apply(BlobMetadata from) {
43      if (from == null)
44         return null;
45      MutableObjectMetadata to = new MutableObjectMetadataImpl();
46      HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata());
47      to.setUri(from.getUri());
48      to.setETag(from.getETag());
49      to.setKey(from.getName());
50      to.setBucket(bucket);
51      to.setLastModified(from.getLastModified());
52      if (from.getUserMetadata() != null) {
53         for (Entry<String, String> entry : from.getUserMetadata().entrySet())
54            to.getUserMetadata().put(entry.getKey().toLowerCase(), entry.getValue());
55      }
56      return to;
57   }
58 
59   @Override
60   public BlobToObjectMetadata setContext(HttpRequest request) {
61      checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest");
62      return setBucket(GeneratedHttpRequest.class.cast(request).getArgs().get(0).toString());
63   }
64 
65   private BlobToObjectMetadata setBucket(String bucket) {
66      this.bucket = bucket;
67      return this;
68   }
69 
70}

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