Example usage for org.apache.commons.chain CatalogFactory getInstance

List of usage examples for org.apache.commons.chain CatalogFactory getInstance

Introduction

In this page you can find the example usage for org.apache.commons.chain CatalogFactory getInstance.

Prototype

public static CatalogFactory getInstance() 

Source Link

Document

Return the singleton CatalogFactory instance for the relevant ClassLoader.

Usage

From source file:info.magnolia.commands.CommandsManager.java

/**
 * Register this catalogue/* w w w . j a v a  2  s.  co m*/
 */
protected void onRegister(Content node) {
    Catalog catalog = new MgnlRepositoryCatalog(node);
    String name = getCatalogName(node);
    if (log.isDebugEnabled()) {
        log.debug("registering catalog {}", name);
    }
    CatalogFactory.getInstance().addCatalog(name, catalog);
}

From source file:com.liulangf.pattern.gof.behavioral.chain.jakarta.simple.ExampleServlet.java

/**
 * <p>Configure a {@link ServletWebContext} for the current request, and
 * pass it to the <code>execute()</code> method of the specified
 * {@link Command}, loaded from our configured {@link Catalog}.</p>
 *
 * @param request The request we are processing
 * @param response The response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 *//*from  w ww.j  ava2s  .c o  m*/
public void service(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    CatalogFactory factory = CatalogFactory.getInstance();
    Catalog catalog = factory.getCatalog(servletName);
    if (catalog == null) {
        catalog = factory.getCatalog();
    }

    ServletWebContext context = new ServletWebContext(getServletContext(), request, response);
    Command command = catalog.getCommand("COMMAND_MAPPER");
    try {
        command.execute(context);
    } catch (Exception e) {
        throw new ServletException(e);
    }

}

From source file:info.magnolia.commands.CommandsManager.java

/**
 * Get the command//from   w w w .j  a v  a 2s .com
 * @param catalogName the catalog containing the command
 * @param commandName the name of the command
 * @return the command to execute
 */
public Command getCommand(String catalogName, String commandName) {
    Catalog catalog = CatalogFactory.getInstance().getCatalog(catalogName);
    if (catalog != null) {
        return catalog.getCommand(commandName);
    } else {
        return null;
    }
}

From source file:net.jradius.handler.EventHandlerChain.java

public Catalog getCatalog() {
    if (this.catalog == null) {
        CatalogFactory factory = CatalogFactory.getInstance();
        this.catalog = factory.getCatalog(getCatalogName());
        if (this.catalog == null) {
            RadiusLog.error("Unknown catalog named: " + getCatalogName());
        }//from w  ww. j  ava 2 s  . co m
    }
    return this.catalog;
}

From source file:org.apache.struts.chain.commands.ExceptionCatcher.java

/**
 * <p> Return the command to be executed if an exception occurs. </p>
 *
 * @return The command to be executed if an exception occurs
 * @throws IllegalArgumentException If catalog cannot be found
 * @throws IllegalStateException    If command property is not specified
 *///from   w  ww  . j  av  a  2  s.  co m
