List of usage examples for java.lang.reflect ParameterizedType getRawType
Type getRawType();
From source file:net.firejack.platform.model.service.reverse.ReverseEngineeringService.java
private void analyzeField(String name, Type type, RelationshipType relationshipType, EntityModel entityModel, XmlElement element, Map<String, EntityModel> models, List<RelationshipModel> relationships, List<FieldModel> fields) { if (type instanceof Class) { Class clazz = (Class) type; boolean required = false; if (element != null) { required = element.required(); if (!name.equals(StringUtils.uncapitalize(element.name())) && !"##default".equals(element.name())) name = element.name();//from w ww . ja v a 2 s . com } if (clazz.isAnnotationPresent(XmlAccessorType.class)) { EntityModel target = createBeanEntity(clazz, entityModel.getParent(), relationships, models); RelationshipModel relationshipModel = createRelationship(name, required, entityModel, target, relationshipType); relationships.add(relationshipModel); } else { FieldModel field = createField(name, clazz, required, entityModel); fields.add(field); } } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; Type rawType = parameterizedType.getRawType(); Type generic = parameterizedType.getActualTypeArguments()[0]; if (rawType == Holder.class) { analyzeField(name, generic, relationshipType, entityModel, element, models, relationships, fields); } else if (rawType == List.class) { if (generic instanceof Class && ((Class) generic).isAnnotationPresent(XmlAccessorType.class)) { analyzeField(name, generic, ASSOCIATION, entityModel, element, models, relationships, fields); } else { analyzeField(name, rawType, relationshipType, entityModel, element, models, relationships, fields); } } else { throw new IllegalStateException("Unknown type: " + type + " entity: " + entityModel.getName()); } } }
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 a 2 s. c o m*/ } } else if (genericType instanceof Class) { Class<?> clazz = (Class<?>) genericType; return supportsInternal(clazz, this.checkForXmlRootElement); } return false; }
From source file:com.link_intersystems.lang.reflect.Class2.java
/** * * @param typeVariable/* www . jav a 2s . c o m*/ * @return the class that is bound on this {@link Generic} type for the * given {@link TypeVariable} or null if the type bound is not a * Class<?>. If the bound type resolved for the {@link TypeVariable} * is itself a ( {@link ParameterizedType} ) the raw type will be * returned. */ @SuppressWarnings("unchecked") public <C> Class<C> getBoundClass(TypeVariable<?> typeVariable) { Type boundType = getBoundType(typeVariable); if (boundType == null) { return null; } if (boundType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) boundType; boundType = parameterizedType.getRawType(); } if (boundType instanceof GenericArrayType) { GenericArrayType genericArrayType = GenericArrayType.class.cast(boundType); Type genericComponentType = genericArrayType.getGenericComponentType(); Class<?> componentType = Class.class.cast(genericComponentType); Object array = Array.newInstance(componentType, 0); boundType = array.getClass(); } return (Class<C>) boundType; }
From source file:org.statefulj.framework.core.StatefulFactory.java
/** * @param entityToRepositoryMapping// w ww .j a v a2s . c om * @param bfName * @param bf * @throws ClassNotFoundException */ private void mapEntityToRepository(Map<Class<?>, String> entityToRepositoryMapping, String bfName, BeanDefinition bf) throws ClassNotFoundException { // Determine the Entity Class associated with the Repo // String value = (String) bf.getAttribute("factoryBeanObjectType"); Class<?> repoInterface = Class.forName(value); Class<?> entityType = null; for (Type type : repoInterface.getGenericInterfaces()) { if (type instanceof ParameterizedType) { ParameterizedType parmType = (ParameterizedType) type; if (Repository.class.isAssignableFrom((Class<?>) parmType.getRawType()) && parmType.getActualTypeArguments() != null && parmType.getActualTypeArguments().length > 0) { entityType = (Class<?>) parmType.getActualTypeArguments()[0]; break; } } } if (entityType == null) { throw new RuntimeException("Unable to determine Entity type for class " + repoInterface.getName()); } // Map Entity to the RepositoryFactoryBeanSupport bean // logger.debug("Mapped \"{}\" to repo \"{}\", beanId=\"{}\"", entityType.getName(), value, bfName); entityToRepositoryMapping.put(entityType, bfName); }
From source file:com.evolveum.midpoint.repo.sql.helpers.ObjectDeltaUpdater.java
private Class getRealOutputType(Attribute attribute) { Class type = attribute.getJavaType(); if (!Collection.class.isAssignableFrom(type)) { return type; }/* w w w . jav a2s. c om*/ Method method = (Method) attribute.getJavaMember(); ParameterizedType parametrized = (ParameterizedType) method.getGenericReturnType(); Type t = parametrized.getActualTypeArguments()[0]; if (t instanceof Class) { return (Class) t; } parametrized = (ParameterizedType) t; return (Class) parametrized.getRawType(); }
From source file:com.link_intersystems.lang.reflect.Class2.java
private Type doGetBoundType(ParameterizedType parameterizedType, TypeVariable<?> typeVariable) { Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); Type rawType = parameterizedType.getRawType(); if (rawType instanceof Class<?>) { Class<?> rawTypeClass = (Class<?>) rawType; TypeVariable<?>[] typeParameters = rawTypeClass.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { TypeVariable<?> typeParameter = typeParameters[i]; if (typeParameter.equals(typeVariable)) { return actualTypeArguments[i]; }//from w ww. j a va 2 s . c om } } return null; }
From source file:org.sleeksnap.ScreenSnapper.java
/** * Gets a filter's parent class type//from w w w . j a va 2s. co m * * @param filter * @return The class representing the filter's upload type */ @SuppressWarnings("unchecked") public Class<? extends Upload> getFilterType(final UploadFilter<?> filter) { // Find the uploader type final Type[] types = filter.getClass().getGenericInterfaces(); for (final Type type : types) { if (type instanceof ParameterizedType) { final ParameterizedType parameterizedType = (ParameterizedType) type; if (parameterizedType.getRawType() == UploadFilter.class) { return (Class<? extends Upload>) parameterizedType.getActualTypeArguments()[0]; } } } throw new RuntimeException("Attempted to load invalid filter!"); }
From source file:com.gatf.generator.core.GatfTestGeneratorMojo.java
@SuppressWarnings("rawtypes") private Object getObject(Type claz, List<Type> heirarchies) throws Exception { ParameterizedType type = null; Class clas = null;//from ww w .j a va 2 s .c o m if (claz instanceof ParameterizedType) { type = (ParameterizedType) claz; clas = (Class) type.getRawType(); } else { clas = (Class) claz; } if (isPrimitive(clas)) { return getPrimitiveValue(clas); } else if (isMap(clas)) { return getMapValue(clas, type.getActualTypeArguments(), heirarchies); } else if (isCollection(clas)) { return getListSetValue(clas, type.getActualTypeArguments(), heirarchies); } else if (!clas.isInterface()) { return getObject(clas, heirarchies); } return null; }
From source file:com.gatf.generator.core.GatfTestGeneratorMojo.java
/** * @param claz//from w w w . java 2 s . c o m * @param parameters * @param naming * @param formpnm * @param isheaderParam * @param heirarchy * @throws Exception Add new ViewFeild objects that represnt the form elements on the test page of the give rest * full service */ @SuppressWarnings("rawtypes") private ViewField getViewField(Type claz) throws Exception { ViewField viewField = null; try { ParameterizedType type = null; Class clas = null; if (claz instanceof ParameterizedType) { type = (ParameterizedType) claz; clas = (Class) type.getRawType(); } else { clas = (Class) claz; } List<Type> heirarchies = new ArrayList<Type>(); if (isPrimitive(clas)) { viewField = new ViewField(); viewField.setClaz(clas); viewField.setValue(getPrimitiveValue(claz)); } else if (isMap(clas)) { viewField = new ViewField(); viewField.setClaz(clas); viewField.setValue(getMapValue(clas, type.getActualTypeArguments(), heirarchies)); } else if (isCollection(clas)) { viewField = new ViewField(); viewField.setClaz(clas); viewField.setValue(getListSetValue(clas, type.getActualTypeArguments(), heirarchies)); } else if (!clas.isInterface()) { viewField = new ViewField(); viewField.setClaz(clas); viewField.setValue(getObject(clas, heirarchies)); } } catch (Exception e) { getLog().error(e); getLog().info( "Invalid class, cannot be represented as a form/object in a test case - class name = " + claz); } return viewField; }
From source file:org.soybeanMilk.core.bean.DefaultGenericConverter.java
/** * ?/*from ww w. j a v a 2s . com*/ * @param map * @param type * @return * @throws ConvertException * @date 2012-5-14 */ @SuppressWarnings("unchecked") protected Object convertMapToType(Map<?, ?> map, Type type) throws ConvertException { Object result = null; // Type customType = getMapCustomTargetType(map, null); if (customType != null) type = customType; if (type == null) { result = map; } else if (SbmUtils.isClassType(type)) { Class<?> clazz = SbmUtils.narrowToClass(type); //Map??? if (customType == null && isAncestorType(Map.class, clazz)) { result = map; } else { result = convertPropertyValueMapToClass(toPropertyValueMap((Map<String, ?>) map), clazz); } } else if (type instanceof ParameterizedType) { boolean convert = true; ParameterizedType pt = (ParameterizedType) type; Type rt = pt.getRawType(); //Map<?, ?>Map<Object, Object>??? if (isAncestorType(rt, map.getClass())) { Type[] at = pt.getActualTypeArguments(); if (at != null && at.length == 2 && ((Object.class.equals(at[0]) && Object.class.equals(at[1])) || (isSimpleWildcardType(at[0]) && isSimpleWildcardType(at[1])))) { convert = false; } } if (convert) result = convertPropertyValueMapToParameterrizedType(toPropertyValueMap((Map<String, ?>) map), pt); else result = map; } else if (type instanceof GenericArrayType) { result = convertPropertyValueMapToGenericArrayType(toPropertyValueMap((Map<String, ?>) map), (GenericArrayType) type); } else if (type instanceof TypeVariable<?>) { result = convertObjectToType(map, reify(type)); } else if (type instanceof WildcardType) { result = convertObjectToType(map, reify(type)); } else result = converterNotFoundThrow(map.getClass(), type); return result; }