Example usage for org.springframework.beans.factory.parsing BeanComponentDefinition BeanComponentDefinition

List of usage examples for org.springframework.beans.factory.parsing BeanComponentDefinition BeanComponentDefinition

Introduction

In this page you can find the example usage for org.springframework.beans.factory.parsing BeanComponentDefinition BeanComponentDefinition.

Prototype

public BeanComponentDefinition(BeanDefinition beanDefinition, String beanName) 

Source Link

Document

Create a new BeanComponentDefinition for the given bean.

Usage

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParser.java

protected BeanReference getSerializationPolicyProviderBeanRef(Element element, ParserContext parserContext) {
    final String serializationPolicyProviderName;

    if (element.hasAttribute(XmlNames.SERIALIZATION_POLICY_PROVIDER_REF_ATTR)
            && !ExtendedSerializationPolicyProvider.DEFAULT_BEAN_ID
                    .equals(element.getAttribute(XmlNames.SERIALIZATION_POLICY_PROVIDER_REF_ATTR))) {
        serializationPolicyProviderName = element.getAttribute(XmlNames.SERIALIZATION_POLICY_PROVIDER_REF_ATTR);
    } else {/*w w  w . jav a  2s .c o  m*/
        serializationPolicyProviderName = ExtendedSerializationPolicyProvider.DEFAULT_BEAN_ID;
        if (!parserContext.getRegistry().containsBeanDefinition(serializationPolicyProviderName)) {
            final RootBeanDefinition bd;

            if (log.isInfoEnabled()) {
                log.info("Registering default serialization policy provider with name '"
                        + serializationPolicyProviderName + "'");
            }
            bd = new RootBeanDefinition(DefaultExtendedSerializationPolicyProvider.class);
            bd.setSource(parserContext.extractSource(element));
            if (parserContext.isDefaultLazyInit()) {
                bd.setLazyInit(true);
            }
            parserContext
                    .registerBeanComponent(new BeanComponentDefinition(bd, serializationPolicyProviderName));
        }
    }

    return new RuntimeBeanReference(serializationPolicyProviderName);
}

From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java

private void registerAspect(Element element, ParserContext parserContext) {
    if (!parserContext.getRegistry().containsBeanDefinition(EHCACHE_CACHING_ASPECT_BEAN_NAME)) {
        final Object elementSource = parserContext.extractSource(element);

        final RuntimeBeanReference cacheAttributeSourceReference = this.setupCacheAttributeSource(element,
                parserContext, elementSource);

        RootBeanDefinition def = new RootBeanDefinition();
        def.setBeanClassName(EHCACHE_CACHING_ASPECT_CLASS_NAME);
        def.setFactoryMethodName("aspectOf");
        def.getPropertyValues().add("cacheAttributeSource", cacheAttributeSourceReference);
        //registerTransactionManager(element, def);
        parserContext.registerBeanComponent(new BeanComponentDefinition(def, EHCACHE_CACHING_ASPECT_BEAN_NAME));
    }/*www.j  a va  2 s .  c  om*/
}

From source file:org.jdal.beans.DefaultsBeanDefinitionParser.java

/**
 * @return//ww w.j  a  v a  2  s.  c  om
 */
private ComponentDefinition registerBinderFactory(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ConfigurableBinderFactory.class);
    bdb.addPropertyReference(ACCESSOR_FACTORY_BEAN_NAME, ACCESSOR_FACTORY_BEAN_NAME);
    BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(),
            BINDER_FACTORY_BEAN_NAME);
    registerBeanComponentDefinition(element, parserContext, bcd);
    return bcd;
}

From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java

