1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache.pojo.util; |
8 |
| |
9 |
| import org.apache.commons.logging.Log; |
10 |
| import org.apache.commons.logging.LogFactory; |
11 |
| import org.jboss.aop.Advised; |
12 |
| import org.jboss.aop.InstanceAdvisor; |
13 |
| import org.jboss.aop.advice.Interceptor; |
14 |
| import org.jboss.cache.Cache; |
15 |
| import org.jboss.cache.Fqn; |
16 |
| import org.jboss.cache.Region; |
17 |
| import org.jboss.cache.pojo.impl.InternalConstant; |
18 |
| import org.jboss.cache.pojo.interceptors.dynamic.BaseInterceptor; |
19 |
| import org.jboss.cache.pojo.interceptors.dynamic.CacheFieldInterceptor; |
20 |
| import org.jboss.util.id.GUID; |
21 |
| |
22 |
| import java.io.Serializable; |
23 |
| import java.util.ArrayList; |
24 |
| import java.util.List; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public final class AopUtil |
32 |
| { |
33 |
| static final Log log = LogFactory.getLog(AopUtil.class.getName()); |
34 |
| public static final String SEPARATOR = "/"; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
0
| static public Interceptor findCacheInterceptor(InstanceAdvisor advisor, Fqn fqn)
|
44 |
| { |
45 |
0
| org.jboss.aop.advice.Interceptor[] interceptors = advisor.getInterceptors();
|
46 |
| |
47 |
0
| for (int i = 0; i < interceptors.length; i++)
|
48 |
| { |
49 |
0
| Interceptor interceptor = interceptors[i];
|
50 |
0
| if (interceptor instanceof CacheFieldInterceptor)
|
51 |
| { |
52 |
0
| CacheFieldInterceptor inter = (CacheFieldInterceptor) interceptor;
|
53 |
0
| if (inter != null && inter.getFqn().equals(fqn))
|
54 |
| { |
55 |
0
| return interceptor;
|
56 |
| } |
57 |
| } |
58 |
| } |
59 |
0
| return null;
|
60 |
| } |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
4476
| static public Interceptor findCacheInterceptor(InstanceAdvisor advisor)
|
71 |
| { |
72 |
| |
73 |
4476
| Interceptor[] interceptors = advisor.getInterceptors();
|
74 |
| |
75 |
4476
| for (int i = 0; i < interceptors.length; i++)
|
76 |
| { |
77 |
2207
| Interceptor interceptor = interceptors[i];
|
78 |
2207
| if (interceptor instanceof CacheFieldInterceptor)
|
79 |
| { |
80 |
2207
| return interceptor;
|
81 |
| } |
82 |
| } |
83 |
2269
| return null;
|
84 |
| } |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
3066
| static public Interceptor findCollectionInterceptor(InstanceAdvisor advisor)
|
95 |
| { |
96 |
| |
97 |
3066
| Interceptor[] interceptors = advisor.getInterceptors();
|
98 |
| |
99 |
3066
| for (int i = 0; i < interceptors.length; i++)
|
100 |
| { |
101 |
3066
| Interceptor interceptor = interceptors[i];
|
102 |
3066
| if (interceptor instanceof BaseInterceptor)
|
103 |
| { |
104 |
3066
| return interceptor;
|
105 |
| } |
106 |
| } |
107 |
0
| return null;
|
108 |
| } |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
7640
| public static void checkObjectType(Object obj)
|
117 |
| { |
118 |
5
| if (obj == null) return;
|
119 |
7635
| if (!(obj instanceof Advised))
|
120 |
| { |
121 |
5202
| boolean allowedType = (obj instanceof Serializable) || (obj.getClass().isArray() && obj.getClass().getComponentType().isPrimitive());
|
122 |
| |
123 |
5202
| if (!allowedType)
|
124 |
| { |
125 |
0
| throw new IllegalArgumentException("PojoCache.putObject(): Object type is neither " +
|
126 |
| " aspectized nor Serializable nor an array of primitives. Object class name is " + obj.getClass().getName()); |
127 |
| } |
128 |
| } |
129 |
| } |
130 |
| |
131 |
| |
132 |
7476
| public static Fqn constructFqn(Fqn baseFqn, Object relative)
|
133 |
| { |
134 |
| |
135 |
| |
136 |
| |
137 |
7476
| return new Fqn(baseFqn, relative.toString());
|
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| } |
144 |
| |
145 |
| |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
7439
| public static Fqn createInternalFqn(Fqn fqn, Cache cache)
|
151 |
| { |
152 |
| |
153 |
| |
154 |
7439
| Fqn trueId = null;
|
155 |
7439
| if (fqn.hasElement(InternalConstant.JBOSS_INTERNAL_ID_SEP_STRING))
|
156 |
| { |
157 |
5901
| List list = new ArrayList();
|
158 |
25347
| for (int i = 0; i < fqn.size(); i++)
|
159 |
| { |
160 |
25347
| if (fqn.get(i).equals(InternalConstant.JBOSS_INTERNAL_STRING))
|
161 |
| { |
162 |
5901
| continue;
|
163 |
| } |
164 |
| |
165 |
19446
| if (fqn.get(i).equals(InternalConstant.JBOSS_INTERNAL_ID_SEP_STRING))
|
166 |
| { |
167 |
5901
| break;
|
168 |
| } |
169 |
13545
| list.add(fqn.get(i));
|
170 |
| } |
171 |
5901
| trueId = new Fqn(list);
|
172 |
| } |
173 |
| else |
174 |
| { |
175 |
1538
| trueId = fqn;
|
176 |
| } |
177 |
| |
178 |
7439
| boolean createIfAbsent = false;
|
179 |
7439
| Region region = cache.getRegion(trueId, createIfAbsent);
|
180 |
| |
181 |
7439
| GUID guid = new GUID();
|
182 |
| |
183 |
7439
| if (region == null || region.getFqn().equals(Fqn.ROOT))
|
184 |
| { |
185 |
| |
186 |
7311
| Fqn f0 = new Fqn(InternalConstant.JBOSS_INTERNAL, trueId);
|
187 |
7311
| Fqn f = new Fqn(f0, InternalConstant.JBOSS_INTERNAL_ID_SEP);
|
188 |
7311
| return new Fqn(f, Fqn.fromString(guid.toString()));
|
189 |
| } |
190 |
| else |
191 |
| { |
192 |
| |
193 |
128
| Fqn rf = region.getFqn();
|
194 |
| |
195 |
128
| Fqn childf = trueId.getSubFqn(rf.size(), trueId.size());
|
196 |
128
| Fqn f0 = new Fqn(InternalConstant.JBOSS_INTERNAL, childf);
|
197 |
128
| Fqn f = new Fqn(f0, InternalConstant.JBOSS_INTERNAL_ID_SEP);
|
198 |
128
| Fqn f1 = new Fqn(rf, f);
|
199 |
128
| return new Fqn(f1, Fqn.fromString(guid.toString()));
|
200 |
| } |
201 |
| } |
202 |
| |
203 |
| } |