当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionUtils类代码示例

本文整理汇总了Java中org.mongodb.morphia.utils.ReflectionUtils的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils类的具体用法?Java ReflectionUtils怎么用?Java ReflectionUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReflectionUtils类属于org.mongodb.morphia.utils包,在下文中一共展示了ReflectionUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: discover

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
protected void discover() {
    for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(getClazz(), true)) {
        field.setAccessible(true);
        final int fieldMods = field.getModifiers();
        if (field.isAnnotationPresent(Transient.class)
            || field.isSynthetic() && (fieldMods & Modifier.TRANSIENT) == Modifier.TRANSIENT
            || getMapper().getOptions().isActLikeSerializer() && ((fieldMods & Modifier.TRANSIENT) == Modifier.TRANSIENT)
            || getMapper().getOptions().isIgnoreFinals() && ((fieldMods & Modifier.FINAL) == Modifier.FINAL)) {
            // ignore these
        } else {
            getPersistenceFields().add(mapField(field));
        }

    }
}
 
开发者ID:groupon,项目名称:DotCi,代码行数:17,代码来源:JenkinsMappedClass.java

示例2: checkRecursivelyHasNoIdAnnotationPresent

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
private void checkRecursivelyHasNoIdAnnotationPresent(final Set<Class<?>> classesToInspect,
                                                      final HashSet<Class<?>> alreadyInspectedClasses, final MappedClass mc,
                                                      final Set<ConstraintViolation> ve) {
    for (final Class<?> clazz : classesToInspect) {
        if (alreadyInspectedClasses.contains(clazz)) {
            continue;
        }
        if (hasTypeFieldAnnotation(clazz, Id.class)) {
            ve.add(new ConstraintViolation(Level.FATAL,
                                           mc,
                                           getClass(),
                                           "You cannot use @Id on any field of an Embedded/Property object"));
        }
        alreadyInspectedClasses.add(clazz);
        final Set<Class<?>> extraClassesToInspect = new HashSet<Class<?>>();
        for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(clazz, true)) {
            if (isFieldToInspect(field)) {
                extraClassesToInspect.add(field.getType());
            }
        }
        checkRecursivelyHasNoIdAnnotationPresent(extraClassesToInspect, alreadyInspectedClasses, mc, ve);
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:24,代码来源:ContainsEmbeddedWithId.java

示例3: check

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
protected void check(final Mapper mapper, final MappedClass mc, final MappedField mf, final Set<ConstraintViolation> ve) {
    if (mf.isMap()) {
        if (mf.hasAnnotation(Serialized.class)) {
            final Class<?> keyClass = ReflectionUtils.getParameterizedClass(mf.getField(), 0);
            final Class<?> valueClass = ReflectionUtils.getParameterizedClass(mf.getField(), 1);
            if (keyClass != null) {
                if (!Serializable.class.isAssignableFrom(keyClass)) {
                    ve.add(new ConstraintViolation(Level.FATAL, mc, mf, getClass(),
                                                   "Key class (" + keyClass.getName() + ") is not Serializable"));
                }
            }
            if (valueClass != null) {
                if (!Serializable.class.isAssignableFrom(valueClass)) {
                    ve.add(new ConstraintViolation(Level.FATAL, mc, mf, getClass(),
                                                   "Value class (" + valueClass.getName() + ") is not Serializable"));
                }
            }
        }
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:MapNotSerializable.java

示例4: check

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
protected void check(final Mapper mapper, final MappedClass mc, final MappedField mf, final Set<ConstraintViolation> ve) {
    if (mf.isMap() && (!mf.hasAnnotation(Serialized.class))) {
        final Class<?> aClass = ReflectionUtils.getParameterizedClass(mf.getField(), 0);
        // WARN if not parameterized : null or Object...
        if (aClass == null || Object.class.equals(aClass)) {
            ve.add(new ConstraintViolation(Level.WARNING, mc, mf, getClass(),
                                           "Maps cannot be keyed by Object (Map<Object,?>); Use a parametrized type that is supported "
                                           + SUPPORTED));
        } else if (!aClass.equals(String.class) && !aClass.equals(ObjectId.class) && !ReflectionUtils.isPrimitiveLike(
                                                                                                                         aClass)) {
            ve.add(new ConstraintViolation(Level.FATAL, mc, mf, getClass(),
                                           "Maps must be keyed by a simple type " + SUPPORTED + "; " + aClass
                                           + " is not supported as a map key type."));
        }
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:18,代码来源:MapKeyDifferentFromString.java

示例5: isSupportedType

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
/**
 * Checks to see if it a Map/Set/List or a property supported by the MongoDB java driver
 *
 * @param clazz the type to check
 * @return true if the type is supported
 */
public static boolean isSupportedType(final Class<?> clazz) {
    if (ReflectionUtils.isPropertyType(clazz)) {
        return true;
    }
    if (clazz.isArray() || Map.class.isAssignableFrom(clazz) || Iterable.class.isAssignableFrom(clazz)) {
        Class<?> subType;
        if (clazz.isArray()) {
            subType = clazz.getComponentType();
        } else {
            subType = ReflectionUtils.getParameterizedClass(clazz);
        }

        //get component type, String.class from List<String>
        if (subType != null && subType != Object.class && !ReflectionUtils.isPropertyType(subType)) {
            return false;
        }

        //either no componentType or it is an allowed type
        return true;
    }
    return false;
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:29,代码来源:MappedClass.java

示例6: validate

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
protected void validate(final MappedField mappedField, final Object value, final List<ValidationFailure> validationFailures) {
    if (value == null) {
        validationFailures.add(new ValidationFailure("For a $mod operation, value cannot be null."));
    } else if (value.getClass().isArray()) {
        if (Array.getLength(value) != 2) {
            validationFailures.add(new ValidationFailure(format("For a $mod operation, value '%s' should be an array with two integer"
                                                                + " elements.  Instead it had %s", value, Array.getLength(value))));

        }
        if (!(ReflectionUtils.isIntegerType(value.getClass().getComponentType()))) {
            validationFailures.add(new ValidationFailure(format("Array value needs to contain integers for $mod, but contained: %s",
                                                                value.getClass().getComponentType())));
        }
    } else {
        validationFailures.add(new ValidationFailure(format("For a $mod operation, value '%s' should be an integer array.  "
                                                            + "Instead it was a: %s",
                                                            value, value.getClass()
                                                           )));
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:ModOperationValidator.java

示例7: decode

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
public Object decode(final Class targetClass, final Object val, final MappedField optionalExtraInfo) {
    if (val == null) {
        return null;
    }

    if (val instanceof Integer) {
        return val;
    }

    if (val instanceof Number) {
        return ((Number) val).intValue();
    }

    if (val instanceof List) {
        final Class<?> type = targetClass.isArray() ? targetClass.getComponentType() : targetClass;
        return ReflectionUtils.convertToArray(type, (List<?>) val);
    }

    return Integer.parseInt(val.toString());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:IntegerConverter.java

示例8: decode

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
public Object decode(final Class targetClass, final Object val, final MappedField optionalExtraInfo) {
    if (val == null) {
        return null;
    }

    if (val instanceof Double) {
        return val;
    }

    if (val instanceof Number) {
        return ((Number) val).doubleValue();
    }

    if (val instanceof List) {
        final Class<?> type = targetClass.isArray() ? targetClass.getComponentType() : targetClass;
        return ReflectionUtils.convertToArray(type, (List<?>) val);
    }

    return Double.parseDouble(val.toString());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:DoubleConverter.java

示例9: decode

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
public Object decode(final Class targetClass, final Object fromDBObject, final MappedField optionalExtraInfo) {
    if (fromDBObject == null) {
        return null;
    }

    if (targetClass.equals(fromDBObject.getClass())) {
        return fromDBObject;
    }

    if (fromDBObject instanceof List) {
        final Class<?> type = targetClass.isArray() ? targetClass.getComponentType() : targetClass;
        return ReflectionUtils.convertToArray(type, (List<?>) fromDBObject);
    }

    if (targetClass.equals(String[].class)) {
        return new String[]{fromDBObject.toString()};
    }

    return fromDBObject.toString();
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:StringConverter.java

示例10: decode

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
public Object decode(final Class targetClass, final Object val, final MappedField optionalExtraInfo) {
    if (val == null) {
        return null;
    }

    if (val instanceof Boolean) {
        return val;
    }

    //handle the case for things like the ok field
    if (val instanceof Number) {
        return ((Number) val).intValue() != 0;
    }

    if (val instanceof List) {
        final Class<?> type = targetClass.isArray() ? targetClass.getComponentType() : targetClass;
        return ReflectionUtils.convertToArray(type, (List<?>) val);
    }

    return Boolean.parseBoolean(val.toString());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:23,代码来源:BooleanConverter.java

示例11: decode

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
@Override
public Object decode(final Class targetClass, final Object val, final MappedField optionalExtraInfo) {
    if (val == null) {
        return null;
    }

    if (val instanceof Long) {
        return val;
    }

    if (val instanceof Number) {
        return ((Number) val).longValue();
    }

    if (val instanceof List) {
        final Class<?> type = targetClass.isArray() ? targetClass.getComponentType() : targetClass;
        return ReflectionUtils.convertToArray(type, (List<?>) val);
    }

    return Long.parseLong(val.toString());
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:22,代码来源:LongConverter.java

示例12: EntryMappedField

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
EntryMappedField(final Field field, final Class<?> clazz, final MappedField mappedField) {
    super(field, clazz);
    super.discover();
    if (MapKeyValueMapper.KEY.equals(field.getName())) {
        this.realType = mappedField.getMapKeyClass();
        this.subType = this.realType.getComponentType();
    } else if (MapKeyValueMapper.VALUE.equals(field.getName())) {
        this.realType = mappedField.getSubClass();
        this.subType = mappedField.getSubType() instanceof ParameterizedType ? ((ParameterizedType) mappedField.getSubType()).getActualTypeArguments()[0] : null;
    } else {
        throw new RuntimeException("Entry field is neither key nor entry");
    }

    if (this.realType.isArray()
        || Collection.class.isAssignableFrom(this.realType)
        || Map.class.isAssignableFrom(this.realType)) {

        this.isSingleValue = false;

        this.isMap = Map.class.isAssignableFrom(this.realType);
        this.isSet = Set.class.isAssignableFrom(this.realType);
        //for debugging
        this.isCollection = Collection.class.isAssignableFrom(this.realType);
        this.isArray = this.realType.isArray();

        if (this.isMap) {
            this.mapKeyType = ReflectionUtils.getParameterizedType(field, 0);
        }
    }
    try {
        this.constructor = this.realType.getDeclaredConstructor();
        this.constructor.setAccessible(true);
    } catch (final NoSuchMethodException e) {
        this.constructor = null;
    }
}
 
开发者ID:groupon,项目名称:DotCi,代码行数:37,代码来源:MapKeyValueMapper.java

示例13: MapOrCollectionMF

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
MapOrCollectionMF(final ParameterizedType t) {
    this();
    this.pType = t;
    final Class rawClass = (Class) t.getRawType();
    this.isSet = ReflectionUtils.implementsInterface(rawClass, Set.class);
    this.isMap = ReflectionUtils.implementsInterface(rawClass, Map.class);
    this.mapKeyType = getMapKeyClass();
    this.subType = getSubType();
    this.isMongoType = ReflectionUtils.isPropertyType(getSubClass());
}
 
开发者ID:groupon,项目名称:DotCi,代码行数:11,代码来源:JenkinsEmbeddedMapper.java

示例14: discover

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
/**
 * Discovers interesting (that we care about) things about the field.
 */
protected void discover(final Mapper mapper) {
    for (final Class<? extends Annotation> clazz : INTERESTING) {
        addAnnotation(clazz);
    }

    //type must be discovered before the constructor.
    discoverType(mapper);
    constructor = discoverConstructor();
    discoverMultivalued();

    // check the main type
    isMongoType = ReflectionUtils.isPropertyType(realType);

    // if the main type isn't supported by the Mongo, see if the subtype is.
    // works for T[], List<T>, Map<?, T>, where T is Long/String/etc.
    if (!isMongoType && subType != null) {
        isMongoType = ReflectionUtils.isPropertyType(subType);
    }

    if (!isMongoType && !isSingleValue && (subType == null || subType == Object.class)) {
        if (LOG.isWarningEnabled() && !mapper.getConverters().hasDbObjectConverter(this)) {
            LOG.warning(format("The multi-valued field '%s' is a possible heterogeneous collection. It cannot be verified. "
                               + "Please declare a valid type to get rid of this warning. %s", getFullName(), subType));
        }
        isMongoType = true;
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:31,代码来源:MappedField.java

示例15: toClass

import org.mongodb.morphia.utils.ReflectionUtils; //导入依赖的package包/类
protected Class toClass(final Type t) {
    if (t == null) {
        return null;
    } else if (t instanceof Class) {
        return (Class) t;
    } else if (t instanceof GenericArrayType) {
        final Type type = ((GenericArrayType) t).getGenericComponentType();
        Class aClass;
        if (type instanceof ParameterizedType) {
            aClass = (Class) ((ParameterizedType) type).getRawType();
        } else if (type instanceof TypeVariable) {
            aClass = ReflectionUtils.getTypeArgument(persistedClass, (TypeVariable<?>) type);
            if (aClass == null) {
                aClass = Object.class;
            }
        } else {
            aClass = (Class) type;
        }
        return Array.newInstance(aClass, 0).getClass();
    } else if (t instanceof ParameterizedType) {
        return (Class) ((ParameterizedType) t).getRawType();
    } else if (t instanceof WildcardType) {
        return (Class) ((WildcardType) t).getUpperBounds()[0];
    }

    throw new RuntimeException("Generic TypeVariable not supported!");

}
 
开发者ID:mongodb,项目名称:morphia,代码行数:29,代码来源:MappedField.java


注:本文中的org.mongodb.morphia.utils.ReflectionUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。