Search in sources :

Example 6 with AegisType

use of org.apache.cxf.aegis.type.AegisType in project qi4j-sdk by Qi4j.

the class ValueCompositeCxfType method writeObject.

@Override
public void writeObject(Object object, final MessageWriter writer, final Context context) throws DatabindingException {
    ValueComposite composite = (ValueComposite) object;
    writer.writeXsiType(NamespaceUtil.convertJavaTypeToQName(first(Qi4j.FUNCTION_DESCRIPTOR_FOR.map(composite).types())));
    AssociationStateHolder state = spi.stateOf(composite);
    for (Property<?> property : state.properties()) {
        Object value = property.get();
        AegisType type = null;
        if (value instanceof ValueComposite) {
            ValueComposite compositeValue = (ValueComposite) value;
            type = getTypeMapping().getType(NamespaceUtil.convertJavaTypeToQName(first(Qi4j.FUNCTION_DESCRIPTOR_FOR.map(compositeValue).types())));
        } else if (value != null) {
            type = getOrCreateNonQi4jType(value);
        }
        QName childName = new QName("", spi.propertyDescriptorFor(property).qualifiedName().name());
        MessageWriter cwriter = writer.getElementWriter(childName);
        if (type != null) {
            type.writeObject(value, cwriter, context);
        } else {
        //                    cwriter.writeXsiNil();
        }
        cwriter.close();
    }
    AegisType type = getTypeMapping().getType(NamespaceUtil.convertJavaTypeToQName(String.class));
    for (Association<?> association : state.allAssociations()) {
        QName childName = new QName("", spi.associationDescriptorFor(association).qualifiedName().name());
        MessageWriter cwriter = writer.getElementWriter(childName);
        if (association.get() != null) {
            type.writeObject(((Identity) association.get()).identity().get(), cwriter, context);
        }
        cwriter.close();
    }
    for (ManyAssociation<?> association : state.allManyAssociations()) {
        QName childName = new QName("", spi.associationDescriptorFor(association).qualifiedName().name());
        MessageWriter cwriter = writer.getElementWriter(childName);
        String ids = null;
        for (Object entity : association) {
            String id = EntityReference.entityReferenceFor(entity).identity();
            if (ids != null) {
                ids += ",";
            }
            ids += id;
        }
        if (ids == null) {
            ids = "";
        }
        type.writeObject(ids, cwriter, context);
        cwriter.close();
    }
    for (NamedAssociation<?> association : state.allNamedAssociations()) {
        QName childName = new QName("", spi.associationDescriptorFor(association).qualifiedName().name());
        MessageWriter cwriter = writer.getElementWriter(childName);
        String ids = null;
        for (String name : association) {
            String id = EntityReference.entityReferenceFor(association.get(name)).identity();
            if (ids != null) {
                ids += ",";
            }
            ids += name + ":" + id;
        }
        if (ids == null) {
            ids = "";
        }
        type.writeObject(ids, cwriter, context);
        cwriter.close();
    }
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) MessageWriter(org.apache.cxf.aegis.xml.MessageWriter) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder) Identity(org.qi4j.api.entity.Identity) ValueComposite(org.qi4j.api.value.ValueComposite)

Aggregations

AegisType (org.apache.cxf.aegis.type.AegisType)6 QName (javax.xml.namespace.QName)4 CollectionType (org.apache.cxf.aegis.type.collection.CollectionType)2 MapType (org.apache.cxf.aegis.type.collection.MapType)2 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)2 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)2 ValueDescriptor (org.qi4j.api.value.ValueDescriptor)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)1 MessageReader (org.apache.cxf.aegis.xml.MessageReader)1 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)1 XmlSchemaAttribute (org.apache.ws.commons.schema.XmlSchemaAttribute)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)1 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)1