當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanDefinitionHolder類代碼示例

本文整理匯總了Java中org.springframework.beans.factory.config.BeanDefinitionHolder的典型用法代碼示例。如果您正苦於以下問題:Java BeanDefinitionHolder類的具體用法?Java BeanDefinitionHolder怎麽用?Java BeanDefinitionHolder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BeanDefinitionHolder類屬於org.springframework.beans.factory.config包,在下文中一共展示了BeanDefinitionHolder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decorate

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {

    // 設置bean scope為version-refresh
    definition.getBeanDefinition().setScope(VersionRefreshScope.SCOPE_NAME);

    String[] dependsOn = null;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(DEPENDS_ON)) {
            dependsOn = StringUtils.tokenizeToStringArray(ele.getAttribute(DEPENDS_ON), ",");
        }
    }

    // 注冊屬性依賴
    DependencyConfigUtils.registerDependency(parserContext.getRegistry(), definition.getBeanName(), dependsOn);

    return definition;
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:20,代碼來源:VersionRefreshBeanDefinitionDecorator.java

示例2: decorate

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    String propertyName = null;
    String converterClassName = null;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(PROPERTY_NAME)) {
            propertyName = ele.getAttribute(PROPERTY_NAME);
        }
        if (ele.hasAttribute(CONVERTER)) {
            converterClassName = ele.getAttribute(CONVERTER);
        }
    }

    // 為配置bean設置factory method
    Class<?> converterType = null;
    if (StringUtils.isNotEmpty(converterClassName)) {
        converterType = ClassUtils.resolveClassName(converterClassName, parserContext.getReaderContext().getBeanClassLoader());
    }
    ConfigBeanConfigUtils.setConfigBeanFactoryMethod(parserContext.getRegistry(),
            definition.getBeanName(), definition.getBeanDefinition(), propertyName, converterType);

    // 注冊屬性依賴
    DependencyConfigUtils.registerDependency(parserContext.getRegistry(), definition.getBeanName(), new String[]{propertyName});

    return definition;
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:28,代碼來源:ConfigBeanBeanDefinitionDecorator.java

示例3: addRefIfNeeded

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
private void addRefIfNeeded(Object v, List<String> refs) {
         if(v == null) return;
         
         if(v instanceof RuntimeBeanReference) {
            RuntimeBeanReference r = (RuntimeBeanReference)v;
            String name = r.getBeanName();
            
            addRefIfNeeded(name, refs);
            
            if(name == null || name.length() == 0) {
               System.err.println("Warning - empty reference " + r);
            }
         } else if(v instanceof BeanDefinitionHolder) {
            // Nested bean definition
            BeanDefinitionHolder bdh = (BeanDefinitionHolder)v;
            processBeanDefinition(bdh.getBeanName(), bdh.getBeanDefinition());
         } else if(v instanceof ManagedList<?>) {
            ManagedList<?> ml = (ManagedList<?>)v;
            for(Object le : ml) {
               addRefIfNeeded(le, refs);
            }
//       } else {
//          System.err.println(v.getClass());
         }
      }
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:26,代碼來源:ContextDependencyLister.java

示例4: parseRefOrBean

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
private Optional<RuntimeBeanReference> parseRefOrBean(Element elem, ParserContext ctx) {
    if (elem != null) {
        String ref = elem.getAttribute("ref").trim();

        Element beanEl = getChildElementByTagName(elem, "bean");

        if (!ref.isEmpty() && beanEl != null) {
            String name = elem.getLocalName();

            ctx.getReaderContext().error('<' + name + ">'s 'ref' attribute can't be mixed with nested <bean> element.", elem);
        } else if (!ref.isEmpty()) {
            return Optional.of(new RuntimeBeanReference(ref));
        } else if (beanEl != null) {
            BeanDefinitionHolder holder = ctx.getDelegate().parseBeanDefinitionElement(beanEl);

            ctx.registerBeanComponent(new BeanComponentDefinition(holder.getBeanDefinition(), holder.getBeanName()));

            return Optional.of(new RuntimeBeanReference(holder.getBeanName()));
        }
    }

    return Optional.empty();
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:24,代碼來源:HekateBeanDefinitionParser.java

示例5: doScan

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
    if (beanDefinitions.isEmpty()) {
        logger.warn("No  mapper was found in '" + Arrays.toString(basePackages) + "' package. Please check your configuration.");
    } else {
        for (BeanDefinitionHolder holder : beanDefinitions) {
            GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
            if (logger.isDebugEnabled()) {
                logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '" + definition.getBeanClassName()
                        + "' mapperInterface");
            }
            definition.getPropertyValues().add("mapperProxy", getRegistry().getBeanDefinition("mapperProxy"));
            definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
            definition.setBeanClass(MapperFactoryBean.class);
            definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        }
    }
    return beanDefinitions;
}
 
