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

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

Introduction

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

Prototype

void setAttribute(String name, @Nullable Object value);

Source Link

Document

Set the attribute defined by name to the supplied value .

Usage

From source file:org.bigtester.ate.xmlschema.SendKeysActionBeanDefinitionParser.java

/**
 * {@inheritDoc}/*from w ww .  j  av  a  2 s  .  co m*/
 */
@Override
protected @Nullable AbstractBeanDefinition parseInternal(@Nullable Element element,
        @Nullable ParserContext parserContext) {
    // Here we parse the Spring elements such as < property>
    if (parserContext == null || element == null)
        throw GlobalUtils.createNotInitializedException("element and parserContext");
    // Here we parse the Spring elements such as < property>
    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element);
    BeanDefinition bDef = holder.getBeanDefinition();
    bDef.setBeanClassName(SendKeysAction.class.getName());

    String data = element.getAttribute(XsdElementConstants.ATTR_SENDKEYSACTION_DATAVALUE);
    if (StringUtils.hasText(data)) {
        //               ConstructorArgumentValues inputDataValueConstrs = new ConstructorArgumentValues();
        //               inputDataValueConstrs.addGenericArgumentValue(data);
        //               BeanDefinition inputDataValueDef = new ChildBeanDefinition(
        //                     XsdElementConstants.ELEMENT_ID_BASEINPUTDATAVALUE,
        //                     StepInputDataValue.class, inputDataValueConstrs, null);
        //
        //               parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id") + "_ELEMENTINPUTDATA_ID", inputDataValueDef);
        bDef.setAttribute(XsdElementConstants.ATTR_SENDKEYSACTION_DATAVALUE, data);
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(data));
    } else {
        bDef.setAttribute(XsdElementConstants.ATTR_SENDKEYSACTION_DATAVALUE, "");
    }

    bDef.setParentName(XsdElementConstants.ELEMENT_ID_BASEELEMENTACTION);

    bDef.setAttribute("id", element.getAttribute("id"));
    parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef);
    return (AbstractBeanDefinition) bDef;
}

From source file:org.bigtester.ate.model.page.elementaction.SendKeysActionPostBeanProcessor.java

/**
 * {@inheritDoc}//from w w w  . ja v a 2 s . c o m
 */
@Override
public void postProcessBeanFactory(@Nullable ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (beanFactory == null)
        throw new IllegalStateException("Spring Container initialization error");
    // String[] homePageNames =
    // beanFactory.getBeanNamesForType(IStepInputData.class, true, false);
    String[] allSendKeysActions = beanFactory.getBeanNamesForType(SendKeysAction.class, true, false);
    for (int index = 0; index < allSendKeysActions.length; index++) {
        BeanDefinition sendKeyActDef = beanFactory.getBeanDefinition(allSendKeysActions[index]);
        String dataValue = ((RuntimeBeanReference) sendKeyActDef.getConstructorArgumentValues()
                .getGenericArgumentValue(RuntimeBeanReference.class).getValue()).getBeanName();
        //.getAttribute(XsdElementConstants.ATTR_SENDKEYSACTION_DATAVALUE);
        if (null == dataValue) {
            throw new IllegalStateException("Spring Container sendKeyActionValue initialization error");
        } else {
            try {
                beanFactory.getBeanDefinition(dataValue);
            } catch (NoSuchBeanDefinitionException NoBeanDef) {

                String idstr;
                BeanDefinitionBuilder definitionBuilder;

                if (StringUtils.isEmpty(dataValue)) {
                    definitionBuilder = BeanDefinitionBuilder
                            .genericBeanDefinition(RandomAlphaTextValueDataHolder.class);
                    idstr = (String) sendKeyActDef.getAttribute("id")
                            + "_SendKeysRandomAlphaTextDataValueBean_ID";
                    definitionBuilder.addConstructorArgValue(idstr);
                    definitionBuilder.addConstructorArgValue(10);

                } else {
                    definitionBuilder = BeanDefinitionBuilder
                            .genericBeanDefinition(ManualAssignedValueDataHolder.class);

                    definitionBuilder.addConstructorArgValue(EnumRunTimeDataType.TEXT);
                    definitionBuilder.addConstructorArgValue(dataValue);

                    idstr = (String) sendKeyActDef.getAttribute("id") + "_SendKeysDataValueBean_ID";
                    definitionBuilder.addConstructorArgValue(idstr);

                }

                getBdReg().registerBeanDefinition(idstr, definitionBuilder.getBeanDefinition());
                sendKeyActDef.setAttribute(XsdElementConstants.ATTR_SENDKEYSACTION_DATAVALUE, idstr);
                sendKeyActDef.getConstructorArgumentValues().getGenericArgumentValue(RuntimeBeanReference.class)
                        .setValue(new RuntimeBeanReference(idstr));
            }
        }
    }

}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

