use of org.qi4j.runtime.activation.ActivatorsModel 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<Application>(applicationAssembly.activators());
List<LayerModel> layerModels = new ArrayList<LayerModel>();
final ApplicationModel applicationModel = new ApplicationModel(applicationAssembly.name(), applicationAssembly.version(), applicationAssembly.mode(), applicationAssembly.metaInfo(), applicationActivators, layerModels);
Map<LayerAssembly, LayerModel> mapAssemblyModel = new HashMap<LayerAssembly, LayerModel>();
Map<LayerAssembly, List<LayerModel>> mapUsedLayers = new HashMap<LayerAssembly, List<LayerModel>>();
// Build all layers
List<LayerAssemblyImpl> layerAssemblies = new ArrayList<LayerAssemblyImpl>(applicationAssembly.layerAssemblies());
for (LayerAssemblyImpl layerAssembly : layerAssemblies) {
List<LayerModel> usedLayers = new ArrayList<LayerModel>();
mapUsedLayers.put(layerAssembly, usedLayers);
UsedLayersModel usedLayersModel = new UsedLayersModel(usedLayers);
List<ModuleModel> moduleModels = new ArrayList<ModuleModel>();
String name = layerAssembly.name();
if (name == null) {
throw new AssemblyException("Layer must have name set");
}
ActivatorsModel<Layer> layerActivators = new ActivatorsModel<Layer>(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;
}
use of org.qi4j.runtime.activation.ActivatorsModel in project qi4j-sdk by Qi4j.
the class ImportedServiceAssemblyImpl method addImportedServiceModel.
void addImportedServiceModel(List<ImportedServiceModel> serviceModels) {
try {
String id = identity;
if (id == null) {
id = generateId(serviceModels, serviceType);
}
ImportedServiceModel serviceModel = new ImportedServiceModel(serviceType, visibility, serviceProvider, id, importOnStartup, new MetaInfo(metaInfo).withAnnotations(serviceType), new ActivatorsModel(activators), moduleAssembly.name());
serviceModels.add(serviceModel);
} catch (Exception e) {
throw new InvalidApplicationException("Could not register " + serviceType.getName(), e);
}
}
use of org.qi4j.runtime.activation.ActivatorsModel in project qi4j-sdk by Qi4j.
the class ServiceAssemblyImpl method newServiceModel.
ServiceModel newServiceModel(StateDeclarations stateDeclarations, AssemblyHelper helper) {
try {
buildComposite(helper, stateDeclarations);
List<Class<? extends Activator<?>>> activatorClasses = Iterables.toList(Iterables.<Class<? extends Activator<?>>>flatten(activators, activatorsDeclarations(types)));
return new ServiceModel(types, visibility, metaInfo, new ActivatorsModel(activatorClasses), mixinsModel, stateModel, compositeMethodsModel, identity, instantiateOnStartup);
} catch (Exception e) {
throw new InvalidApplicationException("Could not register " + types, e);
}
}
Aggregations