Search in sources :

Example 1 with ActivatorsModel

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;
}
Also used : LayerModel(org.qi4j.runtime.structure.LayerModel) UsedLayersModel(org.qi4j.runtime.structure.UsedLayersModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationModel(org.qi4j.runtime.structure.ApplicationModel) ModuleModel(org.qi4j.runtime.structure.ModuleModel) AssemblyException(org.qi4j.bootstrap.AssemblyException) ArrayList(java.util.ArrayList) List(java.util.List) ActivatorsModel(org.qi4j.runtime.activation.ActivatorsModel) Layer(org.qi4j.api.structure.Layer) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) BindingException(org.qi4j.bootstrap.BindingException) Application(org.qi4j.api.structure.Application)

Example 2 with ActivatorsModel

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);
    }
}
Also used : ImportedServiceModel(org.qi4j.runtime.service.ImportedServiceModel) ActivatorsModel(org.qi4j.runtime.activation.ActivatorsModel) MetaInfo(org.qi4j.api.common.MetaInfo) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Example 3 with ActivatorsModel

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);
    }
}
Also used : Activator(org.qi4j.api.activation.Activator) ServiceModel(org.qi4j.runtime.service.ServiceModel) ActivatorsModel(org.qi4j.runtime.activation.ActivatorsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Aggregations

ActivatorsModel (org.qi4j.runtime.activation.ActivatorsModel)3 InvalidApplicationException (org.qi4j.api.common.InvalidApplicationException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Activator (org.qi4j.api.activation.Activator)1 MetaInfo (org.qi4j.api.common.MetaInfo)1 Application (org.qi4j.api.structure.Application)1 Layer (org.qi4j.api.structure.Layer)1 AssemblyException (org.qi4j.bootstrap.AssemblyException)1 BindingException (org.qi4j.bootstrap.BindingException)1 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)1 ImportedServiceModel (org.qi4j.runtime.service.ImportedServiceModel)1 ServiceModel (org.qi4j.runtime.service.ServiceModel)1 ApplicationModel (org.qi4j.runtime.structure.ApplicationModel)1 LayerModel (org.qi4j.runtime.structure.LayerModel)1 ModuleModel (org.qi4j.runtime.structure.ModuleModel)1 UsedLayersModel (org.qi4j.runtime.structure.UsedLayersModel)1