Search in sources :

Example 6 with ApplicationAssembler

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

the class QuikitServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    try {
        mountPoints = new TreeMap<String, Page>();
        documentFactory = DocumentBuilderFactory.newInstance();
        documentFactory.setNamespaceAware(true);
        ClassLoader cl = getClass().getClassLoader();
        SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        Source[] schemaSources = new Source[2];
        schemaSources[0] = new StreamSource(cl.getResourceAsStream("xhtml1-strict.xsd"));
        schemaSources[1] = new StreamSource(cl.getResourceAsStream("xml.xsd"));
        Schema schema = schemaFactory.newSchema(schemaSources);
        documentFactory.setSchema(schema);
        ApplicationAssembler assembler = createApplicationAssembler(config);
        Energy4Java qi4j = new Energy4Java();
        application = qi4j.newApplication(assembler);
        application.activate();
        Module module = application.findModule("WebLayer", "PagesModule");
        finder = module;
        if (application.mode() == Application.Mode.development) {
            DataInitializer initializer = module.newTransient(DataInitializer.class);
            initializer.initialize();
        }
        Iterable<ServiceReference<Page>> iterable = finder.findServices(Page.class);
        for (ServiceReference<Page> page : iterable) {
            PageMetaInfo pageMetaInfo = page.metaInfo(PageMetaInfo.class);
            String mountPoint = pageMetaInfo.mountPoint();
            mountPoints.put(mountPoint, page.get());
        }
    } catch (Exception e) {
        throw new ServletException("Can not initialize Qi4j.", e);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ServiceReference(org.qi4j.api.service.ServiceReference) ServletException(javax.servlet.ServletException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Module(org.qi4j.api.structure.Module)

Example 7 with ApplicationAssembler

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

the class WicketQi4jApplication method getAssembler.

/**
 * Qi4j Assembler
 *
 * To let the custom application class (DCISampleApplication_x) focus on starting up the
 * Wicket environment, I made a convention of having Qi4j Assembler files in an 'assembly'
 * folder beside the custom application class.
 *
 * There's always only one application file, but we could split the assemblage into several
 * files ie. one for each layer. In that case, the Assembler file would be distributing to
 * the individual LayerXAssembler classes.
 *
 * If you like, you can also override this method in the custom application class and simply
 * return an instance of YourAssembler:
 *
 * &#64;Override protected ApplicationAssembler getAssembler() {
 * return new YourAssemblerInAnyPath();
 * }
 */
protected ApplicationAssembler getAssembler() throws Exception {
    String appPath = getClass().getCanonicalName();
    String expectedPathFromApplication = ".assembly.Assembler";
    String assemblerPath = appPath.substring(0, appPath.lastIndexOf(".")) + expectedPathFromApplication;
    try {
        return (ApplicationAssembler) Class.forName(assemblerPath).newInstance();
    } catch (ClassNotFoundException e) {
        throw new Exception("Couldn't find Qi4j assembler in path '" + assemblerPath + "'");
    }
}
Also used : ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ConcurrentEntityModificationException(org.qi4j.api.unitofwork.ConcurrentEntityModificationException) UnitOfWorkCompletionException(org.qi4j.api.unitofwork.UnitOfWorkCompletionException)

Example 8 with ApplicationAssembler

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

the class Main method main.

public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, AssemblyException {
    String applicationAssemblerName = args[0];
    System.out.println("Assembler:" + applicationAssemblerName);
    Class applicationAssemblerClass = Class.forName(applicationAssemblerName);
    ApplicationAssembler assembler = (ApplicationAssembler) applicationAssemblerClass.newInstance();
    Energy4Java energy4Java = new Energy4Java();
    ApplicationDescriptor application = energy4Java.newApplicationModel(assembler);
    new Envisage().run(application);
}
Also used : ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor)

Example 9 with ApplicationAssembler

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

the class AbstractQi4jBaseTest method newApplication.

protected ApplicationDescriptor newApplication() throws AssemblyException {
    ApplicationAssembler assembler = new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            ApplicationAssembly applicationAssembly = applicationFactory.newApplicationAssembly();
            applicationAssembly.setMode(Application.Mode.test);
            defineApplication(applicationAssembly);
            return applicationAssembly;
        }
    };
    try {
        return qi4j.newApplicationModel(assembler);
    } catch (AssemblyException e) {
        assemblyException(e);
        return null;
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly)

Example 10 with ApplicationAssembler

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

the class AbstractQi4jScenarioTest method newApplication.

protected static ApplicationDescriptor newApplication() throws AssemblyException {
    final Assembler asm = assembler;
    ApplicationAssembler assembler = new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            return applicationFactory.newApplicationAssembly(asm);
        }
    };
    try {
        return qi4j.newApplicationModel(assembler);
    } catch (AssemblyException e) {
        assemblyException(e);
        return null;
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Assembler(org.qi4j.bootstrap.Assembler)

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