Java 类org.springframework.beans.factory.support.BeanDefinitionReaderUtils 实例源码

项目:muon-java    文件:MuonRepositoryRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    Set<String> basePackages = getBasePackages(importingClassMetadata);
    ClassPathScanningCandidateComponentProvider scanner = getScanner();
    scanner.addIncludeFilter(new AnnotationTypeFilter(MuonRepository.class));
    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner
                .findCandidateComponents(basePackage);
        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {

                AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
                AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
                Assert.isTrue(annotationMetadata.isInterface(),
                        "@FeignClient can only be specified on an interface");

                BeanDefinitionHolder holder = createBeanDefinition(annotationMetadata);
                BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
            }
        }
    }

}
项目:gemini.blueprint    文件:AbstractReferenceDefinitionParser.java   
protected String generateBeanName(String prefix, BeanDefinition def, ParserContext parserContext) {
    BeanDefinitionRegistry registry = parserContext.getRegistry();
    String name = prefix + BeanDefinitionReaderUtils.generateBeanName(def, registry);
    String generated = name;
    int counter = 0;

    while (registry.containsBeanDefinition(generated)) {
        generated = name + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR + counter;
        if (parserContext.isNested()) {
            generated = generated.concat("#generated");
        }
        counter++;
    }

    return generated;
}
项目: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;
}
项目:gemini.blueprint    文件:ParsingUtils.java   
/**
 * Generates a Blueprint specific bean name.
 * 
 * @param definition
 * @param registry
 * @param isInnerBean
 * @return
 * @throws BeanDefinitionStoreException
 */
