dion        2003/01/15 07:18:32

  Added:       jelly/jelly-tags/dynabean maven.xml .cvsignore
                        project.properties project.xml
               
jelly/jelly-tags/dynabean/src/test/org/apache/commons/jelly/tags/dynabean
                        suite.jelly TestJelly.java
               
jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean
                        package.html DynabeanTag.java
                        DynabeanTagLibrary.java PropertyTag.java
                        SetTag.java DynaclassTag.java
  Log:
  Move dynabean taglib out of core
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/dynabean/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="java:jar">
  
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/dynabean/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  target
  maven.log
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/project.properties
  
  Index: project.properties
  ===================================================================
  # -------------------------------------------------------------------
  # P R O J E C T  P R O P E R T I E S
  # -------------------------------------------------------------------
  
  maven.junit.fork=true
  
  maven.compile.deprecation = on
  
  # Installation dir
  maven.dist.install.dir = /usr/local/jelly
  
  maven.checkstyle.properties=../tag-checkstyle.properties
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/dynabean/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE project [
    <!-- see file for description -->
    <!ENTITY commonDeps SYSTEM "file:../../commonDependencies.ent">
  ]>
  <project>
    <extend>../tag-project.xml</extend>
    <id>commons-jelly-tags-dynabean</id>
    <name>commons-jelly-tags-dynabean</name>
  
    <package>org.apache.commons.jelly.tags.dynabean</package>
  
    <description>
         The Jelly DynaBean Tag Library
    </description>
    <shortDescription>Commons Jelly Dyna Bean Tag Library</shortDescription>
    
    <url>http://jakarta.apache.org/commons/sandbox/jelly/tags/dynabean/</url>
  
    
<siteDirectory>/www/jakarta.apache.org/commons/sandbox/jelly/dynabean/</siteDirectory>
    
<distributionDirectory>/www/jakarta.apache.org/builds/jakarta-commons-sandbox/jelly/tags/dynabean</distributionDirectory>
    <repository>
      
<connection>scm:cvs:pserver:[EMAIL PROTECTED]:/home/cvspublic:jakarta-commons-sandbox/jelly/jelly-tags/dynabean/</connection>
      
<url>http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/jelly-tags/dynabean/</url>
    </repository>
    
    <dependencies>
    
      &commonDeps;
    
      <!-- START for compilation -->
    
      <dependency>
        <id>commons-jelly</id>
        <version>SNAPSHOT</version>
      </dependency>
        
      <!-- END for compilation -->
      
    </dependencies>
    
  </project>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/test/org/apache/commons/jelly/tags/dynabean/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <test:suite 
        xmlns:j="jelly:core"
        xmlns:dynabean="jelly:dynabean" 
        xmlns:test="jelly:junit" 
        xmlns:log="jelly:log">
  
  <test:case name="simpleDynaBean">
  
    <dynabean:dynaclass var="CustomerType" name ="CustomerDynaClass"> 
                <dynabean:property name="name" type="String" />
                <dynabean:property name="address" type="String" />
        </dynabean:dynaclass>
  
    <dynabean:dynabean var="customer" dynaclass="${CustomerType}"/>
  
    <dynabean:set var="customer" property="name" value="Customer 1" />
    <dynabean:set var="customer" property="address" value="Address of Customer 1" />
  
        <test:assertEquals expected="Customer 1" actual="${customer.name}"/>
        <test:assertEquals expected="Address of Customer 1" 
actual="${customer.address}"/>
        <test:assertEquals expected="CustomerDynaClass" 
actual="${customer.dynaClass.name}"/>
  
  </test:case>
  
  
  <test:case name="nestedDynaBean">
  
    <dynabean:dynaclass var="AddressType" name="AddressDynaClass"> 
        <dynabean:property name="city" type="String" />
        <dynabean:property name="street" type="String" />
        <dynabean:property name="housenumber" type="Integer" />
    </dynabean:dynaclass>
  
    <dynabean:dynaclass var="CustomerType" name="CustomerDynaClass"> 
        <dynabean:property name="name" type="String" />
        <dynabean:property name="address" 
