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

COVERAGE SUMMARY FOR SOURCE FILE [FindLocationForResource.java]

nameclass, %method, %block, %line, %
FindLocationForResource.java0%   (0/1)0%   (0/2)0%   (0/55)0%   (0/9)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FindLocationForResource0%   (0/1)0%   (0/2)0%   (0/55)0%   (0/9)
FindLocationForResource (Supplier): void 0%   (0/1)0%   (0/9)0%   (0/4)
apply (ReferenceType): Location 0%   (0/1)0%   (0/46)0%   (0/5)

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.trmk.vcloud_0_8.compute.functions;
20 
21import java.net.URI;
22import java.util.NoSuchElementException;
23import java.util.Set;
24 
25import javax.annotation.Resource;
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.collect.Memoized;
30import org.jclouds.domain.Location;
31import org.jclouds.logging.Logger;
32import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
33 
34import com.google.common.base.Function;
35import com.google.common.base.Supplier;
36 
37/**
38 * @author Adrian Cole
39 */
40@Singleton
41public class FindLocationForResource implements Function<ReferenceType, Location> {
42 
43   @Resource
44   protected Logger logger = Logger.NULL;
45 
46   final Supplier<Set<? extends Location>> locations;
47 
48   @Inject
49   public FindLocationForResource(@Memoized Supplier<Set<? extends Location>> locations) {
50      this.locations = locations;
51   }
52 
53   /**
54    * searches for a location associated with this resource.
55    * 
56    * @throws NoSuchElementException
57    *            if not found
58    */
59   public Location apply(ReferenceType resource) {
60      for (Location input : locations.get()) {
61         do {
62            // The "name" isn't always present, ex inside a vApp we have a rel
63            // link that only includes href and type.
64            if (URI.create(input.getId()).equals(resource.getHref()))
65               return input;
66         } while ((input = input.getParent()) != null);
67      }
68      throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource,
69            locations.get()));
70   }
71}

[all classes][org.jclouds.trmk.vcloud_0_8.compute.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov