commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define beanSample.jelly Customer.java jellyBeanSample.jelly
Date Wed, 17 Jul 2002 17:38:16 GMT
jstrachan    2002/07/17 10:38:16

  Modified:    jelly/src/test/org/apache/commons/jelly/define
                        jellyBeanSample.jelly
  Added:       jelly/src/test/org/apache/commons/jelly/define
                        beanSample.jelly Customer.java
  Log:
  * Added support for <define:attribute> qualifiers in <define:jellybean> tag
so that default values can be specified, or attributes can be marked as being required.
  
  * also <define:jellybean> now expects an invoke method to be specified, otherwise
an exception is thrown
  
  * the new <define:bean> tag allows regular java beans to be created and bound to a
variable, which is useful for entity based beans such as working with OJB or parsing config
files etc.
  
  There are examples of the above, try running
  
  	maven demo:bean
  	maven demo:jellybean
  
  and it will make much more sense.
  
  Revision  Changes    Path
  1.3       +8 -2      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/jellyBeanSample.jelly
  
  Index: jellyBeanSample.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/jellyBeanSample.jelly,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jellyBeanSample.jelly	5 Jul 2002 07:19:38 -0000	1.2
  +++ jellyBeanSample.jelly	17 Jul 2002 17:38:16 -0000	1.3
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<!-- uses a JellyBean -->
  +<!-- uses a JellyBean, which invokes the run() method -->
   <j:jelly 
   	xmlns:j="jelly:core" 
   	xmlns:define="jelly:define" 
  @@ -12,7 +12,11 @@
     <log:info>Lets define a new tag library</log:info>
     
     <define:taglib uri="myDummyTagLib">  
  -    <define:jellybean name="foo" className="org.apache.commons.jelly.define.MyRunnable"/>
  +  
  +    <define:jellybean name="foo" className="org.apache.commons.jelly.define.MyRunnable">
  +      <define:attribute name="y" defaultValue="wine"/>
  +    </define:jellybean>
  +      
     </define:taglib>
   
     <log:info>Now lets invoke the new Jelly bean tag</log:info>
  @@ -20,6 +24,8 @@
     <my:foo x="2" y="cheese"/>
   
     <log:info>Did that work?</log:info>
  +  
  +  <my:foo x="2"/>
     
   </testcase>
     		
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/beanSample.jelly
  
  Index: beanSample.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- creates a Bean -->
  <j:jelly 
  	xmlns:j="jelly:core" 
  	xmlns:define="jelly:define" 
  	xmlns:log="jelly:log" 
  	xmlns:my="myDummyTagLib">
  	
  <testcase>
  
    <log:info>Lets define a new tag library</log:info>
    
    <define:taglib uri="myDummyTagLib">  
    
    	<!-- 
    	  || map the given bean to a jelly tag 
    	  || we'll specify some required attributes and some default values
    	  -->
    	  
      <define:bean name="customer" className="org.apache.commons.jelly.define.Customer">
  	  <define:attribute name="name" required="true"/>
  	  <define:attribute name="location" defaultValue="UK"/>
  	</define:bean>    	
  	
    </define:taglib>
  
    <log:info>Now lets invoke the new Jelly bean tag</log:info>
    
    <my:customer var="c1" name="James"/>
    
    <log:info>Created a customer with name ${c1.name} and location ${c1.location}</log:info>
  
    <my:customer var="c2" name="Bob" location="US"/>
    
    <log:info>Created a customer with name ${c2.name} and location ${c2.location}</log:info>
  
  		
    <j:catch var="exception">
    	<my:customer location="UK"/>
    </j:catch>
    
    <log:info>Caught exception ${exception} with reason: ${exception.reason}</log:info>
    
    <j:if test="${exception == null}">
    	<log:error>Failed! I should have an exception since I didn't specify a 'name' attribute</log:error>
    </j:if>
    
    
  </testcase>
    		
  </j:jelly>
  
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/Customer.java
  
  Index: Customer.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestCoreTags.java,v
1.8 2002/05/28 07:20:06 jstrachan Exp $
   * $Revision: 1.8 $
   * $Date: 2002/05/28 07:20:06 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: TestCoreTags.java,v 1.8 2002/05/28 07:20:06 jstrachan Exp $
   */
  package org.apache.commons.jelly.define;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** 
   * A sample bean that we can script using &lt;define:bean&gt;
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class Customer {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(Customer.class);
  
      private String name;
      private String city;
      private String location;
      
          
      public Customer() {
      }
      
      
      // Properties
      //-------------------------------------------------------------------------
      /**
       * Returns the city.
       * @return String
       */
      public String getCity() {
          return city;
      }
  
      /**
       * Returns the location.
       * @return String
       */
      public String getLocation() {
          return location;
      }
  
      /**
       * Returns the name.
       * @return String
       */
      public String getName() {
          return name;
      }
  
      /**
       * Sets the city.
       * @param city The city to set
       */
      public void setCity(String city) {
          this.city = city;
      }
  
      /**
       * Sets the location.
       * @param location The location to set
       */
      public void setLocation(String location) {
          this.location = location;
      }
  
      /**
       * Sets the name.
       * @param name The name to set
       */
      public void setName(String name) {
          this.name = name;
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message