Example #1
0
  /**
   * Returns the instance of the specified bean of matching type and qualifiers, or if there is no
   * matching bean within the context, the specified {@link CreationalCallback} is called to
   * instantiate and add the bean to the context.
   *
   * @param callback the {@link CreationalCallback} to be called in order to instantiate the bean if
   *     it is not already available withint he current creational context.
   * @param beanType the type of the bean
   * @param qualifiers the qualifiers for the bean
   * @param <T> the type of the bean
   * @return the instance of the bean
   * @see #getSingletonInstanceOrNew(org.jboss.vergere.client.BootstrapperInjectionContext,
   *     CreationalCallback, Class, java.lang.annotation.Annotation[])
   */
  @SuppressWarnings({"unchecked", "UnusedDeclaration"})
  public <T> T getInstanceOrNew(
      final CreationalCallback<T> callback,
      final Class<?> beanType,
      final Annotation[] qualifiers) {
    final BeanRef ref = getBeanReference(beanType, qualifiers);

    if (wired.containsKey(ref)) {
      return (T) wired.get(ref);
    } else {
      return callback.getInstance(this);
    }
  }
Example #2
0
  /**
   * Returns the instance of the specified bean of matching type and qualifiers, or if there is no
   * matching bean within the context, an instance of the bean will be obtained from the {@link
   * BootstrapperInjectionContext}. This method assumes that the caller <em>knows</em> that the bean
   * is a singleton bean. It is called directly by the IOC bootstrapping code.
   *
   * <p>In the event that bean is not available within the {@link BootstrapperInjectionContext}, the
   * specified {@link CreationalCallback} is invoked at the bean is added to the {@link
   * BootstrapperInjectionContext}. This functionality primarily enables proper behavior for
   * singleton producers.
   *
   * @param injectionContext the {@link BootstrapperInjectionContext} of the container
   * @param callback the {@link CreationalCallback} to be called in order to instantiate the bean if
   *     it is not already available withint he current creational context. * @param beanType
   * @param qualifiers the qualifiers for the bean
   * @param <T> the type of the bean
   * @return the instance of the bean
   * @see #getInstanceOrNew(CreationalCallback, Class, java.lang.annotation.Annotation[])
   */
  public <T> T getSingletonInstanceOrNew(
      final BootstrapperInjectionContext injectionContext,
      final CreationalCallback<T> callback,
      final Class<?> beanType,
      final Annotation[] qualifiers) {

    @SuppressWarnings("unchecked")
    T inst = (T) getBeanInstance(beanType, qualifiers);

    if (inst != null) {
      return inst;
    } else {
      inst = callback.getInstance(this);
      injectionContext.addBean(beanType, beanType, callback, inst, qualifiers);
      return inst;
    }
  }