use of org.apache.cxf.aegis.xml.MessageWriter 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();
}
}
Aggregations