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);
}
}
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:
*
* @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 + "'");
}
}
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);
}
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;
}
}
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;
}
}
Aggregations