use of org.qi4j.api.common.ConstructionException in project qi4j-sdk by Qi4j.
the class ActivatorModel method newInstance.
@SuppressWarnings("unchecked")
public Activator<ActivateeType> newInstance(InjectionContext injectionContext) {
try {
Activator<ActivateeType> instance = (Activator<ActivateeType>) constructorsModel.newInstance(injectionContext);
injectionContext = new InjectionContext(injectionContext.module(), injectionContext.uses(), instance);
inject(injectionContext, instance);
return instance;
} catch (Exception ex) {
throw new ConstructionException("Could not instantiate " + activatorType.getName(), ex);
}
}
use of org.qi4j.api.common.ConstructionException in project qi4j-sdk by Qi4j.
the class AbstractModifierModel method newInstance.
// Context
public InvocationHandler newInstance(ModuleInstance moduleInstance, InvocationHandler next, ProxyReferenceInvocationHandler proxyHandler, Method method) {
InjectionContext injectionContext = new InjectionContext(moduleInstance, wrapNext(next), proxyHandler);
Object modifier = constructorsModel.newInstance(injectionContext);
try {
if (FragmentClassLoader.isGenerated(modifier)) {
modifier.getClass().getField("_instance").set(modifier, proxyHandler);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
injectedFieldsModel.inject(injectionContext, modifier);
injectedMethodsModel.inject(injectionContext, modifier);
if (isGeneric()) {
return (InvocationHandler) modifier;
} else {
try {
Method invocationMethod = modifierClass.getMethod("_" + method.getName(), method.getParameterTypes());
TypedModifierInvocationHandler handler = new TypedModifierInvocationHandler();
handler.setFragment(modifier);
handler.setMethod(invocationMethod);
return handler;
} catch (NoSuchMethodException e) {
throw new ConstructionException("Could not find modifier method", e);
}
}
}
use of org.qi4j.api.common.ConstructionException in project qi4j-sdk by Qi4j.
the class MixinModel method newInstance.
public Object newInstance(InjectionContext injectionContext) {
Object mixin;
CompositeInstance compositeInstance = injectionContext.compositeInstance();
mixin = constructorsModel.newInstance(injectionContext);
if (FragmentClassLoader.isGenerated(instantiationClass)) {
try {
instantiationClass.getDeclaredField("_instance").set(mixin, injectionContext.compositeInstance());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
injectedFieldsModel.inject(injectionContext, mixin);
injectedMethodsModel.inject(injectionContext, mixin);
if (mixin instanceof Initializable) {
try {
((Initializable) mixin).initialize();
} catch (InitializationException e) {
List<Class<?>> compositeType = toList(compositeInstance.types());
String message = "Unable to initialize " + mixinClass + " in composite " + compositeType;
throw new ConstructionException(message, e);
}
}
return mixin;
}
use of org.qi4j.api.common.ConstructionException in project qi4j-sdk by Qi4j.
the class Qi4jObjectFactory method createQi4jComposite.
@SuppressWarnings("unchecked")
private Object createQi4jComposite(Class aClass, boolean isAddToTypes) {
if (compositeBuilderFactory == null) {
return null;
}
Object obj = null;
ConstructionException exception = null;
try {
obj = compositeBuilderFactory.newTransient(aClass);
} catch (NoSuchTransientException e) {
return null;
} catch (ConstructionException e) {
exception = e;
}
if (isAddToTypes) {
addToType(aClass, qi4jComposite);
}
if (exception != null) {
throw exception;
}
return obj;
}
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);
}
}
Aggregations