List of usage examples for java.lang.reflect GenericArrayType getGenericComponentType
Type getGenericComponentType();
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; }