Example usage for org.springframework.beans.factory.config BeanDefinitionHolder getBeanDefinition

List of usage examples for org.springframework.beans.factory.config BeanDefinitionHolder getBeanDefinition

Introduction

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

Prototype

public BeanDefinition getBeanDefinition() 

Source Link

Document

Return the wrapped BeanDefinition.

Usage

From source file:com.inspiresoftware.lib.dto.geda.config.XmlDrivenGeDABeanDefinitionParser.java

public BeanDefinitionHolder decorate(final Node node, final BeanDefinitionHolder definition,
        final ParserContext parserContext) {

    final BeanDefinition beanDefinition = definition.getBeanDefinition();

    final String dtoSupportProperty = node.getAttributes().getNamedItem(XSD_ATTR__PROPERTY).getNodeValue();

    final MutablePropertyValues properties = beanDefinition.getPropertyValues();
    properties.add(dtoSupportProperty, new RuntimeBeanReference(dtoSupportBeanName));

    return definition;
}

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

/**
 * {@inheritDoc}/*w  w w  .j a  v a  2  s.c om*/
 */
@Override
protected 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");
    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element);
    BeanDefinition bDef = holder.getBeanDefinition();
    bDef.setBeanClassName(BaseTestStep.class.getName());
    String pageObject = element.getAttribute(XsdElementConstants.ATTR_BASETESTSTEP_PAGEOBJECT);
    if (StringUtils.hasText(pageObject)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(pageObject));
    }
    String myWebElement = element.getAttribute(XsdElementConstants.ATTR_BASETESTSTEP_MYWEBELEMENT);
    if (StringUtils.hasText(myWebElement)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(myWebElement));
    }

    String ead = element.getAttribute(XsdElementConstants.ATTR_ELEMENTSTEP_ELEMENTACTIONDEF);
    if (StringUtils.hasText(ead)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(ead));
    }

    boolean target = Boolean.parseBoolean(element.getAttribute(XsdElementConstants.ATTR_TESTSTEP_TARGETSTEP));
    bDef.getPropertyValues().addPropertyValue(XsdElementConstants.ATTR_TESTSTEP_TARGETSTEP, target);

    boolean optional;

    if (target) {
        optional = false;
    } else {
        optional = Boolean.parseBoolean(element.getAttribute(XsdElementConstants.ATTR_TESTSTEP_OPTIONALSTEP));
        String optionalStepUntilInclusive = element
                .getAttribute(XsdElementConstants.ATTR_TESTSTEP_CORRELATEDOPTIONALSTEPSUTILINCLUSIVE);
        bDef.getPropertyValues().addPropertyValue(
                XsdElementConstants.ATTR_TESTSTEP_CORRELATEDOPTIONALSTEPSUTILINCLUSIVE,
                optionalStepUntilInclusive);
    }
    bDef.getPropertyValues().addPropertyValue(XsdElementConstants.ATTR_TESTSTEP_OPTIONALSTEP, optional);

    String stepName = element.getAttribute(XsdElementConstants.ATTR_TESTSTEP_STEPNAME);
    bDef.getPropertyValues().addPropertyValue(XsdElementConstants.ATTR_TESTSTEP_STEPNAME, stepName);

    String stepDesc = element.getAttribute(XsdElementConstants.ATTR_TESTSTEP_STEPDESCRIPTION);
    bDef.getPropertyValues().addPropertyValue(XsdElementConstants.ATTR_TESTSTEP_STEPDESCRIPTION, stepDesc);

    bDef.getPropertyValues().addPropertyValue("repeatStepLogger",
            new RuntimeBeanReference(GlobalConstants.BEAN_ID_REPEATSTEPEXECUTIONLOGGER));

    String testcaseParentName = element.getParentNode().getAttributes().getNamedItem("id").getNodeValue();
    bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(testcaseParentName));
    //        String text = element.getAttribute("text");
    //        bd.getPropertyValues().addPropertyValue("text", text);
    parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef);
    return (AbstractBeanDefinition) bDef;

}

