You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2003/04/01 02:05:27 UTC

cvs commit: jakarta-tapestry/junit/mock-scripts TestListEdit.xml

hlship      2003/03/31 16:05:27

  Modified:    framework/src/org/apache/tapestry/util/io DataSqueezer.java
               junit/src/org/apache/tapestry/junit/utils
                        TestDataSqueezer.java
               junit/mock-scripts TestListEdit.xml
  Added:       framework/src/org/apache/tapestry/util/io EnumAdaptor.java
  Log:
  Add EnumAdaptor, a DataSqueezer adaptor for Enum types
  
  Revision  Changes    Path
  1.2       +12 -17    jakarta-tapestry/framework/src/org/apache/tapestry/util/io/DataSqueezer.java
  
  Index: DataSqueezer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/util/io/DataSqueezer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataSqueezer.java	5 Mar 2003 22:59:32 -0000	1.1
  +++ DataSqueezer.java	1 Apr 2003 00:05:27 -0000	1.2
  @@ -99,9 +99,9 @@
        *  Resource resolver used to deserialize classes.
        * 
        **/
  -    
  +
       private IResourceResolver _resolver;
  -    
  +
       /**
        *  Creates a new squeezer with the default set of adaptors.
        *
  @@ -124,7 +124,7 @@
       public DataSqueezer(IResourceResolver resolver, ISqueezeAdaptor[] adaptors)
       {
           _resolver = resolver;
  -        
  +
           registerDefaultAdaptors();
   
           if (adaptors != null)
  @@ -145,6 +145,7 @@
           new BooleanAdaptor().register(this);
           new SerializableAdaptor().register(this);
           new ComponentAddressAdaptor().register(this);
  +        new EnumAdaptor().register(this);
       }
   
       /**
  @@ -157,25 +158,19 @@
        *
        **/
   
  -    public synchronized void register(
  -        String prefix,
  -        Class dataClass,
  -        ISqueezeAdaptor adaptor)
  +    public synchronized void register(String prefix, Class dataClass, ISqueezeAdaptor adaptor)
       {
           int prefixLength = prefix.length();
           int offset;
   
           if (prefixLength < 1)
  -            throw new IllegalArgumentException(
  -                Tapestry.getString("DataSqueezer.short-prefix"));
  +            throw new IllegalArgumentException(Tapestry.getString("DataSqueezer.short-prefix"));
   
           if (dataClass == null)
  -            throw new IllegalArgumentException(
  -                Tapestry.getString("DataSqueezer.null-class"));
  +            throw new IllegalArgumentException(Tapestry.getString("DataSqueezer.null-class"));
   
           if (adaptor == null)
  -            throw new IllegalArgumentException(
  -                Tapestry.getString("DataSqueezer.null-adaptor"));
  +            throw new IllegalArgumentException(Tapestry.getString("DataSqueezer.null-adaptor"));
   
           for (int i = 0; i < prefixLength; i++)
           {
  @@ -329,17 +324,17 @@
   
           return buffer.toString();
       }
  -    
  +
       /**
        *  Returns the resource resolver used with this squeezer.
        * 
        *  @since 2.2
        * 
        **/
  -    
  +
       public IResourceResolver getResolver()
       {
           return _resolver;
       }
  -    
  +
   }
  
  
  
  1.1                  jakarta-tapestry/framework/src/org/apache/tapestry/util/io/EnumAdaptor.java
  
  Index: EnumAdaptor.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation", "Tapestry" 
   *    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" 
   *    or "Tapestry", nor may "Apache" or "Tapestry" appear in their 
   *    name, without prior written permission of the Apache Software Foundation.
   *
   * 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 TAPESTRY CONTRIBUTOR COMMUNITY
   * 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/>.
   *
   */
  
  package org.apache.tapestry.util.io;
  
  import java.io.IOException;
  
  import org.apache.commons.lang.enum.Enum;
  import org.apache.commons.lang.enum.EnumUtils;
  
  /**
   *  Adaptor for {@link Enum} classes.
   *
   *  @author Howard Lewis Ship
   *  @version $Id: EnumAdaptor.java,v 1.1 2003/04/01 00:05:27 hlship Exp $
   *  @since 2.4
   *
   **/
  public class EnumAdaptor implements ISqueezeAdaptor
  {
      private static final String PREFIX = "E";
      private static final char SEPARATOR = '@';
  
      public String squeeze(DataSqueezer squeezer, Object o) throws IOException
      {
          Enum e = (Enum) o;
          return PREFIX + e.getClass().getName() + SEPARATOR + e.getName();
      }
  
      public Object unsqueeze(DataSqueezer squeezer, String str) throws IOException
      {
          int pos = str.indexOf(SEPARATOR);
  
          String className = str.substring(1, pos);
          String name = str.substring(pos + 1, str.length());
  
  		Class enumClass = squeezer.getResolver().findClass(className);
  		
          try
          {        	
              return EnumUtils.getEnum(enumClass, name);
          }
          catch (IllegalArgumentException ex)
          {
              throw new IOException(ex.getMessage());
          }
      }
  
      public void register(DataSqueezer squeezer)
      {
          squeezer.register(PREFIX, Enum.class, this);
      }
  
  }
  
  
  
  1.3       +9 -3      jakarta-tapestry/junit/src/org/apache/tapestry/junit/utils/TestDataSqueezer.java
  
  Index: TestDataSqueezer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/junit/src/org/apache/tapestry/junit/utils/TestDataSqueezer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestDataSqueezer.java	6 Mar 2003 17:19:41 -0000	1.2
  +++ TestDataSqueezer.java	1 Apr 2003 00:05:27 -0000	1.3
  @@ -67,6 +67,7 @@
   import junit.framework.AssertionFailedError;
   import junit.framework.TestCase;
   import org.apache.tapestry.IResourceResolver;
  +import org.apache.tapestry.spec.AssetType;
   import org.apache.tapestry.spec.BeanLifecycle;
   import org.apache.tapestry.util.ComponentAddress;
   import org.apache.tapestry.util.DefaultResourceResolver;
  @@ -176,6 +177,13 @@
           attempt("So long, sucker!", "SSo long, sucker!");
       }
   
  +	/** @since 2.4 **/
  +	
  +	public void testEnum() throws IOException
  +	{
  +		attempt(AssetType.PRIVATE, "Eorg.apache.tapestry.spec.AssetType@PRIVATE");
  +	}
  +
       public void testComponentAddress() throws IOException 
       {
           ComponentAddress objAddress = new ComponentAddress("framework:DirectLink", "component.subcomponent");
  @@ -234,8 +242,6 @@
   
       public void testSerializable() throws IOException
       {
  -        attempt(BeanLifecycle.PAGE, s);
  -        attempt(BeanLifecycle.REQUEST, s);
   
           Map map = new HashMap();
   
  
  
  
  1.4       +4 -4      jakarta-tapestry/junit/mock-scripts/TestListEdit.xml
  
  Index: TestListEdit.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/junit/mock-scripts/TestListEdit.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestListEdit.xml	18 Mar 2003 20:55:29 -0000	1.3
  +++ TestListEdit.xml	1 Apr 2003 00:05:27 -0000	1.4
  @@ -24,7 +24,7 @@
   			<match>name="sp" value="S0"</match>
   			<match>name="Form0" value="e,inputColor,inputColor_0,inputColor_1"</match>			
   			<match>name="e" value="Clothing"</match>
  -			<match>name="e" value="Eye Color"</match>
  +			<match>name="e" value="SEye Color"</match>
   			<match>name="e" value="SFood"</match>
   		</assert-output-matches>
   
  @@ -45,7 +45,7 @@
   		<parameter name="sp" value="S0"/>
   		<parameter name="e">
   			<value>Clothing</value>
  -			<value>Eye Color</value>
  +			<value>SEye Color</value>
   			<value>SFood</value>
   		</parameter>
   		<parameter name="inputColor" value="3"/>
  @@ -76,7 +76,7 @@
   		<parameter name="sp" value="S0"/>
   		<parameter name="e">
   			<value>3Clothing</value>
  -			<value>Eye Color</value>
  +			<value>SEye Color</value>
   			<value>SFood</value>
   		</parameter>
   		<parameter name="inputColor" value="3"/>