Example usage for org.springframework.beans.factory.config BeanDefinition getAttribute

List of usage examples for org.springframework.beans.factory.config BeanDefinition getAttribute

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config BeanDefinition getAttribute.

Prototype

@Nullable
Object getAttribute(String name);

Source Link

Document

Get the value of the attribute identified by name .

Usage

From source file:com.github.yulechen.springannotation.test.ConfigurationClassUtils.java

/**
 * Determine the order for the given configuration class bean definition, as
 * set by {@link #checkConfigurationClassCandidate}.
 * /*ww w  . java  2 s . c  om*/
 * @param beanDef
 *            the bean definition to check
 * @return the {@link @Order} annotation value on the configuration class,
 *         or {@link Ordered#LOWEST_PRECEDENCE} if none declared
 * @since 4.2
 */
public static int getOrder(BeanDefinition beanDef) {
    Integer order = (Integer) beanDef.getAttribute(ORDER_ATTRIBUTE);
    return (order != null ? order : Ordered.LOWEST_PRECEDENCE);
}

From source file:com.github.yulechen.springannotation.test.ConfigurationClassUtils.java

/**
 * Determine whether the given bean definition indicates a full
 * {@code @Configuration} class, through checking
 * {@link #checkConfigurationClassCandidate}'s metadata marker.
 *///w w  w.java 2 s.co  m
public static boolean isFullConfigurationClass(BeanDefinition beanDef) {
    return CONFIGURATION_CLASS_FULL.equals(beanDef.getAttribute(CONFIGURATION_CLASS_ATTRIBUTE));
}

From source file:com.github.yulechen.springannotation.test.ConfigurationClassUtils.java

/**
 * Determine whether the given bean definition indicates a lite
 * {@code @Configuration} class, through checking
 * {@link #checkConfigurationClassCandidate}'s metadata marker.
 *//*from   w w  w  . j  a  v a 2s  .c om*/
public static boolean isLiteConfigurationClass(BeanDefinition beanDef) {
    return CONFIGURATION_CLASS_LITE.equals(beanDef.getAttribute(CONFIGURATION_CLASS_ATTRIBUTE));
}

From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java

/**
 * Convenience method to update a template bean definition from overriding XML data.  
 * If <code>overrides</code> contains attribute <code>attribute</code>, transfer that
 * attribute onto <code>template</code>, overwriting the default value.
 *//*from  w w w .j  a va  2s  .c o  m*/
public static String overrideAttribute(String attribute, BeanDefinition template, Element overrides) {
    String value = (String) template.getAttribute(attribute);
    if (overrides.hasAttribute(attribute)) {
        value = overrides.getAttribute(attribute);
        template.setAttribute(attribute, value);
    }
    return value;
}

From source file:org.solmix.runtime.support.spring.ContainerPostProcessor.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    Object inject = container;//w  w  w. ja  v  a2 s.  c o  m
    if (inject == null) {
        inject = getContainerByName(Container.DEFAULT_CONTAINER_ID, beanFactory, true, null);
    } else {
        if (!beanFactory.containsBeanDefinition(Container.DEFAULT_CONTAINER_ID)
                && !beanFactory.containsSingleton(Container.DEFAULT_CONTAINER_ID)) {
            beanFactory.registerSingleton(Container.DEFAULT_CONTAINER_ID, container);
        }
    }
    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
        Object p = beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_ATTRIBUTE);
        if (p == null)
            continue;
        String name = (String) beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_NAME);
        String create = (String) beanDefinition
                .getAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_CREATE);
        Object inj = inject;
        if (name != null) {
            if (container != null) {
                continue;
            }
            inj = getContainerByName(name, beanFactory, create != null, create);
        }
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_NAME);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_ATTRIBUTE);
        beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_CONTAINER_CREATE);
        if (create == null) {
            if (Boolean.valueOf(p.toString())) {
                beanDefinition.getPropertyValues().addPropertyValue("container", inj);
            } else {
                ConstructorArgumentValues constructorArgs = beanDefinition.getConstructorArgumentValues();
                insertConstructorArg(constructorArgs, inj);
            }
        }
    } //end loop bean.

}

From source file:org.carewebframework.api.spring.FrameworkBeanFactory.java

/**
 * Searches this bean definition and all originating bean definitions until it finds the
 * requested attribute./*from  www.j a v a2  s .  com*/
 * 
 * @param beanDefinition Bean definition.
 * @param attributeName Attribute to locate.
 * @return The value of the attribute, or null if not found.
 */
private String getAttribute(BeanDefinition beanDefinition, String attributeName) {
    String value = null;

    while (beanDefinition != null) {
        value = (String) beanDefinition.getAttribute(attributeName);

        if (value != null) {
            break;
        }

        beanDefinition = beanDefinition.getOriginatingBeanDefinition();
    }

    return value;
}

From source file:com.griddynamics.banshun.ContextAnalyzer.java

protected BeanReferenceInfo extractImportReference(BeanDefinition beanDefinition) {
    if (!beanDefinition.hasAttribute(IMPORT_BEAN_DEF_ATTR_NAME)) {
        throw new IllegalArgumentException(
                "BeanDefinition does not contain attribute: " + IMPORT_BEAN_DEF_ATTR_NAME);
    }/* w w w .  ja va 2s  . co m*/
    return (BeanReferenceInfo) beanDefinition.getAttribute(IMPORT_BEAN_DEF_ATTR_NAME);
}

