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

COVERAGE SUMMARY FOR SOURCE FILE [ComputeServiceContextFactory.java]

nameclass, %method, %block, %line, %
ComputeServiceContextFactory.java100% (1/1)42%  (5/12)30%  (37/124)38%  (10/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ComputeServiceContextFactory100% (1/1)42%  (5/12)30%  (37/124)38%  (10/26)
ComputeServiceContextFactory (Properties): void 0%   (0/1)0%   (0/7)0%   (0/2)
createContext (RestContextSpec, Iterable, Properties): ComputeServiceContext 0%   (0/1)0%   (0/11)0%   (0/2)
createContext (RestContextSpec, Properties): ComputeServiceContext 0%   (0/1)0%   (0/10)0%   (0/2)
createContext (String, Iterable, Properties): ComputeServiceContext 0%   (0/1)0%   (0/13)0%   (0/2)
createContext (String, Properties): ComputeServiceContext 0%   (0/1)0%   (0/12)0%   (0/2)
createContext (String, String, String, Iterable): ComputeServiceContext 0%   (0/1)0%   (0/14)0%   (0/2)
createContext (String, String, String, Iterable, Properties): ComputeServiceC... 0%   (0/1)0%   (0/15)0%   (0/2)
buildContextUnwrappingExceptions (ComputeServiceContextBuilder): ComputeServi... 100% (1/1)38%  (3/8)33%  (1/3)
ComputeServiceContextFactory (): void 100% (1/1)100% (6/6)100% (2/2)
ComputeServiceContextFactory (RestContextFactory): void 100% (1/1)100% (6/6)100% (3/3)
createContext (RestContextSpec): ComputeServiceContext 100% (1/1)100% (9/9)100% (2/2)
createContext (String, String, String): ComputeServiceContext 100% (1/1)100% (13/13)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.compute;
20 
21import static org.jclouds.rest.RestContextFactory.createContextBuilder;
22import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException;
23 
24import java.util.Properties;
25 
26import org.jclouds.javax.annotation.Nullable;
27 
28import org.jclouds.rest.RestContextFactory;
29import org.jclouds.rest.RestContextSpec;
30 
31import com.google.inject.Module;
32 
33/**
34 * Helper class to instantiate {@code ComputeServiceContext} instances.
35 * 
36 * @author Adrian Cole
37 */
38public class ComputeServiceContextFactory {
39 
40   private final RestContextFactory contextFactory;
41 
42   /**
43    * Initializes with the default properties built-in to jclouds. This is typically stored in the
44    * classpath resource {@code rest.properties}
45    * 
46    * @see RestContextFactory#getPropertiesFromResource
47    */
48   public ComputeServiceContextFactory() {
49      this(new RestContextFactory());
50   }
51 
52   /**
53    * Finds definitions in the specified properties.
54    */
55   public ComputeServiceContextFactory(Properties properties) {
56      this(new RestContextFactory(properties));
57   }
58 
59   /**
60    * 
61    * Uses the supplied RestContextFactory to create {@link ComputeServiceContext}s
62    */
63   public ComputeServiceContextFactory(RestContextFactory restContextFactory) {
64      this.contextFactory = restContextFactory;
65   }
66 
67   public static <S, A> ComputeServiceContext buildContextUnwrappingExceptions(
68         ComputeServiceContextBuilder<S, A> builder) {
69      try {
70         return builder.buildComputeServiceContext();
71      } catch (Exception e) {
72         return propagateAuthorizationOrOriginalException(e);
73      }
74   }
75 
76   /**
77    * @see RestContextFactory#createContextBuilder(String, String, String)
78    */
79   public ComputeServiceContext createContext(String provider, String identity, String credential) {
80      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(contextFactory
81            .createContextBuilder(provider, identity, credential));
82      return buildContextUnwrappingExceptions(builder);
83   }
84 
85   /**
86    * @see RestContextFactory#createContextBuilder(String, Properties)
87    */
88   public ComputeServiceContext createContext(String provider, Properties overrides) {
89      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(contextFactory
90            .createContextBuilder(provider, overrides));
91      return buildContextUnwrappingExceptions(builder);
92   }
93 
94   /**
95    * @see RestContextFactory#createContextBuilder(String, Iterable)
96    */
97   public ComputeServiceContext createContext(String provider, Iterable<? extends Module> modules, Properties overrides) {
98      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(contextFactory
99            .createContextBuilder(provider, modules, overrides));
100      return buildContextUnwrappingExceptions(builder);
101 
102   }
103 
104   /**
105    * @see RestContextFactory#createContextBuilder(String, String,String, Iterable)
106    */
107   public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
108         Iterable<? extends Module> modules) {
109      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(contextFactory
110            .createContextBuilder(provider, identity, credential, modules));
111      return buildContextUnwrappingExceptions(builder);
112   }
113 
114   /**
115    * @see RestContextFactory#createContextBuilder(String, String,String, Iterable, Properties)
116    */
117   public ComputeServiceContext createContext(String provider, @Nullable String identity, @Nullable String credential,
118         Iterable<? extends Module> modules, Properties overrides) {
119      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(contextFactory
120            .createContextBuilder(provider, identity, credential, modules, overrides));
121      return buildContextUnwrappingExceptions(builder);
122   }
123 
124   /**
125    * @see RestContextFactory#createContextBuilder(RestContextSpec)
126    */
127   public <S, A> ComputeServiceContext createContext(RestContextSpec<S, A> contextSpec) {
128      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class
129            .cast(createContextBuilder(contextSpec));
130      return buildContextUnwrappingExceptions(builder);
131 
132   }
133 
134   /**
135    * @see RestContextFactory#createContextBuilder(RestContextSpec, Properties)
136    */
137   public <S, A> ComputeServiceContext createContext(RestContextSpec<S, A> contextSpec, Properties overrides) {
138      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(createContextBuilder(
139            contextSpec, overrides));
140      return buildContextUnwrappingExceptions(builder);
141   }
142 
143   /**
144    * @see RestContextFactory#createContextBuilder(RestContextSpec, Iterable, Properties)
145    */
146   public <S, A> ComputeServiceContext createContext(RestContextSpec<S, A> contextSpec, Iterable<Module> modules,
147         Properties overrides) {
148      ComputeServiceContextBuilder<?, ?> builder = ComputeServiceContextBuilder.class.cast(createContextBuilder(
149            contextSpec, modules, overrides));
150      return buildContextUnwrappingExceptions(builder);
151   }
152 
153}

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