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);
}
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);
}
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());
}
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");
}
}
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);
}
Aggregations