⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pageflowcreator.java

📁 Ajax 框架,可以用来做数型菜单或者联动下拉列表
💻 JAVA
字号:
package org.directwebremoting.beehive;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;

import org.directwebremoting.Creator;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.create.AbstractCreator;
import org.directwebremoting.util.Logger;

/**
 * Page Flow Creator
 * The name Creator is a little misleading in that implies that a PageFlow is
 * being created.  This class merely returns the current PageFlowController from
 * the Request
 * @author Kevin Conaway
 * @author Joe Walker [joe at getahead dot ltd dot uk]
 */
public class PageFlowCreator extends AbstractCreator implements Creator
{
    /**
     * Test to see what implementations of PageFlow are available.
     * @throws ClassNotFoundException If neither Beehive or Weblogic are around.
     */
    public PageFlowCreator() throws ClassNotFoundException
    {
        // noinspection EmptyCatchBlock
        try
        {
            bhFlowClass = Class.forName("org.apache.beehive.netui.pageflow.PageFlowController"); //$NON-NLS-1$

            Class bhUtilClass = Class.forName("org.apache.beehive.netui.pageflow.PageFlowUtils"); //$NON-NLS-1$
            bhGetter = bhUtilClass.getMethod("getCurrentPageFlow", new Class[] { HttpServletRequest.class }); //$NON-NLS-1$
        }
        catch (Exception ex)
        {
            // We're expecting this to fail, and notice below
        }

        // noinspection EmptyCatchBlock
        try
        {
            wlFlowClass = Class.forName("com.bea.wlw.netui.pageflow.PageFlowController"); //$NON-NLS-1$

            Class wlUtilClass = Class.forName("com.bea.wlw.netui.pageflow.PageFlowUtils"); //$NON-NLS-1$
            wlGetter = wlUtilClass.getMethod("getCurrentPageFlow", new Class[] { HttpServletRequest.class }); //$NON-NLS-1$
        }
        catch (Exception ex)
        {
            // We're expecting this to fail, and notice below
        }

        if ((bhGetter == null && wlGetter == null) ||
           (bhFlowClass == null && wlFlowClass == null))
        {
            throw new ClassNotFoundException("Beehive/Weblogic jar file not available."); //$NON-NLS-1$
        }
    }

    /**
     * What do we do if both Weblogic and Beehive are available.
     * The default is to use Beehive, but this allows us to alter that.
     * @param forceWebLogic Do we use Weblogic if both are available.
     */
    public void setForceWebLogic(boolean forceWebLogic)
    {
        if (forceWebLogic)
        {
            bhGetter = null;
            bhFlowClass = null;
        }
    }

    /* (non-Javadoc)
     * @see org.directwebremoting.Creator#getInstance()
     */
    public Object getInstance() throws InstantiationException
    {
        if (getter == null)
        {
            getter = (bhGetter != null) ? bhGetter : wlGetter;
        }

        try
        {
            HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
            return getter.invoke(null, new Object[] { request });
        }
        catch (InvocationTargetException ex)
        {
            throw new InstantiationException(ex.getTargetException().toString());
        }
        catch (Exception ex)
        {
            throw new InstantiationException(ex.toString());
        }
    }

    /**
     * @return The PageFlowController that we are using (Beehive/Weblogic)
     */
    public Class getType()
    {
        if (instanceType == null)
        {
            try
            {
                instanceType = getInstance().getClass();
            }
            catch (InstantiationException ex)
            {
                log.error("Failed to instansiate object to detect type.", ex); //$NON-NLS-1$
                return Object.class;
            }
        }

        return instanceType;
    }

    /**
     * The log stream
     */
    private static final Logger log = Logger.getLogger(PageFlowCreator.class);

    private Class instanceType;

    private Method getter;
    private Method bhGetter;
    private Method wlGetter;

    private Class bhFlowClass;
    private Class wlFlowClass;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -