/** * Declare Assembler. * @param classname Assembler class name * @return This Module declaration * @throws AssemblyException if unable to load class, not an Assembler or unable to instanciate */ public ModuleDeclaration withAssembler( String classname ) throws AssemblyException { Class<? extends Assembler> clazz = loadClass( classname ); return withAssembler( clazz ); }
/** * {@literal main} method that read JSON from STDIN. * <p>Passivation exceptions are written to STDERR if any.</p> * @param args Unused * @throws AssemblyException if the assembly failed * @throws ActivationException if the activation failed */ public static void main( String[] args ) throws ActivationException, AssemblyException { fromJson( System.in ).withPassivationShutdownHook().newApplication(); } }
/** * Declare Assembler. * @param assemblerClass Assembler class * @return This Module declaration * @throws AssemblyException not an Assembler or if unable to instanciate */ public ModuleDeclaration withAssembler( Class<?> assemblerClass ) throws AssemblyException { Assembler assembler = createAssemblerInstance( assemblerClass ); assemblers.add( assembler ); return this; }
@Test public void givenBuilderUseWhenBuildingApplicationExpectSuccess() throws AssemblyException, ActivationException { ApplicationBuilder builder = new ApplicationBuilder( "Build from API test." ); builder.withLayer( "layer1" ).using( "layer2" ).using( "layer3" ); builder.withLayer( "layer2" ); builder.withLayer( "layer3" ) .withModule( "test module" ) .withAssemblers( findClasses( getClass() ).filter( matches( ".*ServiceAssembler" ) ) .collect( toList() ) ); Application application = builder.newApplication(); Module module = application.findModule( "layer3", "test module" ); TestService service = module.findService( TestService.class ).get(); assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) ); }
@Test public void givenJsonWhenBuildingApplicationExpectSuccess() throws ActivationException, AssemblyException { ApplicationBuilder builder = ApplicationBuilder.fromJson( APPLICATION ); Application application = builder.newApplication(); Module module = application.findModule( "layer3", "test module" ); TestService service = module.findService( TestService.class ).get(); assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) ); }
/** * Load an ApplicationBuilder from a JSONObject. * @param root JSON object * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( JsonObject root ) throws AssemblyException { String applicationName = root.getString( "name" ); ApplicationBuilder builder = new ApplicationBuilder( applicationName ); builder.configureWithJson( root ); return builder; }
/** * Load an ApplicationBuilder from a JSON String. * @param json JSON String * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( String json ) { JsonObject root = Json.createReader( new StringReader( json ) ).readObject(); return fromJson( root ); }
/** * Declare Module. * @param moduleName Name of the Module * @return Module declaration for the given name, new if did not already exists */ public ModuleDeclaration withModule( String moduleName ) { ModuleDeclaration module = modules.get( moduleName ); if( module != null ) { return module; } module = new ModuleDeclaration( moduleName ); modules.put( moduleName, module ); return module; }
/** * Declare Layer. * @param layerName Name of the Layer * @return Layer declaration for the given name, new if did not already exists */ public LayerDeclaration withLayer( String layerName ) { LayerDeclaration layerDeclaration = layers.get( layerName ); if( layerDeclaration != null ) { return layerDeclaration; } layerDeclaration = new LayerDeclaration( layerName ); layers.put( layerName, layerDeclaration ); return layerDeclaration; }
LayerAssembly createLayer( ApplicationAssembly application ) { layer = application.layer( layerName ); layer.setName( layerName ); for( ModuleDeclaration module : modules.values() ) { ModuleAssembly assembly = module.createModule( layer ); } return layer; }
/** * {@literal main} method that read JSON from STDIN. * <p>Passivation exceptions are written to STDERR if any.</p> * @param args Unused * @throws AssemblyException if the assembly failed * @throws ActivationException if the activation failed */ public static void main( String[] args ) throws ActivationException, AssemblyException { fromJson( System.in ).withPassivationShutdownHook().newApplication(); } }
/** * Load an ApplicationBuilder from a JSONObject. * @param root JSON object * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( JsonObject root ) throws AssemblyException { String applicationName = root.getString( "name" ); ApplicationBuilder builder = new ApplicationBuilder( applicationName ); builder.configureWithJson( root ); return builder; }
/** * Declare Assembler. * @param classname Assembler class name * @return This Module declaration * @throws AssemblyException if unable to load class, not an Assembler or unable to instanciate */ public ModuleDeclaration withAssembler( String classname ) throws AssemblyException { Class<? extends Assembler> clazz = loadClass( classname ); return withAssembler( clazz ); }
/** * Load an ApplicationBuilder from a JSON InputStream. * @param json JSON input * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( InputStream json ) throws AssemblyException { JsonObject root = Json.createReader( json ).readObject(); return fromJson( root ); }
/** * Declare Assembler. * @param assemblerClass Assembler class * @return This Module declaration * @throws AssemblyException not an Assembler or if unable to instanciate */ public ModuleDeclaration withAssembler( Class<?> assemblerClass ) throws AssemblyException { Assembler assembler = createAssemblerInstance( assemblerClass ); assemblers.add( assembler ); return this; }
/** * Declare Module. * @param moduleName Name of the Module * @return Module declaration for the given name, new if did not already exists */ public ModuleDeclaration withModule( String moduleName ) { ModuleDeclaration module = modules.get( moduleName ); if( module != null ) { return module; } module = new ModuleDeclaration( moduleName ); modules.put( moduleName, module ); return module; }
/** * Declare Layer. * @param layerName Name of the Layer * @return Layer declaration for the given name, new if did not already exists */ public LayerDeclaration withLayer( String layerName ) { LayerDeclaration layerDeclaration = layers.get( layerName ); if( layerDeclaration != null ) { return layerDeclaration; } layerDeclaration = new LayerDeclaration( layerName ); layers.put( layerName, layerDeclaration ); return layerDeclaration; }
LayerAssembly createLayer( ApplicationAssembly application ) { layer = application.layer( layerName ); layer.setName( layerName ); for( ModuleDeclaration module : modules.values() ) { ModuleAssembly assembly = module.createModule( layer ); } return layer; }
/** * Load an ApplicationBuilder from a JSON InputStream. * @param json JSON input * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( InputStream json ) throws AssemblyException { JsonObject root = Json.createReader( json ).readObject(); return fromJson( root ); }
/** * Load an ApplicationBuilder from a JSON String. * @param json JSON String * @return Application Builder loaded from JSON * @throws AssemblyException if unable to declare the assembly */ public static ApplicationBuilder fromJson( String json ) { JsonObject root = Json.createReader( new StringReader( json ) ).readObject(); return fromJson( root ); }