Clover Coverage Report - guice
Coverage timestamp: Tue Jan 6 2009 19:08:51 CST
../../../../img/srcFileCovDistChart0.png 84% of files have more coverage
6   52   4   2
0   26   0.67   3
3     1.33  
1    
 
  JndiProvider       Line # 24 6 4 9 0% 0.0
 
No Tests
 
1    /**
2    * Copyright (C) 2006 Google Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16   
17    package com.google.inject.example;
18   
19    import com.google.inject.Inject;
20    import com.google.inject.Provider;
21    import javax.naming.Context;
22    import javax.naming.NamingException;
23   
 
24    class JndiProvider<T> implements Provider<T> {
25   
26    @Inject Context context;
27    final String name;
28    final Class<T> type;
29   
 
30  0 toggle JndiProvider(Class<T> type, String name) {
31  0 this.name = name;
32  0 this.type = type;
33    }
34   
 
35  0 toggle public T get() {
36  0 try {
37  0 return type.cast(context.lookup(name));
38    }
39    catch (NamingException e) {
40  0 throw new RuntimeException(e);
41    }
42    }
43   
44    /**
45    * Creates a JNDI provider for the given
46    * type and name.
47    */
 
48  0 toggle static <T> Provider<T> fromJndi(
49    Class<T> type, String name) {
50  0 return new JndiProvider<T>(type, name);
51    }
52    }