use of org.qi4j.bootstrap.ApplicationAssembly 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;
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class VisitableDetailTest method visit.
@Test
public void visit() throws AssemblyException, ActivationException {
ApplicationDescriptor application = new Energy4Java().newApplicationModel(new ApplicationAssembler() {
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
ApplicationAssembly app = applicationFactory.newApplicationAssembly();
app.setName("UnderTestApp");
app.withActivators(ApplicationActivator.class);
LayerAssembly layer = app.layer("LayerName");
layer.withActivators(LayerActivator.class);
ModuleAssembly module = layer.module("ModuleName");
module.withActivators(ModuleActivator.class);
return app;
}
});
ApplicationDetailDescriptor detail = createApplicationDetailDescriptor(application);
Visitor visitor = new Visitor();
detail.accept(visitor);
assertThat(visitor.events, equalTo(Arrays.asList(// Application
"visitEnter( UnderTestApp )", "visit( " + ApplicationActivator.class.getName() + " )", // Layer
"visitEnter( LayerName )", "visit( " + LayerActivator.class.getName() + " )", // Module
"visitEnter( ModuleName )", "visit( " + ModuleActivator.class.getName() + " )", // Leaving Structure
"visitLeave( ModuleName )", "visitLeave( LayerName )", "visitLeave( UnderTestApp )")));
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class SchoolAssembler method assemble.
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
final ApplicationAssembly appAssembly = applicationFactory.newApplicationAssembly();
appAssembly.setName("School");
// Create layers
LayerAssembly layerUI = createUILayer(appAssembly);
LayerAssembly layerDomain = createDomainLayer(appAssembly);
LayerAssembly layerInfra = createInfrastructureLayer(appAssembly);
LayerAssembly layerConfig = createConfigLayer(appAssembly);
layerUI.uses(layerDomain);
layerDomain.uses(layerInfra);
layerDomain.uses(layerConfig);
return appAssembly;
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class ApplicationDocs method main.
public static void main(String[] args) throws Exception {
qi4j = new Energy4Java();
ApplicationDescriptor model = qi4j.newApplicationModel(new ApplicationAssembler() {
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
return createAssembly(applicationFactory);
}
});
Application application = model.newInstance(qi4j.spi());
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class Assembler method assemble.
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
// Application assembly
ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
assembly.setName("DCI Sample (version A)");
assembly.setVersion("A.1.0");
assembly.setMode(development);
// Layers (adding bottom-up - will be assembled in this order)
LayerAssembly infrastructureLayer = assembly.layer("INFRASTRUCTURE");
LayerAssembly dataLayer = assembly.layer("DATA");
LayerAssembly contextLayer = assembly.layer("CONTEXT");
LayerAssembly communicationLayer = assembly.layer("COMMUNICATION");
LayerAssembly bootstrapLayer = assembly.layer("BOOTSTRAP");
// Layer dependencies
bootstrapLayer.uses(communicationLayer, contextLayer, dataLayer, infrastructureLayer);
communicationLayer.uses(contextLayer, dataLayer, infrastructureLayer);
contextLayer.uses(dataLayer, infrastructureLayer);
dataLayer.uses(infrastructureLayer);
// Assemble
assembleBootstrapLayer(bootstrapLayer);
assembleCommunicationLayer(communicationLayer);
assembleContextLayer(contextLayer);
assembleDataLayer(dataLayer);
assembleInfrastructureLayer(infrastructureLayer);
return assembly;
}
Aggregations