Search in sources :

Example 1 with Energy4Java

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;
}
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 Energy4Java

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());
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor)

Example 3 with Energy4Java

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();
}
Also used : Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Energy4Java

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());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter) Test(org.junit.Test)

Example 5 with Energy4Java

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());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter) Test(org.junit.Test)

Aggregations

Energy4Java (org.qi4j.bootstrap.Energy4Java)39 Assembler (org.qi4j.bootstrap.Assembler)19 Application (org.qi4j.api.structure.Application)18 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)17 Test (org.junit.Test)15 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)12 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)11 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)8 AssemblyException (org.qi4j.bootstrap.AssemblyException)8 Before (org.junit.Before)7 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)7 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)7 Module (org.qi4j.api.structure.Module)6 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)6 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)4 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)3 Envisage (org.qi4j.envisage.Envisage)3 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1