public BeanDefinitionHolder parseAsHolder(Element componentElement, ParserContext parserContext) {
    // save parser context
    this.parserContext = parserContext;
    this.defaults = new BlueprintDefaultsDefinition(componentElement.getOwnerDocument(), parserContext);

    // let Spring do its standard parsing
    BeanDefinitionHolder bdHolder = parseComponentDefinitionElement(componentElement, null);

    BeanDefinition bd = bdHolder.getBeanDefinition();
    if (bd != null) {
        bd.setAttribute(ParsingUtils.BLUEPRINT_MARKER_NAME, Boolean.TRUE);
    }//w w w  .  j a  va 2  s  . c  o m

    return bdHolder;
}

From source file:org.eclipse.gemini.blueprint.blueprint.container.support.internal.config.CycleOrderingProcessor.java

private void addSyntheticDependsOn(BeanDefinition definition, String beanName) {
    if (StringUtils.hasText(beanName)) {
        String[] dependsOn = definition.getDependsOn();
        if (dependsOn != null && dependsOn.length > 0) {
            for (String dependOn : dependsOn) {
                if (beanName.equals(dependOn)) {
                    return;
                }// w ww  .  jav a  2 s.  c  o m
            }
        }

        // add depends on
        dependsOn = (String[]) ObjectUtils.addObjectToArray(dependsOn, beanName);
        definition.setDependsOn(dependsOn);
        Collection<String> markers = (Collection<String>) definition.getAttribute(SYNTHETIC_DEPENDS_ON);
        if (markers == null) {
            markers = new ArrayList<String>(2);
            definition.setAttribute(SYNTHETIC_DEPENDS_ON, markers);
        }
        markers.add(beanName);
    }
}

From source file:org.metaeffekt.dcc.commons.spring.xml.CapabilityInheritanceBeanDefinitionPostProcessor.java

@SuppressWarnings("unchecked")
private void enrichBeanDefinition(BeanDefinitionRegistry registry, String definitionName) {
    BeanDefinition definition = registry.getBeanDefinition(definitionName);
    List<CapabilityDefinitionReference> ancestors = new ArrayList<>();
    ancestors.addAll((List<CapabilityDefinitionReference>) definition.getPropertyValues()
            .getPropertyValue(DCCConfigurationBeanDefinitionParser.PROPERTY_CAPABILITY_DEF_ANCESTORS)
            .getValue());/*from w  w w.jav  a2 s .com*/
    definition.setAttribute(DCCConfigurationBeanDefinitionParser.PROPERTY_CAPABILITY_DEF_ANCESTORS, ancestors);
}

From source file:org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.java

public static void setFlag(BeanDefinition bean, String flag) {
    bean.setAttribute(flag, Boolean.TRUE);
}

From source file:org.mule.module.extension.internal.config.XmlExtensionParserUtils.java

/**
 * Sets the {@link MuleHierarchicalBeanDefinitionParserDelegate#MULE_NO_RECURSE} attribute
 * on the given {@code definition}//from  ww  w  .j av  a  2 s.c  om
 *
 * @param definition a {@link BeanDefinition}
 */
static void setNoRecurseOnDefinition(BeanDefinition definition) {
    definition.setAttribute(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE, Boolean.TRUE);
}

From source file:org.mule.security.oauth.config.AbstractDevkitBasedDefinitionParser.java

protected void setNoRecurseOnDefinition(BeanDefinition definition) {
    definition.setAttribute(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE, Boolean.TRUE);
}

From source file:org.springframework.context.annotation.ConfigurationClassPostProcessor.java

/**
 * Post-processes a BeanFactory in search of Configuration class BeanDefinitions;
 * any candidates are then enhanced by a {@link ConfigurationClassEnhancer}.
 * Candidate status is determined by BeanDefinition attribute metadata.
 * @see ConfigurationClassEnhancer/*from   w w  w.  ja  va 2s .  co  m*/
 */
