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

项目:JRediClients    文件:RedissonDefinitionParser.java   
private void parseConfigTypes(Element element, String configType, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
    BeanDefinitionBuilder builder
            = helper.createBeanDefinitionBuilder(element,
                    parserContext, null);
    //Use factory method on the Config bean
    AbstractBeanDefinition bd = builder.getRawBeanDefinition();
    bd.setFactoryMethodName("use" + StringUtils.capitalize(configType));
    bd.setFactoryBeanName(parserContext.getContainingComponent().getName());
    String id = parserContext.getReaderContext().generateBeanName(bd);
    helper.registerBeanDefinition(builder, id,
            helper.parseAliase(element), parserContext);
    helper.parseAttributes(element, parserContext, builder);
    redissonDef.addDependsOn(id);
    parseChildElements(element, id, null, redissonDef, parserContext);
    parserContext.getDelegate().parseQualifierElements(element, bd);
}
项目:JRediClients    文件:RedissonGenericObjectDefinitionParser.java   
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setFactoryBeanName(element.getAttribute(
            RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
    String typeName
            = Conventions.attributeNameToPropertyName(element.getLocalName());
    bd.setFactoryMethodName("get" + StringUtils.capitalize(typeName));

    helper.addConstructorArgs(element, KEY_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, TOPIC_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, PATTERN_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, SERVICE_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, CODEC_REF_ATTRIBUTE,
            Codec.class, builder);
    if (RDestroyable.class.isAssignableFrom(getBeanClass(element))) {
        ((AbstractBeanDefinition) bd).setDestroyMethodName("destroy");
    }
}
项目:JRediClients    文件:AbstractRedissonNamespaceDefinitionParser.java   
@Override
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    Assert.state(helper.isRedissonNS(element),
            "Illegal state. "
                    + this.getClass().getName()
            + " can only parse "
                    + RedissonNamespaceParserSupport.REDISSON_NAMESPACE
            + " namespace elements");
    Assert.state(element.hasAttribute(parentRefAttribute),
            "Illegal state. property \"" + parentRefAttribute 
                    + "\" is required in the \""
            + helper.getName(element)
            + "\" element.");

    helper.populateIdAttribute(element, builder, parserContext);
    AbstractBeanDefinition bd = builder.getRawBeanDefinition();
    parseNested(element, parserContext, builder, bd);
    decorator.decorate(element, parserContext, builder, helper);
    parserContext.getDelegate().parseQualifierElements(element, bd);
    if (parserContext.isNested()) {
        helper.registerBeanDefinition(builder, element, parserContext);
    }
}
项目:hekate    文件:HekateBeanDefinitionParser.java   
@Override
protected String resolveId(Element el, AbstractBeanDefinition def, ParserContext ctx) {
    String id = super.resolveId(el, def, ctx);

    deferredBaseBeans.forEach((baseBeanBuilder, baseBeanName) -> {
        baseBeanBuilder.addPropertyValue("source", new RuntimeBeanReference(id));

        AbstractBeanDefinition baseBean = baseBeanBuilder.getBeanDefinition();

        if (baseBeanName == null) {
            ctx.getRegistry().registerBeanDefinition(ctx.getReaderContext().generateBeanName(baseBean), baseBean);
        } else {
            ctx.getRegistry().registerBeanDefinition(baseBeanName, baseBean);
        }
    });

    return id;
}
项目:jkami    文件:ClassPathMapperScanner.java   
@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;
}
项目:spring-data-tarantool    文件:TarantoolRepositoryConfigurationExtension.java   
@Override
protected AbstractBeanDefinition getDefaultKeyValueTemplateBeanDefinition(
        RepositoryConfigurationSource configurationSource) {
    RootBeanDefinition keyValueTemplateDefinition = new RootBeanDefinition(TarantoolKeyValueTemplate.class);

    ConstructorArgumentValues constructorArgumentValuesForKeyValueTemplate = new ConstructorArgumentValues();
    constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(0,
            new RuntimeBeanReference(TARANTOOL_OPS_IMPL_BEAN_NAME));
    constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(1,
            new RuntimeBeanReference(MAPPING_CONTEXT_BEAN_NAME));
    constructorArgumentValuesForKeyValueTemplate.addIndexedArgumentValue(2,
            new RuntimeBeanReference(TARANTOOL_CONVERTER_BEAN_NAME));

    keyValueTemplateDefinition.setConstructorArgumentValues(constructorArgumentValuesForKeyValueTemplate);

    return keyValueTemplateDefinition;
}
项目:gemini.blueprint    文件:BeanDefinitionFactory.java   
BeanDefinition buildBeanDefinitionFor(ComponentMetadata metadata) {
    // shortcut (to avoid re-rewrapping)
    if (metadata instanceof SimpleComponentMetadata) {
        return ((SimpleComponentMetadata) metadata).getBeanDefinition();
    }

    AbstractBeanDefinition definition = buildBeanDefinition(metadata);
    // add common properties
    definition.setAttribute(MetadataConstants.COMPONENT_METADATA_ATTRIBUTE, metadata);
    definition.setAttribute(MetadataConstants.COMPONENT_NAME, metadata.getId());

    // Set<String> dependencies = metadata.;
    // definition.setDependsOn(dependencies.toArray(new String[dependencies.size()]));
    throw new UnsupportedOperationException("move depends on for BeanMetadata");

    // return definition;
}
项目:gemini.blueprint    文件:BeanDefinitionFactory.java   
private AbstractBeanDefinition buildBeanDefinition(ComponentMetadata metadata) {

        if (metadata instanceof BeanMetadata) {
            return buildLocalComponent((BeanMetadata) metadata);
        }

        if (metadata instanceof ServiceMetadata) {
            return buildExporter((ServiceMetadata) metadata);
        }

        if (metadata instanceof ServiceReferenceMetadata) {
            if (metadata instanceof ReferenceListMetadata) {
                return buildReferenceCollection((ReferenceListMetadata) metadata);
            }
            if (metadata instanceof ReferenceMetadata) {
                return buildReferenceProxy((ReferenceMetadata) metadata);
            }
        }

        // unknown rich metadata type, unable to perform conversion
        throw new IllegalArgumentException("Unknown metadata type" + metadata.getClass());
    }
