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

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

Introduction

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

Prototype

@Nullable
String getBeanClassName();

Source Link

Document

Return the current bean class name of this bean definition.

Usage

From source file:com.googlecode.icegem.serialization.spring.AutoSerializableRegistrarBean.java

private void registerClasses(ClassLoader classLoader) throws ClassNotFoundException {

    List<Class<?>> toRegister = new ArrayList<Class<?>>();

    for (String pack : scanPackages) {
        logger.debug("Scan {}.* for @AutoSerializable classes", pack);
        ClassPathScanningCandidateComponentProvider ppp = new ClassPathScanningCandidateComponentProvider(
                false);//from w  w  w  . j  a v  a 2s  .c o m
        ppp.addIncludeFilter(new AnnotationTypeFilter(AutoSerializable.class));
        Set<BeanDefinition> candidateComponents = ppp.findCandidateComponents(pack);
        for (BeanDefinition beanDefinition : candidateComponents) {
            String className = beanDefinition.getBeanClassName();
            final Class<?> clazz = Class.forName(className);
            toRegister.add(clazz);
        }
    }

    toRegister.addAll(registeredClasses);
    logger.info("All classes that will be registered in GemFire: " + toRegister);

    try {
        HierarchyRegistry.registerAll(classLoader, toRegister);
    } catch (InvalidClassException e) {
        final String msg = "Some class from list " + toRegister + " is nor serializable. Cause: "
                + e.getMessage();
        throw new IllegalArgumentException(msg, e);
    } catch (CannotCompileException e) {
        final String msg = "Can't compile DataSerializer classes for some classes from list " + toRegister
                + ". Cause: " + e.getMessage();
        throw new IllegalArgumentException(msg, e);
    }
}

From source file:com.consol.citrus.admin.executor.ClasspathTestExecutor.java

/**
 * Finds all test cases in classpath starting in given base package. Searches for 
 * **.class files extending AbstractTestNGCitrusTest superclass.
 * //from ww  w .ja  v a2s. c  o m
 * @param basePackage
 * @return
 */
private List<String> findTestsInClasspath(String basePackage) {
    List<String> testCaseNames = new ArrayList<String>();

    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false,
            new StandardServletEnvironment());

    scanner.addIncludeFilter(new CitrusTestTypeFilter());

    Set<BeanDefinition> findings = scanner.findCandidateComponents(basePackage);

    for (BeanDefinition bean : findings) {
        testCaseNames.add(bean.getBeanClassName());
    }

    return testCaseNames;
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenter.java

@SuppressWarnings("unchecked")
private Properties getMapWrappingBeanProperties(BeanDefinition beanDefinition) {
    if (beanDefinition.getBeanClassName().equals(PropertiesFactoryBean.class.getName())) {
        return getPropertiesFactoryBeanProperties(beanDefinition);
    } else {//from   w w  w  . j av  a 2s  .c o  m
        return convert((Map<String, String>) beanDefinition.getPropertyValues().getPropertyValue("sourceMap")
                .getValue());
    }
}

From source file:org.synyx.hades.domain.auditing.support.AuditingBeanFactoryPostProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {

    if (!isSpringConfigured(beanFactory)) {
        return;/*from  w  w  w  . java2 s .com*/
    }

    for (String beanName : beanFactory.getBeanDefinitionNames()) {

        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);

        if (CLASSES_TO_DEPEND.contains(definition.getBeanClassName())) {
            definition.setDependsOn(
                    StringUtils.addStringToArray(definition.getDependsOn(), BEAN_CONFIGURER_ASPECT_BEAN_NAME));
        }
    }

    for (String beanName : BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, AuditorAware.class,
            true, false)) {
        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
        definition.setLazyInit(true);
    }
}

From source file:biz.c24.io.spring.config.C24MarshallerBeanDefinitionParserIntegrationTests.java

@Test
public void plainMarshallerElementSetsUpAMarshallerBean() {
    BeanDefinition definition = getDefinitionFromFile("marshaller.xml", "c24marshaller");

    assertThat(definition, is(notNullValue()));
    assertThat(definition.getBeanClassName(), is(C24Marshaller.class.getName()));
}

From source file:biz.c24.io.spring.config.C24MarshallerBeanDefinitionParserIntegrationTests.java

