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 package nl.openedge.baritus;
33
34 import java.util.ArrayList;
35 import java.util.Iterator;
36 import java.util.List;
37
38 import nl.openedge.baritus.interceptors.Interceptor;
39
40 /***
41 * Registry for interceptors. Each instance of FormBeanBase has its own instance.
42 *
43 * @author Eelco Hillenius
44 */
45 final class InterceptorRegistry
46 {
47
48 private List interceptors = null;
49
50 private List[] flowInterceptors;
51
52
53 /***
54 * add an interceptor to the current list of interceptors
55 * @param interceptor the interceptor to add to the current list of interceptors
56 */
57 public void addInterceptor(Interceptor interceptor)
58 {
59 if(interceptors == null)
60 {
61 interceptors = new ArrayList();
62 }
63 interceptors.add(interceptor);
64 }
65
66 /***
67 * add an interceptor to the current list of interceptors at the specified position
68 * @param index index position where to insert the interceptor
69 * @param interceptor the interceptor to add to the current list of interceptors
70 */
71 public void addInterceptor(int index, Interceptor interceptor)
72 {
73 if(interceptors == null)
74 {
75 interceptors = new ArrayList();
76 }
77 interceptors.add(index, interceptor);
78 }
79
80
81 /***
82 * remove an interceptor from the current list of interceptors
83 * @param interceptor the interceptor to remove from the current list of interceptors
84 */
85 public void removeInterceptor(Interceptor interceptor)
86 {
87 if(interceptors != null)
88 {
89 interceptors.remove(interceptor);
90 if(interceptors.isEmpty()) interceptors = null;
91 }
92 }
93
94 /***
95 * get all registered interceptors of the provided type
96 * @param type the type
97 * @return array of Interceptors or null if none
98 */
99 public Interceptor[] getInterceptors(Class type)
100 {
101 Interceptor[] result = null;
102 if(interceptors != null && (!interceptors.isEmpty()))
103 {
104 List temp = new ArrayList();
105 for(Iterator i = interceptors.listIterator(); i.hasNext(); )
106 {
107 Interceptor intc = (Interceptor)i.next();
108 if(type.isAssignableFrom(intc.getClass()))
109 {
110 temp.add(intc);
111 }
112 }
113 if(!temp.isEmpty())
114 {
115 result = (Interceptor[])temp.toArray(new Interceptor[temp.size()]);
116 }
117 }
118 return result;
119 }
120
121 /***
122 * get the flow interceptors for the provided interceptionPoint
123 * @param interceptionPoint the interception point
124 * @return List flow interceptors or null if none were registered
125 */
126 public List getInterceptorsAtPoint(int interceptionPoint)
127 {
128 return (flowInterceptors != null) ?
129 flowInterceptors[interceptionPoint] : null;
130 }
131
132 }