Package org.springframework.beans.factory.support

Examples of org.springframework.beans.factory.support.AbstractBeanDefinition


      String setterName = "set" + StringUtils.capitalize(propertyName);
      Signature signature = new Signature(setterName, Type.VOID_TYPE, new Type[] { Type.getType(propertyType) });
      maker.add(signature, new Type[0]);
    }
    if (bd instanceof AbstractBeanDefinition) {
      AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
      if (abd.getInitMethodName() != null) {
        Signature signature = new Signature(abd.getInitMethodName(), Type.VOID_TYPE, new Type[0]);
        maker.add(signature, new Type[0]);
      }
      if (abd.getDestroyMethodName() != null) {
        Signature signature = new Signature(abd.getDestroyMethodName(), Type.VOID_TYPE, new Type[0]);
        maker.add(signature, new Type[0]);
      }
    }
    return maker.create();
  }
View Full Code Here


    if (containingBean == null) {
      checkNameUniqueness(beanName, aliases, ele);
    }

    AbstractBeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName, containingBean);
    if (beanDefinition != null) {
      if (!StringUtils.hasText(beanName)) {
        try {
          if (containingBean != null) {
            beanName = BeanDefinitionReaderUtils.generateBeanName(
                beanDefinition, this.readerContext.getRegistry(), true);
          }
          else {
            beanName = this.readerContext.generateBeanName(beanDefinition);
            // Register an alias for the plain bean class name, if still possible,
            // if the generator returned the class name plus a suffix.
            // This is expected for Spring 1.2/2.0 backwards compatibility.
            String beanClassName = beanDefinition.getBeanClassName();
            if (beanClassName != null &&
                beanName.startsWith(beanClassName) && beanName.length() > beanClassName.length() &&
                !this.readerContext.getRegistry().isBeanNameInUse(beanClassName)) {
              this.readerContext.getRegistry().registerAlias(beanName, beanClassName);
            }
View Full Code Here

    }

    try {
      this.parseState.push(new BeanEntry(beanName));

      AbstractBeanDefinition bd = BeanDefinitionReaderUtils.createBeanDefinition(
          parent, className, this.readerContext.getBeanClassLoader());

      if (ele.hasAttribute(SCOPE_ATTRIBUTE)) {
        // Spring 2.0 "scope" attribute
        bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE));
        if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
          error("Specify either 'scope' or 'singleton', not both", ele);
        }
      }
      else if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
        // Spring 1.x "singleton" attribute
        bd.setSingleton(TRUE_VALUE.equals(ele.getAttribute(SINGLETON_ATTRIBUTE)));
      }
      else if (containingBean != null) {
        // Take default from containing bean in case of an inner bean definition.
        bd.setScope(containingBean.getScope());
      }

      if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) {
        bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE)));
      }

      String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE);
      if (DEFAULT_VALUE.equals(lazyInit) && bd.isSingleton()) {
        // Just apply default to singletons, as lazy-init has no meaning for prototypes.
        lazyInit = this.defaults.getLazyInit();
      }
      bd.setLazyInit(TRUE_VALUE.equals(lazyInit));

      String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE);
      bd.setAutowireMode(getAutowireMode(autowire));

      String dependencyCheck = ele.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE);
      bd.setDependencyCheck(getDependencyCheck(dependencyCheck));

      if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) {
        String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE);
        bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, BEAN_NAME_DELIMITERS));
      }

      String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE);
      if ("".equals(autowireCandidate) || DEFAULT_VALUE.equals(autowireCandidate)) {
        String candidatePattern = this.defaults.getAutowireCandidates();
        if (candidatePattern != null) {
          String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern);
          bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName));
        }
      }
      else {
        bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate));
      }

      if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) {
        bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE)));
      }

      if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) {
        String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE);
        if (!"".equals(initMethodName)) {
          bd.setInitMethodName(initMethodName);
        }
      }
      else {
        if (this.defaults.getInitMethod() != null) {
          bd.setInitMethodName(this.defaults.getInitMethod());
          bd.setEnforceInitMethod(false);
        }
      }

      if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) {
        String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE);
        if (!"".equals(destroyMethodName)) {
          bd.setDestroyMethodName(destroyMethodName);
        }
      }
      else {
        if (this.defaults.getDestroyMethod() != null) {
          bd.setDestroyMethodName(this.defaults.getDestroyMethod());
          bd.setEnforceDestroyMethod(false);
        }
      }

      if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) {
        bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE));
      }
      if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) {
        bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE));
      }

      parseMetaElements(ele, bd);
      parseLookupOverrideSubElements(ele, bd.getMethodOverrides());
      parseReplacedMethodSubElements(ele, bd.getMethodOverrides());

      parseConstructorArgElements(ele, bd);
      parsePropertyElements(ele, bd);
      parseQualifierElements(ele, bd);

      bd.setResourceDescription(this.readerContext.getResource().getDescription());
      bd.setSource(extractSource(ele));

      return bd;
    }
    catch (ClassNotFoundException ex) {
      error("Bean class [" + className + "] not found", ele, ex);
View Full Code Here

    doParse(element, parserContext, builder);

    // check whether the bean is mandatory (and if it is, make it top-level
    // bean)

    AbstractBeanDefinition def = builder.getBeanDefinition();

    if (parserContext.isNested()) {
      StringBuffer id = new StringBuffer();
      String value = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
      if (StringUtils.hasText(value)) {
View Full Code Here

    if (mapping == null && context instanceof ConfigurableApplicationContext &&
        context.containsBeanDefinition(beanName)) {
      ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
      BeanDefinition bd = cac.getBeanFactory().getMergedBeanDefinition(beanName);
      if (bd instanceof AbstractBeanDefinition) {
        AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
        if (abd.hasBeanClass()) {
          Class<?> beanClass = abd.getBeanClass();
          mapping = AnnotationUtils.findAnnotation(beanClass, RequestMapping.class);
        }
      }
    }
View Full Code Here

      Set<BeanDefinition> candidates = findCandidateComponents(basePackages[i]);
      for (BeanDefinition candidate : candidates) {
        String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);
        if (checkBeanName(beanName, candidate)) {
          if (candidate instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition abd = (AbstractBeanDefinition) candidate;
            abd.applyDefaults(this.beanDefinitionDefaults);
            if (this.autowireCandidatePatterns != null) {
              abd.setAutowireCandidate(PatternMatchUtils.simpleMatch(this.autowireCandidatePatterns, beanName));
            }
          }
          ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);
          BeanDefinition beanDefinition = applyScope(candidate, beanName, scopeMetadata);
          beanDefinitions.add(new BeanDefinitionHolder(beanDefinition, beanName));
View Full Code Here

    Set<BeanDefinitionHolder> beanDefinitions = scanner.doScan(basePackages);

    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
    for (Iterator it = beanDefinitions.iterator(); it.hasNext();) {
      BeanDefinitionHolder beanDefHolder = (BeanDefinitionHolder) it.next();
      AbstractBeanDefinition beanDef = (AbstractBeanDefinition) beanDefHolder.getBeanDefinition();
      beanDef.setSource(parserContext.extractSource(beanDef.getSource()));
      compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
    }
    parserContext.getReaderContext().fireComponentRegistered(compositeDef);

    // Register annotation config processors, if necessary.
View Full Code Here

   * Parses the supplied <code>&lt;advisor&gt;</code> element and registers the resulting
   * {@link org.springframework.aop.Advisor} and any resulting {@link org.springframework.aop.Pointcut}
   * with the supplied {@link BeanDefinitionRegistry}.
   */
  private void parseAdvisor(Element advisorElement, ParserContext parserContext) {
    AbstractBeanDefinition advisorDef = createAdvisorBeanDefinition(advisorElement, parserContext);
    String id = advisorElement.getAttribute(ID);

    try {
      this.parseState.push(new AdvisorEntry(id));
      String advisorBeanName = id;
      if (StringUtils.hasText(advisorBeanName)) {
        parserContext.getRegistry().registerBeanDefinition(advisorBeanName, advisorDef);
      }
      else {
        advisorBeanName = parserContext.getReaderContext().registerWithGeneratedName(advisorDef);
      }

      Object pointcut = parsePointcutProperty(advisorElement, parserContext);
      if (pointcut instanceof BeanDefinition) {
        advisorDef.getPropertyValues().addPropertyValue(POINTCUT, pointcut);
        parserContext.registerComponent(
            new AdvisorComponentDefinition(advisorBeanName, advisorDef, (BeanDefinition) pointcut));
      }
      else if (pointcut instanceof String) {
        advisorDef.getPropertyValues().addPropertyValue(POINTCUT, new RuntimeBeanReference((String) pointcut));
        parserContext.registerComponent(
            new AdvisorComponentDefinition(advisorBeanName, advisorDef));
      }
    }
    finally {
View Full Code Here

      // ordering semantics right.
      NodeList nodeList = aspectElement.getChildNodes();
      for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (isAdviceNode(node)) {
          AbstractBeanDefinition advisorDefinition = parseAdvice(
              aspectName, i, aspectElement, (Element) node, parserContext, beanDefinitions, beanReferences);
          beanDefinitions.add(advisorDefinition);
        }
      }
View Full Code Here

          "Exactly one of the " + DEFAULT_IMPL + " or " + DELEGATE_REF + " attributes must be specified",
          declareParentsElement, this.parseState.snapshot());
    }

    builder.setSource(parserContext.extractSource(declareParentsElement));
    AbstractBeanDefinition definition = builder.getBeanDefinition();
    parserContext.getReaderContext().registerWithGeneratedName(definition);
    return definition;
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.support.AbstractBeanDefinition

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.