開發者ID:lftao,項目名稱:jkami,代碼行數:21,代碼來源:ClassPathMapperScanner.java

示例6: register

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
public static BeanDefinitionHolder register(Element ele, BeanDefinitionHolder bdHolder, ParserContext parserContext) {
    if (bdHolder != null) {
        String name = bdHolder.getBeanName();
        checkReservedName(name, ele, parserContext);
        checkUniqueName(name, parserContext.getRegistry());
        try {
            // add non-lenient constructor resolution
            BeanDefinition beanDefinition = bdHolder.getBeanDefinition();
            if (beanDefinition instanceof AbstractBeanDefinition) {
                AbstractBeanDefinition abd = (AbstractBeanDefinition) beanDefinition;
                abd.setLenientConstructorResolution(false);
                abd.setNonPublicAccessAllowed(false);
            }

            // Register the final decorated instance.
            BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, parserContext.getRegistry());
        } catch (BeanDefinitionStoreException ex) {
            parserContext.getReaderContext().error(
                    "Failed to register bean definition with name '" + bdHolder.getBeanName() + "'", ele, ex);
        }
        // register component (and send registration events)
        parserContext.registerComponent(new BeanComponentDefinition(bdHolder));
    }
    return bdHolder;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:26,代碼來源:ParsingUtils.java

示例7: decorateIfRequired

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
public static BeanDefinitionHolder decorateIfRequired(Node node, BeanDefinitionHolder originalDef,
        ParserContext parserContext) {

    String namespaceUri = node.getNamespaceURI();
    if (!parserContext.getDelegate().isDefaultNamespace(namespaceUri) && !isRFC124Namespace(namespaceUri)) {
        NamespaceHandler handler =
                parserContext.getReaderContext().getNamespaceHandlerResolver().resolve(namespaceUri);
        if (handler != null) {
            return handler.decorate(node, originalDef, new ParserContext(parserContext.getReaderContext(),
                    parserContext.getDelegate()));
        } else if (namespaceUri.startsWith("http://www.springframework.org/")) {
            parserContext.getReaderContext().error(
                    "Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]",
                    node);
        } else {
            // A custom namespace, not to be handled by Spring - maybe "xml:...".
        }
    }
    return originalDef;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:21,代碼來源:ParsingUtils.java

示例8: parse

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);

    // Obtain bean definitions for all relevant BeanPostProcessors.
    Set<BeanDefinitionHolder> processorDefinitions =
            AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

    // Register component for the surrounding <context:annotation-config> element.
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
    parserContext.pushContainingComponent(compDefinition);

    // Nest the concrete beans in the surrounding component.
    for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
        parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
    }

    // Finally register the composite component.
    parserContext.popAndRegisterContainingComponent();

    return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:AnnotationConfigBeanDefinitionParser.java

示例9: parse

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
public void parse(Set<BeanDefinitionHolder> configCandidates) {
    for (BeanDefinitionHolder holder : configCandidates) {
        BeanDefinition bd = holder.getBeanDefinition();
        try {
            if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).hasBeanClass()) {
                parse(((AbstractBeanDefinition) bd).getBeanClass(), holder.getBeanName());
            }
            else {
                parse(bd.getBeanClassName(), holder.getBeanName());
            }
        }
        catch (IOException ex) {
            throw new BeanDefinitionStoreException("Failed to load bean class: " + bd.getBeanClassName(), ex);
        }
    }
    processDeferredImportSelectors();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:ConfigurationClassParser.java

示例10: registerComponents

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
protected void registerComponents(
        XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

    Object source = readerContext.extractSource(element);
    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

    for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
        compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
    }

    // Register annotation config processors, if necessary.
    boolean annotationConfig = true;
    if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
        annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
    }
    if (annotationConfig) {
        Set<BeanDefinitionHolder> processorDefinitions =
                AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
        for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
            compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
        }
    }

    readerContext.fireComponentRegistered(compositeDef);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:ComponentScanBeanDefinitionParser.java

示例11: doScan

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
/**
 * Perform a scan within the specified base packages,
 * returning the registered bean definitions.
 * <p>This method does <i>not</i> register an annotation config processor
 * but rather leaves this up to the caller.
 * @param basePackages the packages to check for annotated classes
 * @return set of beans registered if any for tooling registration purposes (never {@code null})
 */
protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Assert.notEmpty(basePackages, "At least one base package must be specified");
    Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<BeanDefinitionHolder>();
    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidates = findCandidateComponents(basePackage);
        for (BeanDefinition candidate : candidates) {
            ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);
            candidate.setScope(scopeMetadata.getScopeName());
            String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);
            if (candidate instanceof AbstractBeanDefinition) {
                postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);
            }
            if (candidate instanceof AnnotatedBeanDefinition) {
                AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);
            }
            if (checkCandidate(beanName, candidate)) {
                BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);
                definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
                beanDefinitions.add(definitionHolder);
                registerBeanDefinition(definitionHolder, this.registry);
            }
        }
    }
    return beanDefinitions;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:ClassPathBeanDefinitionScanner.java

示例12: isAutowireCandidate

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
/**
 * Determine whether the provided bean definition is an autowire candidate.
 * <p>To be considered a candidate the bean's <em>autowire-candidate</em>
 * attribute must not have been set to 'false'. Also, if an annotation on
 * the field or parameter to be autowired is recognized by this bean factory
 * as a <em>qualifier</em>, the bean must 'match' against the annotation as
 * well as any attributes it may contain. The bean definition must contain
 * the same qualifier or match by meta attributes. A "value" attribute will
 * fallback to match against the bean name or an alias if a qualifier or
 * attribute does not match.
 * @see Qualifier
 */
@Override
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
    boolean match = super.isAutowireCandidate(bdHolder, descriptor);
    if (match && descriptor != null) {
        match = checkQualifiers(bdHolder, descriptor.getAnnotations());
        if (match) {
            MethodParameter methodParam = descriptor.getMethodParameter();
            if (methodParam != null) {
                Method method = methodParam.getMethod();
                if (method == null || void.class.equals(method.getReturnType())) {
                    match = checkQualifiers(bdHolder, methodParam.getMethodAnnotations());
                }
            }
        }
    }
    return match;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:QualifierAnnotationAutowireCandidateResolver.java

示例13: registerBeanDefinition

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
/**
 * Register the given bean definition with the given bean factory.
 * @param definitionHolder the bean definition including name and aliases
 * @param registry the bean factory to register with
 * @throws BeanDefinitionStoreException if registration failed
 */
public static void registerBeanDefinition(
        BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry)
        throws BeanDefinitionStoreException {

    // Register bean definition under primary name.
    String beanName = definitionHolder.getBeanName();
    registry.registerBeanDefinition(beanName, definitionHolder.getBeanDefinition());

    // Register aliases for bean name, if any.
    String[] aliases = definitionHolder.getAliases();
    if (aliases != null) {
        for (String aliase : aliases) {
            registry.registerAlias(beanName, aliase);
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:BeanDefinitionReaderUtils.java

示例14: isAutowireCandidate

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
/**
 * Determine whether the specified bean definition qualifies as an autowire candidate,
 * to be injected into other beans which declare a dependency of matching type.
 * @param beanName the name of the bean definition to check
 * @param mbd the merged bean definition to check
 * @param descriptor the descriptor of the dependency to resolve
 * @param resolver the AutowireCandidateResolver to use for the actual resolution algorithm
 * @return whether the bean should be considered as autowire candidate
 */
protected boolean isAutowireCandidate(String beanName, RootBeanDefinition mbd,
        DependencyDescriptor descriptor, AutowireCandidateResolver resolver) {

    String beanDefinitionName = BeanFactoryUtils.transformedBeanName(beanName);
    resolveBeanClass(mbd, beanDefinitionName);
    if (mbd.isFactoryMethodUnique) {
        boolean resolve;
        synchronized (mbd.constructorArgumentLock) {
            resolve = (mbd.resolvedConstructorOrFactoryMethod == null);
        }
        if (resolve) {
            new ConstructorResolver(this).resolveFactoryMethodIfPossible(mbd);
        }
    }
    return resolver.isAutowireCandidate(
            new BeanDefinitionHolder(mbd, beanName, getAliases(beanDefinitionName)), descriptor);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:DefaultListableBeanFactory.java

示例15: processBeanDefinition

import org.springframework.beans.factory.config.BeanDefinitionHolder; //導入依賴的package包/類
/**
 * Process the given bean element, parsing the bean definition
 * and registering it with the registry.
 */
protected void processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate) {
    BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(ele);
    if (bdHolder != null) {
        bdHolder = delegate.decorateBeanDefinitionIfRequired(ele, bdHolder);
        try {
            // Register the final decorated instance.
            BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getReaderContext().getRegistry());
        }
        catch (BeanDefinitionStoreException ex) {
            getReaderContext().error("Failed to register bean definition with name '" +
                    bdHolder.getBeanName() + "'", ele, ex);
        }
        // Send registration event.
        getReaderContext().fireComponentRegistered(new BeanComponentDefinition(bdHolder));
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:DefaultBeanDefinitionDocumentReader.java


注:本文中的org.springframework.beans.factory.config.BeanDefinitionHolder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。