Java 类org.springframework.beans.factory.parsing.BeanComponentDefinition 实例源码

项目:hekate    文件:HekateBeanDefinitionParser.java   
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();
}
项目:gemini.blueprint    文件:ParsingUtils.java   
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;
}
项目:lams    文件:AnnotationConfigBeanDefinitionParser.java   
@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;
}
项目:lams    文件:ComponentScanBeanDefinitionParser.java   
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);
}
项目:lams    文件:DefaultBeanDefinitionDocumentReader.java   
/**
 * 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));
    }
}
项目:lams    文件:ScopedProxyBeanDefinitionDecorator.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    boolean proxyTargetClass = true;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
            proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
        }
    }

    // Register the original bean definition as it will be referenced by the scoped proxy
    // and is relevant for tooling (validation, navigation).
    BeanDefinitionHolder holder =
            ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
    String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
    parserContext.getReaderContext().fireComponentRegistered(
            new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
    return holder;
}
项目:spring4-understanding    文件:ScopedProxyBeanDefinitionDecorator.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    boolean proxyTargetClass = true;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
            proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
        }
    }

    // Register the original bean definition as it will be referenced by the scoped proxy
    // and is relevant for tooling (validation, navigation).
    BeanDefinitionHolder holder =
            ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
    String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
    parserContext.getReaderContext().fireComponentRegistered(
            new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
    return holder;
}
项目:spring4-understanding    文件:AnnotationDrivenBeanDefinitionParser.java   
private void registerAsyncExecutionAspect(Element element, ParserContext parserContext) {
    if (!parserContext.getRegistry().containsBeanDefinition(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ASYNC_EXECUTION_ASPECT_CLASS_NAME);
        builder.setFactoryMethod("aspectOf");
        String executor = element.getAttribute("executor");
        if (StringUtils.hasText(executor)) {
            builder.addPropertyReference("executor", executor);
        }
        String exceptionHandler = element.getAttribute("exception-handler");
        if (StringUtils.hasText(exceptionHandler)) {
            builder.addPropertyReference("exceptionHandler", exceptionHandler);
        }
        parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(),
                TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
    }
}
项目:spring4-understanding    文件:AnnotationConfigBeanDefinitionParser.java   
@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;
}
项目:spring4-understanding    文件:ComponentScanBeanDefinitionParser.java   
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);
}
项目:spring4-understanding    文件:MvcNamespaceUtils.java   
/**
 * Adds an alias to an existing well-known name or registers a new instance of a {@link UrlPathHelper}
 * under that well-known name, unless already registered.
 * @return a RuntimeBeanReference to this {@link UrlPathHelper} instance
 */
public static RuntimeBeanReference registerUrlPathHelper(RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, Object source) {
    if (urlPathHelperRef != null) {
        if (parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)) {
            parserContext.getRegistry().removeAlias(URL_PATH_HELPER_BEAN_NAME);
        }
        parserContext.getRegistry().registerAlias(urlPathHelperRef.getBeanName(), URL_PATH_HELPER_BEAN_NAME);
    }
    else if (!parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)
            && !parserContext.getRegistry().containsBeanDefinition(URL_PATH_HELPER_BEAN_NAME)) {
        RootBeanDefinition urlPathHelperDef = new RootBeanDefinition(UrlPathHelper.class);
        urlPathHelperDef.setSource(source);
        urlPathHelperDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        parserContext.getRegistry().registerBeanDefinition(URL_PATH_HELPER_BEAN_NAME, urlPathHelperDef);
        parserContext.registerComponent(new BeanComponentDefinition(urlPathHelperDef, URL_PATH_HELPER_BEAN_NAME));
    }
    return new RuntimeBeanReference(URL_PATH_HELPER_BEAN_NAME);
}
项目:spring4-understanding    文件:MvcNamespaceUtils.java   
/**
 * Adds an alias to an existing well-known name or registers a new instance of a {@link PathMatcher}
 * under that well-known name, unless already registered.
 * @return a RuntimeBeanReference to this {@link PathMatcher} instance
 */
