Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GuiceModuleHandler |
|
| 3.0;3 |
1 | package org.apache.onami.test.handler; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.util.ArrayList; | |
23 | import java.util.List; | |
24 | import java.util.logging.Level; | |
25 | import java.util.logging.Logger; | |
26 | ||
27 | import org.apache.onami.test.annotation.GuiceModules; | |
28 | import org.apache.onami.test.reflection.ClassHandler; | |
29 | import org.apache.onami.test.reflection.HandleException; | |
30 | ||
31 | import com.google.inject.Module; | |
32 | ||
33 | /** | |
34 | * Handler class to handle all {@link GuiceModules} annotations. | |
35 | * | |
36 | * @see org.apache.onami.test.reflection.ClassVisitor | |
37 | */ | |
38 | 17 | public final class GuiceModuleHandler |
39 | implements ClassHandler<GuiceModules> | |
40 | { | |
41 | ||
42 | 1 | private static final Logger LOGGER = Logger.getLogger( GuiceModuleHandler.class.getName() ); |
43 | ||
44 | 12 | private final List<Module> modules = new ArrayList<Module>(); |
45 | ||
46 | /** | |
47 | * @return the modules | |
48 | */ | |
49 | public List<Module> getModules() | |
50 | { | |
51 | 12 | return modules; |
52 | } | |
53 | ||
54 | /** | |
55 | * {@inheritDoc} | |
56 | */ | |
57 | public void handle( GuiceModules annotation, Class<?> element ) | |
58 | throws HandleException | |
59 | { | |
60 | 10 | for ( Class<? extends Module> module : annotation.value() ) |
61 | { | |
62 | 5 | if ( LOGGER.isLoggable( Level.FINER ) ) |
63 | { | |
64 | 3 | LOGGER.finer( " Try to create module: " + module ); |
65 | } | |
66 | try | |
67 | { | |
68 | 5 | modules.add( module.newInstance() ); |
69 | } | |
70 | 0 | catch ( Exception e ) |
71 | { | |
72 | 0 | throw new HandleException( e ); |
73 | 5 | } |
74 | } | |
75 | 5 | } |
76 | ||
77 | } |