protected void preparePostProcessor(Element element, ParserContext parserContext) {
    String id = element.getAttribute("id");
    String name = getName(element);
    BeanDefinitionBuilder postProcessor = BeanDefinitionBuilder
            .genericBeanDefinition(ConfigurationBeanPostProcessor.class);
    postProcessor.addConstructorArgValue(name);
    postProcessor.addConstructorArgReference(id);
    Element annotationConfigElement = selectSingleChildElement(element, "annotation-config", true);
    if (annotationConfigElement != null) {
        String marker = annotationConfigElement.getAttribute("marker");
        if (StringUtils.hasLength(marker)) {
            Class<?> theClass = ClassUtils.resolveClassName(marker,
                    Thread.currentThread().getContextClassLoader());
            if (!theClass.isAnnotation()) {
                throw new ConfigurationException(String.format("The class '%s' is not an annotation", marker));
            }/*from   ww w  .j a va 2s. c o m*/
            postProcessor.addPropertyValue("markerAnnotation", theClass);
        }
    }
    parserContext.registerBeanComponent(
            new BeanComponentDefinition(postProcessor.getBeanDefinition(), id + "-postProcessor"));
}

From source file:org.hdiv.config.xml.EditableValidationsBeanDefinitionParser.java

private RootBeanDefinition createValidator(Element element, Object source, ParserContext parserContext) {
    RootBeanDefinition bean = new RootBeanDefinition(EditableParameterValidator.class);
    bean.setSource(source);//from   ww w. j  a  v  a2 s  . c  o  m
    bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    if (jsr303Present) {

        RootBeanDefinition validatorDef = new RootBeanDefinition(LocalValidatorFactoryBean.class);
        validatorDef.setSource(source);
        validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
        parserContext.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));

        bean.getPropertyValues().addPropertyValue("innerValidator", new RuntimeBeanReference(validatorName));
    }
    return bean;
}

From source file:org.jdal.beans.TableBeanDefinitionParser.java

/**
 * Register BeanDefinition and apply default bean attributes.
 * @param element//from  ww w  .  ja  v a2  s . c o  m
 * @param parserContext
 * @param beanName
 * @param bdb
 */
private void registerBeanDefinition(Element element, ParserContext parserContext, String beanName,
        BeanDefinitionBuilder bdb) {
    AbstractBeanDefinition bd = bdb.getBeanDefinition();
    parserContext.getDelegate().parseBeanDefinitionAttributes(element, beanName, null, bd);
    BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), beanName);
    parserContext.registerBeanComponent(bcd);
}

From source file:org.jdal.beans.DefaultsBeanDefinitionParser.java

/**
 * @return/*from   w  w w .  ja  va2 s . c om*/
 */
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;
}

From source file:org.synyx.hades.dao.config.DaoConfigDefinitionParser.java

/**
 * Registers a {@code GenericDaoFactoryBean} for a bean with the given name
 * and the provided configuration context. It is mainly used to construct
 * bean name, entity class name and DAO interface name.
 * //from www  .  j  a va2s  .  co  m
 * @param parserContext
 * @param name
 * @param context
 */
private void registerGenericDaoFactoryBean(final ParserContext parserContext, final DaoContext context) {

    Object beanSource = parserContext.extractSource(context.getElement());

    BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(context.getDaoFactoryClassName());

    beanDefinitionBuilder.addPropertyValue("daoInterface", context.getInterfaceName());
    beanDefinitionBuilder.addPropertyValue("queryLookupStrategy", context.getQueryLookupStrategy());

    String entityManagerRef = context.getEntityManagerFactoryRef();

    if (null != entityManagerRef) {
        beanDefinitionBuilder.addPropertyValue("entityManager",
                getEntityManagerBeanDefinitionFor(entityManagerRef, beanSource));
    }

    beanDefinitionBuilder.addPropertyValue("transactionManager", context.getTransactionManagerRef());

    String customImplementationBeanName = registerCustomImplementation(context, parserContext, beanSource);

    if (customImplementationBeanName != null) {
        beanDefinitionBuilder.addPropertyReference("customDaoImplementation", customImplementationBeanName);
    }

    AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
    beanDefinition.setSource(beanSource);

    LOG.debug("Registering Hades DAO: {} - DAO interface: {} - Factory: {} - Custom implementation: {}",
            new Object[] { context.getBeanName(), context.getInterfaceName(), context.getDaoFactoryClassName(),
                    customImplementationBeanName });

    BeanComponentDefinition definition = new BeanComponentDefinition(beanDefinition, context.getBeanName());

    parserContext.registerBeanComponent(definition);
}

