Examples of InjectionContext


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

  @Override
  public void renderProvider(final InjectableInstance injectableInstance) {
    if (isRendered()) 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 beanProviderClassRef = parameterizedAs(AsyncBeanProvider.class, typeParametersOf(type));
    final MetaClass creationalCallbackClassRef = 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(beanProviderClassRef).extend()
        .publicOverridesMethod("getInstance", Parameter.of(creationalCallbackClassRef, "callback", true),
            Parameter.of(AsyncCreationalContext.class, "context", true));


    final boolean loadAsync = type.isAnnotationPresent(LoadAsync.class);

    final BlockBuilder<AnonymousClassStructureBuilder> targetBlock;

    if (loadAsync) {
      final BlockBuilder<AnonymousClassStructureBuilder> asyncBuilder = ObjectBuilder.newInstanceOf(RunAsyncCallback.class).extend()
          .publicOverridesMethod("onFailure", Parameter.of(Throwable.class, "throwable"))
          .append(Stmt.throw_(RuntimeException.class, "failed to run asynchronously", Refs.get("throwable")))
          .finish()
          .publicOverridesMethod("onSuccess");

      targetBlock = asyncBuilder;
    }
    else {
      targetBlock = callbackBuilder;
    }
        /* push the method block builder onto the stack, so injection tasks are rendered appropriately. */
    ctx.pushBlockBuilder(targetBlock);

    targetBlock.append(
        Stmt.create().declareFinalVariable("beanRef", BeanRef.class,
            loadVariable("context").invoke("getBeanReference", load(type),
                load(qualifyingMetadata.getQualifiers()))
        ));

    targetBlock.append(
        Stmt.create().declareFinalVariable("async", AsyncBeanContext.class,
            Stmt.create().newObject(AsyncBeanContext.class))
    );

    /* 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 */
    AsyncInjectUtil.getConstructionStrategy(this, injectContext).generateConstructor(new ConstructionStatusCallback() {
      @Override
      public void beanConstructed(final ConstructionType constructionType) {
        /* the bean has been constructed, so get a reference to the BeanRef and set it to the 'beanRef' variable. */

        injectContext.getProcessingContext().append(
            loadVariable("context").invoke("addBean", Refs.get("beanRef"), Refs.get(instanceVarName))
        );

        /* add the bean to SimpleCreationalContext */

        final ObjectBuilder objectBuilder = Stmt.create().newObject(Runnable.class);
        final BlockBuilder<AnonymousClassStructureBuilder> blockBuilder = objectBuilder
            .extend().publicOverridesMethod("run");

        final BlockBuilderUpdater updater
            = new BlockBuilderUpdater(injectContext, AsyncTypeInjector.this, constructionType, targetBlock, blockBuilder);

        setAttribute("BlockBuilderUpdater", updater);
        final Statement beanRef = updater.run();

        injectContext.addBeanReference(type, beanRef);
        addStatementToEndOfInjector(Stmt.loadVariable("async").invoke("runOnFinish", blockBuilder.finish().finish()));

        /* 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.
    */

    targetBlock.appendAll(getAddToEndStatements());

    targetBlock._(Stmt.loadVariable("async").invoke("finish"));

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

    if (loadAsync) {
      final ObjectBuilder objectBuilder = targetBlock.finish().finish();

      final String frameworkOrSystemProperty
          = EnvUtil.getEnvironmentConfig().getFrameworkOrSystemProperty("errai.ioc.testing.simulated_loadasync_latency");
      if (Boolean.parseBoolean(frameworkOrSystemProperty)) {
        callbackBuilder.append(Stmt.invokeStatic(FakeGWT.class, "runAsync", objectBuilder));
      }
      else {
        callbackBuilder.append(Stmt.invokeStatic(GWT.class, "runAsync", objectBuilder));
      }
    }
    /*
      declare a final variable for the BeanProvider and initialize it with the anonymous class we just
      built.
    */
    ctx.getBootstrapBuilder().privateField(creationalCallbackVarName, beanProviderClassRef).modifiers(Modifier.Final)
        .initializesWith(callbackBuilder.finish().finish()).finish();

    if (isSingleton()) {
      registerWithBeanManager(injectContext, Stmt.load(true));
    }
    else {
      registerWithBeanManager(injectContext, Stmt.load(false));
    }

    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

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

    super(decoratesWith);
  }

  @Override
  public List<? extends Statement> generateDecorator(InjectableInstance<Service> injectableInstance) {
    final InjectionContext ctx = injectableInstance.getInjectionContext();

    /**
     * Ensure the the container generates a stub to internally expose the field if it's private.
     */
    injectableInstance.ensureMemberExposed();

    final Statement busHandle = ctx.getInjector(MessageBus.class).getBeanInstance(injectableInstance);

    /**
     * Figure out the service name;
     */
    final String svcName = injectableInstance.getAnnotation().value().equals("")
View Full Code Here

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.
    */
 
View Full Code Here

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

    }
  }

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

    if (isDependent()) {
      return producerInjectableInstance.getValueStatement();
    }

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

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

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

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

            .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

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

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

      log.debug("setting up injection context...");
      final long injectionStart = System.currentTimeMillis();
      final InjectionContext injectionContext = setupContexts(packageName, className);
      log.debug("injection context setup in " + (System.currentTimeMillis() - injectionStart) + "ms");

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

      return gen;
    }
  }