public static RuntimeBeanReference registerPathMatcher(RuntimeBeanReference pathMatcherRef, ParserContext parserContext, Object source) {
    if (pathMatcherRef != null) {
        if (parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)) {
            parserContext.getRegistry().removeAlias(PATH_MATCHER_BEAN_NAME);
        }
        parserContext.getRegistry().registerAlias(pathMatcherRef.getBeanName(), PATH_MATCHER_BEAN_NAME);
    }
    else if (!parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)
            && !parserContext.getRegistry().containsBeanDefinition(PATH_MATCHER_BEAN_NAME)) {
        RootBeanDefinition pathMatcherDef = new RootBeanDefinition(AntPathMatcher.class);
        pathMatcherDef.setSource(source);
        pathMatcherDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        parserContext.getRegistry().registerBeanDefinition(PATH_MATCHER_BEAN_NAME, pathMatcherDef);
        parserContext.registerComponent(new BeanComponentDefinition(pathMatcherDef, PATH_MATCHER_BEAN_NAME));
    }
    return new RuntimeBeanReference(PATH_MATCHER_BEAN_NAME);
}
项目:spring4-understanding    文件:ViewControllerBeanDefinitionParser.java   
private BeanDefinition registerHandlerMapping(ParserContext context, Object source) {
    if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) {
        return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME);
    }
    RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
    beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef);
    context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME));

    beanDef.setSource(source);
    beanDef.getPropertyValues().add("order", "1");
    beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source));
    beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source));
    RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source);
    beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);

    return beanDef;
}
项目:spring4-understanding    文件:ResourcesBeanDefinitionParser.java   
private void registerUrlProvider(ParserContext parserContext, Object source) {
    if (!parserContext.getRegistry().containsBeanDefinition(RESOURCE_URL_PROVIDER)) {
        RootBeanDefinition urlProvider = new RootBeanDefinition(ResourceUrlProvider.class);
        urlProvider.setSource(source);
        urlProvider.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        parserContext.getRegistry().registerBeanDefinition(RESOURCE_URL_PROVIDER, urlProvider);
        parserContext.registerComponent(new BeanComponentDefinition(urlProvider, RESOURCE_URL_PROVIDER));

        RootBeanDefinition interceptor = new RootBeanDefinition(ResourceUrlProviderExposingInterceptor.class);
        interceptor.setSource(source);
        interceptor.getConstructorArgumentValues().addIndexedArgumentValue(0, urlProvider);

        RootBeanDefinition mappedInterceptor = new RootBeanDefinition(MappedInterceptor.class);
        mappedInterceptor.setSource(source);
        mappedInterceptor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);
        mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(1, interceptor);
        String mappedInterceptorName = parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptor);
        parserContext.registerComponent(new BeanComponentDefinition(mappedInterceptor, mappedInterceptorName));
    }
}
项目:spring4-understanding    文件:AnnotationDrivenBeanDefinitionParser.java   
private RuntimeBeanReference getValidator(Element element, Object source, ParserContext parserContext) {
    if (element.hasAttribute("validator")) {
        return new RuntimeBeanReference(element.getAttribute("validator"));
    }
    else if (javaxValidationPresent) {
        RootBeanDefinition validatorDef = new RootBeanDefinition(
                "org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean");
        validatorDef.setSource(source);
        validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
        parserContext.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
        return new RuntimeBeanReference(validatorName);
    }
    else {
        return null;
    }
}
项目:spring4-understanding    文件:DefaultBeanDefinitionDocumentReader.java   
/**
 * 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));
    }
}
项目:my-spring-cache-redis    文件:AnnotationConfigBeanDefinitionParser.java   
@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;
}
项目:my-spring-cache-redis    文件:ComponentScanBeanDefinitionParser.java   
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);
}
项目:spring    文件:AnnotationDrivenBeanDefinitionParser.java   
private void registerAsyncExecutionAspect(Element element, ParserContext parserContext) {
    if (!parserContext.getRegistry().containsBeanDefinition(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ASYNC_EXECUTION_ASPECT_CLASS_NAME);
        builder.setFactoryMethod("aspectOf");
        String executor = element.getAttribute("executor");
        if (StringUtils.hasText(executor)) {
            builder.addPropertyReference("executor", executor);
        }
        String exceptionHandler = element.getAttribute("exception-handler");
        if (StringUtils.hasText(exceptionHandler)) {
            builder.addPropertyReference("exceptionHandler", exceptionHandler);
        }
        parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(),
                TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
    }
}
项目:spring    文件:AnnotationConfigBeanDefinitionParser.java   
@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;
}
项目:spring    文件:ComponentScanBeanDefinitionParser.java   
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);
}
项目:spring    文件:DefaultBeanDefinitionDocumentReader.java   
/**
 * 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));
    }
}
项目:spring    文件:ScopedProxyBeanDefinitionDecorator.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    boolean proxyTargetClass = true;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
            proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
        }
    }

    // Register the original bean definition as it will be referenced by the scoped proxy
    // and is relevant for tooling (validation, navigation).
    BeanDefinitionHolder holder =
            ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
    String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
    parserContext.getReaderContext().fireComponentRegistered(
            new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
    return holder;
}
项目:dubbo-lite    文件:AutoBeanDefinitionParser.java   
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.
    Set<BeanDefinitionHolder> processorDefinitions =
            AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
    for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
        compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
    }

    readerContext.fireComponentRegistered(compositeDef);
}
项目:Camel    文件:CamelNamespaceHandler.java   
private void autoRegisterBeanDefinition(String id, BeanDefinition definition, ParserContext parserContext, String contextId) {
    // it is a bit cumbersome to work with the spring bean definition parser
    // as we kinda need to eagerly register the bean definition on the parser context
    // and then later we might find out that we should not have done that in case we have multiple camel contexts
    // that would have a id clash by auto registering the same bean definition with the same id such as a producer template

    // see if we have already auto registered this id
    BeanDefinition existing = autoRegisterMap.get(id);
    if (existing == null) {
        // no then add it to the map and register it
        autoRegisterMap.put(id, definition);
        parserContext.registerComponent(new BeanComponentDefinition(definition, id));
        if (LOG.isDebugEnabled()) {
            LOG.debug("Registered default: {} with id: {} on camel context: {}", new Object[]{definition.getBeanClassName(), id, contextId});
        }
    } else {
        // ups we have already registered it before with same id, but on another camel context
        // this is not good so we need to remove all traces of this auto registering.
        // end user must manually add the needed XML elements and provide unique ids access all camel context himself.
        LOG.debug("Unregistered default: {} with id: {} as we have multiple camel contexts and they must use unique ids."
                + " You must define the definition in the XML file manually to avoid id clashes when using multiple camel contexts",
                definition.getBeanClassName(), id);

        parserContext.getRegistry().removeBeanDefinition(id);
    }
}
项目:Camel    文件:CamelNamespaceHandler.java   
private void registerEndpoint(Element childElement, ParserContext parserContext, String contextId) {
    String id = childElement.getAttribute("id");
    // must have an id to be registered
    if (ObjectHelper.isNotEmpty(id)) {
        BeanDefinition definition = endpointParser.parse(childElement, parserContext);
        definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
        // Need to add this dependency of CamelContext for Spring 3.0
        try {
            Method method = definition.getClass().getMethod("setDependsOn", String[].class);
            method.invoke(definition, (Object) new String[]{contextId});
        } catch (Exception e) {
            // Do nothing here
        }
        parserContext.registerBeanComponent(new BeanComponentDefinition(definition, id));
    }
}
项目:class-guard    文件:ScopedProxyBeanDefinitionDecorator.java   
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    boolean proxyTargetClass = true;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
            proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
        }
    }

    // Register the original bean definition as it will be referenced by the scoped proxy
    // and is relevant for tooling (validation, navigation).
    BeanDefinitionHolder holder =
            ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
    String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
    parserContext.getReaderContext().fireComponentRegistered(
            new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
    return holder;
}
项目:class-guard    文件:AnnotationConfigBeanDefinitionParser.java   
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;
}
项目:class-guard    文件:ComponentScanBeanDefinitionParser.java   
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);
}
项目:class-guard    文件:ResourcesBeanDefinitionParser.java   
private String registerResourceHandler(ParserContext parserContext, Element element, Object source) {
    String locationAttr = element.getAttribute("location");
    if (!StringUtils.hasText(locationAttr)) {
        parserContext.getReaderContext().error("The 'location' attribute is required.", parserContext.extractSource(element));
        return null;
    }

    ManagedList<String> locations = new ManagedList<String>();
    locations.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(locationAttr)));

    RootBeanDefinition resourceHandlerDef = new RootBeanDefinition(ResourceHttpRequestHandler.class);
    resourceHandlerDef.setSource(source);
    resourceHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    resourceHandlerDef.getPropertyValues().add("locations", locations);

    String cacheSeconds = element.getAttribute("cache-period");
    if (StringUtils.hasText(cacheSeconds)) {
        resourceHandlerDef.getPropertyValues().add("cacheSeconds", cacheSeconds);
    }

    String beanName = parserContext.getReaderContext().generateBeanName(resourceHandlerDef);
    parserContext.getRegistry().registerBeanDefinition(beanName, resourceHandlerDef);
    parserContext.registerComponent(new BeanComponentDefinition(resourceHandlerDef, beanName));
    return beanName;
}
项目:class-guard    文件:AnnotationDrivenBeanDefinitionParser.java   
private RuntimeBeanReference getValidator(Element element, Object source, ParserContext parserContext) {
    if (element.hasAttribute("validator")) {
        return new RuntimeBeanReference(element.getAttribute("validator"));
    }
    else if (javaxValidationPresent) {
        RootBeanDefinition validatorDef = new RootBeanDefinition(
                "org.springframework.validation.beanvalidation.LocalValidatorFactoryBean");
        validatorDef.setSource(source);
        validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
        parserContext.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
        return new RuntimeBeanReference(validatorName);
    }
    else {
        return null;
    }
}
项目:class-guard    文件:AnnotationDrivenBeanDefinitionParser.java   
private RuntimeBeanReference getContentNegotiationManager(Element element, Object source, ParserContext parserContext) {
    RuntimeBeanReference contentNegotiationManagerRef;
    if (element.hasAttribute("content-negotiation-manager")) {
        contentNegotiationManagerRef = new RuntimeBeanReference(element.getAttribute("content-negotiation-manager"));
    }
    else {
        RootBeanDefinition factoryBeanDef = new RootBeanDefinition(ContentNegotiationManagerFactoryBean.class);
        factoryBeanDef.setSource(source);
        factoryBeanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        factoryBeanDef.getPropertyValues().add("mediaTypes", getDefaultMediaTypes());

        String beanName = "mvcContentNegotiationManager";
        parserContext.getReaderContext().getRegistry().registerBeanDefinition(beanName , factoryBeanDef);
        parserContext.registerComponent(new BeanComponentDefinition(factoryBeanDef, beanName));
        contentNegotiationManagerRef = new RuntimeBeanReference(beanName);
    }
    return contentNegotiationManagerRef;
}
项目:class-guard    文件:DefaultBeanDefinitionDocumentReader.java   
/**
 * 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));
    }
}
项目:config-toolkit    文件:PropertySourcesPlaceholderConfigurerConfigBean.java   
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.addPropertyValue("order", Integer.parseInt(element.getAttribute("order")));
    builder.addPropertyValue("ignoreUnresolvablePlaceholders", Boolean.valueOf(element.getAttribute("ignore-unresolvable-placeholders")));

    List<Object> list = parserContext.getDelegate().parseListElement(element, builder.getRawBeanDefinition());

    // Register property sources
    BeanDefinitionBuilder configGroupSourceFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(ConfigGroupSourceFactory.class);
    configGroupSourceFactoryBuilder.setFactoryMethod("create");
    configGroupSourceFactoryBuilder.addConstructorArgValue(list);
    String generatedSourceFactoryName = parserContext.getReaderContext().generateBeanName(configGroupSourceFactoryBuilder.getRawBeanDefinition());
    parserContext
            .registerBeanComponent(new BeanComponentDefinition(configGroupSourceFactoryBuilder.getBeanDefinition(), generatedSourceFactoryName));

    builder.addPropertyValue("propertySources", new RuntimeBeanReference(generatedSourceFactoryName));
}
项目:JGiven    文件:AnnotationDrivenBeanDefinitionParser.java   
@Override
public BeanDefinition parse( Element element, ParserContext parserContext ) {
    AopNamespaceUtils.registerAutoProxyCreatorIfNecessary( parserContext, element );
    if( !parserContext.getRegistry().containsBeanDefinition( BEAN_NAME ) ) {
        Object eleSource = parserContext.extractSource( element );

        RootBeanDefinition stageCreator = new RootBeanDefinition( SpringStageCreator.class );
        stageCreator.setSource( eleSource );
        stageCreator.setRole( BeanDefinition.ROLE_INFRASTRUCTURE );
        String executorName = parserContext.getReaderContext().registerWithGeneratedName( stageCreator );
        logger.debug( "Registered SpringStageCreator with name " + executorName );

        RootBeanDefinition beanFactoryPostProcessor = new RootBeanDefinition( JGivenBeanFactoryPostProcessor.class );
        beanFactoryPostProcessor.setRole( BeanDefinition.ROLE_INFRASTRUCTURE );
        parserContext.getRegistry().registerBeanDefinition( BEAN_NAME, beanFactoryPostProcessor );

        CompositeComponentDefinition componentDefinition = new CompositeComponentDefinition( element.getTagName(), eleSource );
        componentDefinition.addNestedComponent( new BeanComponentDefinition( stageCreator, executorName ) );
        componentDefinition.addNestedComponent( new BeanComponentDefinition( beanFactoryPostProcessor, BEAN_NAME ) );
        parserContext.registerComponent( componentDefinition );
    }
    return null;
}
项目:spring-ldap    文件:LdapTemplateParser.java   
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(LdapTemplate.class);

    String contextSourceRef = getString(element, ATT_CONTEXT_SOURCE_REF, ContextSourceParser.DEFAULT_ID);
    builder.addPropertyReference("contextSource", contextSourceRef);
    builder.addPropertyValue("defaultCountLimit", getInt(element, ATT_COUNT_LIMIT, DEFAULT_COUNT_LIMIT));
    builder.addPropertyValue("defaultTimeLimit", getInt(element, ATT_TIME_LIMIT, DEFAULT_TIME_LIMIT));

    String searchScope = getString(element, ATT_SEARCH_SCOPE, SearchScope.SUBTREE.toString());
    builder.addPropertyValue("defaultSearchScope", SearchScope.valueOf(searchScope).getId());
    builder.addPropertyValue("ignorePartialResultException", getBoolean(element, ATT_IGNORE_PARTIAL_RESULT, false));
    builder.addPropertyValue("ignoreNameNotFoundException", getBoolean(element, ATT_IGNORE_NAME_NOT_FOUND, false));

    String odmRef = element.getAttribute(ATT_ODM_REF);
    if(StringUtils.hasText(odmRef)) {
        builder.addPropertyReference("objectDirectoryMapper", odmRef);
    }

    String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);

    BeanDefinition beanDefinition = builder.getBeanDefinition();
    parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id));

    return beanDefinition;
}
项目:spring-context-template    文件:ImportBeanDefinitionParser.java   
/**
 * Register the given beans to the parser context
 * 
 * @param element
 *            the import XML DOM element
 * @param parserContext
 *            the parser context
 * @param beanDefinitions
 *            the loaded bean definitions
 */
protected void registerBeans(Element element, ParserContext parserContext,
        Map<String, Tuple<BeanDefinition, Boolean>> beanDefinitions) {
    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
            parserContext.extractSource(element));
    parserContext.pushContainingComponent(compositeDef);

    BeanDefinitionRegistry registry = parserContext.getRegistry();
    for (Map.Entry<String, Tuple<BeanDefinition, Boolean>> entry : beanDefinitions.entrySet()) {
        String beanName = entry.getKey();
        BeanDefinition bean = entry.getValue().getKey();
        if (!registry.containsBeanDefinition(beanName)) {
            registry.registerBeanDefinition(beanName, bean);
            parserContext.registerComponent(new BeanComponentDefinition(bean, beanName));
        }
    }

    parserContext.popAndRegisterContainingComponent();
}
项目:jdal    文件:SerializableProxyBeanDefinitionDecorator.java   
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    boolean proxyTargetClass = true;
    if (node instanceof Element) {
        Element ele = (Element) node;
        if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
            proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
        }
    }

    // Register the original bean definition
    BeanDefinitionHolder holder =
            SerializableProxyUtils.createSerializableProxy(definition, parserContext.getRegistry(), proxyTargetClass);
    String targetBeanName = SerializableProxyUtils.getTargetBeanName(definition.getBeanName());
    parserContext.getReaderContext().fireComponentRegistered(
            new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
    return holder;
}
项目:jdal    文件:DefaultsBeanDefinitionParser.java   
/**
 * Register default TablePanel Actions
 * @param element current element
 * @param parserContext parserContext
 * @return a new ComponentDefinition with default table action list.
 */
