use of org.qi4j.api.structure.ApplicationDescriptor in project qi4j-sdk by Qi4j.
the class VisualizeApplicationStructure method main.
public static void main(String[] args) throws Exception {
Energy4Java qi4j = new Energy4Java();
Assembler assembler = new Assembler();
ApplicationDescriptor applicationModel = qi4j.newApplicationModel(assembler);
applicationModel.newInstance(qi4j.spi());
/*
* The Envisage Swing app visualizes the application assemblage structure.
*
* Tree view:
* - Click on elements to expand sub-elements.
* - Scroll to change font size.
* - Right click on viewer to re-size to fit window.
*
* Stacked view:
* - Scroll to zoom in/out of structure levels - might freeze though :-(
*
* Click on any element and see details of that element in the upper right pane.
*
* Pretty cool, eh?
* */
new Envisage().run(applicationModel);
int randomTimeoutMs = 18374140;
Thread.sleep(randomTimeoutMs);
}
use of org.qi4j.api.structure.ApplicationDescriptor 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 )")));
}
use of org.qi4j.api.structure.ApplicationDescriptor in project qi4j-sdk by Qi4j.
the class EnvisageSchoolSample method main.
// START SNIPPET: envisage
public static void main(String[] args) throws Exception {
Energy4Java energy4Java = new Energy4Java();
ApplicationDescriptor applicationModel = energy4Java.newApplicationModel(new SchoolAssembler());
new Envisage().run(applicationModel);
}
use of org.qi4j.api.structure.ApplicationDescriptor in project qi4j-sdk by Qi4j.
the class IssueTest method testLayersCanBeCreatedInOrderDifferentFromTheirDependency.
@Test
public void testLayersCanBeCreatedInOrderDifferentFromTheirDependency() throws AssemblyException {
Energy4Java qi4j = new Energy4Java();
Application app = qi4j.newApplication(new ApplicationAssembler() {
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
LayerAssembly domainLayer = assembly.layer(null);
domainLayer.setName("Domain");
LayerAssembly infrastructureLayer = assembly.layer(null);
infrastructureLayer.setName("Infrastructure");
domainLayer.uses(infrastructureLayer);
return assembly;
}
});
ApplicationDescriptor model = app.descriptor();
model.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {
@Override
public boolean visitEnter(Object visited) throws RuntimeException {
return visited instanceof ApplicationDescriptor;
}
@Override
public boolean visitLeave(Object visited) throws RuntimeException {
return visited instanceof LayerDescriptor;
}
@Override
public boolean visit(Object visited) throws RuntimeException {
if (visited instanceof LayerDescriptor) {
Iterable<? extends LayerDescriptor> usedLayers = ((LayerDescriptor) visited).usedLayers().layers();
for (LayerDescriptor usedLayerModel : usedLayers) {
Assert.assertNotNull("Used layer model is null", usedLayerModel);
}
}
return false;
}
});
}
use of org.qi4j.api.structure.ApplicationDescriptor in project qi4j-sdk by Qi4j.
the class Model2XMLTest method testModel2XML.
@Test
public void testModel2XML() throws AssemblyException, TransformerException {
Energy4Java is = new Energy4Java();
ApplicationDescriptor model = is.newApplicationModel(new ApplicationAssembler() {
@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
assembly.setName("Test application");
LayerAssembly webLayer = assembly.layer("Web");
LayerAssembly domainLayer = assembly.layer("Domain");
LayerAssembly infrastructureLayer = assembly.layer("Infrastructure");
webLayer.uses(domainLayer, infrastructureLayer);
domainLayer.uses(infrastructureLayer);
ModuleAssembly rest = webLayer.module("REST");
rest.transients(TestTransient.class).visibleIn(Visibility.layer);
domainLayer.module("Domain");
infrastructureLayer.module("Database");
return assembly;
}
});
Document document = new Model2XML().map(model);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty("indent", "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(new DOMSource(document), new StreamResult(System.out));
}
Aggregations