From source file:org.devefx.httpmapper.spring.mapper.ClassPathMapperScanner.java

private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
    ScannedGenericBeanDefinition definition;
    for (BeanDefinitionHolder holder : beanDefinitions) {
        definition = (ScannedGenericBeanDefinition) holder.getBeanDefinition();

        if (logger.isDebugEnabled()) {
            logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '"
                    + definition.getBeanClassName() + "' mapperInterface");
        }//from   w  w w.ja va 2s  .co  m
        // the mapper interface is the original class of the bean
        // but, the actual class of the bean is MapperFactoryBean
        definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName());
        definition.setBeanClass(this.factoryBeanClass);

        boolean explicitFactoryUsed = false;
        if (StringUtils.hasText(this.configBeanName)) {
            definition.getPropertyValues().add("config", new RuntimeBeanReference(this.configBeanName));
            explicitFactoryUsed = true;
        }

        if (!explicitFactoryUsed) {
            if (logger.isDebugEnabled()) {
                logger.debug("Enabling autowire by type for MapperFactoryBean with name '"
                        + holder.getBeanName() + "'.");
            }
            definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        }
    }
}

From source file:com.dianping.zebra.monitor.spring.DataSourceAutoMonitor.java

@SuppressWarnings("unchecked")
private void replaceInnerDataSourceInZebra(String beanName, BeanDefinition zebraDataSourceDefinition) {
    MutablePropertyValues propertyValues = zebraDataSourceDefinition.getPropertyValues();
    PropertyValue dataSourcePoolVal = propertyValues.getPropertyValue("dataSourcePool");

    if (dataSourcePoolVal == null) {
        if (logger.isWarnEnabled()) {
            logger.warn("Zebra dataSource's dataSourcePool property not found, maybe its name is modified, "
                    + "change the automonitor's implementation, otherwise some inner dataSource cannot be monitored.");
        }/*  w w  w  .j  a  v a 2  s  . co  m*/
        return;
    }

    Map<TypedStringValue, Object> innerDSDefinitionMap = (Map<TypedStringValue, Object>) dataSourcePoolVal
            .getValue();
    for (Entry<TypedStringValue, Object> innerDSDefEntry : innerDSDefinitionMap.entrySet()) {
        Object innerDSDefVal = innerDSDefEntry.getValue();
        if (innerDSDefVal instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder innerDSDefHolder = (BeanDefinitionHolder) innerDSDefVal;
            BeanDefinition innerDSDefinition = innerDSDefHolder.getBeanDefinition();
            innerDSDefEntry.setValue(
                    new BeanDefinitionHolder(createMonitorableBeanDefinition(beanName, innerDSDefinition),
                            innerDSDefHolder.getBeanName(), innerDSDefHolder.getAliases()));
        }
    }
}

From source file:com.dianping.zebra.monitor.spring.DataSourceAutoMonitor.java

@SuppressWarnings("unchecked")
private boolean checkInnerDataSourceInZebra(String beanName, BeanDefinition zebraDataSourceDefinition) {
    MutablePropertyValues propertyValues = zebraDataSourceDefinition.getPropertyValues();
    PropertyValue dataSourcePoolVal = propertyValues.getPropertyValue("dataSourcePool");

    if (dataSourcePoolVal == null) {
        if (logger.isWarnEnabled()) {
            logger.warn("Zebra dataSource's dataSourcePool property not found, maybe its name is modified, "
                    + "change the automonitor's implementation, otherwise some inner dataSource cannot be monitored.");
        }/*from   w  w  w . j av  a2  s .c  o  m*/
        return true;
    }

    Map<TypedStringValue, Object> innerDSDefinitionMap = (Map<TypedStringValue, Object>) dataSourcePoolVal
            .getValue();
    for (Entry<TypedStringValue, Object> innerDSDefEntry : innerDSDefinitionMap.entrySet()) {
        Object innerDSDefVal = innerDSDefEntry.getValue();
        if (innerDSDefVal instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder innerDSDefHolder = (BeanDefinitionHolder) innerDSDefVal;
            BeanDefinition innerDSDefinition = innerDSDefHolder.getBeanDefinition();
            if (GroupDataSource.class.getName().equals(innerDSDefinition.getBeanClassName())) {
                return false;
            }
        }
    }

    return false;
}

