Package org.apache.commons.chain

Examples of org.apache.commons.chain.Command


    actionCtx.setException(exception);

    // Execute the specified command
    try {
      Command command = lookupExceptionCommand();

      if (command == null) {
        LOG.error("Cannot find exceptionCommand '" + exceptionCommand + "'");
        throw new IllegalStateException("Cannot find exceptionCommand '" + exceptionCommand + "'");
      }

      if (LOG.isTraceEnabled()) {
        LOG.trace("Calling exceptionCommand '" + exceptionCommand + "'");
      }

      command.execute(context);
    } catch (Exception e) {
      LOG.warn("Exception from exceptionCommand '" + exceptionCommand + "'", e);
      throw new IllegalStateException("Exception chain threw exception");
    }
View Full Code Here


  public boolean execute(Context context) throws Exception {
    if (LOG.isTraceEnabled()) {
      LOG.trace("execute [" + this + "]");
    }

    Command command = getCommand(context);

    if (command != null) {
      return command.execute(getContext(context));
    } else {
      return false;
    }
  }
View Full Code Here

   * @param exception
   *            The Exception thrown by another Comamnd in a Chain
   * @return TRUE if there is a Filter to process
   */
  public boolean postprocess(Context context, Exception exception) {
    Command command = getCommand(context);

    if ((command != null) && (command instanceof Filter)) {
      try {
        return ((Filter) command).postprocess(getContext(context), exception);
      } catch (NoSuchMethodException ex) {
View Full Code Here

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

    Command command;
    String name = getName();

    if (name == null) {
      name = (String) context.get(getNameKey());
    }
View Full Code Here

        throw new IllegalArgumentException("Duplicate Catalog name found: " + catalog.getName());
      }
      catMap.put(catalog.getName(), catalog);

      for (final String commandName : catalog.getCommandNames()) {
        final Command command = catalog.getCommand(commandName);
        Assert.notNull(command);
        final CommandKey commandKey = new CommandKey(catalog.getName(), commandName);
        cmdMap.put(commandKey, command);
        log.info("registered CommandKey: {}", commandKey);
      }
View Full Code Here

      // command from context
      String commandName = (String)ctx.get("Command");
      if (commandName == null)
         throw new ServletException("No Command found at the Context");
      Command cmd;
      if (catalogName == null)
         cmd = commandService.getCatalog().getCommand(commandName);
      else
         cmd = commandService.getCatalog(catalogName).getCommand(commandName);

      if (cmd == null)
         throw new ServletException("No Command found " + commandName);
      try
      {
         if (pcClassLoader != null)
         {
            // Set the portal classloader to get all the resources defined within the portal context
            Thread.currentThread().setContextClassLoader(pcClassLoader);
            hasChanged = true;
         }        
         cmd.execute(ctx);
      }
      catch (Exception e)
      {
         log.error("An error occurs while executing the command " + commandName, e);
         throw new ServletException(e);
View Full Code Here

   public void testExcecute() throws Exception
   {

      CommandService cservice = (CommandService)container.getComponentInstanceOfType(CommandService.class);
      Command c1 = cservice.getCatalog().getCommand("Execute2");
      Command c2 = cservice.getCatalog().getCommand("Command1");

      Catalog c = cservice.getCatalog();

      Context ctx = new ContextBase();
      ctx.put("test", Integer.valueOf(0));
      c1.execute(ctx);
      c2.execute(ctx);
      assertEquals(3, ((Integer)ctx.get("test")).intValue());

   }
View Full Code Here

         throw new ServletException("Path undefined " + request.getParameter("path") + " Request: "
            + request.getRequestURI());

      try
      {
         Command cmd;
         if (catalogName == null)
            cmd = commandService.getCatalog().getCommand("displayResource");
         else
            cmd = commandService.getCatalog(catalogName).getCommand("displayResource");

         if (cmd == null)
            throw new Exception("No 'displayResource' command found");
         ctx.put("path", currentPath);
         ctx.put("cache-control-max-age", getServletConfig().getInitParameter("cache-control-max-age"));
         cmd.execute(ctx);
      }
      catch (Exception e)
      {
         e.printStackTrace(); //NOSONAR
         throw new ServletException(e);
View Full Code Here

      // command from context
      String commandName = (String)ctx.get("Command");
      if (commandName == null)
         throw new ServletException("No Command found at the Context");
      Command cmd;
      if (catalogName == null)
         cmd = commandService.getCatalog().getCommand(commandName);
      else
         cmd = commandService.getCatalog(catalogName).getCommand(commandName);

      if (cmd == null)
         throw new ServletException("No Command found " + commandName);
      try
      {
         if (pcClassLoader != null)
         {
            // Set the portal classloader to get all the resources defined within the portal context
            Thread.currentThread().setContextClassLoader(pcClassLoader);
            hasChanged = true;
         }        
         cmd.execute(ctx);
      }
      catch (Exception e)
      {
         log.error("An error occurs while executing the command " + commandName, e);
         throw new ServletException(e);
View Full Code Here

   }

   public void testSetProperty() throws Exception
   {

      Command c = cservice.getCatalog().getCommand("setProperty");
      ctx.put("currentNode", "/foo");
      ctx.put("name", "testProperty");
      ctx.put("propertyType", PropertyType.TYPENAME_STRING);
      ctx.put("values", "testValue");
      ctx.put("multiValued", Boolean.FALSE);

      c.execute(ctx);

      Command save = cservice.getCatalog().getCommand("save");
      save.execute(ctx);

   }
View Full Code Here

TOP

Related Classes of org.apache.commons.chain.Command

Copyright © 2018 www.massapicom. 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.