Example usage for org.springframework.core MethodParameter decreaseNestingLevel

List of usage examples for org.springframework.core MethodParameter decreaseNestingLevel

Introduction

In this page you can find the example usage for org.springframework.core MethodParameter decreaseNestingLevel.

Prototype

@Deprecated
public void decreaseNestingLevel() 

Source Link

Document

Decrease this parameter's nesting level.

Usage

From source file:org.tinygroup.beanwrapper.TypeConverterDelegate.java

protected Collection convertToTypedCollection(Collection original, String propertyName,
        MethodParameter methodParam) {

    Class elementType = null;//  w  w w  .j a  v a  2  s.com
    if (methodParam != null && JdkVersion.isAtLeastJava15()) {
        elementType = GenericCollectionTypeResolver.getCollectionParameterType(methodParam);
    }
    if (elementType == null && !this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
        return original;
    }

    Collection convertedCopy = null;
    Iterator it = null;
    try {
        it = original.iterator();
        if (it == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Collection of type [" + original.getClass().getName()
                        + "] returned null Iterator - injecting original Collection as-is");
            }
            return original;
        }
        convertedCopy = CollectionFactory.createApproximateCollection(original, original.size());
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Cannot access Collection of type [" + original.getClass().getName()
                    + "] - injecting original Collection as-is", ex);
        }
        return original;
    }
    boolean actuallyConverted = false;
    int i = 0;
    for (; it.hasNext(); i++) {
        Object element = it.next();
        String indexedPropertyName = buildIndexedPropertyName(propertyName, i);
        if (methodParam != null) {
            methodParam.increaseNestingLevel();
        }
        Object convertedElement = convertIfNecessary(indexedPropertyName, null, element, elementType, null,
                methodParam);
        if (methodParam != null) {
            methodParam.decreaseNestingLevel();
        }
        convertedCopy.add(convertedElement);
        actuallyConverted = actuallyConverted || (element != convertedElement);
    }
    return (actuallyConverted ? convertedCopy : original);
}

From source file:org.tinygroup.beanwrapper.TypeConverterDelegate.java

protected Map convertToTypedMap(Map original, String propertyName, MethodParameter methodParam) {
    Class keyType = null;/*www . j  a  va 2  s. c o  m*/
    Class valueType = null;
    if (methodParam != null && JdkVersion.isAtLeastJava15()) {
        keyType = GenericCollectionTypeResolver.getMapKeyParameterType(methodParam);
        valueType = GenericCollectionTypeResolver.getMapValueParameterType(methodParam);
    }
    if (keyType == null && valueType == null
            && !this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
        return original;
    }

    Map convertedCopy = null;
    Iterator it = null;
    try {
        it = original.entrySet().iterator();
        if (it == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Map of type [" + original.getClass().getName()
                        + "] returned null Iterator - injecting original Map as-is");
            }
        }
        convertedCopy = CollectionFactory.createApproximateMap(original, original.size());
    } catch (Exception ex) {
        if (logger.isDebugEnabled()) {
            logger.debug("Cannot access Map of type [" + original.getClass().getName()
                    + "] - injecting original Map as-is", ex);
        }
        return original;
    }
    boolean actuallyConverted = false;
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        String keyedPropertyName = buildKeyedPropertyName(propertyName, key);
        if (methodParam != null) {
            methodParam.increaseNestingLevel();
            methodParam.setTypeIndexForCurrentLevel(0);
        }
        Object convertedKey = convertIfNecessary(keyedPropertyName, null, key, keyType, null, methodParam);
        if (methodParam != null) {
            methodParam.setTypeIndexForCurrentLevel(1);
        }
        Object convertedValue = convertIfNecessary(keyedPropertyName, null, value, valueType, null,
                methodParam);
        if (methodParam != null) {
            methodParam.decreaseNestingLevel();
        }
        convertedCopy.put(convertedKey, convertedValue);
        actuallyConverted = actuallyConverted || (key != convertedKey) || (value != convertedValue);
    }
    return (actuallyConverted ? convertedCopy : original);
}