type="org.apache.commons.beanutils.DynaBean"/>
    </dynabean:dynaclass>
  
  
    <dynabean:dynabean var="customer" dynaclass="${CustomerType}" />
    <dynabean:dynabean var="address" dynaclass="${AddressType}" />
  
    <dynabean:set var="customer" property="name" value="Customer 1" />
    <dynabean:set var="customer" property="address" value="${address}" />
    <dynabean:set var="customer" property="address.city" value="London" />
    <dynabean:set var="customer" property="address.street" value="Downing Street" />
    <dynabean:set var="customer" property="address.housenumber" value="10" />
  
        <test:assertEquals expected="Customer 1" actual="${customer.name}"/>
        <test:assertEquals expected="London" actual="${customer.address.city}"/>
        <test:assertEquals expected="Downing Street" 
actual="${customer.address.street}"/>
        
        <!-- #### JellyUnit needs to support type cooercion for this to work...
        <test:assertEquals expected="10" actual="${customer.address.housenumber}"/>
        -->
        
    
  </test:case>
     
  </test:suite>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/test/org/apache/commons/jelly/tags/dynabean/TestJelly.java
  
  Index: TestJelly.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/test/org/apache/commons/jelly/tags/dynabean/TestJelly.java,v
 1.1 2003/01/15 15:18:32 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 15:18:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: TestJelly.java,v 1.1 2003/01/15 15:18:32 dion Exp $
   */
  package org.apache.commons.jelly.tags.dynabean;
  
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.tags.junit.JellyTestSuite;
  
  /** 
   * A helper class to run jelly test cases as part of Ant's JUnit tests
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class TestJelly extends JellyTestSuite {
  
      public static void main( String[] args ) throws Exception {
          TestRunner.run( suite() );
      }
      
      public static TestSuite suite() throws Exception {
          return createTestSuite(TestJelly.class, "suite.jelly");        
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>A tag library for creating new DynaClass and DynaBean objects from the 
    <a href="http://jakarta.apache.org/commons/beanutils.html";>beanutils</a> library
    </p>
    
  </body>
  </html>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/DynabeanTag.java
  
  Index: DynabeanTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/DynabeanTag.java,v
 1.1 2003/01/15 15:18:32 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 15:18:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: DynabeanTag.java,v 1.1 2003/01/15 15:18:32 dion Exp $
   */
  package org.apache.commons.jelly.tags.dynabean;
  
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.commons.beanutils.DynaClass;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  
  /** A tag which conditionally evaluates its body based on some condition
    *
    * @author Theo Niemeijer
    * @version $Revision: 1.1 $
    */
  public class DynabeanTag extends TagSupport {
  
      private DynaClass dynaClass;
      private String var;
  
      public DynabeanTag() {
      }
  
      // Tag interface
      //-------------------------------------------------------------------------
      public void doTag(XMLOutput output) throws Exception {
  
          if (dynaClass == null) {
              throw new MissingAttributeException( "dynaclass" );
          }
  
          if (var == null) {
              throw new MissingAttributeException( "var" );
          }
  
          // Create dynabean instance for this dynaclass
          DynaBean dynaBean = dynaClass.newInstance();
  
          // Place new dynabean in context as a variable
          context.setVariable(getVar(), dynaBean);
      }
  
      // Properties
      //-------------------------------------------------------------------------
      
      /**
       * Sets the DynaClass of the new instance to create
       */
      public void setDynaclass(DynaClass dynaClass) {
          this.dynaClass = dynaClass;
      }
  
      public String getVar() {
          return var;
      }
  
      /**
       * Sets the name of the variable to export the new DynaBean instance to
       */
      public void setVar(String var) {
          this.var = var;
      }
  
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/DynabeanTagLibrary.java
  
  Index: DynabeanTagLibrary.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/DynabeanTagLibrary.java,v
 1.1 2003/01/15 15:18:32 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 15:18:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: DynabeanTagLibrary.java,v 1.1 2003/01/15 15:18:32 dion Exp $
   */
  package org.apache.commons.jelly.tags.dynabean;
  
  import org.apache.commons.jelly.TagLibrary;
  
  /** Describes the Taglib. This class could be generated by XDoclet
    *
    * @author Theo Niemeijer
    * @version $Revision: 1.1 $
    */
  public class DynabeanTagLibrary extends TagLibrary {
  
      public DynabeanTagLibrary() {
          registerTag("dynaclass", DynaclassTag.class);
          registerTag("property", PropertyTag.class);
          registerTag("dynabean", DynabeanTag.class);
          registerTag("set", SetTag.class);
      }
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/PropertyTag.java
  
  Index: PropertyTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/PropertyTag.java,v
 1.1 2003/01/15 15:18:32 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 15:18:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: PropertyTag.java,v 1.1 2003/01/15 15:18:32 dion Exp $
   */
  package org.apache.commons.jelly.tags.dynabean;
  
  import org.apache.commons.beanutils.DynaProperty;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /**
   * DynaProperty tag defines a property of a DynaClass
   * It can only exist inside a DynaClass parent context
   * The properties are added to the properties array
   * of the parent context, and will be used to
   * create the DynaClass object
   * 
   * @author Theo Niemeijer
   * @version 1.0
   */
  public class PropertyTag extends TagSupport {
  
      private String name;
      private String type;
      private Class propertyClass;
      private DynaProperty prop;
  
      public PropertyTag() {
      }
  
      // Tag interface
      //-------------------------------------------------------------------------
      public void doTag (XMLOutput output) throws Exception {
  
          // Check that this tag is used inside the body of
          // a DynaClass tag, so that it can access the
          // context of that tag
          DynaclassTag parentTag = (DynaclassTag) findAncestorWithClass( 
DynaclassTag.class );
          if ( parentTag == null ) {
              throw new JellyException( "This tag must be enclosed inside a 
<dynaclass> tag" );
          }
  
          // Check property name
          if (name == null) {
              throw new MissingAttributeException( "name" );
          }
  
          // Lookup appropriate property class
          Class propClass = propertyClass;
          if (propClass == null) {
              
              // Check property type
              if (type == null) {
                  throw new MissingAttributeException( "type" );
              }
      
              if (type.equals("String")) {
                  propClass = String.class;
              } 
              else if (type.equals("Integer")) {
                  propClass = Integer.TYPE;
              } 
              else if (type.equals("Short")) {
                  propClass = Short.TYPE;
              } 
              else if (type.equals("Long")) {
                  propClass = Long.TYPE;
              } 
              else if (type.equals("Float")) {
                  propClass = Float.TYPE;
              } 
              else if (type.equals("Double")) {
                  propClass = Double.TYPE;
              } 
              else if (type.equals("Long")) {
                  propClass = Long.TYPE;
              }
      
              if (propClass == null) {
                  try {
                      propClass = Class.forName(type);
                  }
                  catch (Exception e) {
                      throw new JellyException
                              ("Class " + type +
                              " not found by Class.forName");
                  }
              }
          }
  
          // Create dynaproperty object with given name and type
          prop = new DynaProperty (name, propClass);
  
          // Add new property to dynaclass context
          parentTag.addDynaProperty(prop);
      }
  
      // Properties
      //-------------------------------------------------------------------------
      
      /**
       * Sets the name of this property
       */
      public void setName(String name) {
          this.name = name;
      }
  
      /**
       * Sets the type name of this property
       */
      public void setType(String type) {
          this.type = type;
      }
      
      /**
       * Returns the Class for this property
       */
      public Class getPropertyClass() {
          return propertyClass;
      }
  
      /**
       * Sets the Class instance for this property
       */
      public void setPropertyClass(Class propertyClass) {
          this.propertyClass = propertyClass;
      }
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/SetTag.java,v
 1.1 2003/01/15 15:18:32 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 15:18:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: SetTag.java,v 1.1 2003/01/15 15:18:32 dion Exp $
   */
  package org.apache.commons.jelly.tags.dynabean;
  
  import java.util.Map;
  
  import org.apache.commons.beanutils.BeanUtils;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** A tag which sets a variable from the result of an expression
    *
   * @author Theo Niemeijer
   * @version 1.0
    */
  public class SetTag extends TagSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(SetTag.class);
  
      /** The variable name to export. */
      private String var;
  
      /** The variable scope to export */
      private String scope;
  
      /** The expression to evaluate. */
      private Expression value;
  
      /** The target object on which to set a property. */
      private Object target;
  
      /** The name of the property to set on the target object. */
      private String property;
  
      public SetTag() {
      }
  
      // Tag interface
      //-------------------------------------------------------------------------
      public void doTag(XMLOutput output) throws Exception {
          Object answer = null;
          if ( value != null ) {
              answer = value.evaluate(context);
          }
          else {
              answer = getBodyText();
          }
  
          // Assume that if a var name and a property is given then
          // var is the name of an object in the context
          if (( var != null )
          && ( property != null)
          && ( target == null ))
          {
              // Get object from context
              if ( scope != null ) {
                 target = context.getVariable(var, scope);
              }
              else {
                  target = context.getVariable(var);
              }
  
              if (target != null) {
                  var = null;
              }
          }
  
          if ( var != null ) {
  
  
              if ( scope != null ) {
                  context.setVariable(var, scope, answer);
              }
              else {
                  context.setVariable(var, answer);
              }
          }
          else {
              if ( target == null ) {
                  throw new JellyException( "Either a 'var' or a 'target' attribute 
must be defined for this tag" );
              }
              if ( property == null ) {
                  throw new JellyException( "You must define a 'property' attribute if 
you specify a 'target'" );
              }
              setPropertyValue( target, property, answer );
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------
      /** Sets the variable name to define for this expression
       */
      public void setVar(String var) {
          this.var = var;
      }
  
      /**
       * Sets the variable scope for this variable. For example setting this value to 
'parent' will
       * set this value in the parent scope. When Jelly is run from inside a Servlet 
environment
       * then other scopes will be available such as 'request', 'session' or 
'application'.
       *
       * Other applications may implement their own custom scopes.
       */
      public void setScope(String scope) {
          this.scope = scope;
      }
  
      /** Sets the expression to evaluate. */
      public void setValue(Expression value) {
          this.value = value;
      }
  
      /** Sets the target object on which to set a property. */
      public void setTarget(Object target) {
          this.target = target;
      }
  
      /** Sets the name of the property to set on the target object. */
      public void setProperty(String property) {
          this.property = property;
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------
      protected void setPropertyValue( Object target, String property, Object value ) 
throws Exception {
          try {
              if ( target instanceof Map ) {
                  Map map = (Map) target;
                  map.put( property, value );
              }
              else {
                  BeanUtils.setProperty( target, property, value );
              }
          }
          catch (Exception e) {
              log.error( "Failed to set the property: " + property + " on bean: " + 
target + " to value: " + value + " due to exception: " + e, e );
          }
      }
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/DynaclassTag.java
  
  Index: DynaclassTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/dynabean/src/java/org/apache/commons/jelly/tags/dynabean/DynaclassTag.java,v
 1.1 2003/01/15 15:18:32 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 15:18:32 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 [EMAIL PROTECTED]
   *
   * 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: DynaclassTag.java,v 1.1 2003/01/15 15:18:32 dion Exp $
   */
  package org.apache.commons.jelly.tags.dynabean;
  
  import java.util.ArrayList;
  
  import org.apache.commons.beanutils.BasicDynaClass;
  import org.apache.commons.beanutils.DynaClass;
  import org.apache.commons.beanutils.DynaProperty;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /**
   * A tag which creates and defines and creates a DynaClass
   * The DynaClass object is placed by name in the context,
   * so that a DynaBean tag can use it by name to instantiate
   * a DynaBean object
   *
   * @author Theo Niemeijer
   * @version 1.0
   */
  public class DynaclassTag extends TagSupport {
  
      private ArrayList propList = new ArrayList();
      private DynaProperty[] props = null;
      private DynaClass dynaClass = null;
  
      private String name;
      private String var;
  
      public DynaclassTag() {
      }
  
      // Tag interface
      //-------------------------------------------------------------------------
      public void doTag(XMLOutput output) throws Exception {
  
          if (name == null) {
              throw new MissingAttributeException("name");
          }
  
          if (var == null) {
              var = name;
          }
  
          // Evaluate the body of the dynaclass definition
          invokeBody(output);
  
          // Convert the list of properties into array
          props =
              (DynaProperty[]) propList.toArray(
                  new DynaProperty[propList.size()]);
  
          if (props == null) {
              throw new JellyException("No properties list");
          }
  
          if (props.length == 0) {
              throw new JellyException("No properties");
          }
  
          // Create the dynaclass with name and properties
          dynaClass = (DynaClass) new BasicDynaClass(name, null, props);
  
          // Place new dynaclass in context
          context.setVariable(getVar(), dynaClass);
      }
  
      // Properties
      //-------------------------------------------------------------------------
      
      /**
       * Sets the name of the new DynaClass 
       */
      public void setName(String name) {
          this.name = name;
      }
  
      public String getVar() {
          return var;
      }
  
      /**
       * Sets the name of the variable to export the DynaClass instance
       */
      public void setVar(String var) {
          this.var = var;
      }
  
      protected void addDynaProperty(DynaProperty prop) {
          propList.add(prop);
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to