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

COVERAGE SUMMARY FOR SOURCE FILE [VAppTemplatesForCatalogItems.java]

nameclass, %method, %block, %line, %
VAppTemplatesForCatalogItems.java0%   (0/4)0%   (0/11)0%   (0/94)0%   (0/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppTemplatesForCatalogItems0%   (0/1)0%   (0/5)0%   (0/42)0%   (0/8)
VAppTemplatesForCatalogItems (VCloudAsyncClient, ExecutorService, VAppTemplat... 0%   (0/1)0%   (0/15)0%   (0/6)
access$000 (VAppTemplatesForCatalogItems): VCloudAsyncClient 0%   (0/1)0%   (0/3)0%   (0/1)
access$100 (VAppTemplatesForCatalogItems): ExecutorService 0%   (0/1)0%   (0/3)0%   (0/1)
access$200 (VAppTemplatesForCatalogItems): VAppTemplatesForCatalogItems$Retur... 0%   (0/1)0%   (0/3)0%   (0/1)
apply (Iterable): Iterable 0%   (0/1)0%   (0/18)0%   (0/1)
     
class VAppTemplatesForCatalogItems$10%   (0/1)0%   (0/2)0%   (0/12)0%   (0/2)
VAppTemplatesForCatalogItems$1 (VAppTemplatesForCatalogItems): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (CatalogItem): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
     
class VAppTemplatesForCatalogItems$20%   (0/1)0%   (0/2)0%   (0/28)0%   (0/2)
VAppTemplatesForCatalogItems$2 (VAppTemplatesForCatalogItems): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (CatalogItem): Future 0%   (0/1)0%   (0/22)0%   (0/1)
     
class VAppTemplatesForCatalogItems$ReturnNullOnAuthorizationException0%   (0/1)0%   (0/2)0%   (0/12)0%   (0/4)
VAppTemplatesForCatalogItems$ReturnNullOnAuthorizationException (): void 0%   (0/1)0%   (0/3)0%   (0/1)
apply (Exception): VAppTemplate 0%   (0/1)0%   (0/9)0%   (0/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.vcloud.functions;
20 
21import static com.google.common.collect.Iterables.filter;
22import static org.jclouds.concurrent.FutureIterables.transformParallel;
23import static org.jclouds.util.Throwables2.propagateOrNull;
24 
25import java.util.concurrent.ExecutorService;
26import java.util.concurrent.Future;
27 
28import javax.annotation.Resource;
29import javax.inject.Inject;
30import javax.inject.Named;
31import javax.inject.Singleton;
32 
33import org.jclouds.Constants;
34import org.jclouds.compute.reference.ComputeServiceConstants;
35import org.jclouds.concurrent.ExceptionParsingListenableFuture;
36import org.jclouds.concurrent.Futures;
37import org.jclouds.logging.Logger;
38import org.jclouds.rest.AuthorizationException;
39import org.jclouds.vcloud.VCloudAsyncClient;
40import org.jclouds.vcloud.VCloudMediaType;
41import org.jclouds.vcloud.domain.CatalogItem;
42import org.jclouds.vcloud.domain.VAppTemplate;
43 
44import com.google.common.base.Function;
45import com.google.common.base.Predicate;
46 
47/**
48 * @author Adrian Cole
49 */
50@Singleton
51public class VAppTemplatesForCatalogItems implements
52         Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> {
53   @Resource
54   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
55   public Logger logger = Logger.NULL;
56   private final VCloudAsyncClient aclient;
57   private final ExecutorService executor;
58   private final ReturnNullOnAuthorizationException returnNullOnAuthorizationException;
59 
60   @Singleton
61   static class ReturnNullOnAuthorizationException implements Function<Exception, VAppTemplate> {
62 
63      public VAppTemplate apply(Exception from) {
64         if (from instanceof AuthorizationException) {
65            return null;
66         }
67         return propagateOrNull(from);
68      }
69   }
70 
71   @Inject
72   VAppTemplatesForCatalogItems(VCloudAsyncClient aclient,
73            @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
74            ReturnNullOnAuthorizationException returnNullOnAuthorizationException) {
75      this.aclient = aclient;
76      this.executor = executor;
77      this.returnNullOnAuthorizationException = returnNullOnAuthorizationException;
78   }
79 
80   @Override
81   public Iterable<? extends VAppTemplate> apply(Iterable<? extends CatalogItem> from) {
82      return transformParallel(filter(from, new Predicate<CatalogItem>() {
83 
84         @Override
85         public boolean apply(CatalogItem input) {
86            return input.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML);
87         }
88 
89      }), new Function<CatalogItem, Future<VAppTemplate>>() {
90 
91         @SuppressWarnings("unchecked")
92         @Override
93         public Future<VAppTemplate> apply(CatalogItem from) {
94            return new ExceptionParsingListenableFuture<VAppTemplate>(Futures.makeListenable(
95                     (Future<VAppTemplate>) VCloudAsyncClient.class.cast(aclient).getVAppTemplateClient().getVAppTemplate(
96                              from.getEntity().getHref()), executor), returnNullOnAuthorizationException);
97         }
98 
99      }, executor, null, logger, "vappTemplates in");
100   }
101 
102}

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