Package org.apache.commons.chain

Examples of org.apache.commons.chain.Command


                    ClayContext subContext = (ClayContext) clayContext.clone();
                    subContext.setDisplayElement(valueChangeListener);
                    subContext.setParent(child);

                    Catalog catalog = getCatalog();
                    Command command = catalog
                            .getCommand(Globals.ADD_VALUE_CHANGE_LISTENER_COMMAND_NAME);
                    command.execute(subContext);

                }
            } else {
                log.error(getMessages().getMessage(
                        "assign.valueChangeListener.error",
View Full Code Here


       clayContext.setFacesContext(facesContext);
       clayContext.setChild(child);
       clayContext.setAttribute(attr);
       clayContext.setDisplayElement(displayElement);
             
       Command command = new PropertyValueCommand();
       boolean isFinal = command.execute(clayContext);
       assertEquals("command finished", true, isFinal);      
       assertEquals("value = 10", child.getValue(), "10");

      
       child = (javax.faces.component.html.HtmlOutputText)
                               facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
       assertNotNull("javax.faces.HtmlOutputText", child);
       clayContext.setChild(child);
      
       servletContext.setAttribute("goodYear", "1969");
       attr.setBindingType(AttributeBean.BINDING_TYPE_VALUE);
       attr.setValue("#{goodYear}");

       isFinal = command.execute(clayContext);
       assertEquals("command finished", true, isFinal);      
       assertEquals("value = 1969", "1969", child.getValue());
      
       child = (javax.faces.component.html.HtmlOutputText)
                             facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
       assertNotNull("javax.faces.HtmlOutputText", child);
       clayContext.setChild(child);
      
       servletContext.setAttribute("ping", "pong");
       attr.setBindingType(AttributeBean.BINDING_TYPE_EARLY);
       attr.setValue("#{ping}");

       isFinal = command.execute(clayContext);
       assertEquals("command finished", true, isFinal);      
       assertEquals("value = pong", child.getValue(), "pong");


       child = (javax.faces.component.html.HtmlOutputText)
                               facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
       assertNotNull("javax.faces.HtmlOutputText", child);
       clayContext.setChild(child);
      
       attr.setBindingType(AttributeBean.BINDING_TYPE_NONE);
       attr.setValue("#{forManfred}");

       isFinal = command.execute(clayContext);
       assertEquals("command finished", true, isFinal);      
       assertEquals("value = #{forManfred}", "#{forManfred}", child.getValue());

       
    }
View Full Code Here

           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           Command command = new PropertyValueCommand();
           boolean isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = 10", "10", child.getValue());

          
           // test a symbol value of an el value
           child = (javax.faces.component.html.HtmlOutputText)
                        facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@value", "#{value}"));
           attr.setBindingType(AttributeBean.BINDING_TYPE_EARLY);
           servletContext.setAttribute("value", "10");
         
           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = 10", "10", child.getValue());

          
           // test a symbol value with a null value symbol replacement
           child = (javax.faces.component.html.HtmlOutputText)
                 facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@value", null));
           attr.setBindingType(AttributeBean.BINDING_TYPE_EARLY);
         
           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = null", null, child.getValue());


           // test a symbol value with an empty String value. 
           // this will evaluate to null since it is a symbol replacement.
           child = (javax.faces.component.html.HtmlOutputText)
                     facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@value", ""));
           attr.setBindingType(AttributeBean.BINDING_TYPE_EARLY);
         
           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = null", null, child.getValue());

           //no symbol replacement for a empty string - should return
           //an empty string.  This allows components like the selectItem
           //to create an empty select list pick.
           attr.setValue("")//empty string          
           child = (javax.faces.component.html.HtmlOutputText)
                        facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = \"\"", "", child.getValue());

           //Case insensitive and reoccurring replacement
           attr.setValue("@TeSt1, @tEst1 never @test2; @test1, @teSt1 till ya @tesT3")//test multiple symbols          
           child = (javax.faces.component.html.HtmlOutputText)
                     facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
           assertNotNull("javax.faces.HtmlOutputText", child);

           displayElement.addSymbol(createSymbol("@test1", "rock"));
           displayElement.addSymbol(createSymbol("@test2", "stop"));
           displayElement.addSymbol(createSymbol("@test3", "drop"));

           clayContext.setFacesContext(facesContext);
           clayContext.setChild(child);
           clayContext.setAttribute(attr);
           clayContext.setDisplayElement(displayElement);
           // normally done in the AssignChildrenCommand
           clayContext.setSymbols(displayElement.getSymbols());
          
           isFinal = command.execute(clayContext);
           assertEquals("command finished", true, isFinal);      
           assertEquals("value = \"rock, rock never stop; rock, rock till ya drop\"",
                   "rock, rock never stop; rock, rock till ya drop", child.getValue());

    }
