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

COVERAGE SUMMARY FOR SOURCE FILE [ParseObjectInfoFromHeaders.java]

nameclass, %method, %block, %line, %
ParseObjectInfoFromHeaders.java100% (1/1)100% (4/4)100% (68/68)100% (18/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseObjectInfoFromHeaders100% (1/1)100% (4/4)100% (68/68)100% (18/18)
ParseObjectInfoFromHeaders (ParseSystemAndUserMetadataFromHeaders, ResourceTo... 100% (1/1)100% (9/9)100% (4/4)
apply (HttpResponse): MutableObjectInfoWithMetadata 100% (1/1)100% (34/34)100% (9/9)
setContainer (String): ParseObjectInfoFromHeaders 100% (1/1)100% (5/5)100% (2/2)
setContext (HttpRequest): ParseObjectInfoFromHeaders 100% (1/1)100% (20/20)100% (3/3)

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.openstack.swift.functions;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
23 
24import javax.inject.Inject;
25 
26import org.jclouds.blobstore.domain.BlobMetadata;
27import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
28import org.jclouds.crypto.CryptoStreams;
29import org.jclouds.http.HttpRequest;
30import org.jclouds.http.HttpResponse;
31import org.jclouds.openstack.swift.blobstore.functions.ResourceToObjectInfo;
32import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata;
33import org.jclouds.rest.InvocationContext;
34import org.jclouds.rest.internal.GeneratedHttpRequest;
35 
36import com.google.common.base.Function;
37 
38/**
39 * This parses @{link {@link MutableObjectInfoWithMetadata} from HTTP headers.
40 * 
41 * @author Adrian Cole
42 */
43public class ParseObjectInfoFromHeaders implements Function<HttpResponse, MutableObjectInfoWithMetadata>,
44         InvocationContext<ParseObjectInfoFromHeaders> {
45   private final ParseSystemAndUserMetadataFromHeaders blobMetadataParser;
46   private final ResourceToObjectInfo blobToObjectInfo;
47   private String container;
48 
49   @Inject
50   public ParseObjectInfoFromHeaders(ParseSystemAndUserMetadataFromHeaders blobMetadataParser,
51            ResourceToObjectInfo blobToObjectInfo) {
52      this.blobMetadataParser = blobMetadataParser;
53      this.blobToObjectInfo = blobToObjectInfo;
54   }
55 
56   /**
57    * parses the http response headers to create a new {@link MutableObjectInfoWithMetadata} object.
58    */
59   public MutableObjectInfoWithMetadata apply(HttpResponse from) {
60      BlobMetadata base = blobMetadataParser.apply(from);
61      MutableObjectInfoWithMetadata to = blobToObjectInfo.apply(base);
62      to.setBytes(attemptToParseSizeAndRangeFromHeaders(from));
63      to.setContainer(container);
64      to.setUri(base.getUri());
65      String eTagHeader = from.getFirstHeaderOrNull("Etag");
66      if (eTagHeader != null) {
67         to.setHash(CryptoStreams.hex(eTagHeader));
68      }
69      return to;
70   }
71 
72   @Override
73   public ParseObjectInfoFromHeaders setContext(HttpRequest request) {
74      blobMetadataParser.setContext(request);
75      checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest");
76      return setContainer(GeneratedHttpRequest.class.cast(request).getArgs().get(0).toString());
77   }
78 
79   private ParseObjectInfoFromHeaders setContainer(String container) {
80      this.container = container;
81      return this;
82   }
83 
84}

[all classes][org.jclouds.openstack.swift.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov