protected AegisType getElementType(QName name, BeanTypeInfo beanTypeInfo, MessageReader reader, Context context) { AegisType type = beanTypeInfo.getType(name); // AegisType can be overriden with a xsi:type attribute type = TypeUtil.getReadType(reader.getXMLStreamReader(), context.getGlobalContext(), type); return type; }
/** * Insist that a Type is a parameterized type of one parameter. * This is used to decompose Holders, for example. * @param type the type * @return the parameter, or null if the type is not what we want. */ public static Type getSingleTypeParameter(Type type) { return getSingleTypeParameter(type, 0); }
protected List<Element> findMappings(Type type) { Class<?> clazz = TypeUtil.getTypeClass(type, false); List<Element> mappings = new ArrayList<>(); if (clazz == null) {
/** * If a Type is a class, return it as a class. * If it is a ParameterizedType, return the raw type as a class. * Otherwise return null. * @param type * @return */ public static Class<?> getTypeRelatedClass(Type type) { Class<?> directClass = getTypeClass(type, false); if (directClass != null) { return directClass; } if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return getTypeRelatedClass(pType.getRawType()); } if (type instanceof GenericArrayType) { GenericArrayType gat = (GenericArrayType) type; Type compType = gat.getGenericComponentType(); Class<?> arrayBaseType = getTypeRelatedClass(compType); // believe it or not, this seems to be the only way to get the // Class object for an array of primitive type. Object instance = Array.newInstance(arrayBaseType, 0); return instance.getClass(); } return null; } }
public static AegisType getWriteTypeStandalone(AegisContext globalContext, Object value, AegisType type) { if (type != null) { return getWriteType(globalContext, value, type); } TypeMapping tm; tm = globalContext.getTypeMapping(); // don't use this for null! type = tm.getType(value.getClass()); return type; }
/** * @return Returns the java type as a Class. * For a generic, return the raw type. For something * truly exotic, return null. */ public Class<?> getTypeClass() { return TypeUtil.getTypeRelatedClass(typeClass); }
info.setMappedName(createQName(parameter, DOMUtils.getAttributeValueEmptyNull(parameter, "mappedName"))); Class<?> relatedClass = TypeUtil.getTypeRelatedClass(info.getType()); if (keyType == null || valueType == null) { if (keyType == null) { keyType = TypeUtil.getSingleTypeParameter(info.getType(), 0); valueType = TypeUtil.getSingleTypeParameter(info.getType(), 1);
/** {@inheritDoc}*/ public Object read(XMLStreamReader reader, AegisType desiredType) throws Exception { setupReaderPosition(reader); ElementReader elReader = new ElementReader(reader); if (elReader.isXsiNil()) { elReader.readToEnd(); return null; } AegisType type = TypeUtil.getReadTypeStandalone(reader, aegisContext, desiredType); if (type == null) { throw new DatabindingException(new Message("NO_MAPPING", LOG)); } return type.readObject(elReader, context); }
/** * Allow writing of collections when the type of the collection object is known via * an {@link java.lang.reflect.Type} object. * @param globalContext the context * @param value the object to write. * @param reflectType the type to use in writing the object. * @return */ public static AegisType getWriteTypeStandalone(AegisContext globalContext, Object value, java.lang.reflect.Type reflectType) { if (reflectType == null) { return getWriteTypeStandalone(globalContext, value, (AegisType)null); } return globalContext.getTypeMapping().getTypeCreator().createType(reflectType); }
public static AegisType getWriteTypeStandalone(AegisContext globalContext, Object value, AegisType type) { if (type != null) { return getWriteType(globalContext, value, type); } TypeMapping tm; tm = globalContext.getTypeMapping(); // don't use this for null! type = tm.getType(value.getClass()); return type; }
/** * @return Returns the java type as a Class. * For a generic, return the raw type. For something * truly exotic, return null. */ public Class<?> getTypeClass() { return TypeUtil.getTypeRelatedClass(typeClass); }
/** * If a Type is a class, return it as a class. * If it is a ParameterizedType, return the raw type as a class. * Otherwise return null. * @param type * @return */ public static Class<?> getTypeRelatedClass(Type type) { Class<?> directClass = getTypeClass(type, false); if (directClass != null) { return directClass; } if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return getTypeRelatedClass(pType.getRawType()); } if (type instanceof GenericArrayType) { GenericArrayType gat = (GenericArrayType) type; Type compType = gat.getGenericComponentType(); Class<?> arrayBaseType = getTypeRelatedClass(compType); // believe it or not, this seems to be the only way to get the // Class object for an array of primitive type. Object instance = Array.newInstance(arrayBaseType, 0); return instance.getClass(); } return null; } }
info.setMappedName(createQName(parameter, DOMUtils.getAttributeValueEmptyNull(parameter, "mappedName"))); Class<?> relatedClass = TypeUtil.getTypeRelatedClass(info.getType()); if (keyType == null || valueType == null) { if (keyType == null) { keyType = TypeUtil.getSingleTypeParameter(info.getType(), 0); valueType = TypeUtil.getSingleTypeParameter(info.getType(), 1);
/** {@inheritDoc}*/ public Object read(XMLStreamReader reader, AegisType desiredType) throws Exception { setupReaderPosition(reader); ElementReader elReader = new ElementReader(reader); if (elReader.isXsiNil()) { elReader.readToEnd(); return null; } AegisType type = TypeUtil.getReadTypeStandalone(reader, aegisContext, desiredType); if (type == null) { throw new DatabindingException(new Message("NO_MAPPING", LOG)); } return type.readObject(elReader, context); }
/** * Allow writing of collections when the type of the collection object is known via * an {@link java.lang.reflect.Type} object. * @param globalContext the context * @param value the object to write. * @param reflectType the type to use in writing the object. * @return */ public static AegisType getWriteTypeStandalone(AegisContext globalContext, Object value, java.lang.reflect.Type reflectType) { if (reflectType == null) { return getWriteTypeStandalone(globalContext, value, (AegisType)null); } return globalContext.getTypeMapping().getTypeCreator().createType(reflectType); }
protected AegisType getElementType(QName name, BeanTypeInfo beanTypeInfo, MessageReader reader, Context context) { AegisType type = beanTypeInfo.getType(name); // AegisType can be overriden with a xsi:type attribute type = TypeUtil.getReadType(reader.getXMLStreamReader(), context.getGlobalContext(), type); return type; }
private void writeEntry(MessageWriter writer, Context context, AegisType kType, AegisType vType, Map.Entry<?, ?> entry) throws DatabindingException { kType = TypeUtil.getWriteType(context.getGlobalContext(), entry.getKey(), kType); vType = TypeUtil.getWriteType(context.getGlobalContext(), entry.getValue(), vType); MessageWriter entryWriter = writer.getElementWriter(getEntryName()); MessageWriter keyWriter = entryWriter.getElementWriter(getKeyName()); kType.writeObject(entry.getKey(), keyWriter, context); keyWriter.close(); if (entry.getValue() != null) { MessageWriter valueWriter = entryWriter.getElementWriter(getValueName()); vType.writeObject(entry.getValue(), valueWriter, context); valueWriter.close(); } entryWriter.close(); }
protected QName createMapQName(TypeClassInfo info, AegisType keyType, AegisType valueType) { String name = keyType.getSchemaType().getLocalPart() + '2' + valueType.getSchemaType().getLocalPart(); Class<?> cls = TypeUtil.getTypeRelatedClass(info.getType()); name += cls.getSimpleName(); // TODO: Get namespace from XML? return new QName(tm.getMappingIdentifierURI(), name); }
protected List<Element> findMappings(Type type) { Class<?> clazz = TypeUtil.getTypeClass(type, false); List<Element> mappings = new ArrayList<>(); if (clazz == null) {
/** * Insist that a Type is a parameterized type of one parameter. * This is used to decompose Holders, for example. * @param type the type * @return the parameter, or null if the type is not what we want. */ public static Type getSingleTypeParameter(Type type) { return getSingleTypeParameter(type, 0); }