List of usage examples for org.apache.commons.chain Command execute
boolean execute(Context context) throws Exception;
Execute a unit of processing work to be performed.
From source file:bridge.toolkit.Controller.java
/** * @param args//ww w .ja v a 2 s. co m */ public static void main(String[] args) { Controller loader = new Controller(); Catalog sampleCatalog = loader.createCatalog(); Command toolkit = sampleCatalog.getCommand("SCORM"); Context ctx = new ContextBase(); ctx.put(Keys.SCPM_FILE, args[0]); ctx.put(Keys.RESOURCE_PACKAGE, args[1]); try { if (args.length > 2) { if (args[2] != null && args[2].equalsIgnoreCase("-scormflash")) { toolkit = sampleCatalog.getCommand("SCORM"); ctx.put(Keys.OUTPUT_TYPE, null); } else if (args[2] != null && args[2].equalsIgnoreCase("-scormhtml")) { toolkit = sampleCatalog.getCommand("SCORM"); ctx.put(Keys.OUTPUT_TYPE, "SCORMHTML"); } else if (args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("-mobileCourse"))) { toolkit = sampleCatalog.getCommand("Mobile"); ctx.put(Keys.OUTPUT_TYPE, "mobileCourse"); } else if (args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("-mobilePerformanceSupport"))) { toolkit = sampleCatalog.getCommand("Mobile"); } else if (args[2] != null && args[2].equalsIgnoreCase("-pdfinstructor")) { toolkit = sampleCatalog.getCommand("PDF"); ctx.put(Keys.PDF_OUTPUT_OPTION, "-instructor"); } else if (args[2] != null && args[2].equalsIgnoreCase("-pdfstudent")) { toolkit = sampleCatalog.getCommand("PDF"); ctx.put(Keys.PDF_OUTPUT_OPTION, "-student"); } if (args.length > 3 && args[3] != null) { ctx.put(Keys.OUTPUT_DIRECTORY, args[3]); } } toolkit.execute(ctx); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getCause().toString()); } }
From source file:com.liulangf.pattern.gof.behavioral.chain.jakarta.simple.ExampleServlet.java
/** * <p>Configure a {@link ServletWebContext} for the current request, and * pass it to the <code>execute()</code> method of the specified * {@link Command}, loaded from our configured {@link Catalog}.</p> * * @param request The request we are processing * @param response The response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */// w w w. ja v a 2 s . c o m public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { CatalogFactory factory = CatalogFactory.getInstance(); Catalog catalog = factory.getCatalog(servletName); if (catalog == null) { catalog = factory.getCatalog(); } ServletWebContext context = new ServletWebContext(getServletContext(), request, response); Command command = catalog.getCommand("COMMAND_MAPPER"); try { command.execute(context); } catch (Exception e) { throw new ServletException(e); } }
From source file:com.azaptree.services.command.impl.CommandServiceImpl.java
@Override public void execute(final CommandKey key, final Context ctx) throws CommandException { Assert.notNull(key, "key is required"); Assert.notNull(ctx, "ctx is required"); final org.apache.commons.chain.Command command = getCommonsChainCommand(key); final CommandExcecutionMetric metric = new CommandExcecutionMetric(key); try {/*from w w w .j a v a 2 s. c o m*/ command.execute(ctx); metric.succeeded(); } catch (final CommandException | ValidationException | IllegalArgumentException e) { metric.failed(e); throw e; } catch (final Throwable t) { metric.failed(t); throw new CommandException(t); } finally { commandMetricLog.info(metric.toString()); } }
From source file:info.magnolia.module.workflow.MgnlParticipant.java
/** * @see openwfe.org.embed.engine.EmbeddedParticipant#consume(openwfe.org.engine.workitem.WorkItem) *///ww w . j a va 2 s. c om public void consume(WorkItem wi) throws Exception { // get participant name if (log.isDebugEnabled()) { log.debug("enter consume().."); } if (wi == null) { log.error("work item is null"); return; } String parName = ((InFlowWorkItem) (wi)).getParticipantName(); if (log.isDebugEnabled()) { log.debug("participant name = " + parName); } if (parName.startsWith(WorkflowConstants.PARTICIPANT_PREFIX_COMMAND)) // handle commands { log.info("consume command " + parName + "..."); if (log.isDebugEnabled()) { log.debug("command name is " + parName); } try { String name = StringUtils.removeStart(parName, WorkflowConstants.PARTICIPANT_PREFIX_COMMAND); Command c = CommandsManager.getInstance().getCommand(name); if (c != null) { log.info("Command has been found through the magnolia catalog:" + c.getClass().getName()); // set parameters in the context Context context = MgnlContext.getInstance(); context = new WorkItemContext(context, wi); // execute c.execute(context); WorkflowModule.getEngine().reply((InFlowWorkItem) wi); } else { // not found, do in the old ways log.error("No command has been found through the magnolia catalog for name:" + parName); } log.info("consume command " + parName + " end."); } catch (Exception e) { log.error("consume command failed", e); } } else { if (log.isDebugEnabled()) { log.debug("storage = " + this.storage); } this.storage.storeWorkItem("", (InFlowWorkItem) wi); } if (log.isDebugEnabled()) { log.debug("leave consume().."); } }
From source file:info.magnolia.cms.servlets.CommandBasedMVCServletHandler.java
/** * Try to get the command from the catalogue *//*ww w . j a v a 2s .c o m*/ public String execute(String commandName) { // get command from command map in JCR repository Command command = findCommand(commandName); if (command == null) { // not found, do in the old ways if (log.isDebugEnabled()) { log.debug("can not find command named " + commandName + " in tree command map"); } return super.execute(commandName); } else { if (log.isDebugEnabled()) { log.debug("found command for " + commandName + ": " + command); } // now prepare the context Context ctx = getCommandContext(commandName); // execute the command try { command.execute(ctx); } catch (Exception e) { log.error("can't execute command", e); } return getViewNameAfterExecution(commandName, ctx); } }
From source file:nz.co.jsrsolutions.ds3.command.test.ListExchangesCommandTest.java
/** * Test that when supplied with a known set of exchanges, * an identical set of exchanges is written to the HDF5 * file./*from www . ja v a 2 s . c o m*/ */ @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()); } }
From source file:nz.co.jsrsolutions.ds3.command.test.UpdateExchangeQuotesCommandTest.java
/** * Test/* ww w. j a v a 2 s . co m*/ */ @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()); } }
From source file:nz.co.jsrsolutions.ds3.command.test.UpdateExchangeQuotesCommandTest.java
/** * Test//from w w w . ja v a 2s. co m */ @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()); } }
From source file:nz.co.jsrsolutions.ds3.command.test.UpdateExchangeSymbolQuotesCommandTest.java
/** * Test//from ww w .jav a 2 s.co m */ @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()); } }
From source file:nz.co.jsrsolutions.ds3.command.test.UpdateExchangeSymbolQuotesCommandTest.java
/** * Test/*w ww . j a v a2 s .c o m*/ */ @Test public void testUpdateExchangeSymbolQuotesCommand_ContainedByAvailableRangeSink() { try { UnitTestData testData = new UnitTestData(); EodDataProvider eodDataProvider = new EodDataProviderMock(testData); EodDataSink eodDataSink = new EodDataSinkContainedByAvailableRangeMock(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()); } }