void initialize( HashMap<String, LayerAssembly> createdLayers ) { for( String uses : using ) { LayerAssembly usedLayer = createdLayers.get( uses ); layer.uses( usedLayer ); } for( ModuleDeclaration module : modules.values() ) { module.initialize(); } } }
void initialize( HashMap<String, LayerAssembly> createdLayers ) { for( String uses : using ) { LayerAssembly usedLayer = createdLayers.get( uses ); layer.uses( usedLayer ); } for( ModuleDeclaration module : modules.values() ) { module.initialize(); } } }
@Override protected void assembleLayers( ApplicationAssembly assembly ) { LayerAssembly accessLayer = createLayer( AccessLayer.class ); LayerAssembly domainLayer = createLayer( DomainLayer.class ); LayerAssembly persistenceLayer = createLayer( PersistenceLayer.class ); LayerAssembly indexingLayer = createLayer( IndexingLayer.class ); LayerAssembly configLayer = createLayer( ConfigLayer.class ); accessLayer.uses( domainLayer ); domainLayer.uses( persistenceLayer, indexingLayer ); persistenceLayer.uses( configLayer ); indexingLayer.uses( configLayer ); }
@Override protected void assembleLayers( ApplicationAssembly assembly ) { LayerAssembly accessLayer = createLayer( AccessLayer.class ); LayerAssembly domainLayer = createLayer( DomainLayer.class ); LayerAssembly persistenceLayer = createLayer( PersistenceLayer.class ); LayerAssembly indexingLayer = createLayer( IndexingLayer.class ); LayerAssembly configLayer = createLayer( ConfigLayer.class ); accessLayer.uses( domainLayer ); domainLayer.uses( persistenceLayer, indexingLayer ); persistenceLayer.uses( configLayer ); indexingLayer.uses( configLayer ); }
public static void main( String[] args ) throws Exception { // Bootstrap Polygene Runtime // Create a Polygene Runtime polygene = new Energy4Java(); // Instantiate the Application Model. application = polygene.newApplication( factory -> { ApplicationAssembly assembly = factory.newApplicationAssembly(); LayerAssembly runtime = createRuntimeLayer( assembly ); LayerAssembly designer = createDesignerLayer( assembly ); LayerAssembly domain = createDomainLayer( assembly ); LayerAssembly messaging = createMessagingLayer( assembly ); LayerAssembly persistence = createPersistenceLayer( assembly ); // declare structure between layers domain.uses( messaging ); domain.uses( persistence ); designer.uses( persistence ); designer.uses( domain ); runtime.uses( domain ); return assembly; } ); // We need to handle shutdown. installShutdownHook(); // Activate the Application Runtime. application.activate(); }
static ApplicationAssembly buildAssembly( ApplicationAssembly app ) throws AssemblyException { LayerAssembly webLayer = createWebLayer( app ); LayerAssembly domainLayer = createDomainLayer( app ); LayerAssembly persistenceLayer = createInfrastructureLayer( app ); LayerAssembly authLayer = createAuth2Layer( app ); LayerAssembly messagingLayer = createMessagingLayer( app ); webLayer.uses( domainLayer ); domainLayer.uses( authLayer ); domainLayer.uses( persistenceLayer ); domainLayer.uses( messagingLayer ); return app; }
private static ApplicationAssembly createAssembly( ApplicationAssemblyFactory factory ) throws AssemblyException { String applicationName = "Example Application"; ApplicationAssembly app = factory.newApplicationAssembly(); app.setName( applicationName ); LayerAssembly webLayer = createWebLayer( app ); LayerAssembly domainLayer = createDomainLayer( app ); LayerAssembly infraLayer = createInfrastructureLayer( app ); webLayer.uses( domainLayer ); webLayer.uses( infraLayer ); // Accesses the WebService domainLayer.uses( infraLayer ); // For persistence return app; }
@Override protected void assembleLayers( ApplicationAssembly assembly ) throws AssemblyException { LayerAssembly configLayer = createLayer( ConfigurationLayer.class ); ModuleAssembly configModule = configLayer.module( "Configuration Module" ); LayerAssembly infraLayer = new InfrastructureLayer( configModule ).assemble( assembly.layer( InfrastructureLayer.NAME )); LayerAssembly domainLayer = createLayer( DomainLayer.class ); LayerAssembly serviceLayer = createLayer( ServiceLayer.class ); LayerAssembly connectivityLayer = createLayer( ConnectivityLayer.class ); connectivityLayer.uses( serviceLayer ); connectivityLayer.uses( domainLayer ); serviceLayer.uses( domainLayer ); domainLayer.uses( infraLayer ); infraLayer.uses( configLayer ); } }
@Override public ApplicationAssembly newApplicationAssembly( Assembler[][][] assemblers ) { ApplicationAssembly applicationAssembly = newApplicationAssembly(); // Build all layers bottom-up LayerAssembly below = null; for( int layer = assemblers.length - 1; layer >= 0; layer-- ) { // Create Layer LayerAssembly layerAssembly = applicationAssembly.layer( "Layer " + ( layer + 1 ) ); for( int module = 0; module < assemblers[ layer ].length; module++ ) { // Create Module ModuleAssembly moduleAssembly = layerAssembly.module( "Module " + ( module + 1 ) ); for( Assembler assembler : assemblers[ layer ][ module ] ) { // Register Assembler assembler.assemble( moduleAssembly ); } } if( below != null ) { layerAssembly.uses( below ); // Link layers } below = layerAssembly; } return applicationAssembly; }
@Override protected void defineApplication( ApplicationAssembly applicationAssembly ) throws AssemblyException { LayerAssembly accessLayer = applicationAssembly.layer( "Access Layer" ); LayerAssembly domainLayer = applicationAssembly.layer( "Domain Layer" ); LayerAssembly infrastructureLayer = applicationAssembly.layer( "Infrastructure Layer" ); LayerAssembly configLayer = applicationAssembly.layer( "Configuration Layer" ); accessLayer.uses( domainLayer.uses( infrastructureLayer.uses( configLayer ) ) ); defineConfigModule( configLayer.module( "Configuration Module" ) ); defineSerializationModule( configLayer.module( "Serialization Module" ) ); defineStorageModule( infrastructureLayer.module( "Storage Module" ) ); defineMonetaryModule( domainLayer.module( "Monetary Module" ) ); definePeopleModule( domainLayer.module( "People Module" ) ); defineLegalModule( domainLayer.module( "Legal Module" ) ); defineTestModule( accessLayer.module( "TestCase Module" ) ); }
@Override protected void defineApplication( ApplicationAssembly applicationAssembly ) throws AssemblyException { LayerAssembly accessLayer = applicationAssembly.layer( "Access Layer" ); LayerAssembly domainLayer = applicationAssembly.layer( "Domain Layer" ); LayerAssembly infrastructureLayer = applicationAssembly.layer( "Infrastructure Layer" ); LayerAssembly configLayer = applicationAssembly.layer( "Configuration Layer" ); accessLayer.uses( domainLayer.uses( infrastructureLayer.uses( configLayer ) ) ); defineConfigModule( configLayer.module( "Configuration Module" ) ); defineSerializationModule( configLayer.module( "Serialization Module" ) ); defineStorageModule( infrastructureLayer.module( "Storage Module" ) ); defineMonetaryModule( domainLayer.module( "Monetary Module" ) ); definePeopleModule( domainLayer.module( "People Module" ) ); defineLegalModule( domainLayer.module( "Legal Module" ) ); defineTestModule( accessLayer.module( "TestCase Module" ) ); }
@Test public void testModel2XML() throws AssemblyException, TransformerException { Energy4Java polygene = new Energy4Java( ); ApplicationDescriptor model = polygene.newApplicationModel( factory -> { ApplicationAssembly assembly = factory.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().apply( 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 ) ); }
private Application createApplication( final ModuleAssemblyBuilder queryServiceModuleBuilder, final ModuleAssemblyBuilder entityStoreModuleBuilder, final LayerAssemblyBuilder domainLayerBuilder ) throws AssemblyException { Energy4Java polygene = new Energy4Java(); Application application = polygene.newApplication( factory -> { ApplicationAssembly applicationAssembly = factory.newApplicationAssembly(); LayerAssembly configLayer = applicationAssembly.layer( "Config" ); configModule.buildModuleAssembly( configLayer, "Configuration" ); LayerAssembly infrastructureLayer = applicationAssembly.layer( "Infrastructure" ); infrastructureLayer.uses( configLayer ); queryServiceModuleBuilder.buildModuleAssembly( infrastructureLayer, "Query Service" ); entityStoreModuleBuilder.buildModuleAssembly( infrastructureLayer, "Entity Store" ); LayerAssembly domainLayer = domainLayerBuilder.buildLayerAssembly( applicationAssembly ); domainLayer.uses( infrastructureLayer ); return applicationAssembly; } ); return application; }
@Override protected final void defineApplication( ApplicationAssembly app ) { app.setName( "app" ); LayerAssembly domain = app.layer( "domain" ); ModuleAssembly model = domain.module( "model" ); model.entities( Person.class, PersonList.class ) .visibleIn( Visibility.layer ); ModuleAssembly services = domain.module( "services" ); services.services( Commands.class, Queries.class ) .instantiateOnStartup() .visibleIn( Visibility.application ); LayerAssembly config = app.layer( "config" ); ModuleAssembly configModule = config.module( "config" ); new EntityTestAssembler() .visibleIn( Visibility.module ) .assemble( configModule ); LayerAssembly infra = app.layer( "infra" ); ModuleAssembly storage = infra.module( "storage" ); entityStoreAssembler( configModule, Visibility.application ) .visibleIn( Visibility.application ) .assemble( storage ); metricsAssembler() .visibleIn( Visibility.application ) .assemble( infra.module( "metrics" ) ); domain.uses( infra ); infra.uses( config ); }
@Override protected final void defineApplication( ApplicationAssembly app ) { app.setName( "app" ); LayerAssembly domain = app.layer( "domain" ); ModuleAssembly model = domain.module( "model" ); model.entities( Person.class, PersonList.class ) .visibleIn( Visibility.layer ); ModuleAssembly services = domain.module( "services" ); services.services( Commands.class, Queries.class ) .instantiateOnStartup() .visibleIn( Visibility.application ); LayerAssembly config = app.layer( "config" ); ModuleAssembly configModule = config.module( "config" ); new EntityTestAssembler() .visibleIn( Visibility.module ) .assemble( configModule ); LayerAssembly infra = app.layer( "infra" ); ModuleAssembly storage = infra.module( "storage" ); entityStoreAssembler( configModule, Visibility.application ) .visibleIn( Visibility.application ) .assemble( storage ); metricsAssembler() .visibleIn( Visibility.application ) .assemble( infra.module( "metrics" ) ); domain.uses( infra ); infra.uses( config ); }
@Test public void createApplicationUsingApplicationAssembly() throws AssemblyException { Energy4Java polygene = new Energy4Java(); polygene.newApplication( factory -> { ApplicationAssembly applicationAssembly = factory.newApplicationAssembly(); // Application Layer LayerAssembly applicationLayer = applicationAssembly.layer( "Application" ); ModuleAssembly applicationModule = applicationLayer.module( "Application" ); new DomainApplicationAssembler().assemble( applicationModule ); // View Layer LayerAssembly viewLayer = applicationAssembly.layer( "View" ); ModuleAssembly viewModule = viewLayer.module( "View" ); new ViewAssembler().assemble( viewModule ); viewLayer.uses( applicationLayer ); return applicationAssembly; } ); }
infrastructureLayer.setName( "Infrastructure" ); domainLayer.uses( infrastructureLayer );
@Override public void assemble( ModuleAssembly module ) throws AssemblyException { LayerAssembly layer = module.layer(); assembleValues( module, Visibility.module ); assembleEntities( module, Visibility.module ); ModuleAssembly storeModule = layer.module( "store" ); new EntityTestAssembler().visibleIn( Visibility.layer ).assemble( storeModule ); assembleValues( storeModule, Visibility.module ); ModuleAssembly indexModule = layer.module( "index" ); new RdfNativeSesameStoreAssembler( Visibility.layer, Visibility.module ).assemble( indexModule ); LayerAssembly configLayer = module.layer().application().layer( "config" ); module.layer().uses( configLayer ); ModuleAssembly config = configLayer.module( "config" ); config.entities( NativeConfiguration.class ).visibleIn( Visibility.application ); config.forMixin( NativeConfiguration.class ).declareDefaults() .dataDirectory().set( tmpDir.getRoot().getAbsolutePath() ); new EntityTestAssembler().assemble( config ); }
@Test public void testInjectionServiceBetweenLayers() throws ActivationException { SingletonAssembler assembly = new SingletonAssembler( module -> { module.services( MyServiceComposite.class ) .identifiedBy( "Foo" ) .setMetaInfo( new ServiceName( "Foo" ) ); module.services( StringService.class, LongService.class ); LayerAssembly layerAssembly = module.layer(); module.objects( ServiceUser.class ); ApplicationAssembly applicationAssembly = layerAssembly.application(); LayerAssembly layer2Assembly = applicationAssembly.layer( "Other layer" ); layerAssembly.uses( layer2Assembly ); ModuleAssembly module2 = layer2Assembly.module( "Other module" ); ServiceDeclaration service2Decl = module2.services( MyServiceComposite2.class ); service2Decl.identifiedBy( "Bar" ).setMetaInfo( new ServiceName( "Bar" ) ).visibleIn( application ); } ); testInjection( assembly ); }
module.layer().uses( configLayer ); ModuleAssembly config = configLayer.module( "config" ); new EntityTestAssembler().assemble( config );