-
Notifications
You must be signed in to change notification settings - Fork 57
/
BentenActionHandlerFactory.java
62 lines (48 loc) · 2.11 KB
/
BentenActionHandlerFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.intuit.benten.handlers;
import com.intuit.benten.common.actionhandlers.ActionHandlerFactory;
import com.intuit.benten.common.actionhandlers.BentenActionHandler;
import com.intuit.benten.common.annotations.ActionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import java.util.HashMap;
/**
* @author Divakar Ungatla
* @version 1.0
*/
@Component
public class BentenActionHandlerFactory implements ActionHandlerFactory {
private static final Logger logger = LoggerFactory.getLogger(BentenActionHandlerFactory.class);
@Autowired
private ApplicationContext applicationContext;
HashMap<String, BentenActionHandler> actionHandlerMap;
ClassPathScanningCandidateComponentProvider scanner;
public BentenActionHandlerFactory() throws NoSuchFieldException {
actionHandlerMap = new HashMap<>();
}
@PostConstruct
public void init() throws ClassNotFoundException {
scanner =
new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(ActionHandler.class));
for (BeanDefinition bd : scanner.findCandidateComponents(""))
{
Object object = applicationContext.getBean(Class.forName(bd.getBeanClassName()));
actionHandlerMap.put(object.getClass().getAnnotation(ActionHandler.class).action(),(BentenActionHandler) object);
}
}
public BentenActionHandler getActionHandler(String action) {
BentenActionHandler actionHandler = this.actionHandlerMap.get(action);
return actionHandler;
}
@Override
public HashMap<String, BentenActionHandler> getActionHandlerMap() {
return actionHandlerMap;
}
}