1
2
3
4
5 package gboat2.approveflow.service;
6
7 import gboat2.approveflow.Activator;
8
9 import java.util.LinkedList;
10 import java.util.List;
11
12 import org.apache.log4j.Logger;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.Filter;
15 import org.osgi.framework.InvalidSyntaxException;
16 import org.osgi.framework.ServiceReference;
17 import org.osgi.util.tracker.ServiceTracker;
18
19
20
21
22
23
24
25
26
27
28
29 public class ApproveFlowNodeCheckerHolder {
30 ServiceTracker exitActionTracker;
31
32 private static Logger logger = Logger.getLogger(ApproveFlowNodeCheckerHolder.class);
33
34 private List<IApproveFlowNodeChecker> checkers = new LinkedList<IApproveFlowNodeChecker>();
35
36 public ApproveFlowNodeCheckerHolder(){
37 BundleContext context = Activator.LOCAL_BUNDLE.getBundleContext();
38 try {
39 Filter exitFilter = context.createFilter("(objectClass=gboat2.approveflow.service.IApproveFlowNodeChecker)");
40 exitActionTracker = new ServiceTracker(Activator.LOCAL_BUNDLE.getBundleContext(),exitFilter,null){
41 @Override
42 public Object addingService(ServiceReference refer){
43 IApproveFlowNodeChecker checker = (IApproveFlowNodeChecker)context.getService(refer);
44 registExitActionHandler(checker);
45 return checker;
46 }
47
48 @Override
49 public void remove(ServiceReference refer){
50 IApproveFlowNodeChecker checker = (IApproveFlowNodeChecker)context.getService(refer);
51 unRegistExitActionHandler(checker);
52 super.remove(refer);
53 }
54 };
55 exitActionTracker.open();
56 } catch (InvalidSyntaxException e) {
57 logger.error(e);
58 }
59 }
60
61 private synchronized void registExitActionHandler(IApproveFlowNodeChecker checker) {
62 checkers.add(checker);
63 }
64
65 private synchronized void unRegistExitActionHandler(IApproveFlowNodeChecker checker) {
66 checkers.remove(checker);
67 }
68
69 public List<IApproveFlowNodeChecker> getNodeCheckers(){
70 return checkers;
71 }
72 }