private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) {
    ManagedList<Object> actions = new ManagedList<Object>(7);
    actions.add(createBeanDefinition(AddAction.class, parserContext));
    actions.add(createBeanDefinition(RefreshAction.class, parserContext));
    actions.add(createBeanDefinition(RemoveAction.class, parserContext));
    actions.add(createBeanDefinition(FindAction.class, parserContext));
    actions.add(createBeanDefinition(ClearFilterAction.class, parserContext));

    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class);
    bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    bdb.addPropertyValue("sourceList", actions);
    bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
            DEFAULT_TABLE_ACTIONS);
    registerBeanComponentDefinition(element, parserContext, bcd);
    return bcd;
}
项目:jdal    文件:DefaultsBeanDefinitionParser.java   
/**
 * @return
 */
private ComponentDefinition registerAccessorFactory(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
            ConfigurableControlAccessorFactory.class);

    Map<Class<?>, Class<?extends ControlAccessor>> accessors = 
            new ManagedMap<Class<?>,Class<?extends ControlAccessor>>();
    accessors.put(JTextComponent.class, TextComponentAccessor.class);
    accessors.put(JList.class, ListAccessor.class);
    accessors.put(Selector.class, SelectorAccessor.class);
    accessors.put(JToggleButton.class, ToggleButtonAccessor.class);
    accessors.put(JComboBox.class, ComboAccessor.class);
    accessors.put(View.class, ViewAccessor.class);
    accessors.put(JLabel.class, LabelAccessor.class);
    accessors.put(TablePanel.class, TablePanelAccessor.class);
    bdb.addPropertyValue("accessors", accessors);

    BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), ACCESSOR_FACTORY_BEAN_NAME);

    registerBeanComponentDefinition(element, parserContext, bcd);   
    return bcd;
}