Example usage for org.springframework.web.context.support XmlWebApplicationContext getBeanFactory

List of usage examples for org.springframework.web.context.support XmlWebApplicationContext getBeanFactory

Introduction

In this page you can find the example usage for org.springframework.web.context.support XmlWebApplicationContext getBeanFactory.

Prototype

@Override
    public final ConfigurableListableBeanFactory getBeanFactory() 

Source Link

Usage

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

private List<ParamResolver> findContextResolvers(XmlWebApplicationContext context) {
    String[] resolverNames = SpringUtils.getBeanNames(context.getBeanFactory(), ParamResolver.class);
    ArrayList<ParamResolver> resolvers = new ArrayList<ParamResolver>(resolverNames.length);
    for (String beanName : resolverNames) {
        ParamResolver resolver = (ParamResolver) context.getBean(beanName);
        Class<?> userClass = ClassUtils.getUserClass(resolver);
        if (userClass.isAnnotationPresent(Ignored.class)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored context resolver:" + resolver);
            }//from   ww w  .ja  v  a  2 s. c om
            continue;
        }
        if (userClass.isAnnotationPresent(NotForSubModules.class)
                && context.getBeanFactory().getBeanDefinition(beanName) == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored context resolver (NotForSubModules):" + resolver);
            }
            continue;
        }
        resolvers.add(resolver);
        if (logger.isDebugEnabled()) {
            logger.debug("context resolver[" + resolver.getClass().getName());
        }
    }
    return resolvers;
}

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

private List<ParamValidator> findContextValidators(XmlWebApplicationContext context) {
    String[] validatorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ParamValidator.class);
    ArrayList<ParamValidator> globalValidators = new ArrayList<ParamValidator>(validatorNames.length);
    for (String beanName : validatorNames) {
        ParamValidator validator = (ParamValidator) context.getBean(beanName);
        Class<?> userClass = ClassUtils.getUserClass(validator);
        if (userClass.isAnnotationPresent(Ignored.class)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored context validator:" + validator);
            }/*from   w  w w  .  j a  v  a 2  s.co m*/
            continue;
        }
        if (userClass.isAnnotationPresent(NotForSubModules.class)
                && context.getBeanFactory().getBeanDefinition(beanName) == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored context validator (NotForSubModules):" + validator);
            }
            continue;
        }
        globalValidators.add(validator);
        if (logger.isDebugEnabled()) {
            logger.debug("add context validator: " + userClass.getName());
        }
    }
    return globalValidators;
}

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

private List<InterceptorDelegate> findInterceptors(XmlWebApplicationContext context) {
    String[] interceptorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ControllerInterceptor.class);
    ArrayList<InterceptorDelegate> interceptors = new ArrayList<InterceptorDelegate>(interceptorNames.length);
    for (String beanName : interceptorNames) {
        ControllerInterceptor interceptor = (ControllerInterceptor) context.getBean(beanName);
        Class<?> userClass = ClassUtils.getUserClass(interceptor);
        if (userClass.isAnnotationPresent(Ignored.class)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored interceptor (Ignored):" + interceptor);
            }/*w w w  . j ava2  s .  c o m*/
            continue;
        }
        if (userClass.isAnnotationPresent(NotForSubModules.class)
                && !context.getBeanFactory().containsBeanDefinition(beanName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored interceptor (NotForSubModules):" + interceptor);
            }
            continue;
        }
        if (!userClass.getSimpleName().endsWith(RoseConstants.INTERCEPTOR_SUFFIX)) {
            logger.error("", new IllegalArgumentException("Interceptor must be end with '"
                    + RoseConstants.INTERCEPTOR_SUFFIX + "': " + userClass.getName()));
            continue;
        }
        InterceptorBuilder builder = new InterceptorBuilder(interceptor);
        Interceptor annotation = userClass.getAnnotation(Interceptor.class);
        if (annotation != null) {
            builder.oncePerRequest(annotation.oncePerRequest());
        }
        String interceporName;
        if (beanName.startsWith(AUTO_BEAN_NAME_PREFIX)) {
            interceporName = StringUtils.removeEnd(StringUtils.uncapitalize(userClass.getSimpleName()),
                    RoseConstants.INTERCEPTOR_SUFFIX);
        } else {
            interceporName = StringUtils.removeEnd(beanName, RoseConstants.INTERCEPTOR_SUFFIX);
        }
        final String rose = "rose";
        if (interceporName.startsWith(rose)
                && (interceporName.length() == rose.length()
                        || Character.isUpperCase(interceporName.charAt(rose.length())))
                && !userClass.getName().startsWith("net.paoding.rose.")) {
            throw new IllegalArgumentException("illegal interceptor name '" + interceporName + "' for "
                    + userClass.getName() + ": don't starts with 'rose', it's reserved");
        }

        builder.name(interceporName);

        InterceptorDelegate wrapper = builder.build();
        interceptors.add(wrapper);
        if (logger.isDebugEnabled()) {
            int priority = 0;
            if (interceptor instanceof Ordered) {
                priority = ((Ordered) interceptor).getPriority();
            }
            logger.debug("recognized interceptor[priority=" + priority + "]: " // \r\n
                    + wrapper.getName() + "=" + userClass.getName());
        }
    }
    Collections.sort(interceptors);
    throwExceptionIfDuplicatedNames(interceptors);
    return interceptors;
}

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

