Search in sources :

Example 1 with AssociationStateHolder

use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.

the class ValueSerializerAdapter method serializeValueComposite.

private void serializeValueComposite(Options options, Object object, OutputType output, boolean rootPass) throws Exception {
    CompositeInstance valueInstance = Qi4j.FUNCTION_COMPOSITE_INSTANCE_OF.map((ValueComposite) object);
    ValueDescriptor descriptor = (ValueDescriptor) valueInstance.descriptor();
    AssociationStateHolder state = (AssociationStateHolder) valueInstance.state();
    onObjectStart(output);
    if (options.getBoolean(Options.INCLUDE_TYPE_INFO) && !rootPass) {
        onFieldStart(output, "_type");
        onValueStart(output);
        onValue(output, first(descriptor.valueType().types()).getName());
        onValueEnd(output);
        onFieldEnd(output);
    }
    for (PropertyDescriptor persistentProperty : descriptor.valueType().properties()) {
        Property<?> property = state.propertyFor(persistentProperty.accessor());
        onFieldStart(output, persistentProperty.qualifiedName().name());
        onValueStart(output);
        doSerialize(options, property.get(), output, false);
        onValueEnd(output);
        onFieldEnd(output);
    }
    for (AssociationDescriptor associationDescriptor : descriptor.valueType().associations()) {
        Association<?> association = state.associationFor(associationDescriptor.accessor());
        Object instance = association.get();
        onFieldStart(output, associationDescriptor.qualifiedName().name());
        onValueStart(output);
        if (instance == null) {
            onValue(output, null);
        } else {
            onValue(output, ((Identity) instance).identity().get());
        }
        onValueEnd(output);
        onFieldEnd(output);
    }
    for (AssociationDescriptor associationDescriptor : descriptor.valueType().manyAssociations()) {
        ManyAssociation<?> manyAssociation = state.manyAssociationFor(associationDescriptor.accessor());
        onFieldStart(output, associationDescriptor.qualifiedName().name());
        onValueStart(output);
        onArrayStart(output);
        for (Object instance : manyAssociation) {
            onValueStart(output);
            onValue(output, ((Identity) instance).identity().get());
            onValueEnd(output);
        }
        onArrayEnd(output);
        onValueEnd(output);
        onFieldEnd(output);
    }
    for (AssociationDescriptor associationDescriptor : descriptor.valueType().namedAssociations()) {
        NamedAssociation<?> namedAssociation = state.namedAssociationFor(associationDescriptor.accessor());
        onFieldStart(output, associationDescriptor.qualifiedName().name());
        onValueStart(output);
        onObjectStart(output);
        for (String name : namedAssociation) {
            onFieldStart(output, name);
            onValueStart(output);
            onValue(output, ((Identity) namedAssociation.get(name)).identity().get());
            onValueEnd(output);
            onFieldEnd(output);
        }
        onObjectEnd(output);
        onValueEnd(output);
        onFieldEnd(output);
    }
    onObjectEnd(output);
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) CompositeInstance(org.qi4j.api.composite.CompositeInstance) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) Identity(org.qi4j.api.entity.Identity)

Example 2 with AssociationStateHolder

use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.

the class ValueToEntityMixin method update.

@Override
public void update(Object entity, Object value) throws NoSuchEntityException {
    EntityComposite eComposite = (EntityComposite) entity;
    ValueComposite vComposite = (ValueComposite) value;
    EntityDescriptor eDesc = spi.entityDescriptorFor(eComposite);
    AssociationStateHolder eState = spi.stateOf(eComposite);
    AssociationStateDescriptor eStateDesc = eDesc.state();
    ValueDescriptor vDesc = spi.valueDescriptorFor(vComposite);
    AssociationStateHolder vState = spi.stateOf(vComposite);
    AssociationStateDescriptor vStateDesc = vDesc.state();
    Unqualified unqualified = vDesc.metaInfo(Unqualified.class);
    if (unqualified == null || !unqualified.value()) {
        doQualifiedUpdate(eState, eStateDesc, vState, vStateDesc);
    } else {
        doUnQualifiedUpdate(eState, eStateDesc, vState, vStateDesc);
    }
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) EntityComposite(org.qi4j.api.entity.EntityComposite) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder) ValueComposite(org.qi4j.api.value.ValueComposite) AssociationStateDescriptor(org.qi4j.api.association.AssociationStateDescriptor)

