1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.enhance; |
16 |
| |
17 |
| import java.lang.reflect.Method; |
18 |
| import java.lang.reflect.Modifier; |
19 |
| import java.util.HashMap; |
20 |
| import java.util.HashSet; |
21 |
| import java.util.Iterator; |
22 |
| import java.util.Map; |
23 |
| import java.util.Set; |
24 |
| |
25 |
| import org.apache.hivemind.ErrorLog; |
26 |
| import org.apache.hivemind.Location; |
27 |
| import org.apache.hivemind.service.MethodSignature; |
28 |
| import org.apache.tapestry.spec.IComponentSpecification; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| public class EnhancedClassValidatorImpl implements EnhancedClassValidator |
38 |
| { |
39 |
| private ErrorLog _errorLog; |
40 |
| |
41 |
393
| public void validate(Class baseClass, Class enhancedClass, IComponentSpecification specification)
|
42 |
| { |
43 |
| |
44 |
| |
45 |
| |
46 |
393
| Set implementedMethods = new HashSet();
|
47 |
| |
48 |
| |
49 |
393
| Map interfaceMethods = new HashMap();
|
50 |
| |
51 |
393
| Location location = specification.getLocation();
|
52 |
| |
53 |
393
| Class current = enhancedClass;
|
54 |
| |
55 |
393
| while (true)
|
56 |
| { |
57 |
1919
| addInterfaceMethods(current, interfaceMethods);
|
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
1919
| Method[] methods = current.getDeclaredMethods();
|
69 |
| |
70 |
1919
| for (int i = 0; i < methods.length; i++)
|
71 |
| { |
72 |
34349
| Method m = methods[i];
|
73 |
| |
74 |
34349
| MethodSignature s = new MethodSignature(m);
|
75 |
| |
76 |
34349
| boolean isAbstract = Modifier.isAbstract(m.getModifiers());
|
77 |
| |
78 |
34349
| if (isAbstract)
|
79 |
| { |
80 |
2341
| if (interfaceMethods.containsKey(s))
|
81 |
524
| continue;
|
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
1817
| if (implementedMethods.contains(s))
|
87 |
1816
| continue;
|
88 |
| |
89 |
1
| _errorLog.error(EnhanceMessages.noImplForAbstractMethod(
|
90 |
| m, |
91 |
| current, |
92 |
| baseClass, |
93 |
| enhancedClass), location, null); |
94 |
| } |
95 |
| |
96 |
32009
| implementedMethods.add(s);
|
97 |
| } |
98 |
| |
99 |
1919
| current = current.getSuperclass();
|
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
1919
| if (current == null || current == Object.class)
|
106 |
393
| break;
|
107 |
| } |
108 |
| |
109 |
393
| Iterator i = interfaceMethods.entrySet().iterator();
|
110 |
393
| while (i.hasNext())
|
111 |
| { |
112 |
18647
| Map.Entry entry = (Map.Entry) i.next();
|
113 |
| |
114 |
18647
| MethodSignature sig = (MethodSignature) entry.getKey();
|
115 |
| |
116 |
18647
| if (implementedMethods.contains(sig))
|
117 |
18646
| continue;
|
118 |
| |
119 |
1
| Method method = (Method) entry.getValue();
|
120 |
| |
121 |
1
| _errorLog.error(EnhanceMessages.unimplementedInterfaceMethod(
|
122 |
| method, |
123 |
| baseClass, |
124 |
| enhancedClass), location, null); |
125 |
| } |
126 |
| |
127 |
| } |
128 |
| |
129 |
1919
| private void addInterfaceMethods(Class current, Map interfaceMethods)
|
130 |
| { |
131 |
1919
| Class[] interfaces = current.getInterfaces();
|
132 |
| |
133 |
1919
| for (int i = 0; i < interfaces.length; i++)
|
134 |
1233
| addMethodsFromInterface(interfaces[i], interfaceMethods);
|
135 |
| } |
136 |
| |
137 |
1233
| private void addMethodsFromInterface(Class interfaceClass, Map interfaceMethods)
|
138 |
| { |
139 |
1233
| Method[] methods = interfaceClass.getMethods();
|
140 |
| |
141 |
1233
| for (int i = 0; i < methods.length; i++)
|
142 |
| { |
143 |
32299
| MethodSignature sig = new MethodSignature(methods[i]);
|
144 |
| |
145 |
32299
| if (interfaceMethods.containsKey(sig))
|
146 |
13652
| continue;
|
147 |
| |
148 |
18647
| interfaceMethods.put(sig, methods[i]);
|
149 |
| } |
150 |
| } |
151 |
| |
152 |
41
| public void setErrorLog(ErrorLog errorLog)
|
153 |
| { |
154 |
41
| _errorLog = errorLog;
|
155 |
| } |
156 |
| } |