项目:gemini.blueprint    文件:BeanDefinitionFactory.java   
private AbstractBeanDefinition buildExporter(ServiceMetadata metadata) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(EXPORTER_CLASS);
    // add properties
    builder.addPropertyValue(EXPORTER_RANKING_PROP, metadata.getRanking());
    builder.addPropertyValue(EXPORTER_INTFS_PROP, metadata.getInterfaces());
    builder.addPropertyValue(EXPORTER_PROPS_PROP, metadata.getServiceProperties());
    builder.addPropertyValue(EXPORTER_AUTO_EXPORT_PROP,
            DefaultInterfaceDetector.values()[metadata.getAutoExport() - 1]);

    BeanMetadataElement beanMetadata = BeanMetadataElementFactory.buildBeanMetadata(metadata.getServiceComponent());
    if (beanMetadata instanceof RuntimeBeanReference) {
        builder.addPropertyValue(EXPORTER_TARGET_BEAN_NAME_PROP, beanMetadata);
    } else {
        builder.addPropertyValue(EXPORTER_TARGET_BEAN_PROP, beanMetadata);
    }

    // FIXME: add registration listeners

    return builder.getBeanDefinition();
}
项目:spring-backend-boilerplate    文件:EnableMenuImportSelector.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes enableMenu = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableMenu.class
                                                                                                            .getName(),
                                                                                                    false));

    if (enableMenu != null) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMenuPlugin.class);
        AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.add("extensionPointId", enableMenu.getString("extensionPointId"));
        mutablePropertyValues.add("pluginId", enableMenu.getString("pluginId"));
        mutablePropertyValues.add("menu", toMenu(enableMenu.getAnnotationArray("menu")));
        beanDefinition.setPropertyValues(mutablePropertyValues);

        registry.registerBeanDefinition("menuPlugin:" + enableMenu.getString("pluginId"), beanDefinition);
    }
}
项目:lams    文件:ConfigurationClassParser.java   
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();
}
项目:lams    文件:AnnotationConfigUtils.java   
static void processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd, AnnotatedTypeMetadata metadata) {
    if (metadata.isAnnotated(Lazy.class.getName())) {
        abd.setLazyInit(attributesFor(metadata, Lazy.class).getBoolean("value"));
    }
    else if (abd.getMetadata().isAnnotated(Lazy.class.getName())) {
        abd.setLazyInit(attributesFor(abd.getMetadata(), Lazy.class).getBoolean("value"));
    }

    if (metadata.isAnnotated(Primary.class.getName())) {
        abd.setPrimary(true);
    }
    if (metadata.isAnnotated(DependsOn.class.getName())) {
        abd.setDependsOn(attributesFor(metadata, DependsOn.class).getStringArray("value"));
    }

    if (abd instanceof AbstractBeanDefinition) {
        AbstractBeanDefinition absBd = (AbstractBeanDefinition) abd;
        if (metadata.isAnnotated(Role.class.getName())) {
            absBd.setRole(attributesFor(metadata, Role.class).getNumber("value").intValue());
        }
        if (metadata.isAnnotated(Description.class.getName())) {
            absBd.setDescription(attributesFor(metadata, Description.class).getString("value"));
        }
    }
}
项目:lams    文件:ClassPathBeanDefinitionScanner.java   
/**
 * 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;
}
项目:spring-boot-starter-dao    文件:AbstractDataBaseBean.java   
protected final AbstractBeanDefinition createSqlSessionFactoryBean(String dataSourceName, String mapperPackage,
        String typeAliasesPackage, Dialect dialect, Configuration configuration) {
    configuration.setDatabaseId(dataSourceName);
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionFactoryBean.class);
    bdb.addPropertyValue("configuration", configuration);
    bdb.addPropertyValue("failFast", true);
    bdb.addPropertyValue("typeAliases", this.saenTypeAliases(typeAliasesPackage));
    bdb.addPropertyReference("dataSource", dataSourceName);
    bdb.addPropertyValue("plugins", new Interceptor[] { new CustomPageInterceptor(dialect) });
    if (!StringUtils.isEmpty(mapperPackage)) {
        try {
            mapperPackage = new StandardEnvironment().resolveRequiredPlaceholders(mapperPackage);
            String mapperPackages = ClassUtils.convertClassNameToResourcePath(mapperPackage);
            String mapperPackagePath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPackages + "/*.xml";
            Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperPackagePath);
            bdb.addPropertyValue("mapperLocations", resources);
        } catch (Exception e) {
            log.error("初始化失败", e);
            throw new RuntimeException( String.format("SqlSessionFactory 初始化失败  mapperPackage=%s", mapperPackage + ""));
        }
    }
    return bdb.getBeanDefinition();
}
项目:lams    文件:BeanDefinitionParserDelegate.java   
@SuppressWarnings("deprecation")
public int getAutowireMode(String attValue) {
    String att = attValue;
    if (DEFAULT_VALUE.equals(att)) {
        att = this.defaults.getAutowire();
    }
    int autowire = AbstractBeanDefinition.AUTOWIRE_NO;
    if (AUTOWIRE_BY_NAME_VALUE.equals(att)) {
        autowire = AbstractBeanDefinition.AUTOWIRE_BY_NAME;
    }
    else if (AUTOWIRE_BY_TYPE_VALUE.equals(att)) {
        autowire = AbstractBeanDefinition.AUTOWIRE_BY_TYPE;
    }
    else if (AUTOWIRE_CONSTRUCTOR_VALUE.equals(att)) {
        autowire = AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR;
    }
    else if (AUTOWIRE_AUTODETECT_VALUE.equals(att)) {
        autowire = AbstractBeanDefinition.AUTOWIRE_AUTODETECT;
    }
    // Else leave default value.
    return autowire;
}
项目:lams    文件:BeanDefinitionParserDelegate.java   
public int getDependencyCheck(String attValue) {
    String att = attValue;
    if (DEFAULT_VALUE.equals(att)) {
        att = this.defaults.getDependencyCheck();
    }
    if (DEPENDENCY_CHECK_ALL_ATTRIBUTE_VALUE.equals(att)) {
        return AbstractBeanDefinition.DEPENDENCY_CHECK_ALL;
    }
    else if (DEPENDENCY_CHECK_OBJECTS_ATTRIBUTE_VALUE.equals(att)) {
        return AbstractBeanDefinition.DEPENDENCY_CHECK_OBJECTS;
    }
    else if (DEPENDENCY_CHECK_SIMPLE_ATTRIBUTE_VALUE.equals(att)) {
        return AbstractBeanDefinition.DEPENDENCY_CHECK_SIMPLE;
    }
    else {
        return AbstractBeanDefinition.DEPENDENCY_CHECK_NONE;
    }
}
项目:lams    文件:GroovyBeanDefinitionWrapper.java   
protected AbstractBeanDefinition createBeanDefinition() {
    AbstractBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(this.clazz);
    if (!CollectionUtils.isEmpty(this.constructorArgs)) {
        ConstructorArgumentValues cav = new ConstructorArgumentValues();
        for (Object constructorArg : this.constructorArgs) {
            cav.addGenericArgumentValue(constructorArg);
        }
        bd.setConstructorArgumentValues(cav);
    }
    if (this.parentName != null) {
        bd.setParentName(this.parentName);
    }
    this.definitionWrapper = new BeanWrapperImpl(bd);
    return bd;
}
项目:lams    文件:ConfigBeanDefinitionParser.java   
/**
 * Create a {@link RootBeanDefinition} for the advisor described in the supplied. Does <strong>not</strong>
 * parse any associated '{@code pointcut}' or '{@code pointcut-ref}' attributes.
 */