View Full Code Here

        clayContext.setParent(parent);
        clayContext.setDisplayElement(displayElement);
        clayContext.setSymbols(displayElement.getSymbols());
        clayContext.setJspIds(new TreeSet());
               
        Command command = new CreateComponentCommand();
        boolean isFinal = command.execute(clayContext);
        assertEquals("command finished", false, isFinal);
       
        UIComponent child = (UIComponent) clayContext.getChild();
        assertNotNull("child", child);
       
        assertEquals("id = test", "test", child.getId());
       
       
        //null component id symbol replacement
        parent = (UIComponent)
             facesContext.getApplication().createComponent("javax.faces.NamingContainer");
        assertNotNull("javax.faces.NamingContainer", parent);
        parent.setId("parent");
       
        displayElement = new ComponentBean();
        displayElement.setJsfid("inputText");
        displayElement.setComponentType("javax.faces.HtmlOutputText");
        displayElement.setId("@wynn");
        displayElement.addSymbol(createSymbol("@wynn", null));
       
        clayContext = new ClayContext();
        clayContext.setFacesContext(facesContext);
        clayContext.setParent(parent);
        clayContext.setDisplayElement(displayElement);
        clayContext.setSymbols(displayElement.getSymbols());
        clayContext.setJspIds(new TreeSet());
               
        command = new CreateComponentCommand();
        try {
            isFinal = command.execute(clayContext);
            assertTrue("id replacement failed", false);
        } catch (RuntimeException e) {
            assertTrue("null component id",
                    e.getMessage().startsWith("The component symbol substitution failed for id \"@wynn\""));   
        }
       
        //missing component id symbol replacement
        parent = (UIComponent)
             facesContext.getApplication().createComponent("javax.faces.NamingContainer");
        assertNotNull("javax.faces.NamingContainer", parent);
        parent.setId("parent");
       
        displayElement = new ComponentBean();
        displayElement.setJsfid("inputText");
        displayElement.setComponentType("javax.faces.HtmlOutputText");
        displayElement.setId("@wynn");
       
        clayContext = new ClayContext();
        clayContext.setFacesContext(facesContext);
        clayContext.setParent(parent);
        clayContext.setDisplayElement(displayElement);
        clayContext.setSymbols(displayElement.getSymbols());
        clayContext.setJspIds(new TreeSet());
               
        command = new CreateComponentCommand();
        try {
            isFinal = command.execute(clayContext);
            assertTrue("id replacement failed", false);
        } catch (RuntimeException e) {
            assertTrue("missing component id",
                    e.getMessage().startsWith("The component symbol substitution failed for id \"@wynn\""));   
        }
