Search in sources :

Example 6 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)

Example 7 with Catalog

use of org.apache.commons.chain.Catalog in project bamboobsc by billchen198318.

the class SimpleChain method getCatalog.

public Catalog getCatalog(String resourceConfig, String catalogName) throws Exception {
    ConfigParser parser = new ConfigParser();
    parser.parse(this.getClass().getResource(resourceConfig));
    Catalog catalog = CatalogFactoryBase.getInstance().getCatalog(catalogName);
    return catalog;
}
Also used : ConfigParser(org.apache.commons.chain.config.ConfigParser) Catalog(org.apache.commons.chain.Catalog)

Example 8 with Catalog

use of org.apache.commons.chain.Catalog in project bamboobsc by billchen198318.

the class SimpleChain method getResultFromResource.

public ChainResultObj getResultFromResource(String commandName, Context context) throws Exception {
    Catalog catalog = this.getCatalog(ChainConstants.CHAIN_RESOURCE_CONFIG, ChainConstants.CHAIN_CATALOG);
    this.addCommand(catalog.getCommand(commandName));
    this.execute(context);
    return this.getResult(context);
}
Also used : Catalog(org.apache.commons.chain.Catalog)

Example 9 with Catalog

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

Example 10 with Catalog

use of org.apache.commons.chain.Catalog in project sonar-java 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)14 Command (org.apache.commons.chain.Command)6 CommandService (org.exoplatform.services.command.impl.CommandService)3 MyContext (com.gpcoder.context.MyContext)2 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