Search in sources :

Example 1 with ApplicationAssembler

use of org.qi4j.bootstrap.ApplicationAssembler 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 ApplicationAssembler

use of org.qi4j.bootstrap.ApplicationAssembler 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 )")));
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) ApplicationDetailDescriptorBuilder.createApplicationDetailDescriptor(org.qi4j.tools.model.descriptor.ApplicationDetailDescriptorBuilder.createApplicationDetailDescriptor) ApplicationDetailDescriptor(org.qi4j.tools.model.descriptor.ApplicationDetailDescriptor) HierarchicalVisitor(org.qi4j.functional.HierarchicalVisitor) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Test(org.junit.Test)

Example 3 with ApplicationAssembler

use of org.qi4j.bootstrap.ApplicationAssembler 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 4 with ApplicationAssembler

use of org.qi4j.bootstrap.ApplicationAssembler in project qi4j-sdk by Qi4j.

the class StructureTest method createApplicationUsingApplicationAssembly.

@Test
public void createApplicationUsingApplicationAssembly() throws AssemblyException {
    Energy4Java boot = new Energy4Java();
    boot.newApplication(new ApplicationAssembler() {

        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            ApplicationAssembly applicationAssembly = applicationFactory.newApplicationAssembly();
            // Application Layer
            LayerAssembly applicationLayer = applicationAssembly.layer("Application");
            ModuleAssembly applicationModule = applicationLayer.module("Application");
            new DomainApplicationAssembler().assemble(applicationModule);
            // View Layer
            LayerAssembly viewLayer = applicationAssembly.layer("View");
            ModuleAssembly viewModule = viewLayer.module("View");
            new ViewAssembler().assemble(viewModule);
            viewLayer.uses(applicationLayer);
            return applicationAssembly;
        }
    });
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) Test(org.junit.Test)

Example 5 with ApplicationAssembler

use of org.qi4j.bootstrap.ApplicationAssembler in project qi4j-sdk by Qi4j.

the class QuikitServlet method createApplicationAssembler.

private ApplicationAssembler createApplicationAssembler(ServletConfig config) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    String assemblerClassname = config.getInitParameter("qi4j-assembler");
    ClassLoader loader = getClass().getClassLoader();
    Class<?> assemblerClass = loader.loadClass(assemblerClassname);
    ApplicationAssembler assembler;
    Constructor cons = assemblerClass.getConstructor(Application.Mode.class);
    if (cons == null) {
        assembler = (ApplicationAssembler) assemblerClass.newInstance();
    } else {
        Application.Mode mode;
        String modeSetting = config.getInitParameter("qi4j-application-mode");
        if (modeSetting == null) {
            mode = Application.Mode.development;
        } else {
            mode = Application.Mode.valueOf(modeSetting);
        }
        assembler = (ApplicationAssembler) cons.newInstance(mode);
    }
    return assembler;
}
Also used : ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Constructor(java.lang.reflect.Constructor) Application(org.qi4j.api.structure.Application)

Aggregations

ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)15 AssemblyException (org.qi4j.bootstrap.AssemblyException)10 Energy4Java (org.qi4j.bootstrap.Energy4Java)10 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)9 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 Application (org.qi4j.api.structure.Application)6 Test (org.junit.Test)5 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)5 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)4 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)4 Module (org.qi4j.api.structure.Module)3 Assembler (org.qi4j.bootstrap.Assembler)3 ConcurrentEntityModificationException (org.qi4j.api.unitofwork.ConcurrentEntityModificationException)2 UnitOfWorkCompletionException (org.qi4j.api.unitofwork.UnitOfWorkCompletionException)2 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1