Beispiel #1
0
  public static BeanRule newInstance(
      String id,
      String className,
      String scanPattern,
      String maskPattern,
      String initMethodName,
      String destroyMethodName,
      String factoryMethodName,
      String scope,
      Boolean singleton,
      Boolean lazyInit,
      Boolean important) {

    if (className == null && scanPattern == null) {
      throw new IllegalArgumentException("The 'bean' element requires a 'class' attribute.");
    }

    ScopeType scopeType = ScopeType.resolve(scope);

    if (scope != null && scopeType == null) {
      throw new IllegalArgumentException("No scope type registered for '" + scope + "'.");
    }

    if (scopeType == null) {
      scopeType =
          (singleton == null || singleton == Boolean.TRUE)
              ? ScopeType.SINGLETON
              : ScopeType.PROTOTYPE;
    }

    BeanRule beanRule = new BeanRule();
    beanRule.setId(id);
    if (scanPattern == null) {
      beanRule.setClassName(className);
    } else {
      beanRule.setScanPattern(scanPattern);
      beanRule.setMaskPattern(maskPattern);
    }
    beanRule.setScopeType(scopeType);
    beanRule.setSingleton(singleton);
    beanRule.setInitMethodName(initMethodName);
    beanRule.setDestroyMethodName(destroyMethodName);
    beanRule.setFactoryMethodName(factoryMethodName);
    beanRule.setLazyInit(lazyInit);
    beanRule.setImportant(important);
    return beanRule;
  }
Beispiel #2
0
  public static BeanRule newOfferedBeanInstance(
      String id,
      String offerBeanId,
      String offerMethodName,
      String initMethodName,
      String destroyMethodName,
      String factoryMethodName,
      String scope,
      Boolean singleton,
      Boolean lazyInit,
      Boolean important) {

    if (offerBeanId == null || offerMethodName == null) {
      throw new IllegalArgumentException(
          "The 'bean' element requires both 'offerBean' attribute and 'offerMethod' attribute.");
    }

    ScopeType scopeType = ScopeType.resolve(scope);

    if (scope != null && scopeType == null) {
      throw new IllegalArgumentException("No scope type registered for '" + scope + "'.");
    }

    if (scopeType == null) {
      scopeType =
          (singleton == null || singleton == Boolean.TRUE)
              ? ScopeType.SINGLETON
              : ScopeType.PROTOTYPE;
    }

    BeanRule beanRule = new BeanRule();
    beanRule.setId(id);
    beanRule.setScopeType(scopeType);
    beanRule.setSingleton(singleton);
    beanRule.setOfferBeanId(offerBeanId);
    beanRule.setOfferMethodName(offerMethodName);
    beanRule.setOffered(true);
    beanRule.setInitMethodName(initMethodName);
    beanRule.setDestroyMethodName(destroyMethodName);
    beanRule.setFactoryMethodName(factoryMethodName);
    beanRule.setLazyInit(lazyInit);
    beanRule.setImportant(important);
    return beanRule;
  }