public static String generateBlueprintBeanName(BeanDefinition definition, BeanDefinitionRegistry registry,
        boolean isInnerBean) throws BeanDefinitionStoreException {

    String initialName =
            BLUEPRINT_GENERATED_NAME_PREFIX
                    + BeanDefinitionReaderUtils.generateBeanName(definition, registry, isInnerBean);

    String generatedName = initialName;
    int counter = 0;
    while (registry.containsBeanDefinition(generatedName)) {
        generatedName = initialName + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + counter;
        counter++;
    }

    return generatedName;
}
项目: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));
    }
}
项目:tephra    文件:ClassReloaderImpl.java   
private void load(ClassLoader loader, String name) {
    try {
        DefaultListableBeanFactory lbf = (DefaultListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
        BeanDefinition bd = BeanDefinitionReaderUtils.createBeanDefinition(null, name, loader);
        String dynamicBeanName = generator.uuid();
        lbf.registerBeanDefinition(dynamicBeanName, bd);
        Object bean = lbf.getBean(dynamicBeanName);
        String beanName = getBeanName(bean.getClass());
        Object oldBean = null;
        if (beanName != null) {
            oldBean = container.getBean(beanName);
            container.mapBeanName(beanName, dynamicBeanName);
        }
        inject(bean.getClass(), null, bean);
        inject(bean, oldBean);
    } catch (Exception e) {
        logger.warn(e, "重新载入[{}]时发生异常!", name);
    }
}
项目: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));
    }
}
项目:spring4-understanding    文件:BeanNameGenerationTests.java   
@Test
public void naming() {
    String className = GeneratedNameBean.class.getName();

    String targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "0";
    GeneratedNameBean topLevel1 = (GeneratedNameBean) beanFactory.getBean(targetName);
    assertNotNull(topLevel1);

    targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "1";
    GeneratedNameBean topLevel2 = (GeneratedNameBean) beanFactory.getBean(targetName);
    assertNotNull(topLevel2);

    GeneratedNameBean child1 = topLevel1.getChild();
    assertNotNull(child1.getBeanName());
    assertTrue(child1.getBeanName().startsWith(className));

    GeneratedNameBean child2 = topLevel2.getChild();
    assertNotNull(child2.getBeanName());
    assertTrue(child2.getBeanName().startsWith(className));

    assertFalse(child1.getBeanName().equals(child2.getBeanName()));
}
项目:spring-soap-client-starter    文件:SoapClientRegistrar.java   
private void registerSoapClient(BeanDefinitionRegistry registry,
                                AnnotationMetadata annotationMetadata,
                                Map<String, Object> attributes) {
    String className = annotationMetadata.getClassName();
    BeanDefinitionBuilder definition = BeanDefinitionBuilder
            .genericBeanDefinition(SoapClientFactoryBean.class);
    validate(attributes);

    Class<?> serviceType = getClientService(attributes);
    // Type name of annotated interface
    definition.addPropertyValue("type", getClassByName(className));
    // Soap service type
    definition.addPropertyValue("service", serviceType);
    definition.addPropertyValue("soapMethods", getAnnotatedMethods(annotationMetadata));
    definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

    String alias = className + "SoapClient";
    AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
    beanDefinition.setPrimary(true);
    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
            new String[] { alias });
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
项目: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-cloud-square    文件:RetrofitClientsRegistrar.java   
private void registerRetrofitClient(BeanDefinitionRegistry registry,
                                 AnnotationMetadata annotationMetadata, Map<String, Object> attributes) {
    String className = annotationMetadata.getClassName();
    BeanDefinitionBuilder definition = BeanDefinitionBuilder
            .genericBeanDefinition(RetrofitClientFactoryBean.class);
    validate(attributes);
    definition.addPropertyValue("url", getUrl(attributes));
    String name = getName(attributes);
    definition.addPropertyValue("name", name);
    definition.addPropertyValue("type", className);
    definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

    String alias = name + "RetrofitClient";
    AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
    beanDefinition.setPrimary(true);

    String qualifier = getQualifier(attributes);
    if (StringUtils.hasText(qualifier)) {
        alias = qualifier;
    }

    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
            new String[] { alias });
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
项目: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));
    }
}
项目:class-guard    文件:BeanNameGenerationTests.java   
public void testNaming() {
    String className = GeneratedNameBean.class.getName();

    String targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "0";
    GeneratedNameBean topLevel1 = (GeneratedNameBean) beanFactory.getBean(targetName);
    assertNotNull(topLevel1);

    targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "1";
    GeneratedNameBean topLevel2 = (GeneratedNameBean) beanFactory.getBean(targetName);
    assertNotNull(topLevel2);

    GeneratedNameBean child1 = topLevel1.getChild();
    assertNotNull(child1.getBeanName());
    assertTrue(child1.getBeanName().startsWith(className));

    GeneratedNameBean child2 = topLevel2.getChild();
    assertNotNull(child2.getBeanName());
    assertTrue(child2.getBeanName().startsWith(className));

    assertFalse(child1.getBeanName().equals(child2.getBeanName()));
}
项目:se    文件:ActionBeanDefinitionParser.java   
public BeanDefinition parse(Element element, ParserContext parserContext) {
    RootBeanDefinition beanDef = new RootBeanDefinition();
    // never null since the schema requires it 
    String id = element.getAttribute(ID);
    String classname = element.getAttribute(CLASS);
    if (!(StringUtils.hasLength(classname))) {
        System.out.println("Tag 'action' must have a 'class' attribute");
        return null;
    }
    beanDef.setBeanClassName(classname);
    parseRef(element, beanDef);
    // create a bean definition holder to be able to register the
    // bean definition with the bean definition registry
    // (obtained through the ParserContext)
    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDef, id);
    // register the BeanDefinitionHolder (which contains the bean definition)
    // with the BeanDefinitionRegistry

    BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());

    return beanDef;
}
项目:se    文件:TransactionBeanDefinitionParser.java   
public BeanDefinition parse(Element element, ParserContext parserContext) {
    RootBeanDefinition beandef = new RootBeanDefinition();
    // never null since the schema requires it 
    String id = element.getAttribute(ID);
    if(classname == null || classname.isEmpty())
        classname = DEFAULT_CLASS;
    beandef.setBeanClassName(classname);

    parseTemplate(element, beandef);
    beandef.setDescription(DomUtils.getChildElementValueByTagName(element, DESCRIPTION));
    parseAction(element, beandef);
    parseFields(element, beandef, parserContext);
    parseChannel(element, beandef);
    BeanDefinitionHolder holder = new BeanDefinitionHolder(beandef, id);
    // register the BeanDefinitionHolder (which contains the bean definition)
    // with the BeanDefinitionRegistry
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());

    return beandef;
}
项目:spring-cloud-aws    文件:AmazonWebserviceClientConfigurationUtils.java   
public static BeanDefinitionHolder registerAmazonWebserviceClient(
        Object source, BeanDefinitionRegistry registry, String serviceNameClassName,
        String customRegionProvider, String customRegion) {

    String beanName = getBeanName(serviceNameClassName);

    if (registry.containsBeanDefinition(beanName)) {
        return new BeanDefinitionHolder(registry.getBeanDefinition(beanName), beanName);
    }

    BeanDefinition definition = getAmazonWebserviceClientBeanDefinition(source, serviceNameClassName, customRegionProvider, customRegion, registry);
    BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, beanName);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);

    return holder;
}
项目:spring-cloud-aws    文件:ContextConfigurationUtils.java   
public static void registerRegionProvider(BeanDefinitionRegistry registry, boolean autoDetect, String configuredRegion) {
    if (autoDetect
            && StringUtils.hasText(configuredRegion)) {
        throw new IllegalArgumentException("No region must be configured if autoDetect is defined as true");
    }

    AbstractBeanDefinition beanDefinition;

    if (autoDetect) {
        beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Ec2MetadataRegionProvider.class).getBeanDefinition();
    } else if (StringUtils.hasText(configuredRegion)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(StaticRegionProvider.class);
        builder.addConstructorArgValue(configuredRegion);
        beanDefinition = builder.getBeanDefinition();
    } else {
        throw new IllegalArgumentException("Region must be manually configured or autoDetect enabled");
    }

    BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(beanDefinition, REGION_PROVIDER_BEAN_NAME), registry);
    AmazonWebserviceClientConfigurationUtils.replaceDefaultRegionProvider(registry, REGION_PROVIDER_BEAN_NAME);
}
项目:spring-cloud-aws    文件:ContextInstanceDataPropertySourceBeanDefinitionParser.java   
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    if (StringUtils.hasText(element.getAttribute("user-tags-map"))) {
        BeanDefinitionBuilder userTagsBuilder = BeanDefinitionBuilder.genericBeanDefinition(USER_TAGS_BEAN_CLASS_NAME);

        userTagsBuilder.addConstructorArgReference(
                getCustomClientOrDefaultClientBeanName(element, parserContext, "amazon-ec2", EC2_CLIENT_CLASS_NAME));

        if (StringUtils.hasText(element.getAttribute("instance-id-provider"))) {
            userTagsBuilder.addConstructorArgReference(element.getAttribute("instance-id-provider"));
        }
        BeanDefinitionReaderUtils.registerBeanDefinition(
                new BeanDefinitionHolder(userTagsBuilder.getBeanDefinition(), element.getAttribute("user-tags-map")),
                parserContext.getRegistry());
    }

    if (isRunningOnCloudEnvironment()) {
        ContextConfigurationUtils.registerInstanceDataPropertySource(parserContext.getRegistry(),
                element.getAttribute("value-separator"), element.getAttribute("attribute-separator"));
    }

    return null;
}
项目:muon-java    文件:AutoConfigurationBeanDefinitionRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnableMuon.class.getName());


    Object serviceNameCandidate = annotationAttributes.get("serviceName");
    if (serviceNameCandidate != null && String.class == serviceNameCandidate.getClass()) {
        String serviceName = (String) serviceNameCandidate;
        BeanDefinitionBuilder definition = BeanDefinitionBuilder
                .genericBeanDefinition(AutoConfigurationFactoryBean.class);
        definition.addPropertyValue("serviceName", serviceName);
        definition.addPropertyValue("tags", annotationAttributes.get("tags"));
        BeanDefinitionReaderUtils.registerBeanDefinition(
                new BeanDefinitionHolder(definition.getBeanDefinition(), AUTO_CONFIGURATION_BEAN_NAME), registry);
    }
}
项目:spring-restlet    文件:RestletSpringApplicationContextServlet.java   
@SuppressWarnings("unchecked")
protected <T> T registerComponent(T bean, String name) {
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) ContextLoader.getCurrentWebApplicationContext()
            .getAutowireCapableBeanFactory();
    Class<T> clazz = (Class<T>) bean.getClass();
    String className = clazz.getCanonicalName();
    BeanDefinition beanDefinition = null;
    try {
        beanDefinition = BeanDefinitionReaderUtils.createBeanDefinition(null, className, clazz.getClassLoader());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    beanDefinition.setScope(BeanDefinition.SCOPE_SINGLETON);
    beanDefinition.setAutowireCandidate(true);

    beanFactory.registerBeanDefinition(name, beanDefinition);
    beanFactory.registerSingleton(name, bean);

    beanFactory.configureBean(bean, name);

    return bean;
}
项目:JRediClients    文件:RedissonNamespaceParserSupport.java   
public BeanComponentDefinition registerBeanDefinition(BeanDefinitionBuilder builder, String id, String[] aliases, ParserContext parserContext) {
    BeanDefinitionHolder holder
            = new BeanDefinitionHolder(builder.getBeanDefinition(), id,
                    aliases);
    BeanDefinitionReaderUtils
            .registerBeanDefinition(holder, parserContext.getRegistry());
    BeanComponentDefinition componentDefinition
            = new BeanComponentDefinition(holder);
    parserContext.registerComponent(componentDefinition);
    return componentDefinition;
}
项目:JRediClients    文件:RedissonNamespaceParserSupport.java   
public BeanComponentDefinition registerBeanDefinition(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) {
    BeanDefinitionHolder holder
            = new BeanDefinitionHolder(builder.getBeanDefinition(),
                    getId(element, builder, parserContext),
                    parseAliase(element));
    BeanDefinitionReaderUtils
            .registerBeanDefinition(holder, parserContext.getRegistry());
    BeanComponentDefinition componentDefinition
            = new BeanComponentDefinition(holder);
    parserContext.registerComponent(componentDefinition);
    return componentDefinition;
}
项目:xm-commons    文件:LepServicesRegistrar.java   
private void registerLepService(BeanDefinitionRegistry registry,
                                AnnotationMetadata annotationMetadata,
                                Map<String, Object> attributes) {
    // has a default, won't be null
    boolean primary = (Boolean) attributes.get("primary");

    String className = annotationMetadata.getClassName();
    BeanDefinitionBuilder definition = BeanDefinitionBuilder
        .genericBeanDefinition(LepServiceFactoryBean.class);
    definition.addPropertyValue("type", className);
    definition.addPropertyValue("annotationMetadata", annotationMetadata);
    definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

    AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
    beanDefinition.setPrimary(primary);

    String name = getBeanName(annotationMetadata, attributes);
    String alias = name + LepService.class.getSimpleName();
    String qualifier = getQualifier(attributes);
    if (StringUtils.hasText(qualifier)) {
        alias = qualifier;
    }

    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, name,
                                                           new String[] {alias});
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
项目:xm-ms-entity    文件:LepServicesRegistrar.java   
private void registerLepService(BeanDefinitionRegistry registry,
                                AnnotationMetadata annotationMetadata,
                                Map<String, Object> attributes) {
    // has a default, won't be null
    boolean primary = (Boolean) attributes.get("primary");

    String className = annotationMetadata.getClassName();
    BeanDefinitionBuilder definition = BeanDefinitionBuilder
        .genericBeanDefinition(LepServiceFactoryBean.class);
    definition.addPropertyValue("type", className);
    definition.addPropertyValue("annotationMetadata", annotationMetadata);
    definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);

    AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
    beanDefinition.setPrimary(primary);

    String name = getBeanName(annotationMetadata, attributes);
    String alias = name + LepService.class.getSimpleName();
    String qualifier = getQualifier(attributes);
    if (StringUtils.hasText(qualifier)) {
        alias = qualifier;
    }

    BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, name,
                                                           new String[] {alias});
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
项目:gemini.blueprint    文件:AbstractReferenceDefinitionParser.java   
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();

    Class<?> beanClass = getBeanClass(element);
    Assert.notNull(beanClass);

    if (beanClass != null) {
        builder.getRawBeanDefinition().setBeanClass(beanClass);
    }

    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    OsgiDefaultsDefinition defaults = resolveDefaults(element.getOwnerDocument(), parserContext);
    applyDefaults(parserContext, defaults, builder);

    doParse(element, parserContext, builder);

    AbstractBeanDefinition def = builder.getBeanDefinition();

    // check whether the bean is mandatory (and if it is, make it top-level
    // bean)
    if (parserContext.isNested()) {
        String value = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
        value = (StringUtils.hasText(value) ? value + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR : "");
        String generatedName = generateBeanName(value, def, parserContext);
        // make the bean lazy (since it is an inner bean initiallly)
        def.setLazyInit(true);
        // disable autowiring for promoted bean
        def.setAutowireCandidate(false);
        def.setAttribute(PROMOTED_REF, Boolean.TRUE);

        BeanDefinitionHolder holder = new BeanDefinitionHolder(def, generatedName);
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
        return createBeanReferenceDefinition(generatedName, def);
    }

    return def;
}
项目:lams    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class.equals(qualifier)) {
                abd.setPrimary(true);
            }
            else if (Lazy.class.equals(qualifier)) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:lams    文件:BeanDefinitionParserDelegate.java   
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
    BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
    if (innerDefinition == null) {
        error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
                "This tag cannot be used nested inside <property>.", ele);
        return null;
    }
    String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
            ObjectUtils.getIdentityHexString(innerDefinition);
    if (logger.isDebugEnabled()) {
        logger.debug("Using generated bean name [" + id +
                "] for nested custom element '" + ele.getNodeName() + "'");
    }
    return new BeanDefinitionHolder(innerDefinition, id);
}
项目:parabuild-ci    文件:DwrNamespaceHandler.java   
public BeanDefinition parse(Element element, ParserContext parserContext)
{
    BeanDefinitionBuilder dwrController = BeanDefinitionBuilder.rootBeanDefinition(DwrController.class);
    List configurators = new ManagedList();
    configurators.add(new RuntimeBeanReference(DEFAULT_SPRING_CONFIGURATOR_ID));
    dwrController.addPropertyValue("configurators", configurators);

    String debug = element.getAttribute("debug");
    if (StringUtils.hasText(debug))
    {
        dwrController.addPropertyValue("debug", debug);
    }

    String beanName = element.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
    String nameAttr = element.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
    String[] aliases = null;
    if (!StringUtils.hasText(beanName))
    {
        beanName = element.getAttribute("name");
    }
    else
    {
        String aliasName = element.getAttribute("name");
        if (StringUtils.hasText(aliasName))
        {
            aliases = StringUtils.tokenizeToStringArray(nameAttr, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
        }
    }

    parseControllerParameters(dwrController, element);

    BeanDefinitionHolder holder = new BeanDefinitionHolder(dwrController.getBeanDefinition(), beanName, aliases);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());

    return dwrController.getBeanDefinition();
}
项目:springboot-analysis    文件:MyBeanFactoryPostProcessor.java   
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    System.out.println("------ register custom bean in BeanFactoryPostProcessor");
    beanFactory.registerSingleton("createByBeanFactoryPostProcessor", new SimpleBeanInBeanFactoryPostProcessor());
    if(beanFactory instanceof BeanDefinitionRegistry) {
        BeanDefinitionReaderUtils.registerBeanDefinition(
                new BeanDefinitionHolder(new AnnotatedGenericBeanDefinition(SimpleBeanWithDefinitionInBeanFactoryPostProcessor.class), "simpleBeanWithDefinitionInBeanFactoryPostProcessor"),                             (BeanDefinitionRegistry) beanFactory
        );
    }
}
项目:dwr    文件:CreatorParserHelper.java   
protected void registerCreator(BeanDefinitionRegistry registry, BeanDefinitionBuilder creatorConfig, String javascript)
{
    String creatorConfigName = "__" + javascript;
    BeanDefinitionHolder holder3 = new BeanDefinitionHolder(creatorConfig.getBeanDefinition(), creatorConfigName);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder3, registry);
    lookupCreators(registry).put(javascript, new RuntimeBeanReference(creatorConfigName));
}
项目:niubi-job    文件:JobDrivenBeanDefinitionParser.java   
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    beanDefinition.setBeanClass(SpringContextJobDriver.class);
    propertyValues.addPropertyValue("packagesToScan", element.getAttribute("packagesToScan"));
    beanDefinition.setPropertyValues(propertyValues);
    beanDefinition.setInitMethodName("init");
    BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, parserContext.getRegistry());
    return beanDefinition;
}
项目:spring4-understanding    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class == qualifier) {
                abd.setPrimary(true);
            }
            else if (Lazy.class == qualifier) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:spring4-understanding    文件:BeanDefinitionParserDelegate.java   
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
    BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
    if (innerDefinition == null) {
        error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
                "This tag cannot be used nested inside <property>.", ele);
        return null;
    }
    String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
            ObjectUtils.getIdentityHexString(innerDefinition);
    if (logger.isDebugEnabled()) {
        logger.debug("Using generated bean name [" + id +
                "] for nested custom element '" + ele.getNodeName() + "'");
    }
    return new BeanDefinitionHolder(innerDefinition, id);
}
项目:leopard    文件:RegisterComponentUtil.java   
public static BeanDefinition registerComponent(ParserContext parserContext, BeanDefinitionBuilder builder, String id) {
    BeanDefinition definition = builder.getBeanDefinition();
    if (!parserContext.isNested()) {
        String[] aliases = new String[0];
        BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
        BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
        parserContext.registerComponent(componentDefinition);
    }
    return definition;
}
项目:beyondj    文件:ProfileBeanDefinitionParser.java   
private BeanDefinition registerBean(Element element,
                                    ParserContext parserContext) {
    BeanDefinitionParserDelegate delegate = parserContext.getDelegate();

    BeanDefinitionHolder holder = delegate
            .parseBeanDefinitionElement(element);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder,
            parserContext.getRegistry());
    return holder.getBeanDefinition();
}
项目:my-spring-cache-redis    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class.equals(qualifier)) {
                abd.setPrimary(true);
            }
            else if (Lazy.class.equals(qualifier)) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:kekoa    文件:MyBeanDefinitionRegistryPostProcessor.java   
