Java 类org.hibernate.internal.TypeLocatorImpl 实例源码

项目:metaworks_framework    文件:MapFieldsFieldMetadataProvider.java   
@Override
public FieldProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) {
        return FieldProviderResponse.NOT_HANDLED;
    }
    //look for any map field metadata that was previously added for the requested field
    for (Map.Entry<String, FieldMetadata> entry : addMetadataFromFieldTypeRequest.getPresentationAttributes().entrySet()) {
        if (entry.getKey().startsWith(addMetadataFromFieldTypeRequest.getRequestedPropertyName() + FieldManager.MAPFIELDSEPARATOR)) {
            TypeLocatorImpl typeLocator = new TypeLocatorImpl(new TypeResolver());

            Type myType = null;
            //first, check if an explicit type was declared
            String valueClass = ((BasicFieldMetadata) entry.getValue()).getMapFieldValueClass();
            if (valueClass != null) {
                myType = typeLocator.entity(valueClass);
            }
            if (myType == null) {
                SupportedFieldType fieldType = ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType();
                Class<?> basicJavaType = getBasicJavaType(fieldType);
                if (basicJavaType != null) {
                    myType = typeLocator.basic(basicJavaType);
                }
            }
            if (myType == null) {
                java.lang.reflect.Type genericType = addMetadataFromFieldTypeRequest.getRequestedField().getGenericType();
                if (genericType instanceof ParameterizedType) {
                    ParameterizedType pType = (ParameterizedType) genericType;
                    Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1];
                    Class<?>[] entities = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getAllPolymorphicEntitiesFromCeiling(clazz);
                    if (!ArrayUtils.isEmpty(entities)) {
                        myType = typeLocator.entity(entities[entities.length-1]);
                    }
                }
            }
            if (myType == null) {
                   throw new IllegalArgumentException("Unable to establish the type for the property (" + entry
                           .getKey() + ")");
            }
            //add property for this map field as if it was a normal field
            super.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(addMetadataFromFieldTypeRequest.getRequestedField(),
                    addMetadataFromFieldTypeRequest.getTargetClass(),
                    addMetadataFromFieldTypeRequest.getForeignField(), addMetadataFromFieldTypeRequest.getAdditionalForeignFields(),
                    addMetadataFromFieldTypeRequest.getMergedPropertyType(), addMetadataFromFieldTypeRequest.getComponentProperties(),
                    addMetadataFromFieldTypeRequest.getIdProperty(),
                    addMetadataFromFieldTypeRequest.getPrefix(),
                    entry.getKey(), myType, addMetadataFromFieldTypeRequest.isPropertyForeignKey(),
                    addMetadataFromFieldTypeRequest.getAdditionalForeignKeyIndexPosition(),
                    addMetadataFromFieldTypeRequest.getPresentationAttributes(), entry.getValue(),
                    ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType(),
                    myType.getReturnedClass(), addMetadataFromFieldTypeRequest.getDynamicEntityDao()), metadata);
        }
    }
    return FieldProviderResponse.HANDLED;
}
项目:SparkCommerce    文件:MapFieldsFieldMetadataProvider.java   
@Override
public FieldProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) {
        return FieldProviderResponse.NOT_HANDLED;
    }
    //look for any map field metadata that was previously added for the requested field
    for (Map.Entry<String, FieldMetadata> entry : addMetadataFromFieldTypeRequest.getPresentationAttributes().entrySet()) {
        if (entry.getKey().startsWith(addMetadataFromFieldTypeRequest.getRequestedPropertyName() + FieldManager.MAPFIELDSEPARATOR)) {
            TypeLocatorImpl typeLocator = new TypeLocatorImpl(new TypeResolver());

            Type myType = null;
            //first, check if an explicit type was declared
            String valueClass = ((BasicFieldMetadata) entry.getValue()).getMapFieldValueClass();
            if (valueClass != null) {
                myType = typeLocator.entity(valueClass);
            }
            if (myType == null) {
                SupportedFieldType fieldType = ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType();
                Class<?> basicJavaType = getBasicJavaType(fieldType);
                if (basicJavaType != null) {
                    myType = typeLocator.basic(basicJavaType);
                }
            }
            if (myType == null) {
                java.lang.reflect.Type genericType = addMetadataFromFieldTypeRequest.getRequestedField().getGenericType();
                if (genericType instanceof ParameterizedType) {
                    ParameterizedType pType = (ParameterizedType) genericType;
                    Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1];
                    Class<?>[] entities = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getAllPolymorphicEntitiesFromCeiling(clazz);
                    if (!ArrayUtils.isEmpty(entities)) {
                        myType = typeLocator.entity(entities[entities.length-1]);
                    }
                }
            }
            if (myType == null) {
                   throw new IllegalArgumentException("Unable to establish the type for the property (" + entry
                           .getKey() + ")");
            }
            //add property for this map field as if it was a normal field
            super.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(addMetadataFromFieldTypeRequest.getRequestedField(),
                    addMetadataFromFieldTypeRequest.getTargetClass(),
                    addMetadataFromFieldTypeRequest.getForeignField(), addMetadataFromFieldTypeRequest.getAdditionalForeignFields(),
                    addMetadataFromFieldTypeRequest.getMergedPropertyType(), addMetadataFromFieldTypeRequest.getComponentProperties(),
                    addMetadataFromFieldTypeRequest.getIdProperty(),
                    addMetadataFromFieldTypeRequest.getPrefix(),
                    entry.getKey(), myType, addMetadataFromFieldTypeRequest.isPropertyForeignKey(),
                    addMetadataFromFieldTypeRequest.getAdditionalForeignKeyIndexPosition(),
                    addMetadataFromFieldTypeRequest.getPresentationAttributes(), entry.getValue(),
                    ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType(),
                    myType.getReturnedClass(), addMetadataFromFieldTypeRequest.getDynamicEntityDao()), metadata);
        }
    }
    return FieldProviderResponse.HANDLED;
}
项目:blcdemo    文件:MapFieldsFieldMetadataProvider.java   
@Override
public FieldProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) {
    if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) {
        return FieldProviderResponse.NOT_HANDLED;
    }
    //look for any map field metadata that was previously added for the requested field
    for (Map.Entry<String, FieldMetadata> entry : addMetadataFromFieldTypeRequest.getPresentationAttributes().entrySet()) {
        if (entry.getKey().startsWith(addMetadataFromFieldTypeRequest.getRequestedPropertyName() + FieldManager.MAPFIELDSEPARATOR)) {
            TypeLocatorImpl typeLocator = new TypeLocatorImpl(new TypeResolver());

            Type myType = null;
            //first, check if an explicit type was declared
            String valueClass = ((BasicFieldMetadata) entry.getValue()).getMapFieldValueClass();
            if (valueClass != null) {
                myType = typeLocator.entity(valueClass);
            }
            if (myType == null) {
                SupportedFieldType fieldType = ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType();
                Class<?> basicJavaType = getBasicJavaType(fieldType);
                if (basicJavaType != null) {
                    myType = typeLocator.basic(basicJavaType);
                }
            }
            if (myType == null) {
                java.lang.reflect.Type genericType = addMetadataFromFieldTypeRequest.getRequestedField().getGenericType();
                if (genericType instanceof ParameterizedType) {
                    ParameterizedType pType = (ParameterizedType) genericType;
                    Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1];
                    Class<?>[] entities = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getAllPolymorphicEntitiesFromCeiling(clazz);
                    if (!ArrayUtils.isEmpty(entities)) {
                        myType = typeLocator.entity(entities[entities.length-1]);
                    }
                }
            }
            if (myType == null) {
                   throw new IllegalArgumentException("Unable to establish the type for the property (" + entry
                           .getKey() + ")");
            }
            //add property for this map field as if it was a normal field
            super.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(addMetadataFromFieldTypeRequest.getRequestedField(),
                    addMetadataFromFieldTypeRequest.getTargetClass(),
                    addMetadataFromFieldTypeRequest.getForeignField(), addMetadataFromFieldTypeRequest.getAdditionalForeignFields(),
                    addMetadataFromFieldTypeRequest.getMergedPropertyType(), addMetadataFromFieldTypeRequest.getComponentProperties(),
                    addMetadataFromFieldTypeRequest.getIdProperty(),
                    addMetadataFromFieldTypeRequest.getPrefix(),
                    entry.getKey(), myType, addMetadataFromFieldTypeRequest.isPropertyForeignKey(),
                    addMetadataFromFieldTypeRequest.getAdditionalForeignKeyIndexPosition(),
                    addMetadataFromFieldTypeRequest.getPresentationAttributes(), entry.getValue(),
                    ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType(),
                    myType.getReturnedClass(), addMetadataFromFieldTypeRequest.getDynamicEntityDao()), metadata);
        }
    }
    return FieldProviderResponse.HANDLED;
}