private List<InterceptorDelegate> findInterceptors(XmlWebApplicationContext context) {
    String[] interceptorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ControllerInterceptor.class);
    ArrayList<InterceptorDelegate> interceptors = new ArrayList<InterceptorDelegate>(interceptorNames.length);
    for (String beanName : interceptorNames) {
        ControllerInterceptor interceptor = (ControllerInterceptor) context.getBean(beanName);
        Class<?> userClass = ClassUtils.getUserClass(interceptor);
        if (userClass.isAnnotationPresent(Ignored.class)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored interceptor (Ignored):" + interceptor);
            }/*from w  ww . ja  va 2  s. c  om*/
            continue;
        }
        if (userClass.isAnnotationPresent(NotForSubModules.class)
                && !context.getBeanFactory().containsBeanDefinition(beanName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored interceptor (NotForSubModules):" + interceptor);
            }
            continue;
        }
        if (!userClass.getSimpleName().endsWith(BlitzConstants.INTERCEPTOR_SUFFIX)) {
            logger.error("", new IllegalArgumentException("Interceptor must be end with '"
                    + BlitzConstants.INTERCEPTOR_SUFFIX + "': " + userClass.getName()));
            continue;
        }
        InterceptorBuilder builder = new InterceptorBuilder(interceptor);
        Interceptor annotation = userClass.getAnnotation(Interceptor.class);
        if (annotation != null) {
            builder.oncePerRequest(annotation.oncePerRequest());
        }
        String interceporName;
        if (beanName.startsWith(AUTO_BEAN_NAME_PREFIX)) {
            interceporName = StringUtils.removeEnd(StringUtils.uncapitalize(userClass.getSimpleName()),
                    BlitzConstants.INTERCEPTOR_SUFFIX);
        } else {
            interceporName = StringUtils.removeEnd(beanName, BlitzConstants.INTERCEPTOR_SUFFIX);
        }
        final String rose = "rose";
        if (interceporName.startsWith(rose)
                && (interceporName.length() == rose.length()
                        || Character.isUpperCase(interceporName.charAt(rose.length())))
                && !userClass.getName().startsWith("net.paoding.rose.")) {
            throw new IllegalArgumentException("illegal interceptor name '" + interceporName + "' for "
                    + userClass.getName() + ": don't starts with 'rose', it's reserved");
        }

        builder.name(interceporName);

        InterceptorDelegate wrapper = builder.build();
        interceptors.add(wrapper);
        if (logger.isDebugEnabled()) {
            int priority = 0;
            if (interceptor instanceof Ordered) {
                priority = ((Ordered) interceptor).getPriority();
            }
            logger.debug("recognized interceptor[priority=" + priority + "]: " // \r\n
                    + wrapper.getName() + "=" + userClass.getName());
        }
    }
    Collections.sort(interceptors);
    throwExceptionIfDuplicatedNames(interceptors);
    return interceptors;
}

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

