use of org.qi4j.bootstrap.Energy4Java 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.Energy4Java 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.Energy4Java in project qi4j-sdk by Qi4j.
the class PluginTest method testPlugins.
@Test
@Ignore("Must fix the TODOs below. This example relied on ability to set Service MetaInfo at runtime, it seems it's not possible anymore.")
public void testPlugins() throws Exception {
Energy4Java runtime = new Energy4Java();
Application app = runtime.newApplication(new MainApplicationAssembler());
app.activate();
}
use of org.qi4j.bootstrap.Energy4Java in project qi4j-sdk by Qi4j.
the class MixinVisibilityTest method testMixinInLowerLayerIsVisible.
@Test
public void testMixinInLowerLayerIsVisible() throws Exception {
Energy4Java boot = new Energy4Java();
Assembler[][][] assemblers = new Assembler[][][] { { // Layer 1
{ new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module A");
module.objects(ObjectA.class);
}
} } }, { // Layer 2
{ new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module B");
module.transients(B1Composite.class).visibleIn(Visibility.application);
}
} } } };
Application app = boot.newApplication(new ApplicationAssemblerAdapter(assemblers) {
});
app.activate();
ObjectA object = app.findModule("Layer 1", "Module A").newObject(ObjectA.class);
assertEquals("ok", object.test1());
assertEquals("abc", object.test2());
}
use of org.qi4j.bootstrap.Energy4Java in project qi4j-sdk by Qi4j.
the class MixinVisibilityTest method testMultipleMixinsInLayerWillFailSameModule.
@Test(expected = AmbiguousTypeException.class)
public void testMultipleMixinsInLayerWillFailSameModule() throws Exception {
Energy4Java boot = new Energy4Java();
Assembler[][][] assemblers = new Assembler[][][] { { // Layer
{ new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module A");
module.objects(ObjectA.class);
}
} }, { new Assembler() {
public void assemble(ModuleAssembly module) throws AssemblyException {
module.setName("Module B");
module.transients(B1Composite.class, B2Composite.class).visibleIn(Visibility.layer);
}
} } } };
Application app = boot.newApplication(new ApplicationAssemblerAdapter(assemblers) {
});
app.activate();
ObjectA object = app.findModule("Layer 1", "Module A").newObject(ObjectA.class);
assertEquals("ok", object.test1());
assertEquals("abc", object.test2());
}
Aggregations