Example usage for org.apache.commons.beanutils.expression Resolver getProperty

List of usage examples for org.apache.commons.beanutils.expression Resolver getProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils.expression Resolver getProperty.

Prototype

String getProperty(String expression);

Source Link

Document

Return the property name from the property expression.

Usage

From source file:nl.ucan.navigate.NestedPath.java

private void setProperty(PathContext pathContext, Object value) throws IllegalAccessException,
        InvocationTargetException, NoSuchMethodException, InstantiationException, IntrospectionException {
    if (pathContext.getPaths().size() > 0) {
        String lastPathElement = getLastElement(pathContext);
        Object lastPathInstance = getLastInstance(pathContext);
        Resolver resolver = pub.getResolver();
        String prop = resolver.getProperty(lastPathElement);
        if (resolver.isMapped(lastPathElement)) {
            ///*from  w  w w  .  j  a  va2 s  .  c o  m*/
            // mapped property
            String key = resolver.getKey(lastPathElement);
            value = propertyValue.mapped(lastPathInstance, prop, key, value);
        } else if (resolver.isIndexed(lastPathElement)) {
            //
            // indexed property
            int idx = resolver.getIndex(lastPathElement);
            value = propertyValue.indexed(lastPathInstance, prop, idx, value);
        } else {
            //
            // simple property
            value = propertyValue.simple(lastPathInstance, lastPathElement, value);
        }
        pub.setProperty(lastPathInstance, lastPathElement, value);
    }
}

From source file:nl.ucan.navigate.NestedPath.java

public PathContext acquirePathContext(Object bean, String path) throws IllegalAccessException,
        InvocationTargetException, InstantiationException, IntrospectionException, NoSuchMethodException {
    PathContext pathContext = new PathContext(ResolverImpl.getNested());
    Object instance = bean;//from  ww w  .ja va 2  s  .c  o  m
    DynaBean dynaBean = getDynaBean(instance);
    pub.copyProperties(instance, bean);
    Resolver resolver = pub.getResolver();
    for (; StringUtils.isNotBlank(path); path = resolver.remove(path)) {
        String prop = resolver.getProperty(path);
        if (resolver.isIndexed(path)) {
            String undeterminedIdx = getUndeterminedIndex(path);
            int positionalIdx = getPositionalIndex(undeterminedIdx);
            if (positionalIdx == -1) {
                Object object = pub.getProperty(dynaBean, prop);
                int idx = indexPointer.firstIndexOf(object, undeterminedIdx);
                if (idx == -1) {
                    Object nestedBean = (pathContext.noPathSpecified() ? bean
                            : pub.getProperty(bean, pathContext.toString()));
                    instance = createInstanceOfCollection(instance.getClass(), prop);
                    indexPointer.setIndexAsProperty(instance, undeterminedIdx);
                    instance = propertyInstance.indexed(nestedBean, prop, indexPointer.size(object), instance);
                    String replace = namedToPositioned(resolver.next(path), indexPointer.size(object));
                    pub.setIndexedProperty(dynaBean, replace, instance); // create object at required position
                    pub.setProperty(bean, (StringUtils.isBlank(pathContext.toString()) ? prop
                            : pathContext.toString() + ResolverImpl.getNested() + prop), object);
                    pathContext.addPart(replace);
                } else {
                    String replace = namedToPositioned(resolver.next(path), idx);
                    pathContext.addPart(replace);
                    instance = indexPointer.get(object, idx);
                }
            } else {
                Object tmp = pub.getIndexedProperty(dynaBean, prop, positionalIdx); // create object at required position
                if (tmp == null) {
                    Object nestedBean = (pathContext.noPathSpecified() ? bean
                            : pub.getProperty(bean, pathContext.toString()));
                    growCollection(instance, prop, positionalIdx);
                    instance = createInstanceOfCollection(instance.getClass(), prop);
                    instance = propertyInstance.indexed(nestedBean, prop, positionalIdx, instance);
                    pathContext.addPart(resolver.next(path));
                    pub.setProperty(bean, pathContext.toString(), instance);
                } else {
                    pathContext.addPart(resolver.next(path));
                    instance = tmp;
                }
            }
        } else {
            instance = pub.getProperty(instance, prop);
            if (instance == null) {
                instance = pub.getProperty(dynaBean, prop);
                Object nestedBean = (pathContext.noPathSpecified() ? bean
                        : pub.getProperty(bean, pathContext.toString()));
                instance = propertyInstance.simple(nestedBean, prop, instance);
                pathContext.addPart(resolver.next(path));
                String tmp = pathContext.toString();
                pub.setProperty(bean, tmp, instance);
            } else {
                pathContext.addPart(resolver.next(path));
            }
        }
        if (resolver.hasNested(path))
            dynaBean = getDynaBean(instance);
    }
    pathContext.setBean(bean);
    return pathContext;
}