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 ApplicationAssemblyFactoryImpl method newApplicationAssembly.
@Override
public ApplicationAssembly newApplicationAssembly(Assembler[][][] assemblers) throws AssemblyException {
ApplicationAssembly applicationAssembly = newApplicationAssembly();
// Build all layers bottom-up
LayerAssembly below = null;
for (int layer = assemblers.length - 1; layer >= 0; layer--) {
// Create Layer
LayerAssembly layerAssembly = applicationAssembly.layer("Layer " + (layer + 1));
for (int module = 0; module < assemblers[layer].length; module++) {
// Create Module
ModuleAssembly moduleAssembly = layerAssembly.module("Module " + (module + 1));
for (Assembler assembler : assemblers[layer][module]) {
// Register Assembler
assembler.assemble(moduleAssembly);
}
}
if (below != null) {
// Link layers
layerAssembly.uses(below);
}
below = layerAssembly;
}
return applicationAssembly;
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class ApplicationDocs method createAssembly.
private static ApplicationAssembly createAssembly(ApplicationAssemblyFactory factory) throws AssemblyException {
String applicationName = "Example Application";
ApplicationAssembly app = factory.newApplicationAssembly();
app.setName(applicationName);
LayerAssembly webLayer = createWebLayer(app);
LayerAssembly domainLayer = createDomainLayer(app);
LayerAssembly infraLayer = createInfrastructureLayer(app);
webLayer.uses(domainLayer);
// Accesses the WebService
webLayer.uses(infraLayer);
// For persistence
domainLayer.uses(infraLayer);
return app;
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class DocumentationSupport method assembledWithValuesModuleSerialization.
// END SNIPPET: io
@Test
public // TODO Include in each ValueSerialization extensions documentation
void assembledWithValuesModuleSerialization() throws Exception {
Application app = new Energy4Java().newApplication(new ApplicationAssembler() {
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
Assembler[][][] pancakes = new Assembler[][][] { { { new Assembler() {
@Override
public void assemble(ModuleAssembly valuesModule) throws AssemblyException {
valuesModule.layer().setName("SINGLE-Layer");
valuesModule.setName("VALUES-Module");
valuesModule.values(SomeValue.class);
}
} }, { new Assembler() {
@Override
public void assemble(ModuleAssembly servicesModule) throws AssemblyException {
servicesModule.setName("SERVICES-Module");
Function<Application, Module> valuesModuleFinder = new Function<Application, Module>() {
@Override
public Module map(Application app) {
return app.findModule("SINGLE-Layer", "VALUES-Module");
}
};
new OrgJsonValueSerializationAssembler().withValuesModuleFinder(valuesModuleFinder).assemble(servicesModule);
}
} } } };
return applicationFactory.newApplicationAssembly(pancakes);
}
});
app.activate();
try {
Module valuesModule = app.findModule("SINGLE-Layer", "VALUES-Module");
SomeValue someValue = someNewValueInstance(valuesModule);
Module servicesModule = app.findModule("SINGLE-Layer", "SERVICES-Module");
ValueSerialization valueSerialization = servicesModule.findService(ValueSerialization.class).get();
String json = valueSerialization.serialize(someValue);
assertThat(json, equalTo("{\"foo\":\"bar\"}"));
SomeValue someNewValue = valueSerialization.deserialize(SomeValue.class, json);
assertThat(someNewValue, equalTo(someValue));
} finally {
app.passivate();
}
}
use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.
the class ServiceInjectionTest method testInjectionServiceBetweenLayers.
@Test
public void testInjectionServiceBetweenLayers() throws ActivationException, AssemblyException {
SingletonAssembler assembly = new SingletonAssembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.services(MyServiceComposite.class).identifiedBy("Foo").setMetaInfo(new ServiceName("Foo"));
module.services(StringService.class, LongService.class);
LayerAssembly layerAssembly = module.layer();
module.objects(ServiceUser.class);
ApplicationAssembly applicationAssembly = layerAssembly.application();
LayerAssembly layer2Assembly = applicationAssembly.layer("Other layer");
layerAssembly.uses(layer2Assembly);
ModuleAssembly module2 = layer2Assembly.module("Other module");
ServiceDeclaration service2Decl = module2.services(MyServiceComposite2.class);
service2Decl.identifiedBy("Bar").setMetaInfo(new ServiceName("Bar")).visibleIn(application);
}
};
testInjection(assembly);
}
Aggregations