From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java

private ElementConfiguration parseBeanObject(Object item) {
    if (item instanceof TypedStringValue) {
        TypedStringValue stringValue = (TypedStringValue) item;
        ElementConfiguration primitiveConfiguration = objectConfigurationFactory
                .createPrimitiveConfiguration(stringValue.getValue());
        return primitiveConfiguration;
    } else if (item instanceof RuntimeBeanReference) {
        RuntimeBeanReference runtimeBeanReference = (RuntimeBeanReference) item;
        // return parseBeanDefinition(runtimeBeanReference.getBeanName());
        ReferenceConfiguration reference = objectConfigurationFactory.createReferenceConfiguration();
        reference.setReferenceName(runtimeBeanReference.getBeanName());
        return reference;
    } else if (item instanceof BeanDefinitionHolder) {
        BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) item;
        return parseBeanDefinition(beanDefinitionHolder.getBeanDefinition());
    } else {//from  ww w  .jav a 2  s  .  c  om
        throw new IllegalArgumentException("Not supported : item class " + item.getClass().getName());
    }

}

From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java

public ElementConfiguration parseProperty(Object value) {
    LOGGER.debug("value : " + value);
    if (value instanceof TypedStringValue) {
        TypedStringValue stringValue = (TypedStringValue) value;
        if (stringValue.getTargetTypeName() != null) {
            return getEnumObjectConfiguration(stringValue);
        } else {//w ww  . j a  v  a2  s . c o m
            PrimitiveConfiguration primitiveConfiguration = objectConfigurationFactory
                    .createPrimitiveConfiguration();
            if (useSPEL(stringValue)) {
                ExpressionParser parser = new SpelExpressionParser();
                String expAsStringWithToken = stringValue.getValue().trim();
                String expAsString = expAsStringWithToken.substring(2, expAsStringWithToken.length() - 1)
                        .trim();
                LOGGER.trace("This property is a SPEL expression: " + expAsString);

                // String regex = "systemProperties\\['([^\\s]+)'\\]";

                Expression exp = parser.parseExpression(expAsString);
                StandardEvaluationContext sec = null;
                if (sec == null) {
                    sec = new StandardEvaluationContext();
                    sec.addPropertyAccessor(new EnvironmentAccessor());
                    sec.addPropertyAccessor(new BeanExpressionContextAccessor());
                    sec.addPropertyAccessor(new BeanFactoryAccessor());
                    sec.addPropertyAccessor(new MapAccessor());
                }
                primitiveConfiguration.setValue(String.valueOf(exp.getValue()));
            } else {
                LOGGER.trace("This property is NOT a SPEL expression: " + stringValue.getValue());
                primitiveConfiguration.setValue(stringValue.getValue());
            }
            return primitiveConfiguration;
        }
    } else if (value instanceof RuntimeBeanReference) {
        RuntimeBeanReference beanReference = (RuntimeBeanReference) value;
        ReferenceConfiguration referenceConfiguration = objectConfigurationFactory
                .createReferenceConfiguration();
        referenceConfiguration.setReferenceName(beanReference.getBeanName());
        return referenceConfiguration;
    } else if (value instanceof ManagedList<?>) {
        return parseValueList((ManagedList<?>) value);
    } else if (value instanceof ManagedMap<?, ?>) {
        return parseValueMap((ManagedMap<?, ?>) value);
    } else if (value instanceof BeanDefinitionHolder) {
        BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) value;
        return parseBeanDefinition(beanDefinitionHolder.getBeanDefinition());
    } else {
        throw new UnsupportedOperationException("The type of property value is not suppported : " + value
                + " (class : " + value.getClass().getName() + ")");
    }
}

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

