Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  package org.richfaces.el;
  
  import java.util.Iterator;
  import java.util.Locale;
 import java.util.Map;
 
 import  javax.faces.context.FacesContext;
 import  javax.faces.el.CompositeComponentExpressionHolder;
 
 import  org.richfaces.validator.GraphValidatorState;

This class wraps original ELContext and capture whole call stack to the target object so it could be used to extract semantic information like annotations or Jena Model properties.

Author(s):
asmirnov
 
 public class CapturingELContext extends ELContext {
     private final ELContext parent;
     private ValueReference reference = null;
     private final InterceptingResolver resolver;
 
     public CapturingELContext(ELContext parent,Map<Object, GraphValidatorState> states) {
         this. = parent;
          = new InterceptingResolver(parent.getELResolver(),states);
     }
 
     public ValueReference getReference() {
         return ;
     }
 
     private boolean isContainerObject(Object base) {
         return base instanceof Collection || base instanceof Map || base.getClass().isArray();
     }
 
     public boolean hasReferenceExpression() {
         return  != null && .getBase() instanceof CompositeComponentExpressionHolder;
     }
 
         CompositeComponentExpressionHolder expressionHolder = (CompositeComponentExpressionHolder) .getBase();
         return expressionHolder.getExpression(.getProperty().toString());
     }
 
     public ValueDescriptor getDescriptor() {
         ValueReference localReference = ;
 
         while (true) {
             if (localReference == null || localReference.getBase() == null || localReference.getProperty() == null) {
                 return null;
             }
 
             Object base = localReference.getBase();
 
             if (isContainerObject(base) && localReference.hasNext()) {
                 localReference = localReference.next();
             } else {
                 return new ValueDescriptor(base.getClass(), localReference.getProperty().toString());
             }
         }
     }
 
     /*
      * (non-Javadoc)
      *
      * @see javax.el.ELContext#getELResolver()
      */
     @Override
     public ELResolver getELResolver() {
         return ;
     }
 
     @SuppressWarnings("unchecked")
     @Override
     public Object getContext(Class key) {
         return .getContext(key);
     }
 
     @Override
     public FunctionMapper getFunctionMapper() {
         return .getFunctionMapper();
     }
 
     @Override
     public Locale getLocale() {
         return .getLocale();
     }
 
    @Override
    public VariableMapper getVariableMapper() {
        return .getVariableMapper();
    }
    @SuppressWarnings("unchecked")
    @Override
    public void putContext(Class keyObject contextObject) {
        .putContext(keycontextObject);
    }
    @Override
    public void setLocale(Locale locale) {
        .setLocale(locale);
    }

    
This resolver records all intermediate objects from the EL-expression that can be used to detect Semantic Beans annotations or Jena Model properties.

Author(s):
asmirnov
    private final class InterceptingResolver extends ELResolver {
        private final ELResolver delegate;
        private boolean clonedObject;
        private final Map<Object, GraphValidatorState> states;
        public InterceptingResolver(ELResolver delegateMap<Object, GraphValidatorState> states) {
            this. = delegate;
            this. = states;
        }
        // Capture the base and property rather than write the value
        @Override
        public void setValue(ELContext contextObject baseObject propertyObject value) {
            if (base != null) {
                // TODO - detect value object from inderect references ( e.g. data table variables ).
                if (this.) {
                    .setValue(contextbasepropertyvalue);
                }
                context.setPropertyResolved(true);
                 = new ValueReference(baseproperty);
            }
        }
        // The rest of the methods simply delegate to the existing context
        @Override
        public Object getValue(ELContext contextObject baseObject property) {
             = new ValueReference(baseproperty);
            Object value = .getValue(contextbaseproperty);
            if (null != value && context.isPropertyResolved() && .containsKey(value)) {
                GraphValidatorState graphValidatorState = .get(value);
                if (graphValidatorState.isActive()) {
                    this. = true;
                    Object clone = graphValidatorState.getCloned();
                    return clone;
                }
            }
            return value;
        }
        @Override
        public Class<?> getType(ELContext contextObject baseObject property) {
            if (base != null) {
                context.setPropertyResolved(true);
                 = new ValueReference(baseproperty);
            }
            return .getType(contextbaseproperty);
        }
        @Override
        public boolean isReadOnly(ELContext contextObject baseObject property) {
            return .isReadOnly(contextbaseproperty);
        }
        @Override
        public Iterator<FeatureDescriptorgetFeatureDescriptors(ELContext contextObject base) {
            return .getFeatureDescriptors(contextbase);
        }
        @Override
        public Class<?> getCommonPropertyType(ELContext contextObject base) {
            return .getCommonPropertyType(contextbase);
        }
    }
New to GrepCode? Check out our FAQ X