private void registerBeanDefinitions(XmlWebApplicationContext context, List<Class<?>> classes) {
    DefaultListableBeanFactory bf = (DefaultListableBeanFactory) context.getBeanFactory();
    String[] definedClasses = new String[bf.getBeanDefinitionCount()];
    String[] definitionNames = bf.getBeanDefinitionNames();
    for (int i = 0; i < definedClasses.length; i++) {
        String name = definitionNames[i];
        definedClasses[i] = bf.getBeanDefinition(name).getBeanClassName();
    }/*from  w  w w .j a  v a 2s .co  m*/
    for (Class<?> clazz : classes) {
        // ?
        if (!isCandidate(clazz)) {
            continue;
        }

        // bean
        String clazzName = clazz.getName();
        if (ArrayUtils.contains(definedClasses, clazzName)) {
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "Ignores bean definition because it has been exist in context: " + clazz.getName());
            }
            continue;
        }
        //
        String beanName = null;
        if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Component.class)) {
            beanName = clazz.getAnnotation(Component.class).value();
        }
        if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Resource.class)) {
            beanName = clazz.getAnnotation(Resource.class).name();
        }
        if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Service.class)) {
            beanName = clazz.getAnnotation(Service.class).value();
        }
        if (StringUtils.isEmpty(beanName)) {
            beanName = AUTO_BEAN_NAME_PREFIX + clazz.getName();
        }

        bf.registerBeanDefinition(beanName, new AnnotatedGenericBeanDefinition(clazz));
    }
}

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 ww w. j a va2  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.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   www .  ja v a2 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;
            }/*  w  w w .  j av a 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 List<InterceptorDelegate> findInterceptors(XmlWebApplicationContext context)
        throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
    String[] interceptorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ControllerInterceptor.class);
    ArrayList<InterceptorDelegate> interceptors = new ArrayList<InterceptorDelegate>(interceptorNames.length);
    for (String beanName : interceptorNames) {
        ControllerInterceptor interceptor = (ControllerInterceptor) context.getBean(beanName);
        Class<?> userClass = ClassUtils.getUserClass(interceptor);
        if (userClass.isAnnotationPresent(Ignored.class)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored interceptor (Ignored):" + interceptor);
            }/*from  w ww. java2s .  c om*/
            continue;
        }
        if (userClass.isAnnotationPresent(NotForSubModules.class)
                && !context.getBeanFactory().containsBeanDefinition(beanName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignored interceptor (NotForSubModules):" + interceptor);
            }
            continue;
        }
        if (!userClass.getSimpleName().endsWith(MvcConstants.INTERCEPTOR_SUFFIX)) {
            logger.error("", new IllegalArgumentException("Interceptor must be end with '"
                    + MvcConstants.INTERCEPTOR_SUFFIX + "': " + userClass.getName()));
            continue;
        }
        InterceptorBuilder builder = new InterceptorBuilder(interceptor);
        Interceptor annotation = userClass.getAnnotation(Interceptor.class);
        if (annotation != null) {
            builder.oncePerRequest(annotation.oncePerRequest());
        }
        String interceporName;
        if (beanName.startsWith(AUTO_BEAN_NAME_PREFIX)) {
            interceporName = StringUtils.removeEnd(StringUtils.uncapitalize(userClass.getSimpleName()),
                    MvcConstants.INTERCEPTOR_SUFFIX);
        } else {
            interceporName = StringUtils.removeEnd(beanName, MvcConstants.INTERCEPTOR_SUFFIX);
        }
        final String mvc = "mvc";
        if (interceporName.startsWith(mvc)
                && (interceporName.length() == mvc.length()
                        || Character.isUpperCase(interceporName.charAt(mvc.length())))
                && !userClass.getName().startsWith("com.sinosoft.one.mvc.")) {
            throw new IllegalArgumentException("illegal interceptor name '" + interceporName + "' for "
                    + userClass.getName() + ": don't starts with 'mvc', it's reserved");
        }

        builder.name(interceporName);

        InterceptorDelegate wrapper = builder.build();
        interceptors.add(wrapper);
        if (logger.isDebugEnabled()) {
            int priority = 0;
            if (interceptor instanceof Ordered) {
                priority = ((Ordered) interceptor).getPriority();
            }
            logger.debug("recognized interceptor[priority=" + priority + "]: " // \r\n
                    + wrapper.getName() + "=" + userClass.getName());
        }
    }

    // start by kylin

    List<String> rList = ResourceLoaderUtil.getResource("interceptors-order.xml", true);
    if (rList != null) {
        Collections.sort(interceptors);
        int tempGlobalPriority = 1;
        for (String configInterName : rList) {
            for (int j = 0, length = interceptors.size(); j < length; j++) {
                InterceptorDelegate interceptorDelegate = interceptors.get(j);
                ControllerInterceptor temp = InterceptorDelegate
                        .getMostInnerInterceptor(interceptorDelegate.getInterceptor());
                if (temp.getClass().getName().startsWith("com.sinosoft.one.mvc.web")
                        || temp.getClass().getName().startsWith("com.sinosoft.one.mvc.controllers")) {
                    continue;
                }
                if (rList.toString().contains(temp.getClass().getName())) {
                    if (configInterName.trim().equals(temp.getClass().getName())) {
                        if (temp instanceof ControllerInterceptorAdapter) {
                            ((ControllerInterceptorAdapter) temp).setPriority(
                                    this.GLOBAL_INTERCEPTOR_CONFIG_START_PRIORITY - tempGlobalPriority++);
                            continue;
                        } else {
                            if (temp instanceof ControllerInterceptorAdapter) {
                                ((ControllerInterceptorAdapter) temp).setPriority(
                                        this.INTERCEPTOR_NOT_CONFIG_START_PRIORITY - tempGlobalPriority++);
                            }
                        }
                    }
                } else {
                    if (temp instanceof ControllerInterceptorAdapter) {
                        ((ControllerInterceptorAdapter) temp)
                                .setPriority(this.INTERCEPTOR_NOT_CONFIG_START_PRIORITY - tempGlobalPriority++);
                    }
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("Interceptor's Priority:" + temp.getClass().getName() + ":"
                            + ((ControllerInterceptorAdapter) temp).getPriority());
                }
            }
        }
    }
    // end by kylin
    Collections.sort(interceptors);
    throwExceptionIfDuplicatedNames(interceptors);
    return interceptors;
}