Search in sources :

Example 6 with ConstructionException

use of org.qi4j.api.common.ConstructionException 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)

Example 7 with ConstructionException

use of org.qi4j.api.common.ConstructionException in project qi4j-sdk by Qi4j.

the class ObjectModel method newInstance.

public Object newInstance(InjectionContext injectionContext) {
    Object instance;
    try {
        instance = constructorsModel.newInstance(injectionContext);
        injectionContext = new InjectionContext(injectionContext.module(), injectionContext.uses(), instance);
        injectedFieldsModel.inject(injectionContext, instance);
        injectedMethodsModel.inject(injectionContext, instance);
    } catch (Exception e) {
        throw new ConstructionException("Could not instantiate " + objectType.getName(), e);
    }
    if (instance instanceof Initializable) {
        try {
            ((Initializable) instance).initialize();
        } catch (InitializationException e) {
            throw new ConstructionException("Unable to initialize " + objectType, e);
        }
    }
    return instance;
}
Also used : Initializable(org.qi4j.api.mixin.Initializable) ConstructionException(org.qi4j.api.common.ConstructionException) InitializationException(org.qi4j.api.mixin.InitializationException) ConstructionException(org.qi4j.api.common.ConstructionException) InitializationException(org.qi4j.api.mixin.InitializationException) InjectionContext(org.qi4j.runtime.injection.InjectionContext)

Example 8 with ConstructionException

use of org.qi4j.api.common.ConstructionException 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);
    }
}
Also used : PropertyDescriptor(org.qi4j.api.property.PropertyDescriptor) EntityAlreadyExistsException(org.qi4j.spi.entitystore.EntityAlreadyExistsException) EntityState(org.qi4j.spi.entity.EntityState) EntityStoreException(org.qi4j.spi.entitystore.EntityStoreException) ConstructionException(org.qi4j.api.common.ConstructionException) EntityCompositeAlreadyExistsException(org.qi4j.api.unitofwork.EntityCompositeAlreadyExistsException)

Example 9 with ConstructionException

use of org.qi4j.api.common.ConstructionException in project qi4j-sdk by Qi4j.

the class CompositeConstraintModel method newInstance.

@Override
@SuppressWarnings({ "raw", "unchecked" })
public ConstraintInstance<?, ?> newInstance() {
    try {
        ValueConstraintsInstance compositeConstraintsInstance = constraintsModel.newInstance();
        Constraint<?, ?> constraint = new CompositeConstraintInstance(compositeConstraintsInstance);
        return new ConstraintInstance(constraint, annotation);
    } catch (Exception e) {
        throw new ConstructionException("Could not instantiate constraint implementation", e);
    }
}
Also used : ConstructionException(org.qi4j.api.common.ConstructionException) ConstructionException(org.qi4j.api.common.ConstructionException)

Example 10 with ConstructionException

use of org.qi4j.api.common.ConstructionException in project qi4j-sdk by Qi4j.

the class CompositeModel method newProxy.

public Composite newProxy(InvocationHandler invocationHandler) throws ConstructionException {
    Class<?> mainType = first(types());
    if (mainType.isInterface()) {
        try {
            return Composite.class.cast(proxyConstructor.newInstance(invocationHandler));
        } catch (Exception e) {
            throw new ConstructionException(e);
        }
    } else {
        try {
            Object[] args = new Object[proxyConstructor.getParameterTypes().length];
            Composite composite = Composite.class.cast(proxyConstructor.newInstance(args));
            proxyClass.getField("_instance").set(composite, invocationHandler);
            return composite;
        } catch (Exception e) {
            throw new ConstructionException(e);
        }
    }
}
Also used : Composite(org.qi4j.api.composite.Composite) ConstructionException(org.qi4j.api.common.ConstructionException) ConstructionException(org.qi4j.api.common.ConstructionException) InvalidCompositeException(org.qi4j.api.composite.InvalidCompositeException)

Aggregations

ConstructionException (org.qi4j.api.common.ConstructionException)11 InjectionContext (org.qi4j.runtime.injection.InjectionContext)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 Initializable (org.qi4j.api.mixin.Initializable)2 InitializationException (org.qi4j.api.mixin.InitializationException)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 Activator (org.qi4j.api.activation.Activator)1 Composite (org.qi4j.api.composite.Composite)1 CompositeInstance (org.qi4j.api.composite.CompositeInstance)1 InvalidCompositeException (org.qi4j.api.composite.InvalidCompositeException)1 NoSuchTransientException (org.qi4j.api.composite.NoSuchTransientException)1 NoSuchObjectException (org.qi4j.api.object.NoSuchObjectException)1 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)1 EntityCompositeAlreadyExistsException (org.qi4j.api.unitofwork.EntityCompositeAlreadyExistsException)1 NoSuchValueException (org.qi4j.api.value.NoSuchValueException)1 ValueSerializationException (org.qi4j.api.value.ValueSerializationException)1 Iterables.toList (org.qi4j.functional.Iterables.toList)1 FragmentClassLoader (org.qi4j.runtime.composite.FragmentClassLoader)1 ValueModel (org.qi4j.runtime.value.ValueModel)1