|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2009 the original author or authors. |
| 2 | + * Copyright 2002-2010 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import java.util.Arrays;
|
22 | 22 | import java.util.HashMap;
|
23 | 23 | import java.util.HashSet;
|
| 24 | +import java.util.LinkedHashSet; |
24 | 25 | import java.util.Map;
|
25 | 26 | import java.util.Set;
|
26 | 27 | import javax.portlet.ClientDataRequest;
|
@@ -145,71 +146,76 @@ else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null)
|
145 | 146 | * @return <code>true</code> if at least 1 handler method has been registered;
|
146 | 147 | * <code>false</code> otherwise
|
147 | 148 | */
|
148 |
| - protected boolean detectHandlerMethods(Class handlerType, final String beanName, final RequestMapping typeMapping) { |
| 149 | + protected boolean detectHandlerMethods(Class<?> handlerType, final String beanName, final RequestMapping typeMapping) { |
149 | 150 | final Set<Boolean> handlersRegistered = new HashSet<Boolean>(1);
|
150 |
| - ReflectionUtils.doWithMethods(handlerType, new ReflectionUtils.MethodCallback() { |
151 |
| - public void doWith(Method method) { |
152 |
| - boolean mappingFound = false; |
153 |
| - String[] modeKeys = new String[0]; |
154 |
| - String[] params = new String[0]; |
155 |
| - String resourceId = null; |
156 |
| - String eventName = null; |
157 |
| - for (Annotation ann : method.getAnnotations()) { |
158 |
| - if (AnnotationUtils.findAnnotation(ann.getClass(), Mapping.class) != null) { |
159 |
| - mappingFound = true; |
160 |
| - if (ann instanceof RequestMapping) { |
161 |
| - RequestMapping rm = (RequestMapping) ann; |
162 |
| - modeKeys = rm.value(); |
163 |
| - params = StringUtils.mergeStringArrays(params, rm.params()); |
| 151 | + Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>(); |
| 152 | + handlerTypes.add(handlerType); |
| 153 | + handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces())); |
| 154 | + for (Class<?> currentHandlerType : handlerTypes) { |
| 155 | + ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() { |
| 156 | + public void doWith(Method method) { |
| 157 | + boolean mappingFound = false; |
| 158 | + String[] modeKeys = new String[0]; |
| 159 | + String[] params = new String[0]; |
| 160 | + String resourceId = null; |
| 161 | + String eventName = null; |
| 162 | + for (Annotation ann : method.getAnnotations()) { |
| 163 | + if (AnnotationUtils.findAnnotation(ann.getClass(), Mapping.class) != null) { |
| 164 | + mappingFound = true; |
| 165 | + if (ann instanceof RequestMapping) { |
| 166 | + RequestMapping rm = (RequestMapping) ann; |
| 167 | + modeKeys = rm.value(); |
| 168 | + params = StringUtils.mergeStringArrays(params, rm.params()); |
| 169 | + } |
| 170 | + else if (ann instanceof ResourceMapping) { |
| 171 | + ResourceMapping rm = (ResourceMapping) ann; |
| 172 | + resourceId = rm.value(); |
| 173 | + } |
| 174 | + else if (ann instanceof EventMapping) { |
| 175 | + EventMapping em = (EventMapping) ann; |
| 176 | + eventName = em.value(); |
| 177 | + } |
| 178 | + else { |
| 179 | + String[] specificParams = (String[]) AnnotationUtils.getValue(ann, "params"); |
| 180 | + params = StringUtils.mergeStringArrays(params, specificParams); |
| 181 | + } |
164 | 182 | }
|
165 |
| - else if (ann instanceof ResourceMapping) { |
166 |
| - ResourceMapping rm = (ResourceMapping) ann; |
167 |
| - resourceId = rm.value(); |
| 183 | + } |
| 184 | + if (mappingFound) { |
| 185 | + if (modeKeys.length == 0) { |
| 186 | + if (typeMapping != null) { |
| 187 | + modeKeys = typeMapping.value(); |
| 188 | + } |
| 189 | + else { |
| 190 | + throw new IllegalStateException( |
| 191 | + "No portlet mode mappings specified - neither at type nor at method level"); |
| 192 | + } |
168 | 193 | }
|
169 |
| - else if (ann instanceof EventMapping) { |
170 |
| - EventMapping em = (EventMapping) ann; |
171 |
| - eventName = em.value(); |
| 194 | + if (typeMapping != null) { |
| 195 | + if (!PortletAnnotationMappingUtils.validateModeMapping(modeKeys, typeMapping.value())) { |
| 196 | + throw new IllegalStateException("Mode mappings conflict between method and type level: " + |
| 197 | + Arrays.asList(modeKeys) + " versus " + Arrays.asList(typeMapping.value())); |
| 198 | + } |
| 199 | + params = StringUtils.mergeStringArrays(typeMapping.params(), params); |
172 | 200 | }
|
173 |
| - else { |
174 |
| - String[] specificParams = (String[]) AnnotationUtils.getValue(ann, "params"); |
175 |
| - params = StringUtils.mergeStringArrays(params, specificParams); |
| 201 | + PortletRequestMappingPredicate predicate; |
| 202 | + if (resourceId != null) { |
| 203 | + predicate = new ResourceMappingPredicate(resourceId); |
176 | 204 | }
|
177 |
| - } |
178 |
| - } |
179 |
| - if (mappingFound) { |
180 |
| - if (modeKeys.length == 0) { |
181 |
| - if (typeMapping != null) { |
182 |
| - modeKeys = typeMapping.value(); |
| 205 | + else if (eventName != null) { |
| 206 | + predicate = new EventMappingPredicate(eventName); |
183 | 207 | }
|
184 | 208 | else {
|
185 |
| - throw new IllegalStateException( |
186 |
| - "No portlet mode mappings specified - neither at type nor at method level"); |
| 209 | + predicate = new ParameterMappingPredicate(params); |
187 | 210 | }
|
188 |
| - } |
189 |
| - if (typeMapping != null) { |
190 |
| - if (!PortletAnnotationMappingUtils.validateModeMapping(modeKeys, typeMapping.value())) { |
191 |
| - throw new IllegalStateException("Mode mappings conflict between method and type level: " + |
192 |
| - Arrays.asList(modeKeys) + " versus " + Arrays.asList(typeMapping.value())); |
| 211 | + for (String modeKey : modeKeys) { |
| 212 | + registerHandler(new PortletMode(modeKey), beanName, predicate); |
| 213 | + handlersRegistered.add(Boolean.TRUE); |
193 | 214 | }
|
194 |
| - params = StringUtils.mergeStringArrays(typeMapping.params(), params); |
195 |
| - } |
196 |
| - PortletRequestMappingPredicate predicate; |
197 |
| - if (resourceId != null) { |
198 |
| - predicate = new ResourceMappingPredicate(resourceId); |
199 |
| - } |
200 |
| - else if (eventName != null) { |
201 |
| - predicate = new EventMappingPredicate(eventName); |
202 |
| - } |
203 |
| - else { |
204 |
| - predicate = new ParameterMappingPredicate(params); |
205 |
| - } |
206 |
| - for (String modeKey : modeKeys) { |
207 |
| - registerHandler(new PortletMode(modeKey), beanName, predicate); |
208 |
| - handlersRegistered.add(Boolean.TRUE); |
209 | 215 | }
|
210 | 216 | }
|
211 |
| - } |
212 |
| - }); |
| 217 | + }, ReflectionUtils.USER_DECLARED_METHODS); |
| 218 | + } |
213 | 219 | return !handlersRegistered.isEmpty();
|
214 | 220 | }
|
215 | 221 |
|
|
0 commit comments