Example 3 with AssociationStateHolder

use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.

the class ValueToEntityMixin method doConversion.

private <T> EntityBuilder<?> doConversion(Class<T> entityType, String identity, Object value) {
    EntityDescriptor eDesc = module.entityDescriptor(entityType.getName());
    if (eDesc == null) {
        throw new EntityTypeNotFoundException(entityType.getName());
    }
    ValueComposite vComposite = (ValueComposite) value;
    ValueDescriptor vDesc = spi.valueDescriptorFor(vComposite);
    AssociationStateHolder vState = spi.stateOf(vComposite);
    AssociationStateDescriptor vStateDesc = vDesc.state();
    Unqualified unqualified = vDesc.metaInfo(Unqualified.class);
    if (unqualified == null || !unqualified.value()) {
        return doQualifiedConversion(entityType, identity, vState, vStateDesc);
    }
    return doUnqualifiedConversion(entityType, identity, vState, vStateDesc);
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) EntityTypeNotFoundException(org.qi4j.api.unitofwork.EntityTypeNotFoundException) ValueDescriptor(org.qi4j.api.value.ValueDescriptor) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder) ValueComposite(org.qi4j.api.value.ValueComposite) AssociationStateDescriptor(org.qi4j.api.association.AssociationStateDescriptor)

Example 4 with AssociationStateHolder

use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.

the class ValueEqualityTest method givenValuesOfDifferentTypesAndDifferentStateWhenTestingValueStateEqualityExpectNotEquals.

@Test
public void givenValuesOfDifferentTypesAndDifferentStateWhenTestingValueStateEqualityExpectNotEquals() {
    Some some = buildSomeValue(module);
    AssociationStateHolder someState = qi4j.spi().stateOf((ValueComposite) some);
    AnotherSome anotherSome = buildAnotherSomeValueWithDifferentState(module);
    AssociationStateHolder anotherSomeState = qi4j.spi().stateOf((ValueComposite) anotherSome);
    assertThat("ValueStates not equal", someState, not(equalTo(anotherSomeState)));
    assertThat("ValueStates hashcode not equal", someState.hashCode(), not(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 5 with AssociationStateHolder

use of org.qi4j.api.association.AssociationStateHolder in project qi4j-sdk by Qi4j.

the class PropertiesPanel method createData.

/**
 * Create table table or properties using the supplied query
 *
 * @param query the Query
 *
 * @return TableModel
 */
protected TableModel createData(Query query) {
    DefaultTableModel model = new DefaultTableModel();
    for (Object qObj : query) {
        AssociationStateHolder state = qi4jspi.stateOf((EntityComposite) qObj);
        EntityDescriptor descriptor = qi4jspi.entityDescriptorFor((EntityComposite) qObj);
        // genereate column, first time only
        if (model.getColumnCount() < 1) {
            for (PropertyDescriptor persistentPropertyDescriptor : descriptor.state().properties()) {
                model.addColumn(persistentPropertyDescriptor.qualifiedName().name());
            }
        }
        Object[] rowData = new Object[model.getColumnCount()];
        int i = 0;
        for (PropertyDescriptor persistentPropertyDescriptor : descriptor.state().properties()) {
            rowData[i++] = state.propertyFor(persistentPropertyDescriptor.accessor());
        }
        model.addRow(rowData);
    }
    return model;
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) DefaultTableModel(javax.swing.table.DefaultTableModel) AssociationStateHolder(org.qi4j.api.association.AssociationStateHolder)

Aggregations

AssociationStateHolder (org.qi4j.api.association.AssociationStateHolder)14 Test (org.junit.Test)5 CompositeInstance (org.qi4j.api.composite.CompositeInstance)5 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)5 ValueDescriptor (org.qi4j.api.value.ValueDescriptor)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 Identity (org.qi4j.api.entity.Identity)3 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)3 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)2 AssociationStateDescriptor (org.qi4j.api.association.AssociationStateDescriptor)2 ValueComposite (org.qi4j.api.value.ValueComposite)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 Association (org.qi4j.api.association.Association)1 ManyAssociation (org.qi4j.api.association.ManyAssociation)1