Beispiel #1
0
 private RequestMappingInfo findMethodRequestMapping(FacesContext context, Bean<?> bean) {
   RequestMappingInfo result = null;
   Class clazz = bean.getBeanClass();
   AnnotatedType annotatedType = beanManager.createAnnotatedType(clazz);
   Set<AnnotatedMethod> annotatedMethodSet = annotatedType.getMethods();
   for (AnnotatedMethod method : annotatedMethodSet) {
     if (method.isAnnotationPresent(RequestMapping.class)) {
       RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
       String[] mappings = requestMapping.value();
       String mapping = null;
       for (String current : mappings) {
         String pathInfo = context.getExternalContext().getRequestPathInfo();
         if (pathInfo.equals(current)) {
           result = new RequestMappingInfo();
           result.setBean(bean);
           result.setMethod(method.getJavaMember());
           result.setRequestMapping(mapping);
           result.setMappingType(RequestMappingInfo.MappingType.EXACT);
           break;
         } else if (current.endsWith("*")) {
           current = current.substring(0, current.length() - 1);
           if (pathInfo.startsWith(current)) {
             if (result == null) {
               result = new RequestMappingInfo();
               result.setBean(bean);
               result.setMethod(method.getJavaMember());
               result.setRequestMapping(current);
               result.setMappingType(RequestMappingInfo.MappingType.PREFIX);
             } else if (current.length() > result.getLength()) {
               result.setBean(bean);
               result.setMethod(method.getJavaMember());
               result.setRequestMapping(current);
               result.setMappingType(RequestMappingInfo.MappingType.PREFIX);
             }
           }
         } else if (current.startsWith("*")) {
           current = current.substring(1);
           if (pathInfo.endsWith(current)) {
             result = new RequestMappingInfo();
             result.setBean(bean);
             result.setMethod(method.getJavaMember());
             result.setRequestMapping(current);
             result.setMappingType(RequestMappingInfo.MappingType.EXTENSION);
             break;
           }
         }
       }
     }
     if (result != null
         && (result.getMappingType().equals(RequestMappingInfo.MappingType.EXACT)
             || (result.getMappingType().equals(RequestMappingInfo.MappingType.EXTENSION)))) {
       break;
     }
   }
   return result;
 }
 private String getPath(RequestMapping classMapping) {
   if (classMapping != null && isNotEmpty(classMapping.value())) {
     return classMapping.value()[0];
   }
   return null;
 }