Search in sources :

Example 6 with ApplicationDescriptor

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);
}
Also used : Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.sample.dcicargo.sample_b.bootstrap.assembly.Assembler) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) Envisage(org.qi4j.envisage.Envisage)

Example 7 with ApplicationDescriptor

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 )")));
}
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 8 with ApplicationDescriptor

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);
}
Also used : Energy4Java(org.qi4j.bootstrap.Energy4Java) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) Envisage(org.qi4j.envisage.Envisage)

Example 9 with ApplicationDescriptor

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;
        }
    });
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor) Test(org.junit.Test)

Example 10 with ApplicationDescriptor

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));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) Model2XML(org.qi4j.library.rdf.model.Model2XML) StreamResult(javax.xml.transform.stream.StreamResult) Document(org.w3c.dom.Document) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) Test(org.junit.Test)

Aggregations

ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)12 Energy4Java (org.qi4j.bootstrap.Energy4Java)8 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)5 Test (org.junit.Test)4 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)4 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)4 AssemblyException (org.qi4j.bootstrap.AssemblyException)4 Application (org.qi4j.api.structure.Application)3 LayerDescriptor (org.qi4j.api.structure.LayerDescriptor)3 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)3 Envisage (org.qi4j.envisage.Envisage)3 MethodDescriptor (org.qi4j.api.composite.MethodDescriptor)2 TransientDescriptor (org.qi4j.api.composite.TransientDescriptor)2 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)2 ModuleDescriptor (org.qi4j.api.structure.ModuleDescriptor)2 Document (org.w3c.dom.Document)2 HashMap (java.util.HashMap)1 Stack (java.util.Stack)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 Transformer (javax.xml.transform.Transformer)1