Package org.jboss.errai.ioc.rebind.ioc.injector.api

Examples of org.jboss.errai.ioc.rebind.ioc.injector.api.InjectionContext


        */
        return loadVariable(creationalCallbackVarName).invoke("getInstance", Refs.get("context"));
      }
    }

    final InjectionContext injectContext = injectableInstance.getInjectionContext();
    final IOCProcessingContext ctx = injectContext.getProcessingContext();

    /*
    get a parameterized version of the CreationalCallback class, parameterized with the type of
    bean it produces.
    */
    final MetaClass creationCallbackRef = parameterizedAs(CreationalCallback.class, typeParametersOf(type));

    /*
    begin building the creational callback, implement the "getInstance" method from the interface
    and assign its BlockBuilder to a callbackBuilder so we can work with it.
    */
    final BlockBuilder<AnonymousClassStructureBuilder> callbackBuilder
        = newInstanceOf(creationCallbackRef).extend()
        .publicOverridesMethod("getInstance", Parameter.of(CreationalContext.class, "context", true));

    /* push the method block builder onto the stack, so injection tasks are rendered appropriately. */
    ctx.pushBlockBuilder(callbackBuilder);

    /* get a new unique variable for the creational callback */
    creationalCallbackVarName = InjectUtil.getNewInjectorName().concat("_")
        .concat(type.getName()).concat("_creational");

    /* get the construction strategy and execute it to wire the bean */
    getConstructionStrategy(this, injectContext).generateConstructor(new ConstructionStatusCallback() {
      @Override
      public void beanConstructed() {
        /* the bean has been constructed, so get a reference to the BeanRef and set it to the 'beanRef' variable. */

        /* add the bean to CreationalContext */
        callbackBuilder.append(
            loadVariable("context").invoke("addBean", loadVariable("context").invoke("getBeanReference", load(type),
                load(qualifyingMetadata.getQualifiers())), Refs.get(instanceVarName))
        );

        /* mark this injector as injected so we don't go into a loop if there is a cycle. */
        setCreated(true);
      }
    });

    /*
    return the instance of the bean from the creational callback.
    */
    callbackBuilder.append(loadVariable(instanceVarName).returnValue());

    /* pop the block builder of the stack now that we're done wiring. */
    ctx.popBlockBuilder();

    /*
    declare a final variable for the CreationalCallback and initialize it with the anonymous class we just
    built.
    */
    ctx.getBootstrapBuilder().privateField(creationalCallbackVarName, creationCallbackRef).modifiers(Modifier.Final)
        .initializesWith(callbackBuilder.finish().finish()).finish();

    final Statement retVal;

    if (isSingleton()) {
      /*
       if the injector is for a singleton, we create a variable to hold the singleton reference in the bootstrapper
       method and assign it with CreationalContext.getInstance().
       */
      ctx.getBootstrapBuilder().privateField(instanceVarName, type).modifiers(Modifier.Final)
          .initializesWith(loadVariable(creationalCallbackVarName).invoke("getInstance", Refs.get("context"))).finish();

      /*
       use the variable we just assigned as the return value for this injector.
       */
      retVal = Refs.get(instanceVarName);
    }
    else {
      /*
       the injector is a dependent scope, so use CreationContext.getInstance() as the return value.
       */
      retVal = loadVariable(creationalCallbackVarName).invoke("getInstance", Refs.get("context"));
    }

    setRendered(true);
    markRendered(injectableInstance);

    /*
      notify any component waiting for this type that is is ready now.
     */
    injectableInstance.getInjectionContext().getProcessingContext()
        .handleDiscoveryOfType(injectableInstance);

    injectContext.markProxyClosedIfNeeded(getInjectedType(), getQualifyingMetadata());
    /*
      return the reference to this bean to whoever called us.
     */
    return retVal;
  }
View Full Code Here


    }
  }

  @Override
  public Statement getBeanInstance(final InjectableInstance injectableInstance) {
    final InjectionContext injectionContext = injectableInstance.getInjectionContext();

    if (isDependent()) {
      renderGlobalCreationalContext(injectableInstance, injectionContext);
      return registerDestructorCallback(injectionContext, injectionContext.getProcessingContext().getBlockBuilder(),
          producerInjectableInstance.getValueStatement(), disposerMethod);
    }

    final BlockBuilder callbackBuilder = injectionContext.getProcessingContext().getBlockBuilder();

    final MetaClass creationCallbackRef = parameterizedAs(CreationalCallback.class,
        typeParametersOf(injectedType));

    final String var = InjectUtil.getUniqueVarName();
View Full Code Here

    final IOCProcessingContext procContext = iocProcContextBuilder.build();

    injectionContextBuilder.processingContext(procContext);
    injectionContextBuilder.reachableTypes(allDeps);
    final InjectionContext injectionContext = injectionContextBuilder.build();

    defaultConfigureProcessor(injectionContext);

    // generator constructor source code
    final IOCProcessorFactory procFactory = new IOCProcessorFactory(injectionContext);
View Full Code Here

                    .methodComment("The main IOC bootstrap method.");

    SourceWriter sourceWriter = new StringSourceWriter();

    procContext = new IOCProcessingContext(logger, context, sourceWriter, buildContext, bootStrapClass, blockBuilder);
    injectionContext = new InjectionContext(procContext);
    procFactory = new IOCProcessorFactory(injectionContext);

    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    Properties props = scanner.getProperties("ErraiApp.properties");
View Full Code Here

        */
        return loadVariable(creationalCallbackVarName).invoke("getInstance", Refs.get("context"));
      }
    }

    final InjectionContext injectContext = injectableInstance.getInjectionContext();
    final IOCProcessingContext ctx = injectContext.getProcessingContext();

    /*
    get a parameterized version of the CreationalCallback class, parameterized with the type of
    bean it produces.
    */
 
