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

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

Introduction

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

Prototype

public boolean hasBeanClass() 

Source Link

Document

Return whether this definition specifies a bean class.

Usage

From source file:com.graby.store.base.remote.RemotingAnnotationHandlerMapping.java

/**
 * Checks for presence of the {@link org.springframework.web.bind.annotation.RequestMapping}
 * annotation on the handler class and on any of its methods.
 *//* w w  w .j  ava 2 s . c  o m*/
protected String[] determineUrlsForHandler(String beanName) {

    ApplicationContext context = getApplicationContext();
    Class<?> handlerType = context.getType(beanName);
    RemotingService mapping = AnnotationUtils.findAnnotation(handlerType, RemotingService.class);
    if (mapping == null && context instanceof ConfigurableApplicationContext
            && context.containsBeanDefinition(beanName)) {
        ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
        BeanDefinition bd = cac.getBeanFactory().getMergedBeanDefinition(beanName);
        if (bd instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
            if (abd.hasBeanClass()) {
                Class<?> beanClass = abd.getBeanClass();
                mapping = AnnotationUtils.findAnnotation(beanClass, RemotingService.class);
            }
        }
    }

    if (mapping != null) {
        this.cachedMappings.put(handlerType, mapping);
        Set<String> urls = new LinkedHashSet<String>();
        String path = mapping.serviceUrl();
        if (path != null) {
            addUrlsForPath(urls, path);
            return StringUtils.toStringArray(urls);
        } else {
            return null;
        }
    } else {
        return null;
    }
}

From source file:com.longio.spring.LioBootstrap.java

private void resolveLservice(ApplicationContext app, DefaultListableBeanFactory bf) {
    for (String name : bf.getBeanDefinitionNames()) {
        AbstractBeanDefinition bd = (AbstractBeanDefinition) bf.getBeanDefinition(name);

        if (!bd.hasBeanClass()) {
            continue;
        }// w  w w  . j ava  2  s  .  c  om

        if (!name.endsWith("Service")) {
            continue;
        }

        Class<?> cls = bd.getBeanClass();
        if (cls != LioFactoryBean.class) {
            continue;
        }

        Object obj = app.getBean(name);
        app.getAutowireCapableBeanFactory().autowireBean(obj);
        Lservice ls = obj.getClass().getAnnotation(Lservice.class);
        if (ls != null) {
            String pkg = ls.path();
            Connector connector = getConnector(bf);
            for (Dispatcher d : connector.getDispatcheres(pkg)) {
                MethodRefFactory mrf = new DefaultMethodRefFactory(cmdLookup);
                d.registerMethodRefs(mrf.createMethodRefs(obj));
            }
            logger.info("load longio [" + pkg + "] service");
        }
        LsAutowired lsa = obj.getClass().getAnnotation(LsAutowired.class);
        if (lsa != null) {
            String pkg = lsa.path();
            logger.info("load longio  client [" + pkg + "] service");
        }

    }

}

From source file:com.longio.spring.LioBootstrap.java

private void resolveLfilters(ApplicationContext app, DefaultListableBeanFactory bf) {

    List<MessageFilter> filters = new ArrayList<MessageFilter>();
    for (String name : bf.getBeanDefinitionNames()) {
        AbstractBeanDefinition bd = (AbstractBeanDefinition) bf.getBeanDefinition(name);
        //System.out.println("+++++++++++++++" + name);
        if (!bd.hasBeanClass()) {
            continue;
        }/*from   ww  w  .ja  va  2  s.  c  o m*/

        if (!name.endsWith("Filter")) {
            continue;
        }

        Class<?> cls = bd.getBeanClass();
        if (cls != LioFactoryBean.class) {
            continue;
        }

        Object obj = app.getBean(name);
        app.getAutowireCapableBeanFactory().autowireBean(obj);
        LsFilter lf = obj.getClass().getAnnotation(LsFilter.class);
        if (lf != null) {
            filters.add((MessageFilter) obj);
        }
    }

    Connector connector = getConnector(bf);
    for (Dispatcher d : connector.getDispatcheres("*")) {
        d.registerMessageFilters(filters);
        for (MessageFilter filter : filters) {
            logger.info("load longio [" + filter.getClass().getCanonicalName() + "] message filter");
        }

    }

}

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;
            }//from w w  w.j a  va2  s .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: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  ww  .j  a v  a  2  s. 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: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 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:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java

/**
 * This implementation attempts to query the FactoryBean's generic parameter metadata
 * if present to determine the object type. If not present, i.e. the FactoryBean is
 * declared as a raw type, checks the FactoryBean's {@code getObjectType} method
 * on a plain instance of the FactoryBean, without bean properties applied yet.
 * If this doesn't return a type yet, a full creation of the FactoryBean is
 * used as fallback (through delegation to the superclass's implementation).
 * <p>The shortcut check for a FactoryBean is only applied in case of a singleton
 * FactoryBean. If the FactoryBean instance itself is not kept as singleton,
 * it will be fully created to check the type of its exposed object.
 *///from   w  w w.  j  a  va 2 s  .com