/**
 * {@inheritDoc}//from  w  w w.  ja v a  2 s .  c om
 */
@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>

    String dataHolderType = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATAHOLDERTYPE)
            .toUpperCase();
    if (null == dataHolderType || !StringUtils.hasText(dataHolderType)) {
        throw GlobalUtils.createNotInitializedException("dataHolderType attribute in xml test case");
    }
    RumtimeDataHolderType enumDataHolderType = RumtimeDataHolderType.valueOf(dataHolderType);
    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element);
    BeanDefinition bDef = holder.getBeanDefinition();
    switch (enumDataHolderType) {
    case PAGESOURCEPARSED:
        bDef.setBeanClassName(PageParsedDataHolder.class.getName());
        break;
    case MANUALASSIGNED:
        bDef.setBeanClassName(ManualAssignedValueDataHolder.class.getName());
        break;
    case CASESERVICEPARSED:
        bDef.setBeanClassName(CaseServiceParsedDataHolder.class.getName());
        break;
    case STEPSERVICEPARSED:
        bDef.setBeanClassName(StepServiceParsedDataHolder.class.getName());
        break;
    case RANDOMALPHATEXT:
        bDef.setBeanClassName(RandomAlphaTextValueDataHolder.class.getName());
        break;
    case RANDOMNUMBERS:
        bDef.setBeanClassName(RandomNumericValueDataHolder.class.getName());
        break;
    case RANDOMTEXTNUMBERS:
        bDef.setBeanClassName(RandomAlphaNumericValueDataHolder.class.getName());
        break;
    case RANDOMEMAIL:
        bDef.setBeanClassName(RandomEmailDataHolder.class.getName());
        break;
    default:
        break;

    }
    String dataType = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATATYPE).toUpperCase();
    if (null != dataType && StringUtils.hasText(dataType)) {
        EnumRunTimeDataType enumDataType = EnumRunTimeDataType.valueOf(dataType);
        bDef.getConstructorArgumentValues().addGenericArgumentValue(enumDataType);
    }

    String dataValue = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_DATAVALUE);
    if (StringUtils.hasText(dataValue)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(dataValue);
    }

    String leftBoundry = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_LEFTBOUNDRY);
    if (StringUtils.hasText(leftBoundry)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(leftBoundry);
    }

    String rightBoundry = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_RIGHTBOUNDRY);
    if (StringUtils.hasText(rightBoundry)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(rightBoundry);
    }

    String page = element.getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_PAGE);
    if (StringUtils.hasText(page)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(page));
    }

    String beanID = element.getAttribute("id");
    bDef.getConstructorArgumentValues().addGenericArgumentValue(beanID);

    String mappedBeanID = element
            .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_SUBCASEMAPPEDDATAHOLDERID);
    if (StringUtils.hasText(mappedBeanID)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(mappedBeanID);
    }

    String indexOfSameTypeDataOnPage = element
            .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_INDEXOFSAMETYPEDATAONPAGE);
    if (StringUtils.hasText(indexOfSameTypeDataOnPage)) {
        int index = Integer.parseInt(indexOfSameTypeDataOnPage);
        bDef.getConstructorArgumentValues().addGenericArgumentValue(index);
    }

    String randomTextLength = element
            .getAttribute(XsdElementConstants.ATTR_RUNTIMEDATAHOLDER_RANDOMINPUTLENGTH);
    if (StringUtils.hasText(randomTextLength)) {
        int length = Integer.parseInt(randomTextLength);
        bDef.getConstructorArgumentValues().addGenericArgumentValue(length);
    }

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

}

From source file:org.mybatis.spring.mapper.MapperScanner.java

