public static void main(String[] args) throws Exception { Energy4Java polygene = new Energy4Java(); // Instantiate the Application Model. Application application = polygene.newApplication( factory -> factory.newApplicationAssembly( new MyAssembler()) ); application.activate(); } }
@Override public final void contextInitialized( ServletContextEvent sce ) { try { ServletContext context = sce.getServletContext(); LOGGER.trace( "Assembling Application" ); polygene = new Energy4Java(); applicationModel = polygene.newApplicationModel( this ); LOGGER.trace( "Instanciating and activating Application" ); application = applicationModel.newInstance( polygene.api() ); api = polygene.api(); beforeApplicationActivation( application ); application.activate(); afterApplicationActivation( application ); LOGGER.trace( "Storing Application in ServletContext" ); context.setAttribute( PolygeneServletSupport.APP_IN_CTX, application ); } catch ( Exception ex ) { if ( application != null ) { try { beforeApplicationPassivation( application ); application.passivate(); afterApplicationPassivation( application ); } catch ( Exception ex1 ) { LOGGER.warn( "Application not null and could not passivate it.", ex1 ); } } throw new InvalidApplicationException( "Unexpected error during ServletContext initialization, see previous log for errors.", ex ); } }
@Before public void setUp() throws Exception { polygene = new Energy4Java(); applicationModel = newApplicationModel(); if( applicationModel == null ) { // An AssemblyException has occurred that the Test wants to check for. return; } application = newApplicationInstance( applicationModel ); initApplication( application ); api = spi = polygene.spi(); application.activate(); }
public static void main( String[] args ) throws Exception { polygene = new Energy4Java(); ApplicationDescriptor model = polygene.newApplicationModel( factory -> createAssembly( factory ) ); Application application = model.newInstance( polygene.spi() ); }
public LayeredApplicationAssembler( String name, String version, Application.Mode mode ) throws AssemblyException { this.name = name; this.version = version; this.mode = mode; polygene = new Energy4Java(); }
@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 ) ); }
public Application newApplication( ApplicationAssembler assembler, Object... importedServiceInstances ) throws AssemblyException { ApplicationDescriptor model = newApplicationModel( assembler ); return model.newInstance( runtime.spi(), importedServiceInstances ); }
protected Application newApplicationInstance( ApplicationDescriptor applicationModel ) { return applicationModel.newInstance( polygene.api() ); }
public final PolygeneAPI runtime() { return polygene.spi(); }
private Application createApplicationInstance() { return polygene.newApplication( applicationFactory -> applicationFactory.newApplicationAssembly( SingletonAssembler.this ) ); }
throws AssemblyException Energy4Java polygene = new Energy4Java(); ApplicationDescriptor model = polygene.newApplicationModel( factory -> { ApplicationAssembly assembly = factory.newApplicationAssembly(); model.newInstance( polygene.spi() );
public LayeredApplicationAssembler( String name, String version, Application.Mode mode ) throws AssemblyException { this.name = name; this.version = version; this.mode = mode; polygene = new Energy4Java(); }
public Application newApplication( ApplicationAssembler assembler, Object... importedServiceInstances ) throws AssemblyException { ApplicationDescriptor model = newApplicationModel( assembler ); return model.newInstance( runtime.spi(), importedServiceInstances ); }
protected Application newApplicationInstance( ApplicationDescriptor applicationModel ) { return applicationModel.newInstance( polygene.api() ); }
public final PolygeneAPI runtime() { return polygene.spi(); }
private Application createApplicationInstance() { return polygene.newApplication( applicationFactory -> applicationFactory.newApplicationAssembly( SingletonAssembler.this ) ); }
private Application createApplication() { Energy4Java polygene = new Energy4Java(); try { return polygene.newApplication( factory -> { ApplicationAssembly applicationAssembly = factory.newApplicationAssembly(); applicationBootstrap.assemble( applicationAssembly ); return applicationAssembly; } ); } catch ( AssemblyException e ) { throw new BeanInitializationException( "Fail to bootstrap Polygene application.", e ); } }
@Override public final void contextInitialized( ServletContextEvent sce ) { try { ServletContext context = sce.getServletContext(); LOGGER.trace( "Assembling Application" ); polygene = new Energy4Java(); applicationModel = polygene.newApplicationModel( this ); LOGGER.trace( "Instanciating and activating Application" ); application = applicationModel.newInstance( polygene.api() ); api = polygene.api(); beforeApplicationActivation( application ); application.activate(); afterApplicationActivation( application ); LOGGER.trace( "Storing Application in ServletContext" ); context.setAttribute( PolygeneServletSupport.APP_IN_CTX, application ); } catch ( Exception ex ) { if ( application != null ) { try { beforeApplicationPassivation( application ); application.passivate(); afterApplicationPassivation( application ); } catch ( Exception ex1 ) { LOGGER.warn( "Application not null and could not passivate it.", ex1 ); } } throw new InvalidApplicationException( "Unexpected error during ServletContext initialization, see previous log for errors.", ex ); } }
@BeforeClass public static void setUp() throws Exception { polygene = new Energy4Java(); applicationModel = newApplication(); if( applicationModel == null ) { // An AssemblyException has occurred that the Test wants to check for. return; } application = applicationModel.newInstance( polygene.spi() ); initApplication( application ); api = spi = polygene.spi(); application.activate(); // Assume only one module module = application.findModule( "Layer 1", "Module 1" ); uowf = module.unitOfWorkFactory(); }
/** * Creates a Polygene Runtime instance containing one Layer with one Module. * The Layer will be named "Layer 1" and the Module will be named "Module 1". It is possible to add * additional layers and modules via the Assembler interface that must be implemented in the subclass of this * class. * * @throws AssemblyException Either if the model can not be created from the disk, or some inconsistency in * the programming model makes it impossible to create it. * @throws ActivationException If the automatic {@code activate()} method is throwing this Exception.. */ public SingletonAssembler() throws AssemblyException, ActivationException { // START SNIPPET: actual polygene = new Energy4Java(); applicationInstance = createApplicationInstance(); activateApplication(); // END SNIPPET: actual moduleInstance = applicationInstance.findModule( layerName(), moduleName() ); }