More bootstrap documentation snippets using lambdas
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/b31e727e Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/b31e727e Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/b31e727e Branch: refs/heads/develop Commit: b31e727e0ddce78538e099e4ea82848f3c20edc1 Parents: 39e23d5 Author: Paul Merlin <[email protected]> Authored: Tue May 23 11:36:19 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Tue May 23 11:36:19 2017 +0200 ---------------------------------------------------------------------- .../bootstrap/DocumentationSupport.java | 380 +++++++++---------- 1 file changed, 190 insertions(+), 190 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b31e727e/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/DocumentationSupport.java ---------------------------------------------------------------------- diff --git a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/DocumentationSupport.java b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/DocumentationSupport.java index 591bacc..635bb1a 100644 --- a/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/DocumentationSupport.java +++ b/core/bootstrap/src/test/java/org/apache/polygene/bootstrap/DocumentationSupport.java @@ -19,6 +19,8 @@ */ package org.apache.polygene.bootstrap; +import java.util.Arrays; +import java.util.List; import java.util.function.Predicate; import org.apache.polygene.api.activation.ActivationException; import org.apache.polygene.api.common.Visibility; @@ -29,250 +31,227 @@ import org.apache.polygene.api.structure.Application; import org.apache.polygene.api.structure.ApplicationDescriptor; import org.apache.polygene.api.structure.Module; -@SuppressWarnings( "ALL" ) +@SuppressWarnings( { "unused", "ConstantConditionalExpression", "MethodNameSameAsClassName" } ) public class DocumentationSupport { + public static Predicate<ObjectAssembly> hasMyTypeSpecification = + item -> item.types().anyMatch( type -> type.equals( String.class ) ); - public static Predicate<ObjectAssembly> hasMyTypeSpecification = new Predicate<ObjectAssembly>() + public static class declarations { + static class MyObject {} - public boolean test( ObjectAssembly item ) - { - return item.types().anyMatch( type -> type.equals(String.class) ); - } + interface MyTransient {} - }; + interface MyValue {} - public static class objects - implements Assembler - { + interface MyEntity {} - public static class MyObject {} + class MyService {} - // START SNIPPET: objects - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + void declaration() { - module.objects( MyObject.class ).visibleIn( Visibility.layer ); + Assembler objects = + // START SNIPPET: objects + ( ModuleAssembly module ) -> module.objects( MyObject.class ).visibleIn( Visibility.layer ) + // END SNIPPET: objects + ; + Assembler transients = + // START SNIPPET: transients + ( ModuleAssembly module ) -> module.transients( MyTransient.class ).visibleIn( Visibility.layer ) + // END SNIPPET: transients + ; + Assembler values = + // START SNIPPET: values + ( ModuleAssembly module ) -> module.values( MyValue.class ).visibleIn( Visibility.layer ) + // END SNIPPET: values + ; + Assembler entities = + // START SNIPPET: entities + ( ModuleAssembly module ) -> module.entities( MyEntity.class ).visibleIn( Visibility.layer ) + // END SNIPPET: entities + ; + Assembler services = + // START SNIPPET: services + ( ModuleAssembly module ) -> module.services( MyService.class ).visibleIn( Visibility.layer ) + // END SNIPPET: services + ; + Assembler taggedServices = + // START SNIPPET: tagged-services + ( ModuleAssembly module ) -> module.services( MyService.class ).taggedWith( "foo", "bar" ) + // END SNIPPET: tagged-services + ; + List<Assembler> importedServices = Arrays.asList( + // START SNIPPET: imported-services + ( ModuleAssembly module ) -> module.importedServices( MyService.class ) + .importedBy( InstanceImporter.class ) + .setMetaInfo( new MyService() ), + + // OR + + ( ModuleAssembly module ) -> { + module.objects( MyService.class ); + module.importedServices( MyService.class ).importedBy( NewObjectImporter.class ); + } + // END SNIPPET: imported-services + ); } - // END SNIPPET: objects - } - public static class transients - implements Assembler + static class defaultPropertyValues { - - public static interface MyTransient {} - - // START SNIPPET: transients - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + interface MyValue { - module.transients( MyTransient.class ).visibleIn( Visibility.layer ); + Property<String> foo(); } - // END SNIPPET: transients - - } - public static class values - implements Assembler - { - - public static interface MyValue {} - - // START SNIPPET: values - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + interface MyEntity { - module.values( MyValue.class ).visibleIn( Visibility.layer ); + Property<String> cathedral(); } - // END SNIPPET: values - } - - public static class entities - implements Assembler - { - - public static interface MyEntity {} - - // START SNIPPET: entities - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + void defaultPropertyValues() { - module.entities( MyEntity.class ).visibleIn( Visibility.layer ); + Assembler assembler = + // START SNIPPET: properties-defaults + ( ModuleAssembly module ) -> { + module.values( MyValue.class ); + MyValue myValueDefaults = module.forMixin( MyValue.class ).declareDefaults(); + myValueDefaults.foo().set( "bar" ); + + module.entities( MyEntity.class ); + MyEntity myEntityDefaults = module.forMixin( MyEntity.class ).declareDefaults(); + myEntityDefaults.cathedral().set( "bazar" ); + } + // END SNIPPET: properties-defaults + ; } - // END SNIPPET: entities - } - public static class services - implements Assembler + public static class singleton { + interface MyService {} - public static interface MyService {} + interface Stuff {} - // START SNIPPET: services - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + void singleton() + throws ActivationException, AssemblyException { - module.services( MyService.class ).visibleIn( Visibility.layer ); + // START SNIPPET: singleton + SingletonAssembler assembler = new SingletonAssembler( + module -> { + module.services( MyService.class ).identifiedBy( "Foo" ); + module.services( MyService.class ).identifiedBy( "Bar" ); + module.objects( Stuff.class ); + } + ); + Module module = assembler.module(); + Stuff stuff = module.newObject( Stuff.class ); + // END SNIPPET: singleton } - // END SNIPPET: services - } - public static class taggedServices - implements Assembler + public static class pancake { - public static interface MyService {} - - // START SNIPPET: tagged-services - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + public static class LoginAssembler implements Assembler { - module.services( MyService.class ).taggedWith( "foo", "bar" ); + public void assemble( ModuleAssembly module ) { } } - // END SNIPPET: tagged-services - } - - public static class importedServices - implements Assembler - { - - public static class MyService {} - // START SNIPPET: imported-services - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + public static class MenuAssembler implements Assembler { - module.importedServices( MyService.class ). - importedBy( InstanceImporter.class ). - setMetaInfo( new MyService() ); - - // OR - - module.objects( MyService.class ); - module.importedServices( MyService.class ). - importedBy( NewObjectImporter.class ); + public void assemble( ModuleAssembly module ) { } } - // END SNIPPET: imported-services - } - public static class defaultPropertyValues - implements Assembler - { - - public interface MyValue { Property<String> foo(); } - public interface MyEntity { Property<String> cathedral(); } + public static class PerspectivesAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) { } + } - // START SNIPPET: properties-defaults - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException + public static class ViewsAssembler implements Assembler { - module.values( MyValue.class ); - MyValue myValueDefaults = module.forMixin( MyValue.class ).declareDefaults(); - myValueDefaults.foo().set( "bar" ); + public void assemble( ModuleAssembly module ) { } + } - module.entities( MyEntity.class ); - MyEntity myEntityDefaults = module.forMixin( MyEntity.class ).declareDefaults(); - myEntityDefaults.cathedral().set( "bazar" ); + public static class ReportingAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) { } } - // END SNIPPET: properties-defaults - } - public static class singleton - { + public static class PdfAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) { } + } - public interface MyService { } - public interface Stuff { } + public static class BookkeepingAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) { } + } - void singleton() - throws ActivationException, AssemblyException + public static class CashFlowAssembler implements Assembler { - // START SNIPPET: singleton - SingletonAssembler assembler = new SingletonAssembler( - module -> { - module.services( MyService.class ).identifiedBy( "Foo" ); - module.services( MyService.class ).identifiedBy( "Bar" ); - module.objects( Stuff.class ); - } - ); - Module module = assembler.module(); - Stuff stuff = module.newObject( Stuff.class ); - // END SNIPPET: singleton + public void assemble( ModuleAssembly module ) { } } - } + public static class BalanceSheetAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) { } + } - public static class pancake - { + public static class PricingAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) { } + } - public static class LoginAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class MenuAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class PerspectivesAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class ViewsAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class ReportingAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class PdfAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class BookkeepingAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class CashFlowAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class BalanceSheetAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class PricingAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class ProductAssembler implements Assembler { public void assemble( ModuleAssembly module ) throws AssemblyException { } } + public static class ProductAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) { } + } private static Energy4Java polygene; // START SNIPPET: pancake public static void main( String[] args ) - throws Exception + throws Exception { polygene = new Energy4Java(); - Assembler[][][] assemblers = new Assembler[][][]{ + Assembler[][][] assemblers = new Assembler[][][] { { // View Layer - { // Login Module - new LoginAssembler() + { // Login Module + new LoginAssembler() // : - }, - { // Main Workbench Module - new MenuAssembler(), - new PerspectivesAssembler(), - new ViewsAssembler() + }, + { // Main Workbench Module + new MenuAssembler(), + new PerspectivesAssembler(), + new ViewsAssembler() // : - }, - { // Printing Module - new ReportingAssembler(), - new PdfAssembler() + }, + { // Printing Module + new ReportingAssembler(), + new PdfAssembler() // : - } + } }, { // Application Layer - { // Accounting Module - new BookkeepingAssembler(), - new CashFlowAssembler(), - new BalanceSheetAssembler() + { // Accounting Module + new BookkeepingAssembler(), + new CashFlowAssembler(), + new BalanceSheetAssembler() // : - }, - { // Inventory Module - new PricingAssembler(), - new ProductAssembler() + }, + { // Inventory Module + new PricingAssembler(), + new ProductAssembler() // : - } + } }, { // Domain Layer - // : + // : }, { // Infrastructure Layer - // : + // : } }; ApplicationDescriptor model = newApplication( assemblers ); @@ -281,28 +260,51 @@ public class DocumentationSupport } private static ApplicationDescriptor newApplication( final Assembler[][][] assemblers ) - throws AssemblyException + throws AssemblyException { return polygene.newApplicationModel( factory -> factory.newApplicationAssembly( assemblers ) ); } // END SNIPPET: pancake - } public static class full { - public static class CustomerViewComposite{} - public static class CustomerEditComposite{} - public static class CustomerListViewComposite{} - public static class CustomerSearchComposite{} - public static class CustomerEntity{} - public static class CountryEntity{} - public static class AddressValue{} - public static class LdapAuthenticationAssembler implements Assembler{ public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class ThrinkAuthorizationAssembler implements Assembler{ public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class UserTrackingAuditAssembler implements Assembler{ public void assemble( ModuleAssembly module ) throws AssemblyException { } } - public static class NeoAssembler implements Assembler{ NeoAssembler( String path ) {} public void assemble( ModuleAssembly module ) throws AssemblyException { } } + static class CustomerViewComposite {} + + static class CustomerEditComposite {} + + static class CustomerListViewComposite {} + + static class CustomerSearchComposite {} + + static class CustomerEntity {} + + static class CountryEntity {} + + static class AddressValue {} + + public static class LdapAuthenticationAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) throws AssemblyException { } + } + + public static class ThrinkAuthorizationAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) throws AssemblyException { } + } + + public static class UserTrackingAuditAssembler implements Assembler + { + public void assemble( ModuleAssembly module ) throws AssemblyException { } + } + + public static class NeoAssembler implements Assembler + { + NeoAssembler( String path ) {} + + public void assemble( ModuleAssembly module ) throws AssemblyException { } + } // START SNIPPET: full private static Energy4Java polygene; @@ -310,7 +312,7 @@ public class DocumentationSupport private static Application application; public static void main( String[] args ) - throws Exception + throws Exception { // Create a Polygene Runtime polygene = new Energy4Java(); @@ -411,7 +413,5 @@ public class DocumentationSupport private static void createMessagingPersistenceModule( LayerAssembly layer ) throws AssemblyException { } - } - }
