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

📄 variableresolverimpl.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
字号:
/* * Copyright 2004 The Apache Software Foundation. *  * 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.apache.myfaces.el;import java.util.HashMap;import java.util.Map;import javax.faces.context.ExternalContext;import javax.faces.context.FacesContext;import javax.faces.el.ReferenceSyntaxException;import javax.faces.el.VariableResolver;import org.apache.myfaces.config.ManagedBeanBuilder;import org.apache.myfaces.config.RuntimeConfig;import org.apache.myfaces.config.element.ManagedBean;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * @author Manfred Geiler (latest modification by $Author: bdudney $) * @author Anton Koinov * @version $Revision: 1.34 $ $Date: 2004/11/08 03:43:20 $ * $Log: VariableResolverImpl.java,v $ * Revision 1.34  2004/11/08 03:43:20  bdudney * Added a div element. x:div to use, inserts a div with class or style attributes * * Revision 1.33  2004/10/13 11:51:00  matze * renamed packages to org.apache * * Revision 1.32  2004/07/27 06:28:34  dave0000 * fix issue with getType of literal expressions (and other improvements) * * Revision 1.31  2004/07/07 08:34:58  mwessendorf * removed unused import-statements * * Revision 1.30  2004/07/07 00:25:07  o_rossmueller * tidy up config/confignew package (moved confignew classes to package config) * * Revision 1.29  2004/07/01 22:05:12  mwessendorf * ASF switch * * Revision 1.28  2004/06/16 23:02:24  o_rossmueller * merged confignew_branch * * Revision 1.27.2.2  2004/06/16 02:07:23  o_rossmueller * get navigation rules from RuntimeConfig * refactored all remaining usages of MyFacesFactoryFinder to use RuntimeConfig * * Revision 1.27.2.1  2004/06/13 15:59:07  o_rossmueller * started integration of new config mechanism: * - factories * - components * - render kits * - managed beans + managed properties (no list/map initialization) * * Revision 1.27  2004/05/12 07:57:43  manolito * Log in javadoc header * */public class VariableResolverImpl    extends VariableResolver{    //~ Static fields/initializers -----------------------------------------------------------------    private static final Log log              = LogFactory.getLog(VariableResolverImpl.class);    //~ Instance fields ----------------------------------------------------------------------------    public static final Map s_standardImplicitObjects = new HashMap(32);    static {        s_standardImplicitObjects.put(            "applicationScope",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getApplicationMap();                }            });        s_standardImplicitObjects.put(            "cookie",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getRequestCookieMap();                }            });        s_standardImplicitObjects.put(            "facesContext",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext;                }            });        s_standardImplicitObjects.put(            "header",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getRequestHeaderMap();                }            });        s_standardImplicitObjects.put(            "headerValues",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getRequestHeaderValuesMap();                }            });        s_standardImplicitObjects.put(            "initParam",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getInitParameterMap();                }            });        s_standardImplicitObjects.put(            "param",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getRequestParameterMap();                }            });        s_standardImplicitObjects.put(            "paramValues",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getRequestParameterValuesMap();                }            });        s_standardImplicitObjects.put(            "requestScope",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getRequestMap();                }            });        s_standardImplicitObjects.put(            "sessionScope",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getExternalContext().getSessionMap();                }            });        s_standardImplicitObjects.put(            "view",            new ImplicitObject()            {                public Object get(FacesContext facesContext)                {                    return facesContext.getViewRoot();                }            });    }        /**     * Stores all implicit objects defined for this instance of <code>VariableResolver</code>     * <p>     * Can store instances of <code>ImplicitObject</code> which have the ability to     * dynamically resolve against FacesContext. Can also store any other object     * which itself is the value for the implicit object (this in effect will be     * a static object).     * </p>     * <p>     * WARNING: this implementation is not serialized as it is thread safe because     *          it does not update/add to _implicitObjects after object initialization.     *          If you need to add your own implicit objects, either extend and add more     *          in an initialization block, or add proper sychronization     * </p>     */    protected final Map _implicitObjects = new HashMap(32);    {        _implicitObjects.putAll(s_standardImplicitObjects);    }    protected static final Map s_standardScopes = new HashMap(16);    static {        s_standardScopes.put(            "request",            new Scope()            {                public void put(ExternalContext extContext, String name, Object obj)                {                    extContext.getRequestMap().put(name, obj);                }            });        s_standardScopes.put(            "session",            new Scope()            {                public void put(ExternalContext extContext, String name, Object obj)                {                    extContext.getSessionMap().put(name, obj);                }            });        s_standardScopes.put(            "application",            new Scope()            {                public void put(ExternalContext extContext, String name, Object obj)                {                    extContext.getApplicationMap().put(name, obj);                }            });        s_standardScopes.put(            "none",            new Scope()            {                public void put(ExternalContext extContext, String name, Object obj)                {                    // do nothing                }            });    }        /**     * Stores all scopes defined for this instance of <code>VariableResolver</code>     * <p>     * Can store instances of <code>Scope</code> which have the ability to     * dynamically resolve against ExternalContext for put operations.     * </p>     * <p>     * WARNING: this implementation is not serialized as it is thread safe because     *          it does not update/add to _scopes after object initialization.     *          If you need to add your own scopes, either extend and add more     *          in an initialization block, or add proper sychronization     * </p>     */    protected final Map _scopes = new HashMap(16);    {        _scopes.putAll(s_standardScopes);    }    /**     * RuntimeConfig is instantiated once per servlet and never changes--we can     * safely cache it     */    private RuntimeConfig _runtimeConfig;    private ManagedBeanBuilder beanBuilder = new ManagedBeanBuilder();    //~ Methods ---------------------------------------------------------------    public Object resolveVariable(FacesContext facesContext, String name)    {        if ((name == null) || (name.length() == 0))        {            throw new ReferenceSyntaxException("Varible name is null or empty");        }        // Implicit objects        Object implicitObject = _implicitObjects.get(name);        if (implicitObject != null)        {            if (implicitObject instanceof ImplicitObject)            {                // a complex runtime object                return ((ImplicitObject) implicitObject).get(facesContext);            }            else            {                // a simple object                return implicitObject;            }        }        ExternalContext externalContext = facesContext.getExternalContext();        // Request context        Map    requestMap = externalContext.getRequestMap();        Object obj = requestMap.get(name);        if (obj != null)        {            return obj;        }        // Session context        obj = externalContext.getSessionMap().get(name);        if (obj != null)        {            return obj;        }        // Application context        obj = externalContext.getApplicationMap().get(name);        if (obj != null)        {            return obj;        }        // ManagedBean        ManagedBean mbc = getRuntimeConfig(facesContext).getManagedBean(name);        if (mbc != null)        {            obj = beanBuilder.buildManagedBean(facesContext, mbc);            // put in scope            String scopeKey = mbc.getManagedBeanScope();                        // find the scope handler object            Scope scope = (Scope) _scopes.get(scopeKey);            if (scope == null)            {                log.error("Managed bean '" + name + "' has illegal scope: "                    + scopeKey);            }            else            {                scope.put(externalContext, name, obj);            }            return obj;        }        log.warn("Variable '" + name + "' could not be resolved.");        return null;    }    protected RuntimeConfig getRuntimeConfig(FacesContext facesContext)    {        if (_runtimeConfig == null)        {            _runtimeConfig = RuntimeConfig.getCurrentInstance(facesContext.getExternalContext());        }        return _runtimeConfig;    }}interface ImplicitObject{    //~ Methods ---------------------------------------------------------------    public Object get(FacesContext facesContext);}interface Scope{    //~ Methods ---------------------------------------------------------------    public void put(ExternalContext extContext, String name, Object obj);}

⌨️ 快捷键说明

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