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.internal;
16:
17: import java.lang.annotation.Annotation;
18: import java.lang.reflect.Method;
19:
20: import org.strecks.exceptions.ApplicationConfigurationException;
21: import org.strecks.navigate.NavigationHandler;
22: import org.strecks.navigate.NavigationHandlerFactory;
23: import org.strecks.navigate.annotation.NavigateForward;
24: import org.strecks.navigate.factory.IdentityNavigationHandlerFactory;
25: import org.strecks.util.ReflectHelper;
26:
27: /**
28: * Implementation of <code>NavigationReader</code> which reads the <code>@NavigationForward</code> annotation
29: * @author Phil Zoio
30: */
31: public class NavigateReader implements NavigationReader {
32:
33: public NavigationHandlerInfo getNavigationHandlerFactory(
34: Annotation annotation, Class actionClass,
35: Method containingMethod) {
36:
37: NavigateForward navigate = (NavigateForward) annotation;
38: Class factory = navigate.handler();
39:
40: if (NavigationHandlerFactory.class.isAssignableFrom(factory)) {
41: NavigationHandlerFactory factoryInstance = ReflectHelper
42: .createInstance(factory,
43: NavigationHandlerFactory.class);
44: return new NavigationHandlerInfo(factoryInstance,
45: containingMethod);
46: } else if (NavigationHandler.class.isAssignableFrom(factory)) {
47: NavigationHandler handler = ReflectHelper.createInstance(
48: factory, NavigationHandler.class);
49: NavigationHandlerFactory factoryInstance = new IdentityNavigationHandlerFactory(
50: handler);
51: return new NavigationHandlerInfo(factoryInstance,
52: containingMethod);
53: } else {
54: throw new ApplicationConfigurationException(
55: actionClass.getName()
56: + ", method "
57: + containingMethod.getName()
58: + "(), uses @"
59: + NavigateForward.class.getSimpleName()
60: + " annotation with an illegal handler. Must implement either "
61: + NavigationHandler.class.getName()
62: + " or "
63: + NavigationHandlerFactory.class.getName());
64: }
65: }
66:
67: }
|