use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.
the class ValueEqualityTest method givenValuesOfSameTypesAndSameStateWhenTestingValueStateEqualityExpectEquals.
//
// ---------------------------------:: Value State equality tests ::------------------------------------------------
//
@Test
public void givenValuesOfSameTypesAndSameStateWhenTestingValueStateEqualityExpectEquals() {
Some some = buildSomeValue(module);
AssociationStateHolder someState = qi4j.spi().stateOf((ValueComposite) some);
Some some2 = buildSomeValue(module);
AssociationStateHolder some2State = qi4j.spi().stateOf((ValueComposite) some2);
assertThat("ValueStates equal", someState, equalTo(some2State));
assertThat("ValueStates hashcode equal", someState.hashCode(), equalTo(some2State.hashCode()));
}
use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.
the class ValueEqualityTest method givenValuesOfDifferentTypesAndSameStateWhenTestingValueStateEqualityExpectEquals.
@Test
public void givenValuesOfDifferentTypesAndSameStateWhenTestingValueStateEqualityExpectEquals() {
Some some = buildSomeValue(module);
AssociationStateHolder someState = qi4j.spi().stateOf((ValueComposite) some);
AnotherSome anotherSome = buildAnotherSomeValue(module);
AssociationStateHolder anotherSomeState = qi4j.spi().stateOf((ValueComposite) anotherSome);
assertThat("ValueStates equal", someState, equalTo(anotherSomeState));
assertThat("ValueStates hashcode equal", someState.hashCode(), equalTo(anotherSomeState.hashCode()));
}
use of org.qi4j.api.association.AssociationStateHolder 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