View Full Code Here

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

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

    final InjectionContext injectionContext = injectionContextBuilder.build();

    defaultConfigureProcessor(injectionContext);

    return injectionContext;
  }
View Full Code Here

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

    if ((isRendered() && isEnabled()) ||
        !injectableInstance.getInjectionContext().isIncluded(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

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

  @Override
  public void renderProvider(final InjectableInstance injectableInstance) {
    if (isRendered()) 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 beanProviderClassRef = parameterizedAs(AsyncBeanProvider.class, typeParametersOf(type));
    final MetaClass creationalCallbackClassRef = 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(beanProviderClassRef).extend()
        .publicOverridesMethod("getInstance", Parameter.of(creationalCallbackClassRef, "callback", true),
            Parameter.of(AsyncCreationalContext.class, "context", true));


    final boolean loadAsync = type.isAnnotationPresent(LoadAsync.class);

    final BlockBuilder<AnonymousClassStructureBuilder> targetBlock;

    if (loadAsync) {
      final BlockBuilder<AnonymousClassStructureBuilder> asyncBuilder = ObjectBuilder.newInstanceOf(RunAsyncCallback.class).extend()
          .publicOverridesMethod("onFailure", Parameter.of(Throwable.class, "throwable"))
          .append(Stmt.throw_(RuntimeException.class, "failed to run asynchronously", Refs.get("throwable")))
          .finish()
          .publicOverridesMethod("onSuccess");

      targetBlock = asyncBuilder;
    }
    else {
      targetBlock = callbackBuilder;
    }
    /* push the method block builder onto the stack, so injection tasks are rendered appropriately. */
    ctx.pushBlockBuilder(targetBlock);

    targetBlock.append(
        Stmt.create().declareFinalVariable("beanRef", BeanRef.class,
            loadVariable("context").invoke("getBeanReference", load(type),
                load(qualifyingMetadata.getQualifiers()))
        ));

    targetBlock.append(
        Stmt.create().declareFinalVariable("async", AsyncBeanContext.class,
            Stmt.create().newObject(AsyncBeanContext.class))
    );

    /* 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 */
    AsyncInjectUtil.getConstructionStrategy(this, injectContext).generateConstructor(new ConstructionStatusCallback() {
      @Override
      public void beanConstructed(final ConstructionType constructionType) {
        /* the bean has been constructed, so get a reference to the BeanRef and set it to the 'beanRef' variable. */

        injectContext.getProcessingContext().append(
            loadVariable("context").invoke("addBean", Refs.get("beanRef"), Refs.get(instanceVarName))
        );

        /* add the bean to SimpleCreationalContext */

        final ObjectBuilder objectBuilder = Stmt.create().newObject(Runnable.class);
        final BlockBuilder<AnonymousClassStructureBuilder> blockBuilder = objectBuilder
            .extend().publicOverridesMethod("run");

        final BlockBuilderUpdater updater
            = new BlockBuilderUpdater(injectContext, AsyncTypeInjector.this, constructionType, targetBlock, blockBuilder);

        setAttribute("BlockBuilderUpdater", updater);
        final Statement beanRef = updater.run();

        injectContext.addBeanReference(type, beanRef);
        addStatementToEndOfInjector(Stmt.loadVariable("async").invoke("runOnFinish", blockBuilder.finish().finish()));

        /* 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.
    */

    targetBlock.appendAll(getAddToEndStatements());

    targetBlock._(Stmt.loadVariable("async").invoke("finish"));

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

    if (loadAsync) {
      final ObjectBuilder objectBuilder = targetBlock.finish().finish();

      final String frameworkOrSystemProperty
          = EnvUtil.getEnvironmentConfig().getFrameworkOrSystemProperty("errai.ioc.testing.simulated_loadasync_latency");
     
      Class<?> fragmentName = type.getAnnotation(LoadAsync.class).value();
     
      Class<?> gwtClass = Boolean.parseBoolean(frameworkOrSystemProperty) ? FakeGWT.class : GWT.class;
      Statement asyncStatement = (NO_FRAGMENT.class.equals(fragmentName)) ?
            Stmt.invokeStatic(gwtClass, "runAsync", objectBuilder) :
              Stmt.invokeStatic(gwtClass, "runAsync", fragmentName, objectBuilder);
      callbackBuilder.append(asyncStatement);
    }
    /*
      declare a final variable for the BeanProvider and initialize it with the anonymous class we just
      built.
    */
    ctx.getBootstrapBuilder().privateField(creationalCallbackVarName, beanProviderClassRef).modifiers(Modifier.Final)
        .initializesWith(callbackBuilder.finish().finish()).finish();

    if (isSingleton()) {
      registerWithBeanManager(injectContext, Stmt.load(true));
    }
    else {
      registerWithBeanManager(injectContext, Stmt.load(false));
    }

    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

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

  public AsyncProducerInjector(final MetaClass injectedType,
                               final MetaClassMember producerMember,
                               final InjectableInstance producerInjectableInstance) {

    final InjectionContext injectionContext = producerInjectableInstance.getInjectionContext();

    switch (producerInjectableInstance.getTaskType()) {
      case PrivateField:
      case PrivateMethod:
        producerInjectableInstance.ensureMemberExposed(PrivateAccessType.Read);
    }

    super.qualifyingMetadata = producerInjectableInstance.getQualifyingMetadata();
    this.provider = true;
    this.injectedType = injectedType;
    this.enclosingType = producerMember.getDeclaringClass();
    this.producerMember = producerMember;
    this.producerInjectableInstance = producerInjectableInstance;

    this.singleton = injectionContext.isElementType(WiringElementType.SingletonBean, getProducerMember());

    this.disposerMethod = findDisposerMethod(injectionContext.getProcessingContext());

    this.creationalCallbackVarName = InjectUtil.getNewInjectorName().concat("_")
        .concat(injectedType.getName().concat("_creational"));

    final Set<Annotation> qualifiers = JSR330QualifyingMetadata.createSetFromAnnotations(producerMember
            .getAnnotations());

    qualifiers.add(BuiltInQualifiers.ANY_INSTANCE);

    qualifyingMetadata = injectionContext.getProcessingContext().getQualifyingMetadataFactory()
        .createFrom(qualifiers.toArray(new Annotation[qualifiers.size()]));

    if (producerMember.isAnnotationPresent(Specializes.class)) {
      makeSpecialized(injectionContext);
    }

    if (producerMember.isAnnotationPresent(Named.class)) {
      final Named namedAnnotation = producerMember.getAnnotation(Named.class);

      this.beanName = namedAnnotation.value().equals("")
          ? ReflectionUtil.getPropertyFromAccessor(producerMember.getName()) : namedAnnotation.value();
    }

    injectionContext.addInjectorRegistrationListener(producerMember.getDeclaringClass(),
        new InjectorRegistrationListener() {
          @Override
          public void onRegister(final MetaClass type, final Injector injector) {
            injector.addDisablingHook(new Runnable() {
              @Override
              public void run() {
                setEnabled(false);
              }
            });
          }
        });

    if (producerMember instanceof MetaMethod && injectionContext.isOverridden((MetaMethod) producerMember)) {
      setEnabled(false);
    }

    if (injectionContext.isInjectorRegistered(enclosingType, qualifyingMetadata)) {
      setRendered(true);
    }
    else {
      injectionContext.getProcessingContext().registerTypeDiscoveryListener(new TypeDiscoveryListener() {
        @Override
        public void onDiscovery(final IOCProcessingContext context,
                                final InjectionPoint injectionPoint,
                                final MetaClass injectedType) {
          if (injectionPoint.getEnclosingType().equals(enclosingType)) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.