Example usage for org.springframework.beans.factory.support AbstractBeanDefinition getBeanClassName

List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition getBeanClassName

Introduction

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

Prototype

@Override
@Nullable
public String getBeanClassName() 

Source Link

Document

Return the current bean class name of this bean definition.

Usage

From source file:br.com.caelum.vraptor.ioc.spring.ComponentScanner.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from   w w  w.  j  av  a 2 s . c  o  m
protected void postProcessBeanDefinition(AbstractBeanDefinition beanDefinition, String beanName) {
    super.postProcessBeanDefinition(beanDefinition, beanName);
    beanDefinition.setPrimary(true);
    beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
    try {
        Class<?> componentType = Class.forName(beanDefinition.getBeanClassName());
        if (ComponentFactory.class.isAssignableFrom(componentType)
                && checkCandidate(beanName, beanDefinition)) {
            registry.registerSingleton(beanDefinition.getBeanClassName(),
                    new ComponentFactoryBean(container, componentType));
        }
    } catch (ClassNotFoundException e) {
        logger.warn("Class " + beanDefinition.getBeanClassName()
                + " was not found during bean definition proccess");
    } catch (ExceptionInInitializerError e) {
        // log and rethrow antipattern is needed, this is rally important
        logger.warn("Class " + beanDefinition.getBeanClassName() + " has problems during initialization",
                e.getCause());
        throw e;
    }
}

From source file:com.liferay.arkadiko.bean.AKBeanDefinition.java

/**
 * Instantiates a new Arkadiko bean definition.
 *
 * @param beanPostProcessor the bean post processor
 * @param abstractBeanDefinition the bean definition
 * @param beanName the bean name// w  w w.  j  av  a  2 s. c om
 * @param interfaces the interfaces
 * @param serviceRegistry the service registry
 */
public AKBeanDefinition(AKBeanPostProcessor beanPostProcessor, AbstractBeanDefinition abstractBeanDefinition,
        String beanName, ServiceRegistry serviceRegistry) {

    super(abstractBeanDefinition);

    _beanPostProcessor = beanPostProcessor;
    _abstractBeanDefinition = abstractBeanDefinition;
    _beanName = beanName;
    _serviceRegistry = serviceRegistry;
    _originalClassName = abstractBeanDefinition.getBeanClassName();
}

From source file:org.agilemicroservices.autoconfigure.orm.RepositoryBeanDefinitionBuilder.java

private String registerCustomImplementation(RepositoryConfiguration<?> configuration) {

    String beanName = configuration.getImplementationBeanName();

    // Already a bean configured?
    if (registry.containsBeanDefinition(beanName)) {
        return beanName;
    }//from  www.  j  a  v  a  2s  .  c  om

    AbstractBeanDefinition beanDefinition = implementationDetector.detectCustomImplementation(
            configuration.getImplementationClassName(), configuration.getBasePackages());

    if (null == beanDefinition) {
        return null;
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Registering custom repository implementation: "
                + configuration.getImplementationBeanName() + " " + beanDefinition.getBeanClassName());
    }

    beanDefinition.setSource(configuration.getSource());

    registry.registerBeanDefinition(beanName, beanDefinition);

    return beanName;
}

From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeansGenerator.java

/**
 * Iterate over registered beans to find any manually-created components
 * (Controllers, Services, Repositories) we can skipp from generating.
 * //from   w ww  .ja  v  a 2  s .  c om
 * @param registry
 */