public void enhanceConfigurationClasses(ConfigurableListableBeanFactory beanFactory) {
    Map<String, AbstractBeanDefinition> configBeanDefs = new LinkedHashMap<>();
    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        if (ConfigurationClassUtils.isFullConfigurationClass(beanDef)) {
            if (!(beanDef instanceof AbstractBeanDefinition)) {
                throw new BeanDefinitionStoreException("Cannot enhance @Configuration bean definition '"
                        + beanName + "' since it is not stored in an AbstractBeanDefinition subclass");
            } else if (logger.isWarnEnabled() && beanFactory.containsSingleton(beanName)) {
                logger.warn("Cannot enhance @Configuration bean definition '" + beanName
                        + "' since its singleton instance has been created too early. The typical cause "
                        + "is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor "
                        + "return type: Consider declaring such methods as 'static'.");
            }
            configBeanDefs.put(beanName, (AbstractBeanDefinition) beanDef);
        }
    }
    if (configBeanDefs.isEmpty()) {
        // nothing to enhance -> return immediately
        return;
    }

    ConfigurationClassEnhancer enhancer = new ConfigurationClassEnhancer();
    for (Map.Entry<String, AbstractBeanDefinition> entry : configBeanDefs.entrySet()) {
        AbstractBeanDefinition beanDef = entry.getValue();
        // If a @Configuration class gets proxied, always proxy the target class
        beanDef.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
        try {
            // Set enhanced subclass of the user-specified bean class
            Class<?> configClass = beanDef.resolveBeanClass(this.beanClassLoader);
            if (configClass != null) {
                Class<?> enhancedClass = enhancer.enhance(configClass, this.beanClassLoader);
                if (configClass != enhancedClass) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(String.format(
                                "Replacing bean definition '%s' existing class '%s' with "
                                        + "enhanced class '%s'",
                                entry.getKey(), configClass.getName(), enhancedClass.getName()));
                    }
                    beanDef.setBeanClass(enhancedClass);
                }
            }
        } catch (Throwable ex) {
            throw new IllegalStateException("Cannot load configuration class: " + beanDef.getBeanClassName(),
                    ex);
        }
    }
}

From source file:org.springframework.context.annotation.ConfigurationClassUtils.java

/**
 * Check whether the given bean definition is a candidate for a configuration class
 * (or a nested component class declared within a configuration/component class,
 * to be auto-registered as well), and mark it accordingly.
 * @param beanDef the bean definition to check
 * @param metadataReaderFactory the current factory in use by the caller
 * @return whether the candidate qualifies as (any kind of) configuration class
 *///  w  w  w.j av  a  2s  . c om
public static boolean checkConfigurationClassCandidate(BeanDefinition beanDef,
        MetadataReaderFactory metadataReaderFactory) {
    String className = beanDef.getBeanClassName();
    if (className == null || beanDef.getFactoryMethodName() != null) {
        return false;
    }

    AnnotationMetadata metadata;
    if (beanDef instanceof AnnotatedBeanDefinition
            && className.equals(((AnnotatedBeanDefinition) beanDef).getMetadata().getClassName())) {
        // Can reuse the pre-parsed metadata from the given BeanDefinition...
        metadata = ((AnnotatedBeanDefinition) beanDef).getMetadata();
    } else if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) beanDef).hasBeanClass()) {
        // Check already loaded Class if present...
        // since we possibly can't even load the class file for this Class.
        Class<?> beanClass = ((AbstractBeanDefinition) beanDef).getBeanClass();
        metadata = new StandardAnnotationMetadata(beanClass, true);
    } else {
        try {
            MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(className);
            metadata = metadataReader.getAnnotationMetadata();
        } catch (IOException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "Could not find class file for introspecting configuration annotations: " + className,
                        ex);
            }
            return false;
        }
    }

    if (isFullConfigurationCandidate(metadata)) {
        beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_FULL);
    } else if (isLiteConfigurationCandidate(metadata)) {
        beanDef.setAttribute(CONFIGURATION_CLASS_ATTRIBUTE, CONFIGURATION_CLASS_LITE);
    } else {
        return false;
    }

    // It's a full or lite configuration candidate... Let's determine the order value, if any.
    Integer order = getOrder(metadata);
    if (order != null) {
        beanDef.setAttribute(ORDER_ATTRIBUTE, order);
    }

    return true;
}