Search in sources :

Example 1 with ValueBuilderWithPrototype

use of org.qi4j.runtime.value.ValueBuilderWithPrototype in project qi4j-sdk by Qi4j.

the class ModuleInstance method newValueBuilderWithPrototype.

@Override
@SuppressWarnings("unchecked")
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<>(modelModule, this, prototype);
}
Also used : NoSuchValueException(org.qi4j.api.value.NoSuchValueException) Composite(org.qi4j.api.composite.Composite) ValueComposite(org.qi4j.api.value.ValueComposite) EntityComposite(org.qi4j.api.entity.EntityComposite) ValueModel(org.qi4j.runtime.value.ValueModel) ValueBuilderWithPrototype(org.qi4j.runtime.value.ValueBuilderWithPrototype) ValueInstance(org.qi4j.runtime.value.ValueInstance)

Aggregations

Composite (org.qi4j.api.composite.Composite)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 NoSuchValueException (org.qi4j.api.value.NoSuchValueException)1 ValueComposite (org.qi4j.api.value.ValueComposite)1 ValueBuilderWithPrototype (org.qi4j.runtime.value.ValueBuilderWithPrototype)1 ValueInstance (org.qi4j.runtime.value.ValueInstance)1 ValueModel (org.qi4j.runtime.value.ValueModel)1