private AbstractBeanDefinition createAdvisorBeanDefinition(Element advisorElement, ParserContext parserContext) {
    RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
    advisorDefinition.setSource(parserContext.extractSource(advisorElement));

    String adviceRef = advisorElement.getAttribute(ADVICE_REF);
    if (!StringUtils.hasText(adviceRef)) {
        parserContext.getReaderContext().error(
                "'advice-ref' attribute contains empty value.", advisorElement, this.parseState.snapshot());
    }
    else {
        advisorDefinition.getPropertyValues().add(
                ADVICE_BEAN_NAME, new RuntimeBeanNameReference(adviceRef));
    }

    if (advisorElement.hasAttribute(ORDER_PROPERTY)) {
        advisorDefinition.getPropertyValues().add(
                ORDER_PROPERTY, advisorElement.getAttribute(ORDER_PROPERTY));
    }

    return advisorDefinition;
}
项目:configx    文件:EnableConfigServiceImportSelector.java   
private void registerConverters(BeanDefinitionRegistry registry, List<Class<?>> types) {

            // Register ConfigConverter by CustomConverterConfigurer
            String name = ConfigBeanConverterConfigurer.class.getName() + "." + EnableConfigService.class.getSimpleName();
            // converters
            List<ConfigBeanConverter> converters = instantiateConverters(types);

            BeanDefinitionBuilder builder = BeanDefinitionBuilder
                    .genericBeanDefinition(ConfigBeanConverterConfigurer.class);
            builder.addPropertyValue("converters", converters);
            AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

            registry.registerBeanDefinition(name, beanDefinition);
        }
