Total Complexity | 5 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | package com.hltech.pact.gen.domain.client.annotation; |
||
9 | public class MappingHandlerFactory { |
||
10 | |||
11 | private static final String PACKAGE = "com.hltech.pact.gen"; |
||
12 | |||
13 | public List<AnnotatedMethodHandler> createAll() { |
||
14 | try { |
||
15 | return createHandlers(findClasses()); |
||
16 | } catch (IllegalAccessException | InstantiationException exception) { |
||
17 | throw new MappingMethodCreationException("Cannot create mapping handler", exception); |
||
18 | } |
||
19 | } |
||
20 | |||
21 | private List<Class<?>> findClasses() { |
||
22 | return new ClassGraph() |
||
23 | .whitelistPackages(PACKAGE) |
||
24 | .enableAnnotationInfo() |
||
25 | .scan() |
||
26 | .getClassesWithAnnotation(MappingMethodHandler.class.getName()) |
||
27 | .loadClasses(); |
||
28 | } |
||
29 | |||
30 | private List<AnnotatedMethodHandler> createHandlers(List<Class<?>> classes) |
||
31 | throws IllegalAccessException, InstantiationException { |
||
32 | |||
33 | List<AnnotatedMethodHandler> result = Lists.newArrayList(); |
||
34 | |||
35 | for (Class<?> handlerClass : classes) { |
||
36 | result.add((AnnotatedMethodHandler) handlerClass.newInstance()); |
||
37 | } |
||
38 | |||
39 | return result; |
||
40 | } |
||
42 |