Runtime Bootstrap API

Qi4j is very flexible in its usage and we don't force people to use any particular mechanism. Therefor Qi4j will not start itself, and has no configuration files, assembly descriptor files and so on. Getting Qi4j running is the responsible for the application, but it should not be mixed up with the domain model and business rules. Instead we expect that every application will have a bootstrapper, that starts everything and hand some artifacts over to the domain model part of the application, which will not have any view of the underlying infrastructure.

The Runtime Bootstrap API is how such bootstrapper code in the application will get everything going.

For instance if you just want to create an Application with one Layer and one Module in that Layer, you would do something like this;

// Create the Qi4j Runtime instance.
Qi4j is = new Energy4Java();

// Create the Assembly for the Module.
Assembly assembly = ...;

// Obtain the ApplicationBuilderFactory.
ApplicationBuilderFactory factory =
    is.getApplicationBuilderFactory();

// Create a helper.
ApplicationBuilderHelper helper = new ApplicationBuilderHelper( factory );

// Create the Application.
Application application = helper.newApplication( assembly );

// Create the Domain model
MyDomain domain = new MyDomainImpl( application );
domain.start();

If the Application has a simple Layered architecture, i.e. no parallel Layers at the same level, but with many Modules in each Layer and many Assemblies in each Module, then another helper method can be used to create it fairly conveniently. Here is an example;
// Create the Qi4j implementation strategy

Qi4j is = new Energy4Java();

Assembly[][][] assemblies = new Assembly[][][]
{
    { // View Layer
        { // Login Module
            new MyAssembly( "login1" ),
            new MyAssembly( "login2" )
        },
        { // Main Workbench Module
            new MyAssembly( "menus" ),
            new MyAssembly( "contextmenus" ),
            new MyAssembly( "perspectives" ),
            new MyAssembly( "views" ),
            new MyAssembly( "editors )
        },
        { // Printing Module
            new MyAssembly( "jasper" ),
            new MyAssembly( "pdf" )
        }
    },
    { // Business Rules Layer
        { // Accounting Module
            new MyAssembly( "bookkeeping" ),
            new MyAssembly( "profitloss" ),
            new MyAssembly( "cashflow" ),
            new MyAssembly( "balancesheet" ),
            new MyAssembly( "glue" )
        },
        { // Inventory Module
            new MyAssembly( "pricing" ),
            new MyAssembly( "products" )
        }
    }
}

// Get the ApplicationBuilderFactory
ApplicationBuilderFactory factory =
    is.getApplicationBuilderFactory();

// Create the helper
ApplicationBuilderHelper helper = new ApplicationBuilderHelper( factory );

// Create the Application instance.
Application application = helper.newApplication( assemblies );

// Use the the Application instance in the Domain Model.

For more complex and modularized applications one should use proper layering and modularization techniques. The principle is that Modules only exposes public Composites for other Modules to use, and that Layers can only reach Modules in the same Layer and Layers below.
ApplicationBuilderFactory sbf =
    api.getApplicationBuilderFactory();

ApplicationBuilder builder = sbf.newApplicationBuilder();
{            
    LayerBuilder applicationLayer = ab.newLayerBuilder();
    {
        {
            ModuleBuilder mb = applicationLayer.newModuleBuilder();
            mb.addAssembly( new ApplicationAssembly() );
        }
    }

    LayerBuilder viewLayer = ab.newLayerBuilder();
    {
        {
            ModuleBuilder mb = viewLayer.newModuleBuilder();
            mb.addAssembly( new ViewAssembly() );
        }
        viewLayer.uses( applicationLayer );
    }
}
Application application = builder.newApplication();

Powered by SiteVisionexternal link.