@SuppressWarnings({"unchecked"}) private DataType<?> createDataType(Class<?> physicalType, Type type, TypeMapping mapping) { if (type instanceof Class) { // not a generic return new JavaClass(physicalType); } else { JavaTypeInfo info = helper.createTypeInfo(type, mapping); return new JavaGenericType(info); } }
@SuppressWarnings({"unchecked"}) public <T> Supplier<Collection<T>> createSupplier(Collection<T> collection, String name, JavaGenericType dataType, Document value, ClassLoader classLoader) { List<JavaTypeInfo> typeInfos = dataType.getTypeInfo().getParameterTypesInfos(); if (typeInfos.size() < 1) { // programming error throw new Fabric3Exception("Collection properties must have a value type"); } Class<?> type = typeInfos.get(0).getRawType(); List<Class<?>> types = new ArrayList<>(); types.add(type); Transformer<Node, ?> transformer = getTransformer(name, PROPERTY_TYPE, new JavaType(type), types); Element root = value.getDocumentElement(); NodeList nodes = root.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i).getFirstChild(); T val = (T) transformer.transform(node, classLoader); collection.add(val); } return () -> collection; }
if (!getType().equals(other.getType())) { return false; for (JavaTypeInfo info : getTypeInfo().getParameterTypesInfos()) { if (!Object.class.equals(info.getRawType())) { bound = true; return getTypeInfo().getRawType().equals(otherClazz.getType()); } else { return other instanceof JavaGenericType && getTypeInfo().equals(((JavaGenericType) other).getTypeInfo()); return getTypeInfo().getRawType().equals(other.getType());
@SuppressWarnings({"unchecked"}) public <T> ObjectFactory<Collection<T>> createFactory(Collection<T> collection, String name, JavaGenericType dataType, Document value, ClassLoader classLoader) throws PropertyTransformException { try { List<JavaTypeInfo> typeInfos = dataType.getLogical().getParameterTypesInfos(); if (typeInfos.size() < 1) { // programming error throw new PropertyTransformException("Collection properties must have a value type"); } Class<?> type = typeInfos.get(0).getRawType(); List<Class<?>> types = new ArrayList<Class<?>>(); types.add(type); Transformer<Node, ?> transformer = getTransformer(name, PROPERTY_TYPE, new JavaClass(type), types); Element root = value.getDocumentElement(); NodeList nodes = root.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i).getFirstChild(); T val = (T) transformer.transform(node, classLoader); collection.add(val); } return new SingletonObjectFactory<Collection<T>>(collection); } catch (TransformationException e) { throw new PropertyTransformException("Unable to transform property value: " + name, e); } }
throws PropertyTransformException { try { List<JavaTypeInfo> typeInfos = type.getLogical().getParameterTypesInfos(); if (typeInfos.size() < 2) { List<Class<?>> keyTypes = new ArrayList<Class<?>>(); keyTypes.add(keyType); Class<?> valueType = type.getLogical().getParameterTypesInfos().get(1).getRawType(); List<Class<?>> valueTypes = new ArrayList<Class<?>>(); valueTypes.add(valueType);
@SuppressWarnings({"unchecked"}) private DataType<?> getDataType(Type type, TypeMapping typeMapping) { if (type instanceof Class) { // non-generic type Class<?> nonGenericType = (Class<?>) type; if (nonGenericType.isPrimitive()) { // convert primitive representation to its object equivalent nonGenericType = ParamTypes.PRIMITIVE_TO_OBJECT.get(nonGenericType); } return new JavaClass(nonGenericType); } else { // a generic JavaTypeInfo info = helper.createTypeInfo(type, typeMapping); return new JavaGenericType(info); } }
@SuppressWarnings({"unchecked"}) public <T> Supplier<Collection<T>> createSupplier(Collection<T> collection, String name, JavaGenericType dataType, Document value, ClassLoader classLoader) { List<JavaTypeInfo> typeInfos = dataType.getTypeInfo().getParameterTypesInfos(); if (typeInfos.size() < 1) { // programming error throw new Fabric3Exception("Collection properties must have a value type"); } Class<?> type = typeInfos.get(0).getRawType(); List<Class<?>> types = new ArrayList<>(); types.add(type); Transformer<Node, ?> transformer = getTransformer(name, PROPERTY_TYPE, new JavaType(type), types); Element root = value.getDocumentElement(); NodeList nodes = root.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i).getFirstChild(); T val = (T) transformer.transform(node, classLoader); collection.add(val); } return () -> collection; }
@SuppressWarnings({"unchecked"}) private DataType getDataType(Type type, TypeMapping typeMapping) { if (type instanceof Class) { // non-generic type Class<?> nonGenericType = (Class<?>) type; if (nonGenericType.isPrimitive()) { // convert primitive representation to its object equivalent nonGenericType = ParamTypes.PRIMITIVE_TO_OBJECT.get(nonGenericType); } return new JavaType(nonGenericType); } else { // a generic JavaTypeInfo info = helper.createTypeInfo(type, typeMapping); return new JavaGenericType(info); } }
@SuppressWarnings({"unchecked"}) public Supplier<Map> createSupplier(String name, JavaGenericType type, Document value, ClassLoader classLoader) { List<JavaTypeInfo> typeInfos = type.getTypeInfo().getParameterTypesInfos(); if (typeInfos.size() < 2) { List<Class<?>> keyTypes = new ArrayList<>(); keyTypes.add(keyType); Class<?> valueType = type.getTypeInfo().getParameterTypesInfos().get(1).getRawType(); List<Class<?>> valueTypes = new ArrayList<>(); valueTypes.add(valueType);
@SuppressWarnings({"unchecked"}) private DataType getDataType(Type type, TypeMapping typeMapping) { if (type instanceof Class) { // non-generic type Class<?> nonGenericType = (Class<?>) type; if (nonGenericType.isPrimitive()) { // convert primitive representation to its object equivalent nonGenericType = ParamTypes.PRIMITIVE_TO_OBJECT.get(nonGenericType); } return new JavaType(nonGenericType); } else { // a generic JavaTypeInfo info = helper.createTypeInfo(type, typeMapping); return new JavaGenericType(info); } }
public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof DataType)) { return false; } DataType other = (DataType) o; if (!getType().equals(other.getType())) { return false; } if (other instanceof JavaGenericType) { boolean bound = false; // unbound parameters are equivalent to non-generic JavaGenericType otherType = (JavaGenericType) other; for (JavaTypeInfo info : otherType.getTypeInfo().getParameterTypesInfos()) { if (!Object.class.equals(info.getRawType())) { bound = true; break; } } return !bound && otherType.getTypeInfo().getRawType().equals(getType()); } return getType().equals(other.getType()); }
/** * Returns a data type from a logical and physical type pairing. * * @param physicalType the physical type * @param type the type to construct the data type from * @param mapping the resolved generic type mappings * @return the data type */ @SuppressWarnings({"unchecked"}) private DataType<?> createDataType(Class<?> physicalType, Type type, TypeMapping mapping) { if (type instanceof Class) { // not a generic return new JavaClass(physicalType); } else { JavaTypeInfo info = helper.createTypeInfo(type, mapping); return new JavaGenericType(info); } }
@SuppressWarnings({"unchecked"}) public Supplier<Map> createSupplier(String name, JavaGenericType type, Document value, ClassLoader classLoader) { List<JavaTypeInfo> typeInfos = type.getTypeInfo().getParameterTypesInfos(); if (typeInfos.size() < 2) { List<Class<?>> keyTypes = new ArrayList<>(); keyTypes.add(keyType); Class<?> valueType = type.getTypeInfo().getParameterTypesInfos().get(1).getRawType(); List<Class<?>> valueTypes = new ArrayList<>(); valueTypes.add(valueType);
/** * Returns a data type from a logical and physical type pairing. * * @param rawType the raw type * @param actualType the type to construct the data type from * @param mapping the resolved generic type mappings * @return the data type */ @SuppressWarnings({"unchecked"}) private DataType createDataType(Class<?> rawType, Type actualType, TypeMapping mapping) { if (actualType instanceof Class) { // not a generic return new JavaType(rawType); } else { JavaTypeInfo info = helper.createTypeInfo(actualType, mapping); return new JavaGenericType(info); } }
@SuppressWarnings({"unchecked"}) private DataType createDataType(Class<?> physicalType, Type type, TypeMapping mapping) { JavaType dataType; if (type instanceof Class) { // not a generic dataType = new JavaType(physicalType); } else { JavaTypeInfo info = helper.createTypeInfo(type, mapping); dataType = new JavaGenericType(info); } for (TypeIntrospector introspector : typeIntrospectors) { introspector.introspect(dataType); } return dataType; }
/** * Returns the key type of the given Map type. * * @param type a type that is a Map * @param typeMapping the type mapping for resolved parameters * @return the key type */ @SuppressWarnings({"unchecked"}) private DataType getKeyType(Type type, TypeMapping typeMapping) { Type actualType = typeMapping.getActualType(type); if (actualType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) actualType; Type actualKeyType = typeMapping.getActualType(parameterizedType.getActualTypeArguments()[0]); if (actualKeyType instanceof Class) { return new JavaType((Class) actualKeyType); } else { return new JavaGenericType(createTypeInfo(actualKeyType, typeMapping)); } } else if (actualType instanceof Map) { // the map is not parameterized return new JavaType(Object.class); } else { throw new IllegalArgumentException("Type not a Map: " + type); } }
/** * Returns the key type of the given Map type. * * @param type a type that is a Map * @param typeMapping the type mapping for resolved parameters * @return the key type */ @SuppressWarnings({"unchecked"}) private DataType<?> getKeyType(Type type, TypeMapping typeMapping) { Type actualType = typeMapping.getActualType(type); if (actualType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) actualType; Type actualKeyType = typeMapping.getActualType(parameterizedType.getActualTypeArguments()[0]); if (actualKeyType instanceof Class) { return new JavaClass((Class) actualKeyType); } else { return new JavaGenericType(createTypeInfo(actualKeyType, typeMapping)); } } else if (actualType instanceof Map) { // the map is not parameterized return new JavaClass<Object>(Object.class); } else { throw new IllegalArgumentException("Type not a Map: " + type); } }