4 Replies Latest reply on Jul 2, 2012 6:38 AM by Michael Anstis

    errai-codegen questions

    Michael Anstis Newbie

      Hi,

       

      I'm need to generate some classes from annotations in developer\user-provided classes; and have a few questions.

       

      Sorry for the lengthy questions, but I have tried to give some background as to what I am trying to achieve and evidence of what I find.

       

      1) Extension to Errai's IOC container

       

      I was thinking of using a custom IOCExtension to handle the generation. It would identify the annotated classed and generate the code I need.

       

      I have written a IOCExtensionConfigurator and can see it is called; however it appears to be called after (at least one implementation of) BootstrapperImpl is created:-

       

      I assume this means, if I generate classes that contain CDI annotations I've missed the boat for them being included in the BootStrapperImpl and hence they won't work.

       

      Can I control the order in which IOCExtensions are executed?

       

      [INFO] Compiling module org.drools.guvnor.GuvnorNGCore

      [ERROR] SLF4J: Class path contains multiple SLF4J bindings.

      [ERROR] SLF4J: Found binding in [jar:file:/home/manstis/.m2/repository/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]

      [ERROR] SLF4J: Found binding in [jar:file:/home/manstis/.m2/repository/org/jboss/weld/servlet/weld-servlet/1.1.6.Final/weld-servlet-1.1.6.Final.jar!/org/slf4j/impl/StaticLoggerBinder.class]

      [ERROR] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

      [INFO]    Scanning for additional dependencies: jar:file:/home/manstis/.m2/repository/org/jboss/errai/errai-ioc/2.1-SNAPSHOT/errai-ioc-2.1-SNAPSHOT.jar!/org/jboss/errai/ioc/client/Container.java

      [INFO]       Computing all possible rebind results for 'org.jboss.errai.ioc.client.Bootstrapper'

      [INFO]          Rebinding org.jboss.errai.ioc.client.Bootstrapper

      [INFO]             Invoking generator org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCGenerator

      [INFO]                Generating Extensions Bootstrapper...

      [INFO]                Checking ErraiApp.properties for configured types ...

      [INFO] ---> WorkbenchIOCExtension.configure

      [INFO] ---> WorkbenchIOCExtension.afterInitialisation

      [INFO]          Rebinding org.jboss.errai.ioc.client.Bootstrapper

      [INFO]             Invoking generator org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCGenerator

      [INFO]                Generating Extensions Bootstrapper...

      [INFO]          Rebinding org.jboss.errai.ioc.client.Bootstrapper

      [INFO]             Invoking generator org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCGenerator

      [INFO]                Generating Extensions Bootstrapper...

      [INFO]          Rebinding org.jboss.errai.ioc.client.Bootstrapper

      [INFO]             Invoking generator org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCGenerator

      [INFO]                Generating Extensions Bootstrapper...

      [INFO]          Rebinding org.jboss.errai.ioc.client.Bootstrapper

      [INFO]             Invoking generator org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCGenerator

      [INFO]                Generating Extensions Bootstrapper...

      [INFO]          Rebinding org.jboss.errai.ioc.client.Bootstrapper

      [INFO]             Invoking generator org.jboss.errai.ioc.rebind.ioc.bootstrapper.IOCGenerator

      [INFO]                Generating Extensions Bootstrapper...

       

      2) IOCExtensionConfigurator.configure

       

      I read the JavaDoc and had a look at JSR299IOCExtensionConfigurator. It looked like it gave me the opportunity to register annotations my extension may be interested in.

       

      However in IOCExtensionConfigurator.afterInitialization I still had to use "ScannerSingleton.getOrCreateInstance().getTypesAnnotatedWith( NameToken.class )" to find the classes I was interested in.

       

      @IOCExtension

      public class WorkbenchIOCExtension

          implements

          IOCExtensionConfigurator {

       

          @Override

          public void configure(IOCProcessingContext context,

                                InjectionContext injectionContext,

                                IOCProcessorFactory procFactory) {

              System.out.println( "---> WorkbenchIOCExtension.configure" );

       

              injectionContext.mapElementType( WiringElementType.DependentBean,

                                               NameToken.class );

       

          }

       

          @Override

          public void afterInitialization(IOCProcessingContext context,

                                          InjectionContext injectionContext,

                                          IOCProcessorFactory procFactory) {

              // TODO Auto-generated method stub

              System.out.println( "---> WorkbenchIOCExtension.afterInitialisation" );

       

              final MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();

              Set<Class< ? >> types = scanner.getTypesAnnotatedWith( NameToken.class );

              for ( Class< ? > type : types ) {

                  System.out.println( "--------> Found @NameToken on " + type.getName() );

              }

       

          }

       

      Is my understanding correct? What should I be configuring in IOCExtensionConfigurator.configure?

       

      Thank-you for your attention.

       

      With kind regards,

       

      Mike