Package org.apache.commons.chain

Examples of org.apache.commons.chain.Command


            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);
        }

    }
View Full Code Here


     * instance is <code>true</code>
     * @throws Exception if and error occurs in the looked-up Command.
     */
    public boolean execute(Context context) throws Exception {

        Command command = getCommand(context);
        if (command != null) {
            boolean result = (command.execute(context));
            if (isIgnoreExecuteResult()) {
                return false;
            }
            return result;
        } else {
View Full Code Here

     * unless the <code>optional</code> property is <code>false</code>, in which
     * case <code>IllegalArgumentException</code> will be thrown.
     */
    public boolean postprocess(Context context, Exception exception) {

        Command command = getCommand(context);
        if (command != null) {
            if (command instanceof Filter) {
                boolean result = (((Filter) command).postprocess(context, exception));
                if (isIgnorePostprocessResult()) {
                    return false;
View Full Code Here

     */
    protected Command getCommand(Context context) {

        Catalog catalog = getCatalog(context);

        Command command = null;
        String name = getCommandName(context);
        if (name != null) {
            command = catalog.getCommand(name);
            if ((command == null) && !isOptional()) {
                if (catalogName == null) {
View Full Code Here

            throw new IllegalStateException(
                "Neither 'method' nor 'methodKey' properties are defined "
            );
        }

        Command command = getCommand(context);

        if (command != null) {
            Method methodObject = extractMethod(command, context);
            Object obj = methodObject.invoke(command, getArguments(context));
            Boolean result = (Boolean)obj;
View Full Code Here

        Object top = digester.peek(0);
        if ((top == null)
            || !(top instanceof Command)) {
            return;
        }
        Command command = (Command) top;

        // Is the next object a Catalog or a Chain?
        Object next = digester.peek(1);
        if (next == null) {
            return;
View Full Code Here

    // Test the ability to add commands
    public void testCommands() {

        checkCommandCount(0);

        Command command1 = new NonDelegatingCommand("1");
        chain.addCommand(command1);
        checkCommandCount(1);

        Command command2 = new DelegatingCommand("2");
        chain.addCommand(command2);
        checkCommandCount(2);

        Command command3 = new ExceptionCommand("3");
        chain.addCommand(command3);
        checkCommandCount(3);

    }
View Full Code Here


    // Verify the number of configured commands
    protected void checkCommandCount(int expected) {
        if (chain instanceof ChainBase) {
            Command commands[] = ((ChainBase) chain).getCommands();
            assertNotNull("getCommands() returned a non-null array",
                          commands);
            assertEquals("Correct command count", expected, commands.length);
        }
    }
View Full Code Here

        // Check overall command count
        load(DEFAULT_XML);
        checkCommandCount(17);

        // Check individual single command instances
        Command command = null;

        command = catalog.getCommand("AddingCommand");
        assertNotNull(command);
        assertTrue(command instanceof AddingCommand);
View Full Code Here

     * <p>Test <code>getCatalog()</code> method.</p>
     */
    public void testCatalogIdentifier() {

        Catalog defaultCatalog = new CatalogBase();
        Command defaultFoo = new NonDelegatingCommand();
        defaultCatalog.addCommand("foo", defaultFoo);
        Command fallback = new NonDelegatingCommand();
        defaultCatalog.addCommand("noSuchCatalog:fallback", fallback);

        factory.setCatalog(defaultCatalog);

        Catalog specificCatalog = new CatalogBase();
        Command specificFoo = new NonDelegatingCommand();
        specificCatalog.addCommand("foo", specificFoo);
        factory.addCatalog("specific", specificCatalog);

        Command command = factory.getCommand("foo");
        assertSame(defaultFoo, command);

        command = factory.getCommand("specific:foo");
        assertSame(specificFoo, command);

View Full Code Here

TOP

Related Classes of org.apache.commons.chain.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.