项目: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);
}
项目:spring-data-documentdb    文件:DocumentDbRepositoryConfigurationExtension.java   
@Override
public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource config) {
    super.registerBeansForRoot(registry, config);

    if (!registry.containsBeanDefinition("documentDbMappingContext")) {
        final RootBeanDefinition definition = new RootBeanDefinition(DocumentDbMappingContext.class);
        definition.setRole(AbstractBeanDefinition.ROLE_INFRASTRUCTURE);
        definition.setSource(config.getSource());

        registry.registerBeanDefinition("documentDbMappingContext", definition);
    }
}
项目:idworker    文件:RegistryBeanDefinitionParser.java   
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(ZookeeperRegistryCenter.class);
    result.addConstructorArgValue(buildZookeeperConfigurationBeanDefinition(element, parserContext));
    result.setInitMethodName("init");
    return result.getBeanDefinition();
}
项目:idworker    文件:RegistryBeanDefinitionParser.java   
private AbstractBeanDefinition buildZookeeperConfigurationBeanDefinition(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(ZookeeperConfiguration.class);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.SERVER_LISTS, "serverLists", element, result);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.NAMESPACE, "namespace", element, result);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.BASE_SLEEP_TIME_MS, "baseSleepTimeMilliseconds", element, result);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.MAX_SLEEP_TIME_MS, "maxSleepTimeMilliseconds", element, result);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.MAX_RETRIES, "maxRetries", element, result);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.SESSION_TIMEOUT_MS, "sessionTimeoutMilliseconds", element, result);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.CONNECTION_TIMEOUT_MS, "connectionTimeoutMilliseconds", element, result);
    addPropertyValueIfNotEmpty(ZookeeperBeanDefinitionTag.DIGEST, "digest", element, result);
    return result.getBeanDefinition();
}
项目:idworker    文件:GeneratorBeanDefinitionParser.java   
@Override
protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(generatorClass);
    result.addConstructorArgValue(buildWorkerNodeRegisterBeanDefinition(element, parserContext));
    result.setInitMethodName("init");
    return result.getBeanDefinition();
}
项目:hekate    文件:HekateRpcServiceConfigurer.java   
@Override
protected void registerBeans(InjectRpcClient annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String tag = annotation.tag().isEmpty() ? "" : '#' + annotation.tag();

    String name = RpcClientBean.class.getName() + tag + "-" + targetType.toString();

    if (!registry.containsBeanDefinition(name)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(RpcClientBean.class)
            .setLazyInit(true)
            .addPropertyValue("rpcInterface", targetType.getType().getTypeName());

        if (!annotation.tag().isEmpty()) {
            builder.addPropertyValue("tag", annotation.tag());
        }

        AbstractBeanDefinition def = builder.getBeanDefinition();

        AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(annotation.annotationType());

        if (!annotation.tag().isEmpty()) {
            qualifier.setAttribute("tag", annotation.tag());
        }

        def.addQualifier(qualifier);

        registry.registerBeanDefinition(name, def);
    }
}
项目:hekate    文件:HekateNetworkServiceConfigurer.java   
@Override
protected void registerBeans(InjectConnector annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = NetworkConnectorBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(NetworkConnectorBean.class)
            .setLazyInit(true)
            .addPropertyValue("protocol", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目:hekate    文件:HekateLocalMetricsServiceConfigurer.java   
@Override
protected void registerBeans(InjectCounter annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = CounterMetricBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(CounterMetricBean.class)
            .setLazyInit(true)
            .addPropertyValue("name", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目:hekate    文件:HekateLocalMetricsServiceConfigurer.java   
@Override
protected void registerBeans(InjectMetric annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = MetricBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(MetricBean.class)
            .setLazyInit(true)
            .addPropertyValue("name", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目:hekate    文件:HekateLockServiceConfigurer.java   
@Override
protected void registerBeans(InjectLockRegion annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = LockRegionBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(LockRegionBean.class)
            .setLazyInit(true)
            .addPropertyValue("region", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目:lams    文件:ConfigBeanDefinitionParser.java   
/**
 * Creates a {@link BeanDefinition} for the {@link AspectJExpressionPointcut} class using
 * the supplied pointcut expression.
 */
protected AbstractBeanDefinition createPointcutDefinition(String expression) {
    RootBeanDefinition beanDefinition = new RootBeanDefinition(AspectJExpressionPointcut.class);
    beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    beanDefinition.setSynthetic(true);
    beanDefinition.getPropertyValues().add(EXPRESSION, expression);
    return beanDefinition;
}
项目:hekate    文件:HekateMessagingServiceConfigurer.java   
@Override
protected void registerBeans(InjectChannel annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = MessagingChannelBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(MessagingChannelBean.class)
            .setLazyInit(true)
            .addPropertyValue("channel", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目: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;
}
项目:gemini.blueprint    文件:AbstractReferenceDefinitionParser.java   
private AbstractBeanDefinition createBeanReferenceDefinition(String beanName, BeanDefinition actualDef) {
    GenericBeanDefinition def = new GenericBeanDefinition();
    def.setBeanClass(BeanReferenceFactoryBean.class);
    def.setAttribute(GENERATED_REF, Boolean.TRUE);
    def.setOriginatingBeanDefinition(actualDef);
    def.setDependsOn(new String[] { beanName });
    def.setSynthetic(true);
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.addPropertyValue(TARGET_BEAN_NAME_PROP, beanName);
    def.setPropertyValues(mpv);
    return def;
}
项目:gemini.blueprint    文件:ServiceBeanDefinitionParser.java   
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
        throws BeanDefinitionStoreException {

    String id = super.resolveId(element, definition, parserContext);
    validateServiceReferences(element, id, parserContext);
    return id;
}
项目:gemini.blueprint    文件:ComponentMetadataFactory.java   
static BeanDefinition unwrapImporterReference(BeanDefinition beanDefinition) {
    if (BEAN_REF_FB_CLASS_NAME.equals(beanDefinition.getBeanClassName())) {
        // check special DM case of nested mandatory
        // references being promoted to top level beans
        if (beanDefinition instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition abd = (AbstractBeanDefinition) beanDefinition;
            if (abd.isSynthetic() && abd.hasAttribute(GENERATED_REF)) {
                BeanDefinition actual = abd.getOriginatingBeanDefinition();
                return actual;
            }
        }
    }

    return null;
}
项目:gemini.blueprint    文件:ComponentMetadataFactory.java   
private static boolean checkBeanDefinitionClassCompatibility(BeanDefinition definition, Class<?> clazz) {
    if (definition instanceof AbstractBeanDefinition) {
        AbstractBeanDefinition abstractDefinition = (AbstractBeanDefinition) definition;
        if (abstractDefinition.hasBeanClass()) {
            Class<?> beanClass = abstractDefinition.getBeanClass();
            return clazz.isAssignableFrom(beanClass);
        }
    }
    return (clazz.getName().equals(definition.getBeanClassName()));
}
项目:gemini.blueprint    文件:SimpleReferenceListenerMetadata.java   
public SimpleReferenceListenerMetadata(AbstractBeanDefinition beanDefinition) {
    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    bindMethodName = (String) MetadataUtils.getValue(pvs, BIND_PROP);
    unbindMethodName = (String) MetadataUtils.getValue(pvs, UNBIND_PROP);

    // listener reference
    if (pvs.contains(LISTENER_NAME_PROP)) {
        listenerComponent = new SimpleRefMetadata((String) MetadataUtils.getValue(pvs, LISTENER_NAME_PROP));
    } else {
        // convert the BeanDefinitionHolder
        listenerComponent = (Target) ValueFactory.buildValue(MetadataUtils.getValue(pvs, LISTENER_PROP));
    }
}
项目:gemini.blueprint    文件:SimpleComponentMetadata.java   
public SimpleComponentMetadata(String name, BeanDefinition definition) {
    if (!(definition instanceof AbstractBeanDefinition)) {
        throw new IllegalArgumentException("Unknown bean definition passed in" + definition);
    }
    this.name = name;
    this.beanDefinition = (AbstractBeanDefinition) definition;

    String[] dpdOn = beanDefinition.getDependsOn();

    if (ObjectUtils.isEmpty(dpdOn)) {
        dependsOn = Collections.<String> emptyList();
    } else {
        List<String> dependencies = new ArrayList<String>(dpdOn.length);
        CollectionUtils.mergeArrayIntoCollection(dpdOn, dependencies);
        Collection<String> syntheticDependsOn =
                (Collection<String>) beanDefinition.getAttribute(CycleOrderingProcessor.SYNTHETIC_DEPENDS_ON);

        if (syntheticDependsOn != null) {
            dependencies.removeAll(syntheticDependsOn);
        }

        dependsOn = Collections.unmodifiableList(dependencies);
    }

    if (!StringUtils.hasText(name)) {
        // nested components are always lazy
        activation = ACTIVATION_LAZY;
    } else {
        activation =
                beanDefinition.isSingleton() ? (beanDefinition.isLazyInit() ? ACTIVATION_LAZY : ACTIVATION_EAGER)
                        : ACTIVATION_LAZY;
    }
}
项目:gemini.blueprint    文件:BlueprintParser.java   
private AbstractBeanDefinition parseAttributes(Element ele, String beanName, AbstractBeanDefinition beanDefinition) {
    AbstractBeanDefinition bd =
            parserContext.getDelegate().parseBeanDefinitionAttributes(ele, beanName, null, beanDefinition);

    // handle lazy flag (initialize)
    String lazyInit = ele.getAttribute(LAZY_INIT_ATTR);
    // check whether the value is "lazy"
    if (StringUtils.hasText(lazyInit)) {
        if (lazyInit.equalsIgnoreCase(LAZY_INIT_VALUE)) {
            bd.setLazyInit(true);
        } else {
            bd.setLazyInit(false);
        }
    } else {
        bd.setLazyInit(getDefaults(ele).getDefaultInitialization());
    }

    // handle factory component
    String componentFactory = ele.getAttribute(FACTORY_REF_ATTR);
    if (StringUtils.hasText(componentFactory)) {
        bd.setFactoryBeanName(componentFactory);
    }

    // check whether the bean is a prototype with destroy method
    if (StringUtils.hasText(bd.getDestroyMethodName())
            && BeanDefinition.SCOPE_PROTOTYPE.equalsIgnoreCase(bd.getScope())) {
        error("Blueprint prototype beans cannot define destroy methods", ele);
    }

    return bd;
}