From source file:com.griddynamics.banshun.ContextAnalyzer.java

protected BeanReferenceInfo extractExportReference(BeanDefinition beanDefinition) {
    if (!beanDefinition.hasAttribute(EXPORT_BEAN_DEF_ATTR_NAME)) {
        throw new IllegalArgumentException(
                "BeanDefinition does not contain attribute: " + EXPORT_BEAN_DEF_ATTR_NAME);
    }/*from   ww w  . ja  v a  2 s  . c  o  m*/
    return (BeanReferenceInfo) beanDefinition.getAttribute(EXPORT_BEAN_DEF_ATTR_NAME);
}

From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java

/**
 * <p>Load the template BeanDefinition and call {@link #transform(ConfigurableListableBeanFactory, BeanDefinition, Element, ParserContext)}
 * to apply runtime configuration value to it.  <code>builder</code> will be configured to instantiate the bean
 * in the Spring context that we are parsing.</p>
 * /*w  w  w  .  j  a v a  2 s. c  om*/
 * <p>During parsing, an instance of {@link TemplateBeanDefinitionParser.TemplateComponentDefinition} is pushed onto <code>ParserContext</code> so
 * that nested tags can access the enclosing template configuration with a call to {@link #findEnclosingTemplateFactory(ParserContext)}.
 * Subclasses can override {@link #newComponentDefinition(String, Object, DefaultListableBeanFactory)} to provide a 
 * subclass of {@link TemplateBeanDefinitionParser.TemplateComponentDefinition} to the parser context if necessary.</p>
 */
@Override
protected final void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    //if we have multiple nested bean definitions, we only parse the template factory
    //once.  this allows configuration changes made by enclosing bean parsers to be inherited
    //by contained beans, which is quite useful.
    DefaultListableBeanFactory templateFactory = findEnclosingTemplateFactory(parserContext);
    TemplateComponentDefinition tcd = null;
    if (templateFactory == null) {

        //no nesting -- load the template XML configuration from the classpath.
        final BeanFactory parentFactory = (BeanFactory) parserContext.getRegistry();
        templateFactory = new DefaultListableBeanFactory(parentFactory);

        //load template bean definitions
        DefaultResourceLoader loader = new DefaultResourceLoader();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(templateFactory);
        reader.setResourceLoader(loader);
        reader.setEntityResolver(new ResourceEntityResolver(loader));
        reader.loadBeanDefinitions(templateResource);

        //propagate factory post-processors from the source factory into the template
        //factory.
        BeanDefinition ppChain = new RootBeanDefinition(ChainingBeanFactoryPostProcessor.class);
        ppChain.getPropertyValues().addPropertyValue("targetFactory", templateFactory);
        parserContext.getReaderContext().registerWithGeneratedName(ppChain);

        //push component definition onto the parser stack for the benefit of
        //nested bean definitions.
        tcd = newComponentDefinition(element.getNodeName(), parserContext.extractSource(element),
                templateFactory);
        parserContext.pushContainingComponent(tcd);
    }

    try {
        //allow subclasses to apply overrides to the template bean definition.
        BeanDefinition def = templateFactory.getBeanDefinition(templateId);
        transform(templateFactory, def, element, parserContext);

        //setup our factory bean to instantiate the modified bean definition upon request.
        builder.addPropertyValue("beanFactory", templateFactory);
        builder.addPropertyValue("beanName", templateId);
        builder.getRawBeanDefinition().setAttribute("id", def.getAttribute("id"));

    } finally {
        if (tcd != null)
            parserContext.popContainingComponent();
    }
}

From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java

/**
 * Get the refresh check delay for the given {@link ScriptFactory} {@link BeanDefinition}.
 * If the {@link BeanDefinition} has a//from  w w w.j a v  a  2 s  .c om
 * {@link org.springframework.core.AttributeAccessor metadata attribute}
 * under the key {@link #REFRESH_CHECK_DELAY_ATTRIBUTE} which is a valid {@link Number}
 * type, then this value is used. Otherwise, the the {@link #defaultRefreshCheckDelay}
 * value is used.
 * @param beanDefinition the BeanDefinition to check
 * @return the refresh check delay
 */
protected long resolveRefreshCheckDelay(BeanDefinition beanDefinition) {
    long refreshCheckDelay = this.defaultRefreshCheckDelay;
    Object attributeValue = beanDefinition.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE);
    if (attributeValue instanceof Number) {
        refreshCheckDelay = ((Number) attributeValue).longValue();
    } else if (attributeValue instanceof String) {
        refreshCheckDelay = Long.parseLong((String) attributeValue);
    } else if (attributeValue != null) {
        throw new BeanDefinitionStoreException(
                "Invalid refresh check delay attribute [" + REFRESH_CHECK_DELAY_ATTRIBUTE + "] with value '"
                        + attributeValue + "': needs to be of type Number or String");
    }
    return refreshCheckDelay;
}