Search in sources :

Example 11 with AssociationStateHolder

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()));
}
Also used : AnotherSome(org.qi4j.runtime.property.PropertyEqualityTest.AnotherSome) Some(org.qi4j.runtime.property.PropertyEqualityTest.Some) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 12 with AssociationStateHolder

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()));
}
Also used : AnotherSome(org.qi4j.runtime.property.PropertyEqualityTest.AnotherSome) Some(org.qi4j.runtime.property.PropertyEqualityTest.Some) AnotherSome(org.qi4j.runtime.property.PropertyEqualityTest.AnotherSome) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 13 with AssociationStateHolder

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();
    }
}
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

AssociationStateHolder (org.qi4j.api.association.AssociationStateHolder)13 Test (org.junit.Test)5 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)5 CompositeInstance (org.qi4j.api.composite.CompositeInstance)4 AnotherSome (org.qi4j.runtime.property.PropertyEqualityTest.AnotherSome)4 Some (org.qi4j.runtime.property.PropertyEqualityTest.Some)4 AccessibleObject (java.lang.reflect.AccessibleObject)3 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)3 ValueComposite (org.qi4j.api.value.ValueComposite)3 ValueDescriptor (org.qi4j.api.value.ValueDescriptor)3 AssociationStateDescriptor (org.qi4j.api.association.AssociationStateDescriptor)2 Identity (org.qi4j.api.entity.Identity)2 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)2 DefaultTableModel (javax.swing.table.DefaultTableModel)1 QName (javax.xml.namespace.QName)1 AegisType (org.apache.cxf.aegis.type.AegisType)1 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)1 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)1