protected void findExistingBeans(BeanDefinitionRegistry registry) {
    for (String name : registry.getBeanDefinitionNames()) {

        BeanDefinition d = registry.getBeanDefinition(name);

        if (d instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition def = (AbstractBeanDefinition) d;
            // if controller
            if (isOfType(def, ModelController.class)) {
                Class<?> entity = GenericTypeResolver.resolveTypeArguments(
                        ClassUtils.getClass(def.getBeanClassName()), ModelController.class)[0];

                ModelContext modelContext = entityModelContextsMap.get(entity);
                if (modelContext != null) {
                    modelContext.setControllerDefinition(def);
                }
            }
            // if service 
            if (isOfType(def, AbstractModelServiceImpl.class)) {
                Class<?> entity = GenericTypeResolver.resolveTypeArguments(
                        ClassUtils.getClass(def.getBeanClassName()), ModelService.class)[0];
                ModelContext modelContext = entityModelContextsMap.get(entity);
                if (modelContext != null) {
                    modelContext.setServiceDefinition(def);
                }
            }
            // if repository
            else if (isOfType(def, JpaRepositoryFactoryBean.class) || isOfType(def, JpaRepository.class)) {
                String repoName = (String) def.getPropertyValues().get("repositoryInterface");

                Class<?> repoInterface = ClassUtils.getClass(repoName);
                if (JpaRepository.class.isAssignableFrom(repoInterface)) {
                    Class<?> entity = GenericTypeResolver.resolveTypeArguments(repoInterface,
                            JpaRepository.class)[0];
                    ModelContext modelContext = entityModelContextsMap.get(entity);
                    if (modelContext != null) {
                        modelContext.setRepositoryDefinition(def);
                    }
                }
            }

        }

    }
}

From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeanGeneratingRegistryPostProcessor.java

/**
 * Iterate over registered beans to find any manually-created components
 * (Controllers, Services, Repositories) we can skipp from generating.
 * //  w w w . j a va 2  s . c om
 * @param registry
 */
protected void findExistingBeans(BeanDefinitionRegistry registry) {
    for (String name : registry.getBeanDefinitionNames()) {

        BeanDefinition d = registry.getBeanDefinition(name);

        if (d instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition def = (AbstractBeanDefinition) d;
            // if controller
            if (isOfType(def, ModelController.class)) {
                Class<?> entity = GenericTypeResolver.resolveTypeArguments(
                        ClassUtils.getClass(def.getBeanClassName()), ModelController.class)[0];

                ModelContext modelContext = entityModelContextsMap.get(entity);
                if (modelContext != null) {
                    modelContext.setControllerDefinition(def);
                }
            }
            // if service
            if (isOfType(def, AbstractModelServiceImpl.class)) {
                Class<?> entity = GenericTypeResolver.resolveTypeArguments(
                        ClassUtils.getClass(def.getBeanClassName()), ModelService.class)[0];
                ModelContext modelContext = entityModelContextsMap.get(entity);
                if (modelContext != null) {
                    modelContext.setServiceDefinition(def);
                }
            }
            // if repository
            else if (isOfType(def, JpaRepositoryFactoryBean.class) || isOfType(def, JpaRepository.class)) {
                String repoName = (String) def.getPropertyValues().get("repositoryInterface");

                Class<?> repoInterface = ClassUtils.getClass(repoName);
                if (JpaRepository.class.isAssignableFrom(repoInterface)) {
                    Class<?> entity = GenericTypeResolver.resolveTypeArguments(repoInterface,
                            JpaRepository.class)[0];
                    ModelContext modelContext = entityModelContextsMap.get(entity);
                    if (modelContext != null) {
                        modelContext.setRepositoryDefinition(def);
                    }
                }
            }

        }

    }
}

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

/**
 * Registers a possibly available custom DAO implementation on the DAO bean.
 * Tries to find an already registered bean to reference or tries to detect
 * a custom implementation itself./* ww  w .  j a v a 2 s . c  o  m*/
 * 
 * @param context
 * @param parserContext
 * @param source
 * @return the bean name of the custom implementation or {@code null} if
 *         none available
 */
private String registerCustomImplementation(final DaoContext context, final ParserContext parserContext,
        final Object source) {

    String beanName = context.getImplementationBeanName();

    // Already a bean configured?
    if (parserContext.getRegistry().containsBeanDefinition(beanName)) {
        return beanName;
    }

    // Autodetect implementation
    if (context.autodetectCustomImplementation()) {

        AbstractBeanDefinition beanDefinition = detectCustomImplementation(context, parserContext);

        if (null == beanDefinition) {
            return null;
        }

        LOG.debug("Registering custom DAO implementation: {} {}", context.getImplementationBeanName(),
                beanDefinition.getBeanClassName());

        beanDefinition.setSource(source);
        parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, beanName));

    } else {

        beanName = context.getCustomImplementationRef();
    }

    return beanName;
}

