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.factory;
16:
17: import org.apache.struts.action.ActionForward;
18: import org.strecks.exceptions.ApplicationConfigurationException;
19: import org.strecks.navigate.NavigationHandler;
20: import org.strecks.navigate.NavigationHandlerFactory;
21: import org.strecks.navigate.handler.ActionForwardNavigationHandler;
22: import org.strecks.navigate.handler.MappingNavigationHandler;
23: import org.strecks.navigate.handler.PageNavigationHandler;
24: import org.strecks.navigate.handler.ViewAdapterNavigationHandler;
25: import org.strecks.page.Page;
26: import org.strecks.view.ViewAdapter;
27:
28: /**
29: * Implementation of <code>NavigationHandlerFactory</code>
30: * @author Phil Zoio
31: */
32: public class DefaultNavigationHandlerFactory implements
33: NavigationHandlerFactory {
34:
35: /**
36: * If the return type is an <code>ActionForward</code>, returns
37: * <code>ActionForwardNavigationHandler</code>, if a <code>String</code>, returns
38: * <code>MappingNavigationHandler</code>, and if a <code>Page</code>, returns
39: * <code>PageNavigationHandler</code>
40: */
41: public NavigationHandler getNavigationHandler(String beanClassName,
42: Class returnType) {
43: if (ActionForward.class.isAssignableFrom(returnType)) {
44: return new ActionForwardNavigationHandler();
45: } else if (String.class.isAssignableFrom(returnType)) {
46: return new MappingNavigationHandler();
47: } else if (Page.class.isAssignableFrom(returnType)) {
48: return new PageNavigationHandler();
49: } else if (ViewAdapter.class.isAssignableFrom(returnType)) {
50: return new ViewAdapterNavigationHandler();
51: } else {
52: throw new ApplicationConfigurationException(
53: "Unsupported return type "
54: + returnType.getClass().getName()
55: + " for method with @Navigation annotation in class "
56: + beanClassName);
57: }
58: }
59:
60: }
|