Ejemplo n.º 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;
  }