Package org.strecks.navigate.internal

Source Code of org.strecks.navigate.internal.NavigateReader

/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.strecks.navigate.internal;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.strecks.exceptions.ApplicationConfigurationException;
import org.strecks.navigate.NavigationHandler;
import org.strecks.navigate.NavigationHandlerFactory;
import org.strecks.navigate.annotation.NavigateForward;
import org.strecks.navigate.factory.IdentityNavigationHandlerFactory;
import org.strecks.util.ReflectHelper;

/**
* Implementation of <code>NavigationReader</code> which reads the <code>@NavigationForward</code> annotation
* @author Phil Zoio
*/
public class NavigateReader implements NavigationReader
{

  public NavigationHandlerInfo getNavigationHandlerFactory(Annotation annotation, Class actionClass,
      Method containingMethod)
  {

    NavigateForward navigate = (NavigateForward) annotation;
    Class factory = navigate.handler();

    if (NavigationHandlerFactory.class.isAssignableFrom(factory))
    {
      NavigationHandlerFactory factoryInstance = ReflectHelper.createInstance(factory,
          NavigationHandlerFactory.class);
      return new NavigationHandlerInfo(factoryInstance, containingMethod);
    }
    else if (NavigationHandler.class.isAssignableFrom(factory))
    {
      NavigationHandler handler = ReflectHelper.createInstance(factory, NavigationHandler.class);
      NavigationHandlerFactory factoryInstance = new IdentityNavigationHandlerFactory(handler);
      return new NavigationHandlerInfo(factoryInstance, containingMethod);
    }
    else
    {
      throw new ApplicationConfigurationException(actionClass.getName() + ", method "
          + containingMethod.getName() + "(), uses @" + NavigateForward.class.getSimpleName()
          + " annotation with an illegal handler. Must implement either " + NavigationHandler.class.getName()
          + " or " + NavigationHandlerFactory.class.getName());
    }
  }

}
TOP

Related Classes of org.strecks.navigate.internal.NavigateReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.