use of org.qi4j.api.mixin.Initializable 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.mixin.Initializable 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;
}
Aggregations