Example usage for org.springframework.data.mapping PropertyPath PropertyPath

List of usage examples for org.springframework.data.mapping PropertyPath PropertyPath

Introduction

In this page you can find the example usage for org.springframework.data.mapping PropertyPath PropertyPath.

Prototype

PropertyPath(String name, TypeInformation<?> owningType, List<PropertyPath> base) 

Source Link

Document

Creates a leaf PropertyPath (no nested ones with the given name and owning type.

Usage

From source file:org.springframework.data.mapping.PropertyPath.java

/**
 * Tries to look up a chain of {@link PropertyPath}s by trying the givne source first. If that fails it will split the
 * source apart at camel case borders (starting from the right side) and try to look up a {@link PropertyPath} from
 * the calculated head and recombined new tail and additional tail.
 * // w  ww  .j  ava2  s  .  c o  m
 * @param source
 * @param type
 * @param addTail
 * @return
 */
private static PropertyPath create(String source, TypeInformation<?> type, String addTail,
        List<PropertyPath> base) {

    PropertyReferenceException exception = null;
    PropertyPath current = null;

    try {

        current = new PropertyPath(source, type, base);

        if (!base.isEmpty()) {
            base.get(base.size() - 1).next = current;
        }

        List<PropertyPath> newBase = new ArrayList<PropertyPath>(base);
        newBase.add(current);

        if (StringUtils.hasText(addTail)) {
            current.next = create(addTail, current.type, newBase);
        }

        return current;

    } catch (PropertyReferenceException e) {

        if (current != null) {
            throw e;
        }

        exception = e;
    }

    Pattern pattern = Pattern.compile("\\p{Lu}+\\p{Ll}*$");
    Matcher matcher = pattern.matcher(source);

    if (matcher.find() && matcher.start() != 0) {

        int position = matcher.start();
        String head = source.substring(0, position);
        String tail = source.substring(position);

        try {
            return create(head, type, tail + addTail, base);
        } catch (PropertyReferenceException e) {
            throw e.hasDeeperResolutionDepthThan(exception) ? e : exception;
        }
    }

    throw exception;
}