EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute]

COVERAGE SUMMARY FOR SOURCE FILE [ComputeServiceContextBuilder.java]

nameclass, %method, %block, %line, %
ComputeServiceContextBuilder.java100% (2/2)78%  (7/9)81%  (54/67)77%  (10/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ComputeServiceContextBuilder$1100% (1/1)50%  (1/2)55%  (6/11)50%  (1/2)
apply (Module): boolean 0%   (0/1)0%   (0/5)0%   (0/1)
ComputeServiceContextBuilder$1 (ComputeServiceContextBuilder): void 100% (1/1)100% (6/6)100% (1/1)
     
class ComputeServiceContextBuilder100% (1/1)86%  (6/7)86%  (48/56)83%  (10/12)
ComputeServiceContextBuilder (Class, Class): void 0%   (0/1)0%   (0/8)0%   (0/2)
ComputeServiceContextBuilder (Class, Class, Properties): void 100% (1/1)100% (6/6)100% (2/2)
addImageResolutionModule (): void 100% (1/1)100% (1/1)100% (1/1)
addImageResolutionModuleIfNotPresent (): void 100% (1/1)100% (11/11)100% (3/3)
buildComputeServiceContext (): ComputeServiceContext 100% (1/1)100% (20/20)100% (1/1)
buildInjector (): Injector 100% (1/1)100% (5/5)100% (2/2)
withModules (Iterable): ComputeServiceContextBuilder 100% (1/1)100% (5/5)100% (1/1)

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.compute;
20 
21import java.util.Properties;
22 
23import org.jclouds.compute.config.ResolvesImages;
24import org.jclouds.compute.internal.ComputeServiceContextImpl;
25import org.jclouds.rest.RestContextBuilder;
26 
27import com.google.common.base.Predicate;
28import com.google.common.collect.Iterables;
29import com.google.inject.Injector;
30import com.google.inject.Key;
31import com.google.inject.Module;
32import com.google.inject.util.Types;
33 
34/**
35 * @author Adrian Cole
36 */
37public abstract class ComputeServiceContextBuilder<S, A> extends RestContextBuilder<S, A> {
38 
39   public ComputeServiceContextBuilder(Class<S> syncClientType, Class<A> asyncClientType) {
40      this(syncClientType, asyncClientType, new Properties());
41   }
42 
43   public ComputeServiceContextBuilder(Class<S> syncClientType, Class<A> asyncClientType,
44            Properties properties) {
45      super(syncClientType, asyncClientType, properties);
46 
47   }
48 
49   @Override
50   public Injector buildInjector() {
51      addImageResolutionModuleIfNotPresent();
52      return super.buildInjector();
53   }
54 
55   /**
56    * {@inheritDoc}
57    */
58   @Override
59   public ComputeServiceContextBuilder<S, A> withModules(Iterable<Module> modules) {
60      return (ComputeServiceContextBuilder<S, A>) super.withModules(modules);
61   }
62 
63   public ComputeServiceContext buildComputeServiceContext() {
64      // need the generic type information
65      return (ComputeServiceContext) buildInjector().getInstance(
66               Key.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType,
67                        asyncClientType)));
68   }
69 
70   protected void addImageResolutionModuleIfNotPresent() {
71      if (!Iterables.any(modules, new Predicate<Module>() {
72         public boolean apply(Module input) {
73            return input.getClass().isAnnotationPresent(ResolvesImages.class);
74         }
75 
76      })) {
77         addImageResolutionModule();
78      }
79   }
80 
81   protected void addImageResolutionModule() {
82      // do nothing;
83      // this is to be overridden when needed
84   }
85}

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