use of org.qi4j.bootstrap.BindingException in project qi4j-sdk by Qi4j.
the class MixinsModel method bind.
// Binding
@Override
public void bind(final Resolution resolution) throws BindingException {
// Order mixins based on @This usages
UsageGraph<MixinModel> deps = new UsageGraph<MixinModel>(mixinModels, new Uses(), true);
mixinModels = deps.resolveOrder();
// Populate mappings
for (int i = 0; i < mixinModels.size(); i++) {
MixinModel mixinModel = mixinModels.get(i);
mixinIndex.put(mixinModel.mixinClass(), i);
}
for (Map.Entry<Method, MixinModel> methodClassEntry : methodImplementation.entrySet()) {
methodIndex.put(methodClassEntry.getKey(), mixinIndex.get(methodClassEntry.getValue().mixinClass()));
}
for (MixinModel mixinModel : mixinModels) {
mixinModel.accept(new HierarchicalVisitorAdapter<Object, Object, BindingException>() {
@Override
public boolean visitEnter(Object visited) throws BindingException {
if (visited instanceof InjectedFieldModel) {
InjectedFieldModel fieldModel = (InjectedFieldModel) visited;
fieldModel.bind(resolution.forField(fieldModel.field()));
return false;
} else if (visited instanceof Binder) {
Binder constructorsModel = (Binder) visited;
constructorsModel.bind(resolution);
return false;
}
return true;
}
@Override
public boolean visit(Object visited) throws BindingException {
if (visited instanceof Binder) {
((Binder) visited).bind(resolution);
}
return true;
}
});
}
}
use of org.qi4j.bootstrap.BindingException in project qi4j-sdk by Qi4j.
the class ApplicationModelFactoryImpl method newApplicationModel.
@Override
public ApplicationDescriptor newApplicationModel(ApplicationAssembly assembly) throws AssemblyException {
AssemblyHelper helper = new AssemblyHelper();
ApplicationAssemblyImpl applicationAssembly = (ApplicationAssemblyImpl) assembly;
ActivatorsModel<Application> applicationActivators = new ActivatorsModel<>(applicationAssembly.activators());
List<LayerModel> layerModels = new ArrayList<>();
final ApplicationModel applicationModel = new ApplicationModel(applicationAssembly.name(), applicationAssembly.version(), applicationAssembly.mode(), applicationAssembly.metaInfo(), applicationActivators, layerModels);
Map<LayerAssembly, LayerModel> mapAssemblyModel = new HashMap<>();
Map<LayerAssembly, List<LayerModel>> mapUsedLayers = new HashMap<>();
// Build all layers
List<LayerAssemblyImpl> layerAssemblies = new ArrayList<>(applicationAssembly.layerAssemblies());
for (LayerAssemblyImpl layerAssembly : layerAssemblies) {
List<LayerModel> usedLayers = new ArrayList<>();
mapUsedLayers.put(layerAssembly, usedLayers);
UsedLayersModel usedLayersModel = new UsedLayersModel(usedLayers);
List<ModuleModel> moduleModels = new ArrayList<>();
String name = layerAssembly.name();
if (name == null) {
throw new AssemblyException("Layer must have name set");
}
ActivatorsModel<Layer> layerActivators = new ActivatorsModel<>(layerAssembly.activators());
LayerModel layerModel = new LayerModel(name, layerAssembly.metaInfo(), usedLayersModel, layerActivators, moduleModels);
for (ModuleAssemblyImpl moduleAssembly : layerAssembly.moduleAssemblies()) {
moduleModels.add(moduleAssembly.assembleModule(helper));
}
mapAssemblyModel.put(layerAssembly, layerModel);
layerModels.add(layerModel);
}
// Populate used layer lists
for (LayerAssemblyImpl layerAssembly : layerAssemblies) {
Set<LayerAssembly> usesLayers = layerAssembly.uses();
List<LayerModel> usedLayers = mapUsedLayers.get(layerAssembly);
for (LayerAssembly usesLayer : usesLayers) {
LayerModel layerModel = mapAssemblyModel.get(usesLayer);
usedLayers.add(layerModel);
}
}
// This will resolve all dependencies
try {
// applicationModel.bind();
applicationModel.accept(new BindingVisitor(applicationModel));
} catch (BindingException e) {
throw new AssemblyException("Unable to bind: " + applicationModel, e);
}
return applicationModel;
}
Aggregations