|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.codehaus.wadi.aop.tracker.basic; |
|
17 |
| |
|
18 |
| import java.util.Arrays; |
|
19 |
| import java.util.Collection; |
|
20 |
| |
|
21 |
| import org.codehaus.wadi.aop.tracker.InstanceTrackerException; |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| public class CollectionReplacer extends AbstractReplacer { |
|
28 |
| |
|
29 |
18
| public CollectionReplacer(InstanceAndTrackerReplacer parentReplacer) {
|
|
30 |
18
| super(parentReplacer);
|
|
31 |
| } |
|
32 |
| |
|
33 |
112
| public boolean canProcess(Object instance) {
|
|
34 |
112
| return instance instanceof Collection;
|
|
35 |
| } |
|
36 |
| |
|
37 |
0
| protected Object replace(Object instance, Replacer replacer) {
|
|
38 |
0
| Collection collection = (Collection) instance;
|
|
39 |
0
| Collection newCollection = newCollection(collection);
|
|
40 |
| |
|
41 |
0
| Object[] instances = collection.toArray();
|
|
42 |
0
| instances = (Object[]) replacer.replace(instances);
|
|
43 |
0
| newCollection.addAll(Arrays.asList(instances));
|
|
44 |
0
| return newCollection;
|
|
45 |
| } |
|
46 |
| |
|
47 |
0
| protected Collection newCollection(Collection collection) {
|
|
48 |
0
| Collection newCollection;
|
|
49 |
0
| Class collClass = collection.getClass();
|
|
50 |
0
| try {
|
|
51 |
0
| newCollection = (Collection) collClass.getConstructor().newInstance();
|
|
52 |
| } catch (Exception e) { |
|
53 |
0
| throw new InstanceTrackerException(e);
|
|
54 |
| } |
|
55 |
0
| return newCollection;
|
|
56 |
| } |
|
57 |
| |
|
58 |
| } |