use of org.qi4j.api.property.PropertyDescriptor in project qi4j-sdk by Qi4j.
the class StateInjectionProviderFactory method newInjectionProvider.
@Override
public InjectionProvider newInjectionProvider(Resolution resolution, DependencyModel dependencyModel) throws InvalidInjectionException {
if (StateHolder.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State StateHolder properties;
return new StateInjectionProvider();
} else if (UnitOfWork.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
if (!(resolution.model() instanceof EntityDescriptor)) {
throw new InvalidInjectionException("Only EntityComposites can be injected with '@State UnitOfWork'");
}
return new UnitOfWorkInjectionProvider();
} else if (Property.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State Property<String> name;
StateDescriptor descriptor;
descriptor = ((StatefulCompositeDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
PropertyDescriptor propertyDescriptor = descriptor.findPropertyModelByName(name);
return new PropertyInjectionProvider(propertyDescriptor);
} else if (Association.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State Association<MyEntity> name;
AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
AssociationDescriptor model = descriptor.getAssociationByName(name);
return new AssociationInjectionProvider(model);
} else if (ManyAssociation.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State ManyAssociation<MyEntity> name;
AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
AssociationDescriptor model = descriptor.getManyAssociationByName(name);
return new ManyAssociationInjectionProvider(model);
} else if (NamedAssociation.class.isAssignableFrom(dependencyModel.rawInjectionType())) {
// @State NamedAssociation<MyEntity> name;
AssociationStateDescriptor descriptor = ((EntityDescriptor) resolution.model()).state();
State annotation = (State) dependencyModel.injectionAnnotation();
String name;
if (annotation.value().isEmpty()) {
name = resolution.field().getName();
} else {
name = annotation.value();
}
AssociationDescriptor model = descriptor.getNamedAssociationByName(name);
return new NamedAssociationInjectionProvider(model);
}
throw new InjectionProviderException("Injected value has invalid type");
}
use of org.qi4j.api.property.PropertyDescriptor in project qi4j-sdk by Qi4j.
the class EntityModel method newEntityState.
public EntityState newEntityState(EntityStoreUnitOfWork store, EntityReference identity) throws ConstraintViolationException, EntityStoreException {
try {
// New EntityState
EntityState entityState = store.newEntityState(identity, this);
// Set identity property
PropertyDescriptor persistentPropertyDescriptor = state().propertyModelFor(IDENTITY_METHOD);
entityState.setPropertyValue(persistentPropertyDescriptor.qualifiedName(), identity.identity());
return entityState;
} catch (EntityAlreadyExistsException e) {
throw new EntityCompositeAlreadyExistsException(identity);
} catch (EntityStoreException e) {
throw new ConstructionException("Could not create new entity in store", e);
}
}
use of org.qi4j.api.property.PropertyDescriptor in project qi4j-sdk by Qi4j.
the class EntityStateInstance method checkConstraints.
public void checkConstraints() {
for (PropertyDescriptor propertyDescriptor : stateModel.properties()) {
ConstraintsCheck constraints = (ConstraintsCheck) propertyDescriptor;
Property<Object> property = this.propertyFor(propertyDescriptor.accessor());
constraints.checkConstraints(property.get());
}
for (AssociationDescriptor associationDescriptor : stateModel.associations()) {
ConstraintsCheck constraints = (ConstraintsCheck) associationDescriptor;
Association<Object> association = this.associationFor(associationDescriptor.accessor());
constraints.checkConstraints(association.get());
}
// TODO Should ManyAssociations be checked too?
}
use of org.qi4j.api.property.PropertyDescriptor in project qi4j-sdk by Qi4j.
the class Qi4jSPITest method validateState.
private void validateState(AssociationStateHolder state, EntityDescriptor entityDescriptor) {
for (PropertyDescriptor propertyDescriptor : entityDescriptor.state().properties()) {
Property<?> prop = state.propertyFor(propertyDescriptor.accessor());
assertThat("Properties could be listed", prop, CoreMatchers.notNullValue());
}
AssociationStateDescriptor descriptor = entityDescriptor.state();
for (AssociationDescriptor associationDescriptor : descriptor.associations()) {
AbstractAssociation assoc = state.associationFor(associationDescriptor.accessor());
assertThat("Assocs could be listed", assoc, CoreMatchers.notNullValue());
}
}
use of org.qi4j.api.property.PropertyDescriptor in project qi4j-sdk by Qi4j.
the class PropertyEqualityTest method givenValuesOfTheSameTypeWhenTestingPropertyDescriptorEqualityExpectEquals.
//
// ------------------------------:: PropertyDescriptor equality tests ::--------------------------------------------
//
@Test
public void givenValuesOfTheSameTypeWhenTestingPropertyDescriptorEqualityExpectEquals() {
Some some = buildSomeValue(module);
ValueDescriptor someDescriptor = qi4j.api().valueDescriptorFor(some);
PropertyDescriptor someCharPropDesc = someDescriptor.state().findPropertyModelByName("characterProperty");
Some other = buildSomeValue(module);
ValueDescriptor otherDescriptor = qi4j.api().valueDescriptorFor(other);
PropertyDescriptor otherCharPropDesc = otherDescriptor.state().findPropertyModelByName("characterProperty");
assertThat("PropertyDescriptors equal", someCharPropDesc, equalTo(otherCharPropDesc));
assertThat("PropertyDescriptors hashcode equal", someCharPropDesc.hashCode(), equalTo(otherCharPropDesc.hashCode()));
}
Aggregations