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

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

Introduction

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

Prototype

public abstract Catalog getCatalog();

Source Link

Document

Gets the default instance of Catalog associated with the factory (if any); otherwise, return null.

Usage

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  w w  w  .jav a2s . c o 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");
    }
}