From source file:net.paoding.rose.web.impl.module.ModulesBuilderImpl.java

private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module)
        throws IllegalAccessException {
    AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory()
            .getBeanDefinition(beanName);
    String beanClassName = beanDefinition.getBeanClassName();
    String controllerSuffix = null;
    for (String suffix : RoseConstants.CONTROLLER_SUFFIXES) {
        if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) {
            if (suffix.length() == 1 && Character
                    .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) {
                continue;
            }/*  w  w w.  j  a v a2  s .co  m*/
            controllerSuffix = suffix;
            break;
        }
    }
    if (controllerSuffix == null) {
        if (beanDefinition.hasBeanClass()) {
            Class<?> beanClass = beanDefinition.getBeanClass();
            if (beanClass.isAnnotationPresent(Path.class)) {
                throw new IllegalArgumentException(
                        "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, "
                                + "is it a Resource/Controller? wrong spelling? : " + beanClassName);
            }
        }
        // ?l?r?uer?or???
        if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor")
                || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) {
            // ?throw???
            logger.error("", new IllegalArgumentException(
                    "invalid class name end wrong spelling? : " + beanClassName));
        }
        return false;
    }
    String[] controllerPaths = null;
    if (!beanDefinition.hasBeanClass()) {
        try {
            beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader());
        } catch (ClassNotFoundException e) {
            throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e);
        }
    }
    final Class<?> clazz = beanDefinition.getBeanClass();
    final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz),
            controllerSuffix);
    Path reqMappingAnnotation = clazz.getAnnotation(Path.class);
    if (reqMappingAnnotation != null) {
        controllerPaths = reqMappingAnnotation.value();
    }
    if (controllerPaths != null) {
        // controllerPaths.length==0path?controller
        for (int i = 0; i < controllerPaths.length; i++) {
            if ("#".equals(controllerPaths[i])) {
                controllerPaths[i] = "/" + controllerName;
            } else if (controllerPaths[i].equals("/")) {
                controllerPaths[i] = "";
            } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') {
                controllerPaths[i] = "/" + controllerPaths[i];
            }
            if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) {
                if (controllerPaths[i].endsWith("//")) {
                    throw new IllegalArgumentException("invalid path '" + controllerPaths[i]
                            + "' for controller " + beanClassName + ": don't end with more than one '/'");
                }
                controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1);
            }
        }
    } else {
        // TODO: ?0.91.0?201007??
        if (controllerName.equals("index") || controllerName.equals("home")
                || controllerName.equals("welcome")) {
            // ??IndexController/HomeController/WelcomeController@Path("")
            throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName());
        } else {
            controllerPaths = new String[] { "/" + controllerName };
        }
    }
    // Controller??Context??
    // Context???
    Object controller = context.getBean(beanName);
    module.addController(//
            controllerPaths, clazz, controllerName, controller);
    if (Proxy.isProxyClass(controller.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() + "': add controller "
                    + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName());
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() //
                    + "': add controller " + Arrays.toString(controllerPaths) + "= "
                    + controller.getClass().getName());
        }
    }
    return true;
}

From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java

