01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.navigate.spring;
16:
17: import java.lang.annotation.Annotation;
18: import java.lang.reflect.Method;
19:
20: import org.springframework.web.servlet.ModelAndView;
21: import org.strecks.exceptions.ApplicationConfigurationException;
22: import org.strecks.navigate.NavigationHandlerFactory;
23: import org.strecks.navigate.factory.IdentityNavigationHandlerFactory;
24: import org.strecks.navigate.internal.NavigationHandlerInfo;
25: import org.strecks.navigate.internal.NavigationReader;
26: import org.strecks.navigate.spring.annotation.SpringView;
27:
28: /**
29: * Implementation of the <code>NavigationReader</code> interface, with logic to read the
30: * @SpringView annotation
31: * @author Phil Zoio
32: */
33: public class SpringViewNavigationReader implements NavigationReader {
34:
35: public NavigationHandlerInfo getNavigationHandlerFactory(
36: Annotation annotation, Class actionClass,
37: Method containingMethod) {
38:
39: SpringView view = (SpringView) annotation;
40: SpringViewNavigationHandler springViewNavigationHandler = new SpringViewNavigationHandler(
41: view.resolver());
42:
43: Class<?> returnType = containingMethod.getReturnType();
44: if (!ModelAndView.class.isAssignableFrom(returnType)) {
45: throw new ApplicationConfigurationException("Method "
46: + containingMethod.getName() + "() in class "
47: + containingMethod.getDeclaringClass().getName()
48: + " must return object of type "
49: + ModelAndView.class.getName());
50: }
51:
52: NavigationHandlerFactory factoryInstance = new IdentityNavigationHandlerFactory(
53: springViewNavigationHandler);
54: return new NavigationHandlerInfo(factoryInstance,
55: containingMethod);
56: }
57: }
|