public static Class<?> getElementType(Class<?> type, Type genericType) throws IllegalStateException { if(!isCollectionType(type, genericType)){ throw new IllegalStateException("The given type '" + type + "' is not a collection type"); } if(type.isArray()){ return type.getComponentType(); } if(null == genericType){ return Object.class; } return Types.getActualTypeArgument(genericType); }
public static TypeInfo getTypeInfo(Class<?> type,Type genericType) { MTypeKind kind = null; Class<?> elementType = null; TypeInfo elementTypeInfo = null; if(isSimpleType(type, genericType)){ kind = MTypeKind.SIMPLE; }else if(isCollectionType(type, genericType)){ kind = MTypeKind.COLLECTION; elementType = getElementType(type, genericType); elementTypeInfo = getTypeInfo(elementType, null); }else{ kind = MTypeKind.COMPLEX; } return new TypeInfo(type, genericType, kind,elementType,elementTypeInfo); }
@Override public MType getMType(Class<?> declaringClass, Class<?> type, Type genericType, MTypeContext context) { Args.notNull(context.root(), "Root factory must be exists!"); if(Types.isSimpleType(type,genericType) || Types.isCollectionType(type,genericType)) { return null; } for(OrmContext c : ormContexts) { EntityMapping em = c.getMetadata().tryGetEntityMapping(type); if(null != em) { return getMType(type, context, c, em); } } return null; }