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

COVERAGE SUMMARY FOR SOURCE FILE [OrgNameVDCNameResourceNameToEndpoint.java]

nameclass, %method, %block, %line, %
OrgNameVDCNameResourceNameToEndpoint.java100% (1/1)100% (2/2)58%  (65/112)82%  (17.9/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OrgNameVDCNameResourceNameToEndpoint100% (1/1)100% (2/2)58%  (65/112)82%  (17.9/22)
apply (Object): URI 100% (1/1)53%  (53/100)76%  (12.9/17)
OrgNameVDCNameResourceNameToEndpoint (Supplier, ReferenceType, ReferenceType)... 100% (1/1)100% (12/12)100% (5/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.vcloud.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Preconditions.checkState;
23 
24import java.net.URI;
25import java.util.Map;
26import java.util.NoSuchElementException;
27 
28import javax.inject.Inject;
29 
30import org.jclouds.vcloud.domain.ReferenceType;
31import org.jclouds.vcloud.domain.VDC;
32import org.jclouds.vcloud.endpoints.Org;
33 
34import com.google.common.base.Function;
35import com.google.common.base.Supplier;
36import com.google.common.collect.Iterables;
37/**
38 * 
39 * @author Adrian Cole
40 */
41public abstract class OrgNameVDCNameResourceNameToEndpoint  implements Function<Object, URI>{
42 
43   protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
44   protected final ReferenceType defaultOrg;
45   protected final ReferenceType defaultVDC;
46 
47   @Inject
48   public OrgNameVDCNameResourceNameToEndpoint(
49         Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
50         @Org ReferenceType defaultOrg, @org.jclouds.vcloud.endpoints.VDC ReferenceType defaultVDC) {
51      this.orgVDCMap = orgVDCMap;
52      this.defaultOrg = defaultOrg;
53      this.defaultVDC = defaultVDC;
54   }
55 
56   @SuppressWarnings("unchecked")
57   public URI apply(Object from) {
58      Iterable<Object> orgVDC = (Iterable<Object>) checkNotNull(from, "args");
59      Object org = Iterables.get(orgVDC, 0);
60      Object vDC = Iterables.get(orgVDC, 1);
61      Object resource = Iterables.get(orgVDC, 2);
62      if (org == null)
63         org = defaultOrg.getName();
64      if (vDC == null)
65         vDC = defaultVDC.getName();
66      Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get();
67      checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
68      Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org);
69      if (vDCs == null)
70         throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
71      org.jclouds.vcloud.domain.VDC vDCObject = vDCs.get(vDC);
72      if (vDCObject == null)
73         throw new NoSuchElementException("vdc " + vDC + " in org " + org + " not found in " + vDCs.keySet());
74      return getEndpointOfResourceInVDC(org, vDC, resource, vDCObject);
75   }
76 
77   protected abstract URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource, VDC vDCObject);
78 
79}

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