Search in sources :

Example 1 with NoSuchValueException

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);
}
Also used : NoSuchValueException(org.qi4j.api.value.NoSuchValueException) ValueModel(org.qi4j.runtime.value.ValueModel) ValueBuilderWithState(org.qi4j.runtime.value.ValueBuilderWithState) FunctionStateResolver(org.qi4j.runtime.composite.FunctionStateResolver) StateResolver(org.qi4j.runtime.composite.StateResolver) FunctionStateResolver(org.qi4j.runtime.composite.FunctionStateResolver)

Example 2 with NoSuchValueException

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);
}
Also used : ValueBuilderInstance(org.qi4j.runtime.value.ValueBuilderInstance) NoSuchValueException(org.qi4j.api.value.NoSuchValueException) ValueModel(org.qi4j.runtime.value.ValueModel) FunctionStateResolver(org.qi4j.runtime.composite.FunctionStateResolver) StateResolver(org.qi4j.runtime.composite.StateResolver)

Example 3 with NoSuchValueException

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

Example 4 with NoSuchValueException

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);
    }
}
Also used : NoSuchValueException(org.qi4j.api.value.NoSuchValueException) ValueModel(org.qi4j.runtime.value.ValueModel) ValueSerializationException(org.qi4j.api.value.ValueSerializationException) ConstructionException(org.qi4j.api.common.ConstructionException)

Aggregations

NoSuchValueException (org.qi4j.api.value.NoSuchValueException)4 ValueModel (org.qi4j.runtime.value.ValueModel)4 FunctionStateResolver (org.qi4j.runtime.composite.FunctionStateResolver)2 StateResolver (org.qi4j.runtime.composite.StateResolver)2 ConstructionException (org.qi4j.api.common.ConstructionException)1 Composite (org.qi4j.api.composite.Composite)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 ValueComposite (org.qi4j.api.value.ValueComposite)1 ValueSerializationException (org.qi4j.api.value.ValueSerializationException)1 ValueBuilderInstance (org.qi4j.runtime.value.ValueBuilderInstance)1 ValueBuilderWithPrototype (org.qi4j.runtime.value.ValueBuilderWithPrototype)1 ValueBuilderWithState (org.qi4j.runtime.value.ValueBuilderWithState)1 ValueInstance (org.qi4j.runtime.value.ValueInstance)1