protected Command lookupExceptionCommand() {
    String catalogName = getCatalogName();
    Catalog catalog;

    if (catalogName == null) {
        catalog = CatalogFactory.getInstance().getCatalog();

        if (catalog == null) {
            LOG.error("Cannot find default catalog");
            throw new IllegalArgumentException("Cannot find default catalog");
        }
    } else {
        catalog = CatalogFactory.getInstance().getCatalog(catalogName);

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

    String exceptionCommand = getExceptionCommand();

    if (exceptionCommand == null) {
        LOG.error("No exceptionCommand property specified");
        throw new IllegalStateException("No exceptionCommand property specfied");
    }

    return catalog.getCommand(exceptionCommand);
}

From source file:org.apache.struts.chain.commands.ExecuteCommand.java

/**
 * <p> Retrieve the specified Command from the specified Catalog. </p>
 *
 * @param commandName The Command to retrieve.
 * @param catalogName The Catalog to search.
 * @return Instantiated Command, or null
 *//*from ww w  . j  ava  2 s.co  m*/
protected Command getCommand(String commandName, String catalogName) {
    if (commandName == null) {
        return null;
    }

    Catalog catalog;

    if (catalogName != null) {
        catalog = CatalogFactory.getInstance().getCatalog(catalogName);

        if (catalog == null) {
            LOG.warn("When looking up " + commandName + "," + " no catalog found under " + catalogName);

            return null;
        }
    } else {
        catalogName = "the default catalog";
        catalog = CatalogFactory.getInstance().getCatalog();

        if (catalog == null) {
            LOG.warn("When looking up " + commandName + "," + " no default catalog found.");

            return null;
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("looking up command " + commandName + " in " + catalogName);
    }

    return catalog.getCommand(commandName);
}

From source file:org.apache.struts.chain.commands.generic.WrappingLookupCommand.java

/**
 * <p>Return the Command to process for this Context.</p>
 *
 * @param context The Context we are processing
 * @return The Command to process for this Context
 *//*from ww w .j  a  va2  s. co  m*/
protected Command getCommand(Context context) {
    CatalogFactory catalogFactory = CatalogFactory.getInstance();
    String catalogName = getCatalogName();
    Catalog catalog;

    if (catalogName == null) {
        catalog = catalogFactory.getCatalog();
        catalogName = "{default}"; // for debugging purposes
    } else {
        catalog = catalogFactory.getCatalog(catalogName);
    }

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

    Command command;
    String name = getName();

    if (name == null) {
        name = (String) context.get(getNameKey());
    }

    if (name != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Lookup command " + name + " in catalog " + catalogName);
        }

        command = catalog.getCommand(name);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Found command " + command + ";" + " optional: " + isOptional());
        }

        if ((command == null) && !isOptional()) {
            throw new IllegalArgumentException(
                    "Cannot find command " + "'" + name + "' in catalog '" + catalogName + "'");
        } else {
            return command;
        }
    } else {
        throw new IllegalArgumentException("No command name");
    }
}

From source file:org.apache.struts.chain.ComposableRequestProcessor.java

/**
 * <p> Establish the CatalogFactory which will be used to look up the
 * catalog which has the request processing command. </p><p> The base
 * implementation simply calls CatalogFactory.getInstance(), unless the
 * catalogFactory property of this object has already been set, in which
 * case it is not changed. </p>//w  w w.j  av  a 2 s .c  om
 *
 * @param servlet      The ActionServlet we are processing
 * @param moduleConfig The ModuleConfig we are processing
 */
protected void initCatalogFactory(ActionServlet servlet, ModuleConfig moduleConfig) {
    if (this.catalogFactory != null) {
        return;
    }

    this.catalogFactory = CatalogFactory.getInstance();
}

From source file:org.apache.struts.chain.ExceptionCatcher.java

/**
 * <p>If an exception was thrown by a subsequent <code>Command</code>,
 * pass it on to the specified exception handling chain.  Otherwise,
 * do nothing.</p>//ww  w  .  j a va 2  s  . c  om
 *
 * @param context The {@link Context} to be processed by this
 *  {@link Filter}
 * @param exception The <code>Exception</code> (if any) that was thrown
 *  by the last {@link Command} that was executed; otherwise
 *  <code>null</code>
 */
public boolean postprocess(Context context, Exception exception) {

    // Do nothing if there was no exception thrown
    if (exception == null) {
        return (false);
    }

    // Stash the exception in the specified context attribute
    if (log.isDebugEnabled()) {
        log.debug("Attempting to handle a thrown exception");
    }
    context.put(getExceptionKey(), exception);

    // Execute the specified command
    try {
        String catalogName = getCatalogName();
        Catalog catalog = null;
        if (catalogName == null) {
            catalog = CatalogFactory.getInstance().getCatalog();
            if (catalog == null) {
                log.error("Cannot find default catalog");
                throw new IllegalArgumentException("Cannot find default catalog");
            }
        } else {
            catalog = CatalogFactory.getInstance().getCatalog(catalogName);
            if (catalog == null) {
                log.error("Cannot find catalog '" + catalogName + "'");
                throw new IllegalArgumentException("Cannot find catalog '" + catalogName + "'");
            }
        }
        String exceptionCommand = getExceptionCommand();
        if (exceptionCommand == null) {
            log.error("No exceptionCommand property specified");
            throw new IllegalStateException("No exceptionCommand property specfied");
        }
        Command command = catalog.getCommand(exceptionCommand);
        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");
    }
    return (true);

}

From source file:org.apache.struts.chain.legacy.ChainAction.java

/**
 * <p>Return the <code>Catalog</code> we will use to acquire the
 * <code>Command</code> to be executed.  NOTE: Any race condition
 * calling this method is harmless, so do not bother to synchronize.</p>
 *//*from  ww  w.j  av a 2s.  c  o  m*/
protected Catalog getCatalog() {

    if (catalog == null) {
        catalog = CatalogFactory.getInstance().getCatalog();
    }
    return catalog;

}