Search in sources :

Example 1 with DefaultMapEntry

use of org.apache.commons.collections4.keyvalue.DefaultMapEntry in project alien4cloud by alien4cloud.

the class AbstractTypeNodeParser method findWrapperPropertyByPath.

/**
 * For example:
 * <ul>
 * <li>.something : the value will be set to the property of root named 'something'
 * <li>child1.child2.prop : the value will be mapped u getChild1().getChild2().setProp()
 * </ul>
 */
private Entry<BeanWrapper, String> findWrapperPropertyByPath(BeanWrapper root, BeanWrapper current, String path) {
    int dotIdx = path.indexOf(".");
    if (dotIdx < 0) {
        return new DefaultMapEntry<BeanWrapper, String>(current, path);
    }
    BeanWrapper base = current;
    String nextPath = path;
    if (path.startsWith("../")) {
        base = new BeanWrapperImpl(ParsingContextExecution.getParent(current));
        nextPath = path.substring(3);
    } else if (path.startsWith(".")) {
        base = root;
        nextPath = path.substring(1);
    } else {
        String wrapperCandidateName = path.substring(0, path.indexOf("."));
        Object wrapperCandidate = current.getPropertyValue(wrapperCandidateName);
        base = new BeanWrapperImpl(wrapperCandidate);
        nextPath = path.substring(path.indexOf(".") + 1);
    }
    return findWrapperPropertyByPath(root, base, nextPath);
}
Also used : DefaultMapEntry(org.apache.commons.collections4.keyvalue.DefaultMapEntry) BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Aggregations

DefaultMapEntry (org.apache.commons.collections4.keyvalue.DefaultMapEntry)1 BeanWrapper (org.springframework.beans.BeanWrapper)1 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)1