Package ognl

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();
              Method setter = ReflectionBasedNullHandler.findMethod(origin.getClass(),
                      "set" + Info.capitalize(fieldName), origin.getClass(), null);
              EmptyElementsRemoval removal = (EmptyElementsRemoval) context.get("removal");
              removal.add(newArray, setter, origin);
View Full Code Here


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

        OgnlContext ctx = (OgnlContext) context;

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

        GenericNullHandler generic = new GenericNullHandler(removal);
        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()));
        }

        String propertyCapitalized = Info.capitalize((String) property);
    Method getter = findMethod(target.getClass(), "get" + propertyCapitalized, target.getClass(), null);
        Type returnType = getter.getGenericReturnType();
View Full Code Here

        errors.add(new ValidationMessage(ex.getMessage(), param.name));
        return null;
      }
    }

    OgnlContext context = createOgnlContextFor(param, bundle);
    for (Entry<String, String[]> parameter : requestNames.entrySet()) {
      String key = parameter.getKey().replaceFirst("^" + param.name + "\\.?", "");
      String[] values = parameter.getValue();
      setProperty(context, key, values, errors);
    }

    if (param.clazz.isArray()) {
      return removal.removeNullsFromArray(context.getRoot());
    }

    return context.getRoot();
  }
View Full Code Here

      logger.trace("Reason:", e);
    }
  }

  private OgnlContext createOgnlContextFor(Parameter param, ResourceBundle bundle) {
    OgnlContext context;
    try {
      context = (OgnlContext) Ognl.createDefaultContext(new GenericNullHandler(removal).instantiate(param.actualType()));
    } catch (Exception ex) {
      throw new InvalidParameterException("unable to instantiate type " + param.type, ex);
    }
    context.setTraceEvaluations(true);
    context.put("rootType", param.type);
    context.put("removal", removal);

    VRaptorConvertersAdapter adapter = new VRaptorConvertersAdapter(converters, bundle);
    Ognl.setTypeConverter(context, adapter);

    return context;
View Full Code Here

    }
    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

    }

    public void activateObject(Object obj)
    throws Exception
    {
        OgnlContext context = (OgnlContext)obj;
       
        if (context.getRoot() != null || context.getValues().size() > 0) {
            context.clear();
            context.setRoot(null);
        }
    }
View Full Code Here

    HiveMindExpressionCompiler _compiler = new HiveMindExpressionCompiler(_classFactory);

    public void test_Duplicate_Class_Compiler()
    throws Exception
    {
        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
        BasicObject root = new BasicObject();
        String expr = "name";
        Node expression = (Node) Ognl.parseExpression(expr);

        _compiler.compileExpression(context, expression, root);
View Full Code Here

    }

    public void test_Divide_By_Zero()
    throws Exception
    {
        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
        String expr = "true ? 1 : 1/0";

        Node expression = (Node) Ognl.parseExpression(expr);
        _compiler.compileExpression(context, expression, expr);
       
View Full Code Here

    }

    public void test_ClassFab_Generation_Count_With_Uncompilable_Expression()
            throws Exception
    {
        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
        BasicObject root = new BasicObject();

        String exprStr = "user != null && user.name != null ? user.name : name";
        Node expression = (Node) Ognl.parseExpression(exprStr);
View Full Code Here

    }

    public void test_ClassFab_Generation_Count_With_Uncompilable_Expression2()
            throws Exception
    {
        OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
        BasicObject root = new BasicObject();

        String exprStr = "user ? user.name : name";
        Node expression = (Node) Ognl.parseExpression(exprStr);
View Full Code Here

TOP

Related Classes of ognl.OgnlContext

Copyright © 2018 www.massapicom. 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.