Search in sources :

Example 1 with Catalog

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

the class ExceptionCatcher method lookupExceptionCommand.

/**
     * <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
     */
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);
}
Also used : Catalog(org.apache.commons.chain.Catalog)

Example 2 with Catalog

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

the class ExceptionCatcher method lookupExceptionCommand.

/**
 * <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
 */
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);
}
Also used : Catalog(org.apache.commons.chain.Catalog)

Example 3 with Catalog

use of org.apache.commons.chain.Catalog in project kernel by exoplatform.

the class CommandServiceTest method testExcecute.

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());
}
Also used : Context(org.apache.commons.chain.Context) Command(org.apache.commons.chain.Command) CommandService(org.exoplatform.services.command.impl.CommandService) Catalog(org.apache.commons.chain.Catalog) ContextBase(org.apache.commons.chain.impl.ContextBase)

Example 4 with Catalog

use of org.apache.commons.chain.Catalog 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 5 with Catalog

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

the class ExecuteCommand method getCommand.

/**
     * <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
     */
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);
}
Also used : Catalog(org.apache.commons.chain.Catalog)

Aggregations

Catalog (org.apache.commons.chain.Catalog)12 Command (org.apache.commons.chain.Command)4 CommandService (org.exoplatform.services.command.impl.CommandService)3 CatalogFactory (org.apache.commons.chain.CatalogFactory)2 Context (org.apache.commons.chain.Context)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ConfigParser (org.apache.commons.chain.config.ConfigParser)1 ContextBase (org.apache.commons.chain.impl.ContextBase)1 Test (org.junit.Test)1