private void registerBean(BeanDefinitionRegistry registry, String name,Class<?> beanClass) {
    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(beanClass);

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    // 可以自动生成name
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, registry));

    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd,beanName);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder,registry);
}
项目:spring    文件:AnnotatedBeanDefinitionReader.java   
public void registerBean(Class<?> annotatedClass, String name,
        @SuppressWarnings("unchecked") Class<? extends Annotation>... qualifiers) {

    AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
    if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
        return;
    }

    ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
    abd.setScope(scopeMetadata.getScopeName());
    String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
    AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
    if (qualifiers != null) {
        for (Class<? extends Annotation> qualifier : qualifiers) {
            if (Primary.class == qualifier) {
                abd.setPrimary(true);
            }
            else if (Lazy.class == qualifier) {
                abd.setLazyInit(true);
            }
            else {
                abd.addQualifier(new AutowireCandidateQualifier(qualifier));
            }
        }
    }

    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
    BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
项目:spring    文件:BeanDefinitionParserDelegate.java   
private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
    BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
    if (innerDefinition == null) {
        error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
                "This tag cannot be used nested inside <property>.", ele);
        return null;
    }
    String id = ele.getNodeName() + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR +
            ObjectUtils.getIdentityHexString(innerDefinition);
    if (logger.isDebugEnabled()) {
        logger.debug("Using generated bean name [" + id +
                "] for nested custom element '" + ele.getNodeName() + "'");
    }
    return new BeanDefinitionHolder(innerDefinition, id);
}
项目:xap-openspaces    文件:RemotingAnnotationBeanDefinitionParser.java   
public BeanDefinition parse(Element element, ParserContext parserContext) {
    if (!this.registered) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(RemotingAnnotationBeanPostProcessor.class);
        builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
        BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
        this.registered = true;
    }
    return null;
}