Package ognl

Examples of ognl.OgnlContext


    @SuppressWarnings("unchecked")
    @Test
    public void testGetSourceSetter() {
        PropertyAccessorDelegateFactory<Integer> factory = createMock(PropertyAccessorDelegateFactory.class);
        PropertyAccessor mockAccessor = createMock(PropertyAccessor.class);
        OgnlContext context = createMock(OgnlContext.class);
        expect(factory.getPropertyAccessor("property", 1)).andReturn(mockAccessor);
        expect(mockAccessor.getSourceSetter(context, 1, "property")).andReturn("method");

        replay(factory, mockAccessor, context);
        PropertyAccessor accessor = new DelegatePropertyAccessor<Integer>(factory);
View Full Code Here


    @SuppressWarnings("unchecked")
    @Test
    public void testGetSourceAccessor() {
        NestedObjectExtractor<Integer> nestedObjectExtractor = createMock(NestedObjectExtractor.class);
        PropertyAccessor propertyAccessor = createMock(PropertyAccessor.class);
        OgnlContext context = createMock(OgnlContext.class);
        expect(propertyAccessor.getSourceAccessor(context, "nested", "property")).andReturn("method");
        expect(nestedObjectExtractor.getNestedObject(1)).andReturn("nested");

        replay(nestedObjectExtractor, propertyAccessor, context);
        PropertyAccessor accessor = new NestedObjectDelegatePropertyAccessor<Integer>(
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testGetSourceSetter() {
        NestedObjectExtractor<Integer> nestedObjectExtractor = createMock(NestedObjectExtractor.class);
        PropertyAccessor propertyAccessor = createMock(PropertyAccessor.class);
        OgnlContext context = createMock(OgnlContext.class);
        expect(propertyAccessor.getSourceSetter(context, "nested", "property")).andReturn("method");
        expect(nestedObjectExtractor.getNestedObject(1)).andReturn("nested");

        replay(nestedObjectExtractor, propertyAccessor, context);
        PropertyAccessor accessor = new NestedObjectDelegatePropertyAccessor<Integer>(
View Full Code Here

    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

        int index = (Integer) key;
        int length = Array.getLength(array);
        if (length <= index) {
            array = copyOf(array, index, length);
            OgnlContext ctx = (OgnlContext) context;
            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);
            Container container = (Container) context.get(Container.class);
            EmptyElementsRemoval removal = container.instanceFor(EmptyElementsRemoval.class);
            removal.add(array, setter, origin);
View Full Code Here

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

        OgnlContext ctx = (OgnlContext) context;

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

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

        try {

            Container container = (Container) context.get(Container.class);
            if (target instanceof List) {
                return list.instantiate(container, target, property, 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

    try {
      root = type.getDeclaredConstructor().newInstance();
    } catch (Exception ex) {
      throw new InvalidParameterException("unable to instantiate type" + type.getName(), ex);
    }
    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(root);
    context.setTraceEvaluations(true);
    context.put(Container.class, this.container);

    VRaptorConvertersAdapter adapter = new VRaptorConvertersAdapter(converters, bundle);
    Ognl.setTypeConverter(context, adapter);
    for (Enumeration<?> enumeration = request.getParameterNames(); enumeration.hasMoreElements();) {
      String key = (String) enumeration.nextElement();
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
      if (ctx.getRoot() != target) {
        Evaluation eval = ctx.getCurrentEvaluation();
        Evaluation previous = eval.getPrevious();
        String fieldName = previous.getNode().toString();
        Object origin = previous.getSource();
        Method getter = ReflectionBasedNullHandler.findMethod(origin.getClass(), "get"
            + Info.capitalize(fieldName), origin.getClass(), null);
View Full Code Here

  public static Object injectInto(Object objectToInject, Object target, String property) {
    if (target == null) {
      throw new JTesterException("Target for injection should not be null");
    }
    try {
      OgnlContext ognlContext = new OgnlContext();
      ognlContext.setMemberAccess(new DefaultMemberAccess(true));
      Object ognlExpression = Ognl.parseExpression(property);

      Object oldValue = null;
      try {
        Ognl.getValue(ognlExpression, ognlContext, target);
View Full Code Here

    }

    private boolean isEvalExpression(Object tree, Map<String, Object> context) throws OgnlException {
        if (tree instanceof SimpleNode) {
            SimpleNode node = (SimpleNode) tree;
            OgnlContext ognlContext = null;

            if (context!=null && context instanceof OgnlContext) {
                ognlContext = (OgnlContext) context;
            }
            return node.isEvalChain(ognlContext);
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.