Search in sources :

Example 1 with LayerAssembly

use of org.qi4j.bootstrap.LayerAssembly in project qi4j-sdk by Qi4j.

the class ApplicationBuilder method newApplication.

/**
     * Create and activate a new Application.
     * @return Activated Application
     * @throws AssemblyException if the assembly failed
     * @throws ActivationException if the activation failed
     */
public Application newApplication() throws AssemblyException, ActivationException {
    Energy4Java qi4j = new Energy4Java();
    ApplicationDescriptor model = qi4j.newApplicationModel(new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory factory) throws AssemblyException {
            ApplicationAssembly assembly = factory.newApplicationAssembly();
            assembly.setName(applicationName);
            HashMap<String, LayerAssembly> createdLayers = new HashMap<>();
            for (Map.Entry<String, LayerDeclaration> entry : layers.entrySet()) {
                LayerAssembly layer = entry.getValue().createLayer(assembly);
                createdLayers.put(entry.getKey(), layer);
            }
            for (LayerDeclaration layer : layers.values()) {
                layer.initialize(createdLayers);
            }
            return assembly;
        }
    });
    Application application = model.newInstance(qi4j.api());
    for (ActivationEventListener activationListener : activationListeners) {
        application.registerActivationEventListener(activationListener);
    }
    beforeActivation();
    application.activate();
    afterActivation();
    return application;
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) HashMap(java.util.HashMap) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ActivationEventListener(org.qi4j.api.activation.ActivationEventListener) Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application)

Example 2 with LayerAssembly

use of org.qi4j.bootstrap.LayerAssembly in project qi4j-sdk by Qi4j.

the class ApplicationDocs method createWebLayer.

private static LayerAssembly createWebLayer(ApplicationAssembly application) {
    LayerAssembly layer = application.layer("Web Layer");
    createCustomerWebModule(layer);
    return layer;
}
Also used : LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Example 3 with LayerAssembly

use of org.qi4j.bootstrap.LayerAssembly 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;
}
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 4 with LayerAssembly

use of org.qi4j.bootstrap.LayerAssembly in project qi4j-sdk by Qi4j.

the class StructureTest method createApplicationUsingApplicationAssembly.

@Test
public void createApplicationUsingApplicationAssembly() throws AssemblyException {
    Energy4Java boot = new Energy4Java();
    boot.newApplication(new ApplicationAssembler() {

        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            ApplicationAssembly applicationAssembly = applicationFactory.newApplicationAssembly();
            // Application Layer
            LayerAssembly applicationLayer = applicationAssembly.layer("Application");
            ModuleAssembly applicationModule = applicationLayer.module("Application");
            new DomainApplicationAssembler().assemble(applicationModule);
            // View Layer
            LayerAssembly viewLayer = applicationAssembly.layer("View");
            ModuleAssembly viewModule = viewLayer.module("View");
            new ViewAssembler().assemble(viewModule);
            viewLayer.uses(applicationLayer);
            return applicationAssembly;
        }
    });
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) Test(org.junit.Test)

Example 5 with LayerAssembly

use of org.qi4j.bootstrap.LayerAssembly in project qi4j-sdk by Qi4j.

the class AbstractQi4jTest method defineApplication.

@Override
protected void defineApplication(ApplicationAssembly applicationAssembly) throws AssemblyException {
    LayerAssembly layer = applicationAssembly.layer("Layer 1");
    ModuleAssembly module = layer.module("Module 1");
    module.objects(AbstractQi4jTest.this.getClass());
    assemble(module);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Aggregations

LayerAssembly (org.qi4j.bootstrap.LayerAssembly)31 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)16 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)15 AssemblyException (org.qi4j.bootstrap.AssemblyException)5 Test (org.junit.Test)4 Application (org.qi4j.api.structure.Application)4 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)4 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)4 Energy4Java (org.qi4j.bootstrap.Energy4Java)4 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)3 HashMap (java.util.HashMap)2 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ActivationEventListener (org.qi4j.api.activation.ActivationEventListener)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 Layer (org.qi4j.api.structure.Layer)1 LayerDescriptor (org.qi4j.api.structure.LayerDescriptor)1 Module (org.qi4j.api.structure.Module)1 Assembler (org.qi4j.bootstrap.Assembler)1