use of org.qi4j.api.structure.ApplicationDescriptor 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.api.structure.ApplicationDescriptor 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.api.structure.ApplicationDescriptor 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.api.structure.ApplicationDescriptor in project qi4j-sdk by Qi4j.
the class EnvisageSchoolSample method main.
// START SNIPPET: envisage
public static void main(String[] args) throws Exception {
Energy4Java energy4Java = new Energy4Java();
ApplicationDescriptor applicationModel = energy4Java.newApplicationModel(new SchoolAssembler());
new Envisage().run(applicationModel);
}
use of org.qi4j.api.structure.ApplicationDescriptor in project qi4j-sdk by Qi4j.
the class ApplicationAssemblerTest method testApplicationAssembler.
@Test
public void testApplicationAssembler() throws AssemblyException {
Energy4Java is = new Energy4Java();
ApplicationDescriptor model = is.newApplicationModel(new ApplicationAssembler() {
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
LayerAssembly layer1 = assembly.layer("Layer1");
ModuleAssembly module = layer1.module("Module1");
module.services(TestService.class);
module.entities(TestEntity.class);
layer1.services(AssemblySpecifications.types(TestService.class)).instantiateOnStartup();
layer1.services(Specifications.<Object>TRUE()).visibleIn(Visibility.layer);
layer1.entities(Specifications.<Object>TRUE()).visibleIn(Visibility.application);
return assembly;
}
});
model.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {
@Override
public boolean visitEnter(Object visited) throws RuntimeException {
if (visited instanceof ServiceDescriptor) {
ServiceDescriptor serviceDescriptor = (ServiceDescriptor) visited;
Assert.assertTrue(serviceDescriptor.isInstantiateOnStartup());
Assert.assertTrue(serviceDescriptor.visibility() == Visibility.layer);
return false;
} else if (visited instanceof EntityDescriptor) {
EntityDescriptor entityDescriptor = (EntityDescriptor) visited;
Assert.assertTrue(entityDescriptor.visibility() == Visibility.application);
return false;
}
return true;
}
});
model.newInstance(is.spi());
}
Aggregations