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