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

COVERAGE SUMMARY FOR SOURCE FILE [ParseObjectFromHeadersAndHttpContent.java]

nameclass, %method, %block, %line, %
ParseObjectFromHeadersAndHttpContent.java100% (1/1)100% (4/4)100% (90/90)100% (18/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ParseObjectFromHeadersAndHttpContent100% (1/1)100% (4/4)100% (90/90)100% (18/18)
ParseObjectFromHeadersAndHttpContent (ParseSystemMetadataFromHeaders, ParseUs... 100% (1/1)100% (21/21)100% (5/5)
apply (HttpResponse): AtmosObject 100% (1/1)100% (49/49)100% (9/9)
setContext (HttpRequest): ParseObjectFromHeadersAndHttpContent 100% (1/1)100% (15/15)100% (2/2)
setPath (String): ParseObjectFromHeadersAndHttpContent 100% (1/1)100% (5/5)100% (2/2)

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.atmos.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
23 
24import java.net.URI;
25 
26import javax.inject.Inject;
27 
28import org.jclouds.atmos.domain.AtmosObject;
29import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
30import org.jclouds.http.HttpRequest;
31import org.jclouds.http.HttpResponse;
32import org.jclouds.rest.InvocationContext;
33import org.jclouds.rest.internal.GeneratedHttpRequest;
34 
35import com.google.common.base.Function;
36 
37/**
38 * Parses response headers and creates a new AtmosObject from them and the HTTP content.
39 * 
40 * @see ParseMetadataFromHeaders
41 * @author Adrian Cole
42 */
43public class ParseObjectFromHeadersAndHttpContent implements Function<HttpResponse, AtmosObject>,
44         InvocationContext<ParseObjectFromHeadersAndHttpContent> {
45 
46   private final ParseSystemMetadataFromHeaders systemMetadataParser;
47   private final ParseUserMetadataFromHeaders userMetadataParser;
48   private final AtmosObject.Factory objectProvider;
49   private URI uri;
50   private String path;
51 
52   @Inject
53   public ParseObjectFromHeadersAndHttpContent(ParseSystemMetadataFromHeaders systemMetadataParser,
54            ParseUserMetadataFromHeaders userMetadataParser, AtmosObject.Factory objectProvider) {
55      this.systemMetadataParser = checkNotNull(systemMetadataParser, "systemMetadataParser");
56      this.userMetadataParser = checkNotNull(userMetadataParser, "userMetadataParser");
57      this.objectProvider = checkNotNull(objectProvider, "objectProvider");
58   }
59 
60   /**
61    * First, calls {@link ParseSystemAndUserMetadataFromHeaders}.
62    * 
63    * Then, sets the object size based on the Content-Length header and adds the content to the
64    * {@link AtmosObject} result.
65    * 
66    * @throws org.jclouds.http.HttpException
67    */
68   public AtmosObject apply(HttpResponse from) {
69      checkNotNull(from, "http response");
70      AtmosObject object = objectProvider.create(systemMetadataParser.apply(from), userMetadataParser.apply(from));
71      object.getContentMetadata().setName(object.getSystemMetadata().getObjectName());
72      object.getContentMetadata().setPath(path);
73      object.getContentMetadata().setUri(uri);
74      object.getAllHeaders().putAll(from.getHeaders());
75      object.setPayload(from.getPayload());
76      object.getContentMetadata().setContentLength(attemptToParseSizeAndRangeFromHeaders(from));
77      return object;
78   }
79 
80   @Override
81   public ParseObjectFromHeadersAndHttpContent setContext(HttpRequest request) {
82      this.uri = request.getEndpoint();
83      return setPath(GeneratedHttpRequest.class.cast(request).getArgs().get(0).toString());
84   }
85 
86   private ParseObjectFromHeadersAndHttpContent setPath(String path) {
87      this.path = path;
88      return this;
89   }
90}

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