/**
 * Calls the parent search that will search and register all the candidates.
 * Then the registered objects are post processed to set them as
 * MapperFactoryBeans/* w  w  w.  j  ava 2  s  . c  om*/
 */
@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);

    if (beanDefinitions.isEmpty()) {
        logger.warn("No MyBatis 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");
            }

            // the mapper interface is the original class of the bean
            // but, the actual class of the bean is MapperFactoryBean
            definition.getPropertyValues().add("mapperInterface", definition.getBeanClassName());
            definition.setBeanClass(MapperFactoryBean.class);

            definition.getPropertyValues().add("addToConfig", this.addToConfig);

            boolean explicitFactoryUsed = false;
            if (StringUtils.hasText(this.sqlSessionFactoryBeanName)) {
                definition.getPropertyValues().add("sqlSessionFactory",
                        new RuntimeBeanReference(this.sqlSessionFactoryBeanName));
                explicitFactoryUsed = true;
            } else if (this.sqlSessionFactory != null) {
                definition.getPropertyValues().add("sqlSessionFactory", this.sqlSessionFactory);
                explicitFactoryUsed = true;
            }

            if (StringUtils.hasText(this.sqlSessionTemplateBeanName)) {
                if (explicitFactoryUsed) {
                    logger.warn(
                            "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
                }
                definition.getPropertyValues().add("sqlSessionTemplate",
                        new RuntimeBeanReference(this.sqlSessionTemplateBeanName));
                definition.getPropertyValues().add("sqlSessionFactory", null);
            } else if (this.sqlSessionTemplate != null) {
                if (explicitFactoryUsed) {
                    logger.warn(
                            "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
                }
                definition.getPropertyValues().add("sqlSessionTemplate", this.sqlSessionTemplate);
                definition.getPropertyValues().add("sqlSessionFactory", null);
            }
        }
    }

    return beanDefinitions;
}

From source file:org.mybatis.spring.mapper.ClassPathMapperScanner.java

private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
    GenericBeanDefinition definition;/*from   w  w w.j av a  2  s.  c  om*/
    for (BeanDefinitionHolder holder : beanDefinitions) {
        definition = (GenericBeanDefinition) holder.getBeanDefinition();

        if (logger.isDebugEnabled()) {
            logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() + "' and '"
                    + definition.getBeanClassName() + "' mapperInterface");
        }

        // the mapper interface is the original class of the bean
        // but, the actual class of the bean is MapperFactoryBean
        definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName()); // issue #59
        definition.setBeanClass(this.mapperFactoryBean.getClass());

        definition.getPropertyValues().add("addToConfig", this.addToConfig);

        boolean explicitFactoryUsed = false;
        if (StringUtils.hasText(this.sqlSessionFactoryBeanName)) {
            definition.getPropertyValues().add("sqlSessionFactory",
                    new RuntimeBeanReference(this.sqlSessionFactoryBeanName));
            explicitFactoryUsed = true;
        } else if (this.sqlSessionFactory != null) {
            definition.getPropertyValues().add("sqlSessionFactory", this.sqlSessionFactory);
            explicitFactoryUsed = true;
        }

        if (StringUtils.hasText(this.sqlSessionTemplateBeanName)) {
            if (explicitFactoryUsed) {
                logger.warn(
                        "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
            }
            definition.getPropertyValues().add("sqlSessionTemplate",
                    new RuntimeBeanReference(this.sqlSessionTemplateBeanName));
            explicitFactoryUsed = true;
        } else if (this.sqlSessionTemplate != null) {
            if (explicitFactoryUsed) {
                logger.warn(
                        "Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored.");
            }
            definition.getPropertyValues().add("sqlSessionTemplate", this.sqlSessionTemplate);
            explicitFactoryUsed = true;
        }

        if (!explicitFactoryUsed) {
            if (logger.isDebugEnabled()) {
                logger.debug("Enabling autowire by type for MapperFactoryBean with name '"
                        + holder.getBeanName() + "'.");
            }
            definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
        }
    }
}