From source file:org.springjutsu.validation.namespace.ValidationConfigurationDefinitionParser.java

/**
 * Do actual parsing.//from   w  w  w  .j ava  2s. c  om
 */
public BeanDefinition parse(Element configNode, ParserContext context) {

    BeanDefinitionBuilder validationManagerBuilder = BeanDefinitionBuilder
            .genericBeanDefinition(ValidationManager.class);
    BeanDefinitionBuilder validationErrorMessageHandlerBuilder = BeanDefinitionBuilder
            .genericBeanDefinition(ValidationErrorMessageHandler.class);
    BeanDefinitionBuilder ruleExecutorContainerBuilder = BeanDefinitionBuilder
            .genericBeanDefinition(RuleExecutorContainer.class);
    BeanDefinitionBuilder contextHandlerContainerBuilder = BeanDefinitionBuilder
            .genericBeanDefinition(ValidationContextHandlerContainer.class);
    BeanDefinitionBuilder validationRulesContainerBuilder = BeanDefinitionBuilder
            .genericBeanDefinition(ValidationRulesContainer.class);

    // Parse message configuration...
    Element messageConfig = (Element) configNode
            .getElementsByTagNameNS(configNode.getNamespaceURI(), "message-config").item(0);
    if (messageConfig != null) {
        validationErrorMessageHandlerBuilder.addPropertyValue("errorMessagePrefix",
                messageConfig.getAttribute("errorMessagePrefix"));
        validationErrorMessageHandlerBuilder.addPropertyValue("fieldLabelPrefix",
                messageConfig.getAttribute("fieldLabelPrefix"));
        validationErrorMessageHandlerBuilder.addPropertyValue("enableSuperclassFieldLabelLookup",
                messageConfig.getAttribute("enableSuperclassFieldLabelLookup"));
    }

    // Parse rules configuration...
    Element rulesConfig = (Element) configNode
            .getElementsByTagNameNS(configNode.getNamespaceURI(), "rules-config").item(0);
    if (rulesConfig != null) {
        boolean addDefaultRules = Boolean.valueOf(rulesConfig.getAttribute("addDefaultRuleExecutors"));
        ruleExecutorContainerBuilder.addPropertyValue("addDefaultRuleExecutors", addDefaultRules);

        List<KeyedBeanRegistrant> ruleExecutors = new ArrayList<KeyedBeanRegistrant>();
        NodeList ruleExecutorNodes = rulesConfig.getElementsByTagNameNS(rulesConfig.getNamespaceURI(),
                "rule-executor");
        for (int executorNbr = 0; executorNbr < ruleExecutorNodes.getLength(); executorNbr++) {
            Element ruleExecutorNode = (Element) ruleExecutorNodes.item(executorNbr);
            BeanDefinitionBuilder executorBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(ruleExecutorNode.getAttribute("class"));
            String ruleExecutorBeanName = registerInfrastructureBean(context, executorBuilder);
            ruleExecutors
                    .add(new KeyedBeanRegistrant(ruleExecutorBeanName, ruleExecutorNode.getAttribute("name")));
        }
        ruleExecutorContainerBuilder.addPropertyValue("ruleExecutorBeanRegistrants", ruleExecutors);

        List<Class<?>> excludeAnnotations = new ArrayList<Class<?>>();
        excludeAnnotations.add(RecursiveValidationExclude.class);

        NodeList excludeAnnotationNodes = rulesConfig.getElementsByTagNameNS(rulesConfig.getNamespaceURI(),
                "recursion-exclude-annotation");
        for (int excludeNbr = 0; excludeNbr < excludeAnnotationNodes.getLength(); excludeNbr++) {
            Element excludeNode = (Element) excludeAnnotationNodes.item(excludeNbr);
            String excludeAnnotationClass = excludeNode.getAttribute("class");
            try {
                excludeAnnotations.add(Class.forName(excludeAnnotationClass));
            } catch (ClassNotFoundException cnfe) {
                throw new IllegalArgumentException(
                        "Invalid exclude annotation class: " + excludeAnnotationClass, cnfe);
            }
        }
        validationRulesContainerBuilder.addPropertyValue("excludeAnnotations", excludeAnnotations);

        List<Class<?>> includeAnnotations = new ArrayList<Class<?>>();
        includeAnnotations.add(RecursiveValidationInclude.class);

        NodeList includeAnnotationNodes = rulesConfig.getElementsByTagNameNS(rulesConfig.getNamespaceURI(),
                "recursion-include-annotation");
        for (int includeNbr = 0; includeNbr < includeAnnotationNodes.getLength(); includeNbr++) {
            Element includeNode = (Element) includeAnnotationNodes.item(includeNbr);
            String includeAnnotationClass = includeNode.getAttribute("class");
            try {
                includeAnnotations.add(Class.forName(includeAnnotationClass));
            } catch (ClassNotFoundException cnfe) {
                throw new IllegalArgumentException(
                        "Invalid include annotation class: " + includeAnnotationClass, cnfe);
            }
        }
        validationRulesContainerBuilder.addPropertyValue("includeAnnotations", includeAnnotations);
    }

    // Parse context configuration...
    Element contextConfig = (Element) configNode
            .getElementsByTagNameNS(configNode.getNamespaceURI(), "context-config").item(0);
    if (contextConfig != null) {
        boolean addDefaultContextHandlers = Boolean
                .valueOf(contextConfig.getAttribute("addDefaultContextHandlers"));
        contextHandlerContainerBuilder.addPropertyValue("addDefaultContextHandlers", addDefaultContextHandlers);

        List<KeyedBeanRegistrant> contextHandlers = new ArrayList<KeyedBeanRegistrant>();
        NodeList contextHandlerNodes = contextConfig.getElementsByTagNameNS(contextConfig.getNamespaceURI(),
                "context-handler");
        for (int handlerNbr = 0; handlerNbr < contextHandlerNodes.getLength(); handlerNbr++) {
            Element contextHandlerNode = (Element) contextHandlerNodes.item(handlerNbr);
            BeanDefinitionBuilder handlerBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(contextHandlerNode.getAttribute("class"));
            String ruleExecutorBeanName = registerInfrastructureBean(context, handlerBuilder);
            contextHandlers.add(
                    new KeyedBeanRegistrant(ruleExecutorBeanName, contextHandlerNode.getAttribute("type")));
        }
        contextHandlerContainerBuilder.addPropertyValue("contextHandlerBeanRegistrants", contextHandlers);
    }

    // Register them beans.
    registerInfrastructureBean(context, validationRulesContainerBuilder);
    registerInfrastructureBean(context, ruleExecutorContainerBuilder);
    registerInfrastructureBean(context, contextHandlerContainerBuilder);
    registerInfrastructureBean(context, validationErrorMessageHandlerBuilder);
    context.registerBeanComponent(new BeanComponentDefinition(validationManagerBuilder.getBeanDefinition(),
            configNode.getAttribute("validatorName")));

    return null;
}

From source file:org.jdal.beans.DefaultsBeanDefinitionParser.java

/**
 * @return//  w w w  .ja  va 2s. c  o  m
 */
private ComponentDefinition registerPropertyEditors(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
    Map<String, String> map = new HashMap<String, String>();
    map.put("java.awt.Image", "org.jdal.beans.ImagePropertyEditor");
    map.put("javax.swing.Icon", "org.jdal.beans.IconPropertyEditor");
    bdb.addPropertyValue("customEditors", map);
    BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(),
            CUSTOM_EDITOR_CONFIGURER_BEAN_NAME);
    registerBeanComponentDefinition(element, parserContext, bcd);
    return bcd;
}