View Full Code Here

      final String gen;

      log.info("generating IOC bootstrapping class...");
      final long st = System.currentTimeMillis();

      final InjectionContext injectionContext = setupContexts(packageName, className);

      gen = generateBootstrappingClassSource(injectionContext);
      log.info("generated IOC bootstrapping class in " + (System.currentTimeMillis() - st) + "ms "
          + "(" + injectionContext.getAllKnownInjectionTypes().size() + " beans processed)");

      return _bootstrapperCache = gen;
    }
  }
View Full Code Here

    injectionContextBuilder.processingContext(processingContext);
    injectionContextBuilder.reachableTypes(allDeps);
    injectionContextBuilder.asyncBootstrap(asyncBootstrap);

    final InjectionContext injectionContext = injectionContextBuilder.build();

    defaultConfigureProcessor(injectionContext);

    return injectionContext;
  }
View Full Code Here

    final IOCProcessingContext procContext = iocProcContextBuilder.build();

    injectionContextBuilder.processingContext(procContext);
    injectionContextBuilder.reachableTypes(allDeps);
    final InjectionContext injectionContext = injectionContextBuilder.build();

    defaultConfigureProcessor(injectionContext);

    // generator constructor source code
    final IOCProcessorFactory procFactory = new IOCProcessorFactory(injectionContext);
View Full Code Here

    if ((isRendered() && isEnabled()) ||
        injectableInstance.getInjectionContext().isBlacklisted(type)) {
      return;
    }

    final InjectionContext injectContext = injectableInstance.getInjectionContext();
    final IOCProcessingContext ctx = injectContext.getProcessingContext();

     /*
     get a parameterized version of the BeanProvider class, parameterized with the type of
     bean it produces.
     */
    final MetaClass creationCallbackRef = parameterizedAs(BeanProvider.class, typeParametersOf(type));

     /*
     begin building the creational callback, implement the "getInstance" method from the interface
     and assign its BlockBuilder to a callbackBuilder so we can work with it.
     */
    final BlockBuilder<AnonymousClassStructureBuilder> callbackBuilder
        = newInstanceOf(creationCallbackRef).extend()
        .publicOverridesMethod("getInstance", Parameter.of(CreationalContext.class, "context", true));

     /* push the method block builder onto the stack, so injection tasks are rendered appropriately. */
    ctx.pushBlockBuilder(callbackBuilder);

     /* get a new unique variable for the creational callback */
    creationalCallbackVarName = InjectUtil.getNewInjectorName().concat("_")
        .concat(type.getName()).concat("_creational");

     /* get the construction strategy and execute it to wire the bean */
    getConstructionStrategy(this, injectContext).generateConstructor(new ConstructionStatusCallback() {
      @Override
      public void beanConstructed(final ConstructionType constructionType) {
        final Statement beanRef = Refs.get(instanceVarName);

        callbackBuilder.append(
            loadVariable("context").invoke("addBean", loadVariable("context").invoke("getBeanReference", load(type),
                load(qualifyingMetadata.getQualifiers())), beanRef)
        );

         /* mark this injector as injected so we don't go into a loop if there is a cycle. */
        setCreated(true);
      }
    });


    callbackBuilder.appendAll(getAddToEndStatements());

     /*
     return the instance of the bean from the creational callback.
     */
    if (isProxied()) {
      callbackBuilder.appendAll(createProxyDeclaration(injectContext));
      callbackBuilder.append(loadVariable(getProxyInstanceVarName()).returnValue());
    }
    else {
      callbackBuilder.append(loadVariable(instanceVarName).returnValue());
    }
     /* pop the block builder of the stack now that we're done wiring. */
    ctx.popBlockBuilder();

     /*
     declare a final variable for the BeanProvider and initialize it with the anonymous class we just
     built.
     */
    ctx.getBootstrapBuilder().privateField(creationalCallbackVarName, creationCallbackRef).modifiers(Modifier.Final)
        .initializesWith(callbackBuilder.finish().finish()).finish();

    if (isSingleton()) {
       /*
        if the injector is for a singleton, we create a variable to hold the singleton reference in the bootstrapper
        method and assign it with SimpleCreationalContext.getInstance().
        */
      ctx.getBootstrapBuilder().privateField(instanceVarName, type).modifiers(Modifier.Final)
          .initializesWith(loadVariable(creationalCallbackVarName).invoke("getInstance", Refs.get("context"))).finish();

      registerWithBeanManager(injectContext, Refs.get(instanceVarName));
    }
    else {
      registerWithBeanManager(injectContext, null);
    }

    setRendered(true);
    markRendered(injectableInstance);

     /*
       notify any component waiting for this type that is is ready now.
      */
    injectableInstance.getInjectionContext().getProcessingContext()
        .handleDiscoveryOfType(injectableInstance, getInjectedType());

    injectContext.markProxyClosedIfNeeded(getInjectedType(), getQualifyingMetadata());
  }
View Full Code Here

      final String gen;

      log.info("generating IOC bootstrapping class...");
      final long st = System.currentTimeMillis();

      final InjectionContext injectionContext = setupContexts(packageName, className);

      gen = generateBootstrappingClassSource(injectionContext);
      log.info("generated IOC bootstrapping class in " + (System.currentTimeMillis() - st) + "ms "
          + "(" + injectionContext.getAllKnownInjectionTypes().size() + " beans processed)");

      ThreadUtil.execute(new Runnable() {
        @Override
        public void run() {
          RebindUtils.writeStringToFile(cacheFile, gen);
View Full Code Here

TOP

Related Classes of org.jboss.errai.ioc.rebind.ioc.injector.api.InjectionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.