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