Example usage for org.springframework.core ResolvableType getGeneric

List of usage examples for org.springframework.core ResolvableType getGeneric

Introduction

In this page you can find the example usage for org.springframework.core ResolvableType getGeneric.

Prototype

public ResolvableType getGeneric(@Nullable int... indexes) 

Source Link

Document

Return a ResolvableType representing the generic parameter for the given indexes.

Usage

From source file:com.ocs.dynamo.utils.ClassUtils.java

/**
 * Return a Class<?> representing the generic parameter for the given indexes. Indexes are zero
 * based; for example given the type Map<Integer, List<String>>, getGeneric(0) will access the
 * Integer. Nested generics can be accessed by specifying multiple indexes; for example
 * getGeneric(1, 0) will access the String from the nested List. For convenience, if no indexes
 * are specified the first generic is returned.
 * //from w w  w  .ja v  a2 s  .  c om
 * @param type
 * @param fieldName
 * @param indexes
 * @return
 */
public static <T> Class<?> getResolvedType(Class<T> type, String fieldName, int... indexes) {
    Field field = getField(type, fieldName);
    if (field != null) {
        ResolvableType rt = ResolvableType.forField(field);
        if (rt != null) {
            if (indexes != null && indexes.length > 0) {
                rt = rt.getGeneric(indexes);
            }
            if (rt != null) {
                return rt.resolve();
            }

        }
    }
    return null;
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Is value a comma separated value of database indexes
 *
 * @param type the type of the value/*w ww . jav  a  2s  . c  o m*/
 * @return boolean
 */
private Boolean isValueCSVDatabaseIndexes(final ResolvableType type) {
    return java.util.Collection.class.isAssignableFrom(type.getRawClass()) && (type.getGeneric(0) != null)
            && (type.getGeneric(0).getRawClass().getAnnotation(SchemaRepository.class) != null);
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * processes an array//from   www.  j  a v  a 2  s  .c  o m
 *
 * @param value value to process
 * @param type  type of this array
 * @return new list
 * @throws JSONException the exception
 */
private Object parseArray(final JSONArray value, final ResolvableType type) throws JSONException {
    final List<Object> elements = new ArrayList<>();
    if (isValueArrayOfDatabaseEntities(type.getGeneric(0).getRawClass())) {
        elements.addAll(parseArrayOfDatabaseEntities(value, type.getGeneric(0).getRawClass()));
    }
    return elements;
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * Parses a simple value//from w ww. jav a  2s  .  c o  m
 *
 * @param value the value
 * @param type  the value type
 * @return parsed result
 */
private Object parseValue(final Object value, final ResolvableType type) {
    Object returnVar = null;
    if (isTypeStandard(type.getRawClass())) {
        returnVar = value;
    } else if (isValueCSVDatabaseIndexes(type)) {
        returnVar = parseCSVDatabaseIndexes(value.toString(), type.getGeneric(0).getRawClass());
    } else if (isValueDateTime(value, type)) {
        returnVar = parseDateTime(value);
    } else if (isValueDatabaseIndex(type)) {
        returnVar = parseDatabaseIndex(value.toString(), type.getRawClass());
    } else if (isValuePeriod(type)) {
        returnVar = parsePeriod(value.toString());
    } else if (isValueEnum(type)) {
        returnVar = parseEnum(value.toString(), type.getRawClass());
    }
    return returnVar;
}

From source file:org.openscore.lang.compiler.modeller.TransformersHandler.java

private Class getTransformerFromType(Transformer transformer) {
    ResolvableType resolvableType = ResolvableType.forClass(Transformer.class, transformer.getClass());
    return resolvableType.getGeneric(0).resolve();
}