@Test
public void plainMessageConverterElementSetsUpAConverterAndDefaultMarshaller() {

    BeanDefinition definition = getDefinitionFromFile("converter.xml", "xml");

    assertThat(definition, is(notNullValue()));
    assertThat(definition.getBeanClassName(), is(C24HttpMessageConverter.class.getName()));

    ValueHolder constructorArgument = definition.getConstructorArgumentValues().getArgumentValue(0, null);
    assertThat(constructorArgument, is(notNullValue()));
    Object argument = constructorArgument.getValue();
    assertThat(argument, is(RuntimeBeanReference.class));
    assertThat(((RuntimeBeanReference) argument).getBeanName(),
            is(C24ModelBeanDefinitionParser.DEFAULT_BEAN_NAME));

    constructorArgument = definition.getConstructorArgumentValues().getArgumentValue(1, null);
    assertThat(constructorArgument, is(notNullValue()));
    assertThat(constructorArgument.getValue(), is(Collection.class));
}

From source file:org.jolokia.support.spring.config.SpringConfigTest.java

@Test
public void simpleServer() throws ParserConfigurationException, IOException, SAXException {

    reader.loadBeanDefinitions(new ClassPathResource("/simple-server.xml"));

    BeanDefinition bd = beanFactory.getBeanDefinition("jolokiaServer");
    assertEquals(bd.getBeanClassName(), SpringJolokiaAgent.class.getName());
    MutablePropertyValues props = bd.getPropertyValues();
    assertEquals(props.size(), 3);/* w  w  w.  ja v a 2  s  .  c o  m*/
    assertEquals(props.getPropertyValue("lookupConfig").getValue(), false);
    assertEquals(props.getPropertyValue("lookupServices").getValue(), false);
    BeanDefinition cBd = (BeanDefinition) props.getPropertyValue("config").getValue();
    ;
    assertEquals(cBd.getBeanClassName(), SpringJolokiaConfigHolder.class.getName());
    MutablePropertyValues cProps = cBd.getPropertyValues();
    assertEquals(cProps.size(), 1);
    verifyConfig(cProps);
}

From source file:com.dianping.simple.spring.TestBeanFactoryPostProcessor.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    // TODO Auto-generated method stub
    BeanDefinition bd = beanFactory.getBeanDefinition("testServiceTarget");
    bd.getPropertyValues().addPropertyValue("name", "no monkey");
    logger.info("postProcessBeanFactory " + bd.getBeanClassName());
}

From source file:com.agileapes.motorex.cli.value.impl.SpringValueReaderContext.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    final String[] names = beanFactory.getBeanDefinitionNames();
    for (String name : names) {
        final BeanDefinition definition = beanFactory.getBeanDefinition(name);
        if (definition.isSingleton()) {
            final String className = definition.getBeanClassName();
            try {
                final Class<?> beanType = ClassUtils.forName(className, beanFactory.getBeanClassLoader());
                if (ValueReader.class.isAssignableFrom(beanType)) {
                    register(beanFactory.getBean(name, ValueReader.class));
                }/* ww w.jav a2 s. com*/
            } catch (ClassNotFoundException e) {
                throw new BeanCreationNotAllowedException(name, "Failed to access bean");
            }
        }
    }
}

From source file:org.bytesoft.bytetcc.supports.spring.CompensableContextPostProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();

    String targetBeanId = null;/*from   w  ww.jav a  2 s .  com*/
    List<BeanDefinition> beanDefList = new ArrayList<BeanDefinition>();
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        Class<?> beanClass = null;
        try {
            beanClass = cl.loadClass(beanClassName);
        } catch (Exception ex) {
            logger.debug("Cannot load class {}, beanId= {}!", beanClassName, beanName, ex);
            continue;
        }

        if (CompensableContextAware.class.isAssignableFrom(beanClass)) {
            beanDefList.add(beanDef);
        }

        if (CompensableContext.class.isAssignableFrom(beanClass)) {
            if (targetBeanId == null) {
                targetBeanId = beanName;
            } else {
                throw new FatalBeanException("Duplicated compensable-context defined.");
            }
        }

    }

    for (int i = 0; targetBeanId != null && i < beanDefList.size(); i++) {
        BeanDefinition beanDef = beanDefList.get(i);
        MutablePropertyValues mpv = beanDef.getPropertyValues();
        RuntimeBeanReference beanRef = new RuntimeBeanReference(targetBeanId);
        mpv.addPropertyValue(CompensableContextAware.COMPENSABLE_CONTEXT_FIELD_NAME, beanRef);
    }

}