Search in sources :

Example 1 with CatalogFactory

use of org.apache.commons.chain.CatalogFactory in project sonarqube by SonarSource.

the class WrappingLookupCommand method getCommand.

/**
     * <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
     */
protected Command getCommand(Context context) {
    CatalogFactory catalogFactory = CatalogFactory.getInstance();
    String catalogName = getCatalogName();
    Catalog catalog;
    if (catalogName == null) {
        catalog = catalogFactory.getCatalog();
        // for debugging purposes
        catalogName = "{default}";
    } 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");
    }
}
Also used : Command(org.apache.commons.chain.Command) CatalogFactory(org.apache.commons.chain.CatalogFactory) Catalog(org.apache.commons.chain.Catalog)

Example 2 with CatalogFactory

use of org.apache.commons.chain.CatalogFactory in project sonar-java by SonarSource.

the class WrappingLookupCommand method getCommand.

/**
 * <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
 */
protected Command getCommand(Context context) {
    CatalogFactory catalogFactory = CatalogFactory.getInstance();
    String catalogName = getCatalogName();
    Catalog catalog;
    if (catalogName == null) {
        catalog = catalogFactory.getCatalog();
        // for debugging purposes
        catalogName = "{default}";
    } 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");
    }
}
Also used : Command(org.apache.commons.chain.Command) CatalogFactory(org.apache.commons.chain.CatalogFactory) Catalog(org.apache.commons.chain.Catalog)

Aggregations

Catalog (org.apache.commons.chain.Catalog)2 CatalogFactory (org.apache.commons.chain.CatalogFactory)2 Command (org.apache.commons.chain.Command)2