View Full Code Here

        clayContext.setAttribute(attr);
        clayContext.setDisplayElement(displayElement);
        // normally done in the AssignChildrenCommand
        clayContext.setSymbols(displayElement.getSymbols());
               
        Command command = new PropertyValueCommand();
        boolean isFinal = command.execute(clayContext);
        assertEquals("command finished", true, isFinal);      
        assertEquals("value = 6743", "6743", child.getValue());     

   
        //create a target component
        child = (javax.faces.component.html.HtmlOutputText)
                           facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
        assertNotNull("javax.faces.HtmlOutputText", child);

        attr.setValue("@{a}@{ab}")//symbolic attribute
        displayElement.addSymbol(createSymbol("@{ab}", "43"));
        displayElement.addSymbol(createSymbol("@{a}", "67"));

        clayContext.setChild(child);

        isFinal = command.execute(clayContext);
        assertEquals("command finished", true, isFinal);      
        assertEquals("value = 6743", "6743", child.getValue());     


       
        //create a target component
        child = (javax.faces.component.html.HtmlOutputText)
                           facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
        assertNotNull("javax.faces.HtmlOutputText", child);

        attr.setValue("@(a)@(ab)")//symbolic attribute
        displayElement.addSymbol(createSymbol("@(ab)", "43"));
        displayElement.addSymbol(createSymbol("@(a)", "67"));

        clayContext.setChild(child);

        isFinal = command.execute(clayContext);
        assertEquals("command finished", true, isFinal);      
        assertEquals("value = 6743", "6743", child.getValue());     
       
       
    }
View Full Code Here

                    ClayContext subContext = (ClayContext) clayContext.clone();
                    subContext.setDisplayElement(actionListener);
                    subContext.setParent(child);

                    Catalog catalog = getCatalog();
                    Command command = catalog
                            .getCommand(Globals.ADD_ACTION_LISTENER_COMMAND_NAME);
                    command.execute(subContext);

                }
            } else {
                log.error(getMessages().getMessage("assign.action.listener.error",
                        new Object[] { displayElement }));
View Full Code Here

            subContext.setChild(null);
            subContext.setChildIndex(childIndex);
            subContext.setJspIds(clayContext.getJspIds());

            Catalog catalog = getCatalog();
            Command command = catalog
                    .getCommand(Globals.ADD_COMPONENT_COMMAND_NAME);
            command.execute(subContext);

            UIComponent child = (UIComponent) subContext.getChild();

            // Increment the index if the new component is not a facet
            if (parent.getChildren().contains(child)) {
View Full Code Here

        Iterator ai = displayElement.getAttributeIterator();
        Catalog defaultCatalog = getCatalog();
        Catalog customizationCatalog = getCustomizationCatalog();

        Command defaultCommand = defaultCatalog.getCommand(Globals.SET_ATTRIBUTE_COMMAND_NAME);
        next: while (ai.hasNext()) {
            AttributeBean a = (AttributeBean) ai.next();
            if (a.getValue() == null) {
               continue next;
            }

            Command command = null;
            //look for a command override in the customization catalog first
            if (customizationCatalog != null) {
                command = customizationCatalog.getCommand(a.getName());
            }
            //look for a command override in the defaut catalog
            if (command == null) {
               command = defaultCatalog.getCommand(a.getName());
            }
            //use the default command
            if (command == null) {
               command = defaultCommand;
            }

            clayContext.setAttribute(a);

            try {
                command.execute(clayContext);
            } catch (Exception e) {
                log.error(getMessages().getMessage("assign.property.error",
                        new Object[] { a }), e);
                        throw e;
View Full Code Here

                    ClayContext subContext = (ClayContext) clayContext.clone();
                    subContext.setDisplayElement(validator);
                    subContext.setParent(child);

                    Catalog catalog = getCatalog();
                    Command command = catalog
                            .getCommand(Globals.ADD_VALIDATOR_COMMAND_NAME);
                    command.execute(subContext);

                }
            } else {
                log.error(getMessages().getMessage("assign.validator.error",
                        new Object[] { displayElement }));
View Full Code Here

                ClayContext subContext = (ClayContext) clayContext.clone();
                subContext.setDisplayElement(displayElement.getConverter());
                subContext.setParent(child);

                Catalog catalog = getCatalog();
                Command command = catalog
                        .getCommand(Globals.ADD_CONVERTER_COMMAND_NAME);
                command.execute(subContext);

            } else {
                log.error(getMessages().getMessage("assign.converter.error",
                        new Object[] { displayElement }));
            }
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.