本文整理汇总了Java中org.apache.commons.chain.Command类的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Command类属于org.apache.commons.chain包,在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommandLine
import org.apache.commons.chain.Command; //导入依赖的package包/类
public void executeCommandLine(CommandLine commandLine)
throws DataScraper3Exception {
if (!commandLine.hasOption(CommandLineOptions.COMMAND)) {
throw new DataScraper3Exception("No command supplied.");
}
CommandContext context = new CommandContext();
context.put(CommandContext.EODDATAPROVIDER_KEY, _eodDataProvider);
context.put(CommandContext.EODDATASINK_KEY, _eodDataSink);
context.put(CommandContext.EMAILSERVICE_KEY, _emailService);
// place optional argument values into the context
if (commandLine.hasOption(CommandLineOptions.EXCHANGE)) {
context.put(CommandContext.EXCHANGE_KEY,
commandLine.getOptionValue(CommandLineOptions.EXCHANGE));
}
if (commandLine.hasOption(CommandLineOptions.SYMBOL)) {
context.put(CommandContext.SYMBOL_KEY,
commandLine.getOptionValue(CommandLineOptions.SYMBOL));
}
try {
Command command = (Command)_appContext.getBean(commandLine
.getOptionValue(CommandLineOptions.COMMAND));
command.execute(context);
} catch (Exception e) {
throw new DataScraper3Exception(e);
}
}
示例2: execute
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* <p>Invoke the Command for a Context, returning TRUE if processing
* should halt.</p>
*
* @param context Our ActionContext
* @return TRUE if processing should halt
* @throws Exception On any error
*/
public boolean execute(Context context)
throws Exception {
if (LOG.isTraceEnabled()) {
LOG.trace("execute [" + this + "]");
}
Command command = getCommand(context);
if (command != null) {
return command.execute(getContext(context));
} else {
return false;
}
}
示例3: getCommand
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* <p>Return the command specified by the <code>command</code> and
* <code>catalog</code> properties of the <code>forwardConfig</code>
* property of the given <code>ActionContext</code>. If
* <code>forwardConfig</code> is null, return null.</p>
*
* @param context Our ActionContext
* @return Command to execute or null
*/
protected Command getCommand(ActionContext context) {
ForwardConfig forwardConfig = context.getForwardConfig();
if (forwardConfig == null) {
return null;
}
return getCommand(forwardConfig.getCommand(), forwardConfig.getCatalog());
}
示例4: execute
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* <p>If the <code>context</code> is "valid", lookup a command and execute
* it.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return the result of the lookup command's <code>execute</code> method,
* if executed, or <code>false</code> if it was not executed.
* @throws Exception on any error
*/
public boolean execute(ActionContext actionCtx)
throws Exception {
if (shouldProcess(actionCtx)) {
Command command = getCommand(actionCtx);
if (command != null) {
return (command.execute(actionCtx));
}
}
return (false);
}
示例5: getCommand
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* <p>Find the <code>ActionConfig</code> in the current context and, if it
* is properly configured, lookup the appropriate <code>commons-chain</code>
* command.</p>
*
* @param context A valid ActionContext
* @return a <code>Command</code> to execute, or null if none is specified
* or if the specified command cannot be found.
*/
protected Command getCommand(ActionContext context) {
ActionConfig actionConfig = context.getActionConfig();
String commandName = actionConfig.getCommand();
if (commandName == null) {
return null;
}
String catalogName = actionConfig.getCatalog();
return getCommand(commandName, catalogName);
}
示例6: postprocess
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* <p>If an exception was thrown by a subsequent <code>Command</code>,
* pass it on to the specified exception handling chain. Otherwise, do
* nothing.</p>
*
* @param context The {@link Context} to be processed by this {@link
* Filter}
* @param exception The <code>Exception</code> (if any) that was thrown by
* the last {@link Command} that was executed; otherwise
* <code>null</code>
* @return TRUE if post processing an exception occurred and the exception
* processing chain invoked
* @throws IllegalStateException If exception throws exception
*/
public boolean postprocess(Context context, Exception exception) {
// Do nothing if there was no exception thrown
if (exception == null) {
return (false);
}
// Stash the exception in the specified context attribute
if (LOG.isDebugEnabled()) {
LOG.debug("Attempting to handle a thrown exception");
}
ActionContext actionCtx = (ActionContext) context;
actionCtx.setException(exception);
// Execute the specified command
try {
Command command = lookupExceptionCommand();
if (command == null) {
LOG.error("Cannot find exceptionCommand '" + exceptionCommand
+ "'");
throw new IllegalStateException(
"Cannot find exceptionCommand '" + exceptionCommand + "'");
}
if (LOG.isTraceEnabled()) {
LOG.trace("Calling exceptionCommand '" + exceptionCommand + "'");
}
command.execute(context);
} catch (Exception e) {
LOG.warn("Exception from exceptionCommand '" + exceptionCommand
+ "'", e);
throw new IllegalStateException("Exception chain threw exception");
}
return (true);
}
示例7: getResultFromClass
import org.apache.commons.chain.Command; //导入依赖的package包/类
public ChainResultObj getResultFromClass(Class<Command>[] clazz, Context context) throws Exception {
for (int i=0; i<clazz.length; i++) {
this.addCommand(clazz[i].newInstance());
}
this.execute(context);
return this.getResult(context);
}
示例8: setCommand
import org.apache.commons.chain.Command; //导入依赖的package包/类
public void setCommand(Command command) {
this.command = command;
}
示例9: getCommand
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* <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();
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");
}
}
示例10: lookupExceptionCommand
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* <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);
}
示例11: getCommand
import org.apache.commons.chain.Command; //导入依赖的package包/类
public static Command getCommand(String commandID) throws IllegalArgumentException
{
// XXX: This function taken from CVS version of CatalogFactory
String DELIMITER = ":";
String commandName = commandID;
String catalogName = null;
Catalog catalog = null;
if (commandID != null)
{
int splitPos = commandID.indexOf(DELIMITER);
if (splitPos != -1)
{
catalogName = commandID.substring(0, splitPos);
commandName = commandID.substring(splitPos + DELIMITER.length());
if (commandName.indexOf(DELIMITER) != -1)
{
throw new IllegalArgumentException("commandID [" + commandID + "] has too many delimiters (reserved for future use)");
}
}
}
if (catalogName != null)
{
catalog = factory.getCatalog(catalogName);
if (catalog == null)
{
RadiusLog.warn("No catalog found for name: " + catalogName + ".");
return null;
}
}
else
{
catalog = factory.getCatalog();
if (catalog == null)
{
RadiusLog.warn("No default catalog found.");
return null;
}
}
return catalog.getCommand(commandName);
}
示例12: testListExchangesCommand
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* Test that when supplied with a known set of exchanges,
* an identical set of exchanges is written to the HDF5
* file.
*/
@Test
public void testListExchangesCommand() {
try {
UnitTestData testData = new UnitTestData();
EodDataProvider eodDataProvider = new EodDataProviderMock(testData);
EodDataSink eodDataSink = new EodDataSinkEmptyMock(testData);
CommandContext context = new CommandContext();
context.put(CommandContext.EODDATAPROVIDER_KEY, eodDataProvider);
context.put(CommandContext.EODDATASINK_KEY, eodDataSink);
context.put(CommandContext.EXCHANGE_KEY, testData.getTestExchange());
context.put(CommandContext.SYMBOL_KEY, testData.getTestSymbol());
Command command = new ListExchangesCommand();
command.execute(context);
} catch (Exception e) {
fail(e.getMessage());
}
}
示例13: testUpdateExchangeQuotesCommand_EmptySink
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* Test
*/
@Test
public void testUpdateExchangeQuotesCommand_EmptySink() {
try {
UnitTestData testData = new UnitTestData();
EodDataProvider eodDataProvider = new EodDataProviderMock(testData);
EodDataSink eodDataSink = new EodDataSinkEmptyMock(testData);
EmailService emailService = new EmailServiceMock();
CommandContext context = new CommandContext();
// context.put(CommandContext.EODDATAPROVIDER_KEY, eodDataProvider);
// context.put(CommandContext.EODDATASINK_KEY, eodDataSink);
context.put(CommandContext.EXCHANGE_KEY, testData.getTestExchange());
context.put(CommandContext.SYMBOL_KEY, testData.getTestSymbol());
Command command = new UpdateExchangeQuotesCommand(
Executors.newSingleThreadExecutor(), eodDataProvider,
eodDataSink, emailService);
command.execute(context);
} catch (Throwable t) {
t.printStackTrace();
fail(t.getCause().toString());
}
}
示例14: testUpdateExchangeQuotesCommand_OneDayOrLessAvailable
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* Test
*/
@Test
public void testUpdateExchangeQuotesCommand_OneDayOrLessAvailable() {
try {
UnitTestData testData = new UnitTestData();
EodDataProvider eodDataProvider = new EodDataProviderOneDayAvailableMock(
testData);
EodDataSink eodDataSink = new EodDataSinkFirstElementLessThanOneDayAfterFirstAvailable(
testData);
EmailService emailService = new EmailServiceMock();
CommandContext context = new CommandContext();
// context.put(CommandContext.EODDATAPROVIDER_KEY, eodDataProvider);
// context.put(CommandContext.EODDATASINK_KEY, eodDataSink);
context.put(CommandContext.EXCHANGE_KEY, testData.getTestExchange());
context.put(CommandContext.SYMBOL_KEY, testData.getTestSymbol());
Command command = new UpdateExchangeQuotesCommand(
Executors.newSingleThreadExecutor(), eodDataProvider,
eodDataSink, emailService);
command.execute(context);
} catch (Throwable t) {
t.printStackTrace();
fail(t.getCause().getMessage());
}
}
示例15: testUpdateExchangeSymbolQuotesCommand_EmptySink
import org.apache.commons.chain.Command; //导入依赖的package包/类
/**
* Test
*/
@Test
public void testUpdateExchangeSymbolQuotesCommand_EmptySink() {
try {
UnitTestData testData = new UnitTestData();
EodDataProvider eodDataProvider = new EodDataProviderMock(testData);
EodDataSink eodDataSink = new EodDataSinkEmptyMock(testData);
CommandContext context = new CommandContext();
context.put(CommandContext.EODDATAPROVIDER_KEY, eodDataProvider);
context.put(CommandContext.EODDATASINK_KEY, eodDataSink);
context.put(CommandContext.EXCHANGE_KEY, testData.getTestExchange());
context.put(CommandContext.SYMBOL_KEY, testData.getTestSymbol());
Command command = new UpdateExchangeSymbolQuotesCommand();
command.execute(context);
} catch (Throwable t) {
fail(t.toString());
}
}