Examples of PluginControllerInfo


Examples of com.quickwebframework.mvc.spring.entity.impl.PluginControllerInfo

        ex.printStackTrace();
      }
      return null;
    }

    PluginControllerInfo pluginControllerInfo = bundleNamePluginControllerInfoMap
        .get(bundleName);

    // 请求的HTTP方法
    String requestMethod = request.getMethod().toUpperCase();

    // URL的模板:[requestMethod]_/[bundleName]/[methodName]
    String mappingUrl = requestMethod + "_" + "/" + bundleName + "/"
        + methodName;

    // 如果方法名称为null或Map中不存在此方法名称
    if (methodName == null) {
      try {
        response.sendError(404, "未找到方法名称!");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      return null;
    }

    // 正则匹配得到处理器对象
    Object handler = null;
    for (String urlTemplate : pluginControllerInfo
        .getMappingUrlHandlerMap().keySet()) {
      if (pathMatcher.match(urlTemplate, mappingUrl)) {
        handler = pluginControllerInfo.getMappingUrlHandlerMap().get(
            urlTemplate);
        break;
      }
    }

    if (handler == null) {
      try {
        response.sendError(404, "未找到插件名称为[" + bundleName + "],方法名称为["
            + methodName + "]的处理器!");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      return null;
    }

    // 得到该处理器对应的适配器
    AnnotationMethodHandlerAdapter adapter = pluginControllerInfo
        .getHandlerAdapterMap().get(handler);

    try {
      // 执行处理,得到模型与视图
      ModelAndView mav = adapter.handle(request, response, handler);
View Full Code Here

Examples of com.quickwebframework.mvc.spring.entity.impl.PluginControllerInfo

  private static Log log = LogFactory.getLog(BundleControllerHandler.class);

  public void registerBundle(Bundle bundle,
      ApplicationContext applicationContext) {
    PluginControllerInfo pluginControllerInfo = new PluginControllerInfo(
        bundle);
    // Bundle的名称
    String bundleName = bundle.getSymbolicName();
    // 从ApplicationContext得到MVC控制器列表
    final Map<String, Object> handlerMap = applicationContext
        .getBeansWithAnnotation(Controller.class);

    Collection<Object> handlers = handlerMap.values();

    if (handlers != null) {
      for (Object handler : handlers) {
        Class<?> controllerClazz = handler.getClass();
        Method[] methods = controllerClazz.getMethods();
        for (Method method : methods) {
          // 查找RequestMapping注解
          RequestMapping requestMapping = method
              .getAnnotation(RequestMapping.class);
          if (requestMapping == null)
            continue;

          for (String methodName : requestMapping.value()) {
            // 内部URL,仅用于 Spring MVC内部匹配到控制器方法
            // 要获取外部URL,请调用WebContext.getBundleMethodUrl方法
            String innerMappingUrl = methodName;
            if (!innerMappingUrl.startsWith("/")) {
              innerMappingUrl = "/" + innerMappingUrl;
            }
            innerMappingUrl = "/" + bundleName + innerMappingUrl;

            RequestMethod[] requestMethods = requestMapping
                .method();
            // 如果方法为空,则映射所有的HTTP方法
            if (requestMethods == null
                || requestMethods.length == 0) {
              requestMethods = RequestMethod.values();
            }

            StringBuilder sb = new StringBuilder();

            for (RequestMethod requestMethod : requestMethods) {
              sb.append(requestMethod.name());
              sb.append(",");

              // 添加到映射MAP中
              String tmpMappingUrl = requestMethod.name()
                  .toUpperCase() + "_" + innerMappingUrl;
              pluginControllerInfo.getMappingUrlHandlerMap().put(
                  tmpMappingUrl, handler);
            }

            if (sb.length() == 0)
              // 正常情况下,这儿不可能被执行到。
              sb.append("所有");
            else
              sb.setLength(sb.length() - 1);

            log.debug(String.format(
                "Spring MVC:映射内部URL路径[%s]的[%s]HTTP请求到处理器'%s'",
                innerMappingUrl, sb.toString(), handler
                    .getClass().getName()));

            // 将处理器与对应的适配器放入映射中
            if (!pluginControllerInfo.getHandlerAdapterMap()
                .containsKey(handler)) {
              AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
              adapter.setPathMatcher(new PluginPathMatcher(bundle
                  .getSymbolicName()));
              adapter.setUrlPathHelper(new PluginUrlPathHelper());
              pluginControllerInfo.getHandlerAdapterMap().put(
                  handler, adapter);
            }
          }
        }
      }
View Full Code Here

Examples of com.quickwebframework.mvc.spring.entity.impl.PluginControllerInfo

  public Map<String, String[]> getBundleUrlsMap() {
    String viewTypeName = Activator.getViewTypeServlet().getViewTypeName();

    Map<String, String[]> rtnMap = new HashMap<String, String[]>();
    for (String key : bundleNamePluginControllerInfoMap.keySet()) {
      PluginControllerInfo pluginControllerInfo = bundleNamePluginControllerInfoMap
          .get(key);

      List<String> tmpList = new ArrayList<String>();

      for (String tmpStr : pluginControllerInfo.getMappingUrlHandlerMap()
          .keySet()) {
        int spIndex = tmpStr.indexOf("/");
        String tmpUrl1 = tmpStr.substring(spIndex + 1);
        int spIndex2 = tmpUrl1.indexOf("/");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.