예제 #1
0
  @Override
  protected synchronized RequestProcessor getRequestProcessor(ModuleConfig moduleConfig)
      throws ServletException {

    ServletContext servletContext = getServletContext();

    String key = Globals.REQUEST_PROCESSOR_KEY + moduleConfig.getPrefix();

    RequestProcessor requestProcessor = (RequestProcessor) servletContext.getAttribute(key);

    if (requestProcessor == null) {
      ControllerConfig controllerConfig = moduleConfig.getControllerConfig();

      try {
        requestProcessor =
            (RequestProcessor)
                InstanceFactory.newInstance(
                    ClassLoaderUtil.getPortalClassLoader(), controllerConfig.getProcessorClass());
      } catch (Exception e) {
        throw new ServletException(e);
      }

      requestProcessor.init(this, moduleConfig);

      servletContext.setAttribute(key, requestProcessor);
    }

    return requestProcessor;
  }
  /**
   * Initialize this request processor instance.
   *
   * @param servlet The ActionServlet we are associated with
   * @param moduleConfig The ModuleConfig we are associated with.
   * @throws ServletException If an error occurs during initialization
   */
  public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException {
    LOG.info(
        "Initializing composable request processor for module prefix '"
            + moduleConfig.getPrefix()
            + "'");
    super.init(servlet, moduleConfig);

    initCatalogFactory(servlet, moduleConfig);

    ControllerConfig controllerConfig = moduleConfig.getControllerConfig();

    String catalogName = controllerConfig.getCatalog();

    catalog = this.catalogFactory.getCatalog(catalogName);

    if (catalog == null) {
      throw new ServletException("Cannot find catalog '" + catalogName + "'");
    }

    String commandName = controllerConfig.getCommand();

    command = catalog.getCommand(commandName);

    if (command == null) {
      throw new ServletException("Cannot find command '" + commandName + "'");
    }

    this.setActionContextClassName(controllerConfig.getProperty(ACTION_CONTEXT_CLASS));
  }