private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module)
        throws IllegalAccessException {
    AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory()
            .getBeanDefinition(beanName);
    String beanClassName = beanDefinition.getBeanClassName();
    String controllerSuffix = null;
    for (String suffix : BlitzConstants.CONTROLLER_SUFFIXES) {
        if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) {
            if (suffix.length() == 1 && Character
                    .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) {
                continue;
            }/*from w w w .  ja va 2 s  . c  om*/
            controllerSuffix = suffix;
            break;
        }
    }
    if (controllerSuffix == null) {
        if (beanDefinition.hasBeanClass()) {
            Class<?> beanClass = beanDefinition.getBeanClass();
            if (beanClass.isAnnotationPresent(Path.class)) {
                throw new IllegalArgumentException(
                        "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, "
                                + "is it a Resource/Controller? wrong spelling? : " + beanClassName);
            }
        }
        // ?l?r?uer?or???
        if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor")
                || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) {
            // ?throw???
            logger.error("", new IllegalArgumentException(
                    "invalid class name end wrong spelling? : " + beanClassName));
        }
        return false;
    }
    String[] controllerPaths = null;
    if (!beanDefinition.hasBeanClass()) {
        try {
            beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader());
        } catch (ClassNotFoundException e) {
            throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e);
        }
    }
    final Class<?> clazz = beanDefinition.getBeanClass();
    final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz),
            controllerSuffix);
    Path reqMappingAnnotation = clazz.getAnnotation(Path.class);
    if (reqMappingAnnotation != null) {
        controllerPaths = reqMappingAnnotation.value();
    }
    if (controllerPaths != null) {
        // controllerPaths.length==0path?controller
        for (int i = 0; i < controllerPaths.length; i++) {
            if ("#".equals(controllerPaths[i])) {
                controllerPaths[i] = "/" + controllerName;
            } else if (controllerPaths[i].equals("/")) {
                controllerPaths[i] = "";
            } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') {
                controllerPaths[i] = "/" + controllerPaths[i];
            }
            if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) {
                if (controllerPaths[i].endsWith("//")) {
                    throw new IllegalArgumentException("invalid path '" + controllerPaths[i]
                            + "' for controller " + beanClassName + ": don't end with more than one '/'");
                }
                controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1);
            }
        }
    } else {
        // TODO: ?0.91.0?201007??
        if (controllerName.equals("index") || controllerName.equals("home")
                || controllerName.equals("welcome")) {
            // ??IndexController/HomeController/WelcomeController@Path("")
            throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName());
        } else {
            controllerPaths = new String[] { "/" + controllerName };
        }
    }
    // Controller??Context??
    // Context???
    Object controller = context.getBean(beanName);
    module.addController(//
            controllerPaths, clazz, controllerName, controller);
    if (Proxy.isProxyClass(controller.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() + "': add controller "
                    + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName());
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() //
                    + "': add controller " + Arrays.toString(controllerPaths) + "= "
                    + controller.getClass().getName());
        }
    }
    return true;
}

From source file:com.sinosoft.one.mvc.web.impl.module.ModulesBuilderImpl.java

private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module)
        throws IllegalAccessException {
    AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory()
            .getBeanDefinition(beanName);
    String beanClassName = beanDefinition.getBeanClassName();
    String controllerSuffix = null;
    for (String suffix : MvcConstants.CONTROLLER_SUFFIXES) {
        if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) {
            if (suffix.length() == 1 && Character
                    .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) {
                continue;
            }/*from  w  w w .j a v a 2s.c  o  m*/
            controllerSuffix = suffix;
            break;
        }
    }
    if (controllerSuffix == null) {
        if (beanDefinition.hasBeanClass()) {
            Class<?> beanClass = beanDefinition.getBeanClass();
            if (beanClass.isAnnotationPresent(Path.class)) {
                throw new IllegalArgumentException(
                        "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, "
                                + "is it a Resource/Controller? wrong spelling? : " + beanClassName);
            }
        }
        // ?l?r?uer?or???
        if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor")
                || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) {
            // ?throw???
            logger.error("", new IllegalArgumentException(
                    "invalid class name end wrong spelling? : " + beanClassName));
        }
        return false;
    }
    String[] controllerPaths = null;
    if (!beanDefinition.hasBeanClass()) {
        try {
            beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader());
        } catch (ClassNotFoundException e) {
            throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e);
        }
    }
    final Class<?> clazz = beanDefinition.getBeanClass();
    final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz),
            controllerSuffix);
    Path reqMappingAnnotation = clazz.getAnnotation(Path.class);
    if (reqMappingAnnotation != null) {
        controllerPaths = reqMappingAnnotation.value();
    }
    if (controllerPaths != null) {
        // controllerPaths.length==0path?controller
        for (int i = 0; i < controllerPaths.length; i++) {
            if ("#".equals(controllerPaths[i])) {
                controllerPaths[i] = "/" + controllerName;
            } else if (controllerPaths[i].equals("/")) {
                controllerPaths[i] = "";
            } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') {
                controllerPaths[i] = "/" + controllerPaths[i];
            }
            if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) {
                if (controllerPaths[i].endsWith("//")) {
                    throw new IllegalArgumentException("invalid path '" + controllerPaths[i]
                            + "' for controller " + beanClassName + ": don't end with more than one '/'");
                }
                controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1);
            }
        }
    } else {
        // TODO: ?0.91.0?201007??
        if (controllerName.equals("index") || controllerName.equals("home")
                || controllerName.equals("welcome")) {
            // ??IndexController/HomeController/WelcomeController@Path("")
            throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName());
        } else {
            controllerPaths = new String[] { "/" + controllerName };
        }
    }
    // Controller??Context??
    // Context???
    Object controller = context.getBean(beanName);
    module.addController(//
            controllerPaths, clazz, controllerName, controller);
    if (Proxy.isProxyClass(controller.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() + "': add controller "
                    + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName());
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() //
                    + "': add controller " + Arrays.toString(controllerPaths) + "= "
                    + controller.getClass().getName());
        }
    }
    return true;
}

From source file:org.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java

/**
 * Add a property defined by an attribute to the bean we are constructing.
 *
 * <p>Since an attribute value is always a string, we don't have to deal with complex types
 * here - the only issue is whether or not we have a reference.  References are detected
 * by explicit annotation or by the "-ref" at the end of an attribute name.  We do not
 * check the Spring repo to see if a name already exists since that could lead to
 * unpredictable behaviour./*from ww w  .  j a v  a 2s.  c o m*/
 * (see {@link org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration})
 * @param attribute The attribute to add
 */
public void extendBean(Attr attribute) {
    AbstractBeanDefinition beanDefinition = bean.getBeanDefinition();
    String oldName = SpringXMLUtils.attributeName(attribute);
    String oldValue = attribute.getNodeValue();
    if (attribute.getNamespaceURI() == null) {
        if (!beanConfig.isIgnored(oldName)) {
            logger.debug(attribute + " for " + beanDefinition.getBeanClassName());
            String newName = bestGuessName(beanConfig, oldName, beanDefinition.getBeanClassName());
            Object newValue = beanConfig.translateValue(oldName, oldValue);
            addPropertyWithReference(beanDefinition.getPropertyValues(), beanConfig.getSingleProperty(oldName),
                    newName, newValue);
        }
    } else if (isAnnotationsPropertyAvailable(beanDefinition.getBeanClass())) {
        //Add attribute defining namespace as annotated elements. No reconciliation is done here ie new values override old ones.
        QName name;
        if (attribute.getPrefix() != null) {
            name = new QName(attribute.getNamespaceURI(), attribute.getLocalName(), attribute.getPrefix());
        } else {
            name = new QName(attribute.getNamespaceURI(), attribute.getLocalName());
        }
        Object value = beanConfig.translateValue(oldName, oldValue);
        addAnnotationValue(beanDefinition.getPropertyValues(), name, value);
        MuleContext muleContext = MuleApplicationContext.getCurrentMuleContext().get();
        if (muleContext != null) {
            Map<QName, Set<Object>> annotations = muleContext.getConfigurationAnnotations();
            Set<Object> values = annotations.get(name);
            if (values == null) {
                values = new HashSet<Object>();
                annotations.put(name, values);
            }
            values.add(value);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Cannot assign " + beanDefinition.getBeanClass() + " to " + AnnotatedObject.class);
        }
    }
}