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

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

Introduction

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

Prototype

boolean hasNested(String expression);

Source Link

Document

Indicates whether or not the expression contains nested property expressions or not.

Usage

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;//www. ja  v  a 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;
}