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

📄 valuebindingimpl.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {                Object[] baseAndProperty = (Object[]) base_;                Object base      = baseAndProperty[0];                Object property  = baseAndProperty[1];                PropertyResolver propertyResolver =                     _application.getPropertyResolver();                Integer index = ELParserHelper.toIndex(base, property);                if (index == null)                {                    Class clazz = propertyResolver.getType(base, property);                    propertyResolver.setValue(                        base, property, coerce(newValue, clazz));                }                else                {                    int indexVal = index.intValue();                    Class clazz = propertyResolver.getType(base, indexVal);                    propertyResolver.setValue(                        base, indexVal, coerce(newValue, clazz));                }            }        }        catch (IndexOutOfBoundsException e)         {            // ArrayIndexOutOfBoundsException also here            throw new PropertyNotFoundException(                "Expression: '" + _expressionString + "'", e);        }        catch (Exception e)        {            if (newValue == null)            {                log.error("Cannot set value for expression '"                     + _expressionString + "' to null.", e);            }            else            {                log.error("Cannot set value for expression '"                     + _expressionString + "' to a new value of type "                     + newValue.getClass().getName(), e);            }            throw new EvaluationException(                "Expression: '" + _expressionString + "'", e);        }    }        private void setValueInScope(        FacesContext facesContext, String name, Object newValue)    throws ELException    {        ExternalContext externalContext = facesContext.getExternalContext();                 // Request context        Map scopeMap = externalContext.getRequestMap();        Object obj = scopeMap.get(name);        if (obj != null)        {            scopeMap.put(name, coerce(newValue, obj.getClass()));            return;        }        // Session context        scopeMap = externalContext.getSessionMap();          obj = scopeMap.get(name);        if (obj != null)        {            scopeMap.put(name, coerce(newValue, obj.getClass()));            return;        }        // Application context        scopeMap = externalContext.getApplicationMap();        obj = scopeMap.get(name);        if (obj != null)        {            scopeMap.put(name, coerce(newValue, obj.getClass()));            return;        }                // Check for ManagedBean        ManagedBean mbConfig =            getRuntimeConfig(facesContext).getManagedBean(name);        if (mbConfig != null)        {            String scopeName = mbConfig.getManagedBeanScope();                        // find the scope handler object            // Note: this does not handle user-extended _scope values            Scope scope =                 (Scope) VariableResolverImpl.s_standardScopes.get(scopeName);            if (scope != null)            {                scope.put(externalContext, name,                     coerce(newValue, mbConfig.getManagedBeanClass()));                return;            }                        log.error("Managed bean '" + name + "' has illegal scope: "                + scopeName);            externalContext.getRequestMap().put(name,                 coerce(newValue, mbConfig.getManagedBeanClass()));            return;        }                // unknown target class, put newValue into request scope without coercion         externalContext.getRequestMap().put(name, newValue);    }    public Object getValue(FacesContext facesContext)    throws PropertyNotFoundException    {        try        {            return _expression instanceof Expression                 ? ((Expression) _expression).evaluate(                    new ELVariableResolver(facesContext),                    s_functionMapper, ELParserHelper.LOGGER)                : ((ExpressionString) _expression).evaluate(                    new ELVariableResolver(facesContext),                    s_functionMapper, ELParserHelper.LOGGER);        }        catch (IndexOutOfBoundsException e)         {            // ArrayIndexOutOfBoundsException also here            throw new PropertyNotFoundException(                "Expression: '" + _expressionString + "'", e);        }        catch (Exception e)        {            log.error("Cannot get value for expression '" + _expressionString                 + "'", e);            if (e instanceof ELException)            {                log.error("Root cause for exception : ",                     ((ELException) e).getRootCause());            }            throw new EvaluationException(                "Expression: '" + _expressionString + "'", e);        }    }        protected Object resolveToBaseAndProperty(FacesContext facesContext)         throws ELException, NotVariableReferenceException     {        if (facesContext == null)        {            throw new NullPointerException("facesContext");        }                VariableResolver variableResolver =             new ELVariableResolver(facesContext);        Object expression = _expression;                while (expression instanceof ConditionalExpression)        {            ConditionalExpression conditionalExpression =                 ((ConditionalExpression) expression);            // first, evaluate the condition (and coerce the result to a            // boolean value)            boolean condition =              Coercions.coerceToBoolean(                  conditionalExpression.getCondition().evaluate(                      variableResolver, s_functionMapper,                       ELParserHelper.LOGGER),                       ELParserHelper.LOGGER)                  .booleanValue();            // then, use this boolean to branch appropriately            expression = condition ? conditionalExpression.getTrueBranch()                : conditionalExpression.getFalseBranch();        }        if (expression instanceof NamedValue)        {            return ((NamedValue) expression).getName();        }            if (!(expression instanceof ComplexValue)) {            // all other cases are not variable references            throw new NotVariableReferenceException(                "Parsed Expression of unsupported type for this operation. Expression class: "                    + _expression.getClass().getName() + ". Expression: '"                    + _expressionString + "'");        }                ComplexValue complexValue = (ComplexValue) expression;                // resolve the prefix        Object base = complexValue.getPrefix()            .evaluate(variableResolver, s_functionMapper,                 ELParserHelper.LOGGER);        if (base == null)        {            throw new PropertyNotFoundException("Base is null: "                 + complexValue.getPrefix().getExpressionString());        }        // Resolve and apply the suffixes        List suffixes = complexValue.getSuffixes();        int max = suffixes.size() - 1;        for (int i = 0; i < max; i++)         {            ValueSuffix suffix = (ValueSuffix) suffixes.get(i);            base = suffix.evaluate(base, variableResolver, s_functionMapper,                ELParserHelper.LOGGER);            if (base == null)            {                throw new PropertyNotFoundException("Base is null: "                     + suffix.getExpressionString());            }        }                // Resolve the last suffix        ArraySuffix arraySuffix = (ArraySuffix) suffixes.get(max);        Expression arraySuffixIndex = arraySuffix.getIndex();                Object index;        if (arraySuffixIndex != null)        {            index = arraySuffixIndex.evaluate(                    variableResolver, s_functionMapper,                     ELParserHelper.LOGGER);            if (index == null)            {                throw new PropertyNotFoundException("Index is null: "                     + arraySuffixIndex.getExpressionString());            }        }        else        {            index = ((PropertySuffix) arraySuffix).getName();        }                return new Object[] {base, index};    }    private Object coerce(Object value, Class clazz) throws ELException    {        return (value == null) ? null            : (clazz == null) ? value :                 Coercions.coerce(value, clazz, ELParserHelper.LOGGER);    }        protected RuntimeConfig getRuntimeConfig(FacesContext facesContext)    {        if (_runtimeConfig == null)        {            _runtimeConfig = RuntimeConfig.getCurrentInstance(facesContext.getExternalContext());        }        return _runtimeConfig;    }        public String toString()    {        return _expressionString;    }    //~ State Holder ------------------------------------------------------    private boolean _transient = false;    /**     * Empty constructor, so that new instances can be created when restoring      * state.     */    public ValueBindingImpl()    {        _application = null;        _expressionString = null;        _expression = null;    }    public Object saveState(FacesContext facesContext)    {        return _expressionString;    }    public void restoreState(FacesContext facesContext, Object obj)    {        _application = facesContext.getApplication();        _expressionString  = (String) obj;        _expression = s_expressionCache.get(_expressionString);    }    public boolean isTransient()    {        return _transient;    }    public void setTransient(boolean flag)    {        _transient = flag;    }        //~ Internal classes ------------------------------------------------------    public static class ELVariableResolver implements VariableResolver {        private final FacesContext _facesContext;                public ELVariableResolver(FacesContext facesContext)         {            _facesContext = facesContext;        }                public Object resolveVariable(String pName)            throws ELException        {            return _facesContext.getApplication().getVariableResolver()                .resolveVariable(_facesContext, pName);        }    }        public static final class NotVariableReferenceException         extends ReferenceSyntaxException    {        public NotVariableReferenceException(String message)        {            super(message);        }    }}

⌨️ 快捷键说明

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