Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 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 uelbox;
 
 import java.util.Map;
 
 import  javax.el.ELContext;
 import  javax.el.ELResolver;
 import  javax.el.FunctionMapper;
 import  javax.el.ValueExpression;
 import  javax.el.VariableMapper;
 
ELContext wrapper which wraps the ELResolver and may shadow variables, locale settings, and context objects.
 
 public abstract class ELContextWrapper extends ELContext {
     private final ELResolver elResolver;
     private final VariableMapper variableMapper;

    
Map in which context objects are potentially stored so that we can remove them if desired.

See also:
removeContext(Class)
 
     private Map<Class<?>, ObjectcontextObjects;
 
     protected final ELContext wrapped;

    
Create a new ELContextWrapper.

Parameters:
wrapped
 
     protected ELContextWrapper(ELContext wrapped) {
         this. = Validate.notNull(wrapped"wrapped ELContext");
         this. = Validate.notNull(wrap(wrapped.getELResolver()));
         this. = new SimpleVariableMapper() {
             @Override
             public ValueExpression resolveVariable(String variable) {
                 if (containsVariable(variable)) {
                     return super.resolveVariable(variable);
                 }
                 return ELContextWrapper.this..getVariableMapper().resolveVariable(variable);
             }
         };
     }

    
Create a wrapped ELResolver for use with the wrapped ELContext.

Parameters:
elResolver to wrap
Returns:
ELResolver
 
     protected abstract ELResolver wrap(ELResolver elResolver);
 
     @Override
     public ELResolver getELResolver() {
         return ;
     }
 
     @Override
     public FunctionMapper getFunctionMapper() {
         return .getFunctionMapper();
     }
 
     @Override
     public VariableMapper getVariableMapper() {
         return ;
     }
 
     @Override
     public Locale getLocale() {
         final Locale result = super.getLocale();
         return result == null ? super.getLocale() : result;
     }
 
     @Override
     public Object getContext(@SuppressWarnings("rawtypes"Class key) {
         if ( != null && .containsKey(key)) {
             return .get(key);
         }
         return .getContext(key);
    }
    @Override
    public void putContext(@SuppressWarnings("rawtypes"Class keyObject contextObjectthrows NullPointerException {
        Validate.notNull(contextObject"context object must not be null");
        putContextInternal(keycontextObject);
    }

    
Dedicated method for removing a context value, as putContext(Class, Object) is declared to throw NullPointerException for a null value.

Parameters:
key
Returns:
previously stored context object
    public Object removeContext(Class<?> key) {
        // hide the context objects of a wrapped ELContext by storing a null value:
        final Object result = putContextInternal(keynull);
        return result == null ? .getContext(key) : result;
    }
    private synchronized Object putContextInternal(Class<?> keyObject value) {
        Validate.notNull(key"context key must not be null");
        if ( == null) {
             = new HashMap<Class<?>, Object>();
        }
        return .put(keyvalue);
    }

    
Convenience method to return a typed context object when key resolves per documented convention to an object of the same type.

Parameters:
<T>
key
Returns:
T
See also:
ELContext.getContext(Class)
    public final <T> T getTypedContext(Class<T> key) {
        return UEL.getContext(thiskey);
    }

    
Convenience method to return a typed context object when key resolves per documented convention to an object of the same type.

Parameters:
<T>
key
defaultValue if absent
Returns:
T
See also:
ELContext.getContext(Class)
    public final <T> T getTypedContext(Class<T> key, T defaultValue) {
        return UEL.getContext(thiskeydefaultValue);
    }
    
New to GrepCode? Check out our FAQ X