mindbridge    2005/08/11 21:48:20

  Modified:    framework/src/java/org/apache/tapestry/coerce
                        BooleanArrayToIteratorConverter.java
               framework/src/descriptor/META-INF tapestry.coerce.xml
  Added:       framework/src/java/org/apache/tapestry/coerce
                        NullToListConverter.java
                        ObjectArrayToListConverter.java
                        CharArrayToListConverter.java
                        ObjectToListConverter.java
                        CollectionToListConverter.java
                        BooleanArrayToListConverter.java
  Log:
  Adding List convertions to the possible types of coercions
  
  Revision  Changes    Path
  1.2       +0 -2      
jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/BooleanArrayToIteratorConverter.java
  
  Index: BooleanArrayToIteratorConverter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/BooleanArrayToIteratorConverter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BooleanArrayToIteratorConverter.java      21 Jul 2005 15:43:35 -0000      
1.1
  +++ BooleanArrayToIteratorConverter.java      12 Aug 2005 04:48:20 -0000      
1.2
  @@ -17,8 +17,6 @@
   import java.util.ArrayList;
   import java.util.List;
   
  -import org.apache.tapestry.coerce.TypeConverter;
  -
   /**
    * Converts primitive arrays of booleans to a Iterator (of a List of ) 
Boolean.
    * 
  
  
  
  1.1                  
jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/NullToListConverter.java
  
  Index: NullToListConverter.java
  ===================================================================
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.coerce;
  
  import java.util.Collections;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class NullToListConverter implements TypeConverter
  {
  
      public Object convertValue(Object value)
      {
          return Collections.EMPTY_LIST;
      }
  
  }
  
  
  1.1                  
jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/ObjectArrayToListConverter.java
  
  Index: ObjectArrayToListConverter.java
  ===================================================================
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.coerce;
  
  import java.util.Arrays;
  import java.util.List;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class ObjectArrayToListConverter implements TypeConverter
  {
  
      public Object convertValue(Object value)
      {
          Object[] a = (Object[]) value;
  
          List l = Arrays.asList(a);
  
          return l;
      }
  
  }
  
  
  1.1                  
jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/CharArrayToListConverter.java
  
  Index: CharArrayToListConverter.java
  ===================================================================
  // Copyright 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.coerce;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * @author Laurent ETIEMBLE, Howard M. Lewis Ship
   * @since 4.0
   */
  public class CharArrayToListConverter implements TypeConverter
  {
      public Object convertValue(Object value)
      {
          char[] characters = (char[]) value;
  
          List list = new ArrayList(characters.length);
  
          for (int i = 0; i < characters.length; i++)
          {
              list.add(new Character(characters[i]));
          }
  
          return list;
      }
  
  }
  
  
  
  1.1                  
jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/ObjectToListConverter.java
  
  Index: ObjectToListConverter.java
  ===================================================================
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.coerce;
  
  import java.util.Collections;
  
  /** 
   * Converts a lone object into an Iterator over a list of the one object.
   * 
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class ObjectToListConverter implements TypeConverter
  {
  
      public Object convertValue(Object value)
      {
          return Collections.singletonList(value);
      }
  
  }
  
  
  
  1.1                  
jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/CollectionToListConverter.java
  
  Index: CollectionToListConverter.java
  ===================================================================
  // Copyright 2004, 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.coerce;
  
  import java.util.ArrayList;
  import java.util.Collection;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 4.0
   */
  public class CollectionToListConverter implements TypeConverter
  {
  
      public Object convertValue(Object value)
      {
          Collection c = (Collection) value;
          return new ArrayList(c);
      }
  
  }
  
  
  1.1                  
jakarta-tapestry/framework/src/java/org/apache/tapestry/coerce/BooleanArrayToListConverter.java
  
  Index: BooleanArrayToListConverter.java
  ===================================================================
  // Copyright 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.coerce;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Converts primitive arrays of booleans to a Iterator (of a List of ) 
Boolean.
   * 
   * @author Laurent ETIEMBLE, Howard M. Lewis Ship
   * @since 4.0
   */
  public class BooleanArrayToListConverter implements TypeConverter
  {
  
      public Object convertValue(Object value)
      {
          boolean[] booleans = (boolean[]) value;
  
          List list = new ArrayList(booleans.length);
  
          for (int i = 0; i < booleans.length; i++)
          {
              boolean b = booleans[i];
  
              list.add(b ? Boolean.TRUE : Boolean.FALSE);
          }
  
          return list;
      }
  
  }
  
  
  
  1.8       +20 -0     
jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.coerce.xml
  
  Index: tapestry.coerce.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.coerce.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- tapestry.coerce.xml       21 Jul 2005 15:43:35 -0000      1.7
  +++ tapestry.coerce.xml       12 Aug 2005 04:48:20 -0000      1.8
  @@ -82,6 +82,25 @@
       </invoke-factory>
     </service-point>  
     
  +  <configuration-point id="ListConverters" schema-id="Converters"/>
  +  
  +  <contribution configuration-id="ListConverters">
  +    <converter class="java.lang.Object" 
object="instance:ObjectToListConverter"/>
  +    <converter class="java.util.Collection" 
object="instance:CollectionToListConverter"/>
  +    <converter class="java.lang.Object[]" 
object="instance:ObjectArrayToListConverter"/>
  +    <converter class="char[]" object="instance:CharArrayToListConverter"/>
  +    <converter class="boolean[]" 
object="instance:BooleanArrayToListConverter"/>    
  +  </contribution>
  +  
  +  <service-point id="ListConverter" interface="TypeConverter">
  +    <invoke-factory>
  +      <construct class="TypeConverterWrapper">
  +        <set-configuration property="contributions" 
configuration-id="ListConverters"/>
  +        <set-object property="nullConverter" 
value="instance:NullToListConverter"/>
  +      </construct>
  +    </invoke-factory>
  +  </service-point>  
  +  
     <configuration-point id="TypeConverters" schema-id="Converters">
       
       Defines converters used by the ValueConverter service; the class 
identifies the 
  @@ -93,6 +112,7 @@
     <contribution configuration-id="TypeConverters">
       <converter class="java.lang.Boolean" object="service:BooleanConverter"/>
       <converter class="java.util.Iterator" 
object="service:IteratorConverter"/>
  +    <converter class="java.util.List" object="service:ListConverter"/>
       <converter class="java.lang.String" 
object="instance:ObjectToStringConverter"/>
     </contribution>
     
  
  
  

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

Reply via email to