Examples of OgnlContext


Examples of ognl.OgnlContext

        // TODO we could use caching here but then we'd have possible
        // concurrency issues
        // so lets assume that the provider caches
        Map values = new HashMap();
        populateContext(values, exchange);
        OgnlContext oglContext = new OgnlContext();
        try {
            return Ognl.getValue(expression, oglContext, new RootObject(exchange));
        } catch (OgnlException e) {
            throw new ExpressionEvaluationException(this, exchange, e);
        }
View Full Code Here

Examples of ognl.OgnlContext

    public static OgnlExpression ognl(String expression) {
        return new OgnlExpression(new OgnlLanguage(), expression, Object.class);
    }

    public <T> T evaluate(Exchange exchange, Class<T> tClass) {
        OgnlContext oglContext = new OgnlContext();
        try {
            Object value = Ognl.getValue(expression, oglContext, new RootObject(exchange));
            return exchange.getContext().getTypeConverter().convertTo(tClass, value);
        } catch (OgnlException e) {
            throw new ExpressionEvaluationException(this, exchange, e);
View Full Code Here

Examples of ognl.OgnlContext

    }

    public Object evaluate(Exchange exchange) {
        // TODO we could use caching here but then we'd have possible
        // concurrency issues so lets assume that the provider caches
        OgnlContext oglContext = new OgnlContext();
        try {
            return Ognl.getValue(expression, oglContext, new RootObject(exchange));
        } catch (OgnlException e) {
            throw new ExpressionEvaluationException(this, exchange, e);
        }
View Full Code Here

Examples of ognl.OgnlContext

            {
                // Means not a property/association
            }

            // Is target#name a field? e.g. action.field1, where field1 is extracted from a composite
            OgnlContext ognlContext = (OgnlContext) aContext;
            try
            {
                return getFieldValue( ognlContext, aTarget, aFieldName, true );
            }
            catch( NoSuchFieldException e )
View Full Code Here

Examples of ognl.OgnlContext

            if( Property.class.isAssignableFrom( memberClass ) )
            {
                Property property = (Property) qi4jField;

                OgnlContext ognlContext = (OgnlContext) aContext;
                Class<?> propertyType = (Class) api.propertyDescriptorFor( property ).type();
                Object convertedValue = getConvertedType(
                    ognlContext, aTarget, null, fieldName, aPropertyValue, propertyType );
                try
                {
                    property.set( convertedValue );
                }
                catch( ConstraintViolationException e )
                {
                    Collection<ConstraintViolation> violations = e.constraintViolations();
                    handleConstraintViolation( aContext, aTarget, fieldName, convertedValue, violations );
                }

                return;
            }
            else if( Association.class.isAssignableFrom( memberClass ) )
            {
                Association association = (Association) qi4jField;
                OgnlContext ognlContext = (OgnlContext) aContext;
                Class<?> associationType = (Class) api.associationDescriptorFor( association ).type();
                Object convertedValue = getConvertedType(
                    ognlContext, aTarget, null, fieldName, aPropertyValue, associationType );
                if( convertedValue == OgnlRuntime.NoConversionPossible )
                {
View Full Code Here

Examples of ognl.OgnlContext

  int index = (Integer) key;
  int length = Array.getLength(array);
  if (length <= index) {
    Object newArray = copyOf(array, index, length);
    OgnlContext ctx = (OgnlContext) context;
    if (array == ctx.getRoot()) {
      ctx.setRoot(newArray);
    } else {
      String fieldName = ctx.getCurrentEvaluation().getPrevious().getNode().toString();
      Object origin = ctx.getCurrentEvaluation().getPrevious().getSource();
     
      Proxifier proxifier = (Proxifier) context.get("proxifier");
      Method setter = new ReflectionBasedNullHandler(proxifier).findMethod(origin.getClass(),
        "set" + StringUtils.capitalize(fieldName), origin.getClass(), null);
     
View Full Code Here

Examples of ognl.OgnlContext

  }

  @Override
  public Object nullPropertyValue(Map context, Object target, Object property) {

  OgnlContext ctx = (OgnlContext) context;

  EmptyElementsRemoval removal = (EmptyElementsRemoval) ctx.get("removal");

  NullHandler nullHandler = (NullHandler) ctx.get("nullHandler");
  ListNullHandler list = new ListNullHandler(removal);

  if (target == ctx.getRoot() && target instanceof List) {
    return list.instantiate(target, property, (Type) context.get("rootType"));
  }

  int indexInParent = ctx.getCurrentEvaluation().getNode().getIndexInParent();
  int maxIndex = ctx.getRootEvaluation().getNode().jjtGetNumChildren() - 1;

  if (!(indexInParent != -1 && indexInParent < maxIndex)) {
    return null;
  }

  if (target instanceof List) {
    return list.instantiate(target, property, list.getListType(target, ctx.getCurrentEvaluation().getPrevious(), ctx));
  }

  String propertyCapitalized = StringUtils.capitalize((String) property);
  Method getter = findGetter(target, propertyCapitalized);
  Type returnType = getter.getGenericReturnType();
View Full Code Here

Examples of ognl.OgnlContext

    OgnlRuntime.setPropertyAccessor(Object[].class, new ArrayAccessor());
  }

  public void startContext(String name, Type type, Object root, ResourceBundle bundle) {

    OgnlContext context = createOgnlContext(root);

    context.setTraceEvaluations(true);
    context.put("rootType", type);
    context.put("removal", removal);
    context.put("nullHandler", nullHandler());
    context.put(ResourceBundle.class, bundle);
  context.put("proxifier", proxifier);

    Ognl.setTypeConverter(context, createAdapter(bundle));

    contexts.put(name, context);
  }
View Full Code Here

Examples of ognl.OgnlContext

    return new GenericNullHandler(removal);
  }

  public void setValue(String name, String key, String[] values) {
    try {
      OgnlContext ctx = contexts.get(name);
      Ognl.setValue(key, ctx, ctx.getRoot(), values.length == 1 ? values[0] : values);
      contexts.put(ctx.getRoot(), ctx);
    } catch (MethodFailedException e) { // setter threw an exception

      Throwable cause = e.getCause();
      if (cause.getClass().isAnnotationPresent(ValidationException.class)) {
        throw new ConversionError(cause.getLocalizedMessage());
View Full Code Here

Examples of ognl.OgnlContext

    }
    if (value instanceof String) {
      // it might be that suckable ognl did not call convert, i.e.: on the
      // values[i] = 2l in a List<Long>.
      // we all just looooove ognl.
      OgnlContext ctx = (OgnlContext) context;
      // if direct injecting, cannot find out what to do, use string

      Type genericType = extractGenericType(ctx, target);

    Class type = getActualType(genericType);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.