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 |
786
| public void validate(Class baseClass, Class enhancedClass, IComponentSpecification specification)
|
42 |
| { |
43 |
| |
44 |
| |
45 |
| |
46 |
786
| Set implementedMethods = new HashSet();
|
47 |
| |
48 |
| |
49 |
786
| Map interfaceMethods = new HashMap();
|
50 |
| |
51 |
786
| Location location = specification.getLocation();
|
52 |
| |
53 |
786
| Class current = enhancedClass;
|
54 |
| |
55 |
786
| while (true)
|
56 |
| { |
57 |
3838
| addInterfaceMethods(current, interfaceMethods);
|
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
3838
| Method[] methods = current.getDeclaredMethods();
|
69 |
| |
70 |
3838
| for (int i = 0; i < methods.length; i++)
|
71 |
| { |
72 |
68698
| Method m = methods[i];
|
73 |
| |
74 |
68698
| MethodSignature s = new MethodSignature(m);
|
75 |
| |
76 |
68698
| boolean isAbstract = Modifier.isAbstract(m.getModifiers());
|
77 |
| |
78 |
68698
| if (isAbstract)
|
79 |
| { |
80 |
4682
| if (interfaceMethods.containsKey(s))
|
81 |
1048
| continue;
|
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
3634
| if (implementedMethods.contains(s))
|
87 |
3632
| continue;
|
88 |
| |
89 |
2
| _errorLog.error(EnhanceMessages.noImplForAbstractMethod(
|
90 |
| m, |
91 |
| current, |
92 |
| baseClass, |
93 |
| enhancedClass), location, null); |
94 |
| } |
95 |
| |
96 |
64018
| implementedMethods.add(s);
|
97 |
| } |
98 |
| |
99 |
3838
| current = current.getSuperclass();
|
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
3838
| if (current == null || current == Object.class)
|
106 |
786
| break;
|
107 |
| } |
108 |
| |
109 |
786
| Iterator i = interfaceMethods.entrySet().iterator();
|
110 |
786
| while (i.hasNext())
|
111 |
| { |
112 |
37294
| Map.Entry entry = (Map.Entry) i.next();
|
113 |
| |
114 |
37294
| MethodSignature sig = (MethodSignature) entry.getKey();
|
115 |
| |
116 |
37294
| if (implementedMethods.contains(sig))
|
117 |
37292
| continue;
|
118 |
| |
119 |
2
| Method method = (Method) entry.getValue();
|
120 |
| |
121 |
2
| _errorLog.error(EnhanceMessages.unimplementedInterfaceMethod(
|
122 |
| method, |
123 |
| baseClass, |
124 |
| enhancedClass), location, null); |
125 |
| } |
126 |
| |
127 |
| } |
128 |
| |
129 |
3838
| private void addInterfaceMethods(Class current, Map interfaceMethods)
|
130 |
| { |
131 |
3838
| Class[] interfaces = current.getInterfaces();
|
132 |
| |
133 |
3838
| for (int i = 0; i < interfaces.length; i++)
|
134 |
2466
| addMethodsFromInterface(interfaces[i], interfaceMethods);
|
135 |
| } |
136 |
| |
137 |
2466
| private void addMethodsFromInterface(Class interfaceClass, Map interfaceMethods)
|
138 |
| { |
139 |
2466
| Method[] methods = interfaceClass.getMethods();
|
140 |
| |
141 |
2466
| for (int i = 0; i < methods.length; i++)
|
142 |
| { |
143 |
64598
| MethodSignature sig = new MethodSignature(methods[i]);
|
144 |
| |
145 |
64598
| if (interfaceMethods.containsKey(sig))
|
146 |
27304
| continue;
|
147 |
| |
148 |
37294
| interfaceMethods.put(sig, methods[i]);
|
149 |
| } |
150 |
| } |
151 |
| |
152 |
82
| public void setErrorLog(ErrorLog errorLog)
|
153 |
| { |
154 |
82
| _errorLog = errorLog;
|
155 |
| } |
156 |
| } |