Example usage for java.lang.reflect GenericArrayType getGenericComponentType

List of usage examples for java.lang.reflect GenericArrayType getGenericComponentType

Introduction

In this page you can find the example usage for java.lang.reflect GenericArrayType getGenericComponentType.

Prototype

Type getGenericComponentType();

Source Link

Document

Returns a Type object representing the component type of this array.

Usage

From source file:org.springframework.core.GenericTypeResolver.java

/**
 * Extract a class instance from given Type.
 *///from www. j  a v a2s .c  om
private static Class extractClass(Class ownerClass, Type arg) {
    if (arg instanceof ParameterizedType) {
        return extractClass(ownerClass, ((ParameterizedType) arg).getRawType());
    } else if (arg instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) arg;
        Type gt = gat.getGenericComponentType();
        Class<?> componentClass = extractClass(ownerClass, gt);
        return Array.newInstance(componentClass, 0).getClass();
    } else if (arg instanceof TypeVariable) {
        TypeVariable tv = (TypeVariable) arg;
        arg = getTypeVariableMap(ownerClass).get(tv);
        if (arg == null) {
            arg = extractBoundForTypeVariable(tv);
        } else {
            arg = extractClass(ownerClass, arg);
        }
    }
    return (arg instanceof Class ? (Class) arg : Object.class);
}

From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java

@Override
public boolean supports(Type genericType) {
    if (genericType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) genericType;
        if (JAXBElement.class == parameterizedType.getRawType()
                && parameterizedType.getActualTypeArguments().length == 1) {
            Type typeArgument = parameterizedType.getActualTypeArguments()[0];
            if (typeArgument instanceof Class) {
                Class<?> classArgument = (Class<?>) typeArgument;
                return (((classArgument.isArray() && Byte.TYPE == classArgument.getComponentType()))
                        || isPrimitiveWrapper(classArgument) || isStandardClass(classArgument)
                        || supportsInternal(classArgument, false));
            } else if (typeArgument instanceof GenericArrayType) {
                GenericArrayType arrayType = (GenericArrayType) typeArgument;
                return (Byte.TYPE == arrayType.getGenericComponentType());
            }//w w w  .  j a  v  a2  s  .c o  m
        }
    } else if (genericType instanceof Class) {
        Class<?> clazz = (Class<?>) genericType;
        return supportsInternal(clazz, this.checkForXmlRootElement);
    }
    return false;
}