@Override
@Nullable
protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) {
    if (mbd.getInstanceSupplier() != null) {
        ResolvableType targetType = mbd.targetType;
        if (targetType != null) {
            Class<?> result = targetType.as(FactoryBean.class).getGeneric().resolve();
            if (result != null) {
                return result;
            }
        }
        if (mbd.hasBeanClass()) {
            Class<?> result = GenericTypeResolver.resolveTypeArgument(mbd.getBeanClass(), FactoryBean.class);
            if (result != null) {
                return result;
            }
        }
    }

    String factoryBeanName = mbd.getFactoryBeanName();
    String factoryMethodName = mbd.getFactoryMethodName();

    if (factoryBeanName != null) {
        if (factoryMethodName != null) {
            // Try to obtain the FactoryBean's object type from its factory method declaration
            // without instantiating the containing bean at all.
            BeanDefinition fbDef = getBeanDefinition(factoryBeanName);
            if (fbDef instanceof AbstractBeanDefinition) {
                AbstractBeanDefinition afbDef = (AbstractBeanDefinition) fbDef;
                if (afbDef.hasBeanClass()) {
                    Class<?> result = getTypeForFactoryBeanFromMethod(afbDef.getBeanClass(), factoryMethodName);
                    if (result != null) {
                        return result;
                    }
                }
            }
        }
        // If not resolvable above and the referenced factory bean doesn't exist yet,
        // exit here - we don't want to force the creation of another bean just to
        // obtain a FactoryBean's object type...
        if (!isBeanEligibleForMetadataCaching(factoryBeanName)) {
            return null;
        }
    }

    // Let's obtain a shortcut instance for an early getObjectType() call...
    FactoryBean<?> fb = (mbd.isSingleton() ? getSingletonFactoryBeanForTypeCheck(beanName, mbd)
            : getNonSingletonFactoryBeanForTypeCheck(beanName, mbd));

    if (fb != null) {
        // Try to obtain the FactoryBean's object type from this early stage of the instance.
        Class<?> result = getTypeForFactoryBean(fb);
        if (result != null) {
            return result;
        } else {
            // No type found for shortcut FactoryBean instance:
            // fall back to full creation of the FactoryBean instance.
            return super.getTypeForFactoryBean(beanName, mbd);
        }
    }

    if (factoryBeanName == null && mbd.hasBeanClass()) {
        // No early bean instantiation possible: determine FactoryBean's type from
        // static factory method signature or from class inheritance hierarchy...
        if (factoryMethodName != null) {
            return getTypeForFactoryBeanFromMethod(mbd.getBeanClass(), factoryMethodName);
        } else {
            return GenericTypeResolver.resolveTypeArgument(mbd.getBeanClass(), FactoryBean.class);
        }
    }

    return null;
}

From source file:org.springframework.flex.config.HibernateSerializationConfigPostProcessor.java

private boolean isAmfConversionServiceProcessorConfigured(ConfigurableListableBeanFactory beanFactory,
        ManagedSet<RuntimeBeanReference> configProcessors) {

    for (RuntimeBeanReference configProcessor : configProcessors) {
        BeanDefinition bd = beanFactory.getMergedBeanDefinition(configProcessor.getBeanName());
        if (bd instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
            if (!abd.hasBeanClass()) {
                try {
                    abd.resolveBeanClass(beanFactory.getBeanClassLoader());
                } catch (ClassNotFoundException ex) {
                    throw new CannotLoadBeanClassException(abd.getResourceDescription(),
                            configProcessor.getBeanName(), abd.getBeanClassName(), ex);
                }//ww  w.  j  ava2 s.  c  o  m
            }
            if (AbstractAmfConversionServiceConfigProcessor.class.isAssignableFrom(abd.getBeanClass())) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.springframework.flex.config.RemotingAnnotationPostProcessor.java

/**
 * Helper that searches the BeanFactory for beans annotated with @RemotingDestination, being careful not to force
 * eager creation of the beans if it can be avoided.
 * //from  w  ww .  j  a v  a  2s.c o m
 * @param beanFactory the BeanFactory to search
 * @return a set of collected RemotingDestinationMetadata
 */
private Set<RemotingDestinationMetadata> findRemotingDestinations(ConfigurableListableBeanFactory beanFactory) {
    Set<RemotingDestinationMetadata> remotingDestinations = new HashSet<RemotingDestinationMetadata>();
    Set<String> beanNames = new HashSet<String>();
    beanNames.addAll(Arrays.asList(beanFactory.getBeanDefinitionNames()));
    if (beanFactory.getParentBeanFactory() instanceof ListableBeanFactory) {
        beanNames.addAll(Arrays
                .asList(((ListableBeanFactory) beanFactory.getParentBeanFactory()).getBeanDefinitionNames()));
    }
    for (String beanName : beanNames) {
        if (beanName.startsWith("scopedTarget.")) {
            continue;
        }
        RemotingDestination remotingDestination = null;
        BeanDefinition bd = beanFactory.getMergedBeanDefinition(beanName);
        if (bd.isAbstract() || bd.isLazyInit()) {
            continue;
        }
        if (bd instanceof AbstractBeanDefinition) {
            AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
            if (abd.hasBeanClass()) {
                Class<?> beanClass = abd.getBeanClass();
                remotingDestination = AnnotationUtils.findAnnotation(beanClass, RemotingDestination.class);
                if (remotingDestination != null) {
                    remotingDestinations
                            .add(new RemotingDestinationMetadata(remotingDestination, beanName, beanClass));
                    continue;
                }
            }
        }
        Class<?> handlerType = beanFactory.getType(beanName);
        if (handlerType != null) {
            remotingDestination = AnnotationUtils.findAnnotation(handlerType, RemotingDestination.class);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Could not get type of bean '" + beanName + "' from bean factory.");
            }
        }
        if (remotingDestination != null) {
            remotingDestinations
                    .add(new RemotingDestinationMetadata(remotingDestination, beanName, handlerType));
        }
    }
    return remotingDestinations;
}