use of org.qi4j.api.value.NoSuchValueException in project qi4j-sdk by Qi4j.
the class ModuleInstance method newValueBuilderWithState.
@Override
public <T> ValueBuilder<T> newValueBuilderWithState(Class<T> mixinType, Function<PropertyDescriptor, Object> propertyFunction, Function<AssociationDescriptor, EntityReference> associationFunction, Function<AssociationDescriptor, Iterable<EntityReference>> manyAssociationFunction, Function<AssociationDescriptor, Map<String, EntityReference>> namedAssociationFunction) {
NullArgumentException.validateNotNull("propertyFunction", propertyFunction);
NullArgumentException.validateNotNull("associationFunction", associationFunction);
NullArgumentException.validateNotNull("manyAssociationFunction", manyAssociationFunction);
NullArgumentException.validateNotNull("namedAssociationFunction", namedAssociationFunction);
ModelModule<ValueModel> compositeModelModule = typeLookup.lookupValueModel(mixinType);
if (compositeModelModule == null) {
throw new NoSuchValueException(mixinType.getName(), name());
}
StateResolver stateResolver = new FunctionStateResolver(propertyFunction, associationFunction, manyAssociationFunction, namedAssociationFunction);
return new ValueBuilderWithState<>(compositeModelModule, this, stateResolver);
}
use of org.qi4j.api.value.NoSuchValueException in project qi4j-sdk by Qi4j.
the class ModuleInstance method newValueBuilder.
@Override
public <T> ValueBuilder<T> newValueBuilder(Class<T> mixinType) throws NoSuchValueException {
NullArgumentException.validateNotNull("mixinType", mixinType);
ModelModule<ValueModel> compositeModelModule = typeLookup.lookupValueModel(mixinType);
if (compositeModelModule == null) {
throw new NoSuchValueException(mixinType.getName(), name());
}
StateResolver stateResolver = new InitialStateResolver(compositeModelModule.module());
return new ValueBuilderInstance<>(compositeModelModule, this, stateResolver);
}
use of org.qi4j.api.value.NoSuchValueException in project qi4j-sdk by Qi4j.
the class ModuleInstance method newValueBuilderWithPrototype.
@Override
public <T> ValueBuilder<T> newValueBuilderWithPrototype(T prototype) {
NullArgumentException.validateNotNull("prototype", prototype);
ValueInstance valueInstance = ValueInstance.valueInstanceOf((ValueComposite) prototype);
Class<Composite> valueType = (Class<Composite>) first(valueInstance.types());
ModelModule<ValueModel> modelModule = typeLookup.lookupValueModel(valueType);
if (modelModule == null) {
throw new NoSuchValueException(valueType.getName(), name());
}
return new ValueBuilderWithPrototype<T>(modelModule, this, prototype);
}
use of org.qi4j.api.value.NoSuchValueException in project qi4j-sdk by Qi4j.
the class ModuleInstance method newValueFromSerializedState.
@Override
public <T> T newValueFromSerializedState(Class<T> mixinType, String serializedState) throws NoSuchValueException, ConstructionException {
NullArgumentException.validateNotNull("mixinType", mixinType);
ModelModule<ValueModel> modelModule = typeLookup.lookupValueModel(mixinType);
if (modelModule == null) {
throw new NoSuchValueException(mixinType.getName(), name());
}
try {
return valueSerialization().deserialize(modelModule.model().valueType(), serializedState);
} catch (ValueSerializationException ex) {
throw new ConstructionException("Could not create value from serialized state", ex);
}
}
Aggregations