rdonkin     2004/09/28 15:21:20

  Modified:    betwixt/src/java/org/apache/commons/betwixt/strategy
                        TypeBindingStrategy.java
               betwixt/src/test/org/apache/commons/betwixt/strategy
                        TestSimpleTypeMapper.java
               betwixt/xdocs tasks.xml
  Log:
  All Throwable subclasses should now be bound as complex tpyes. Patch supplied by 
Christoph Gaffga.
  
  Revision  Changes    Path
  1.2       +48 -9     
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/TypeBindingStrategy.java
  
  Index: TypeBindingStrategy.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/TypeBindingStrategy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeBindingStrategy.java  14 Jul 2004 21:37:54 -0000      1.1
  +++ TypeBindingStrategy.java  28 Sep 2004 22:21:20 -0000      1.2
  @@ -121,6 +121,26 @@
       public static final class Default extends TypeBindingStrategy {
   
           /**
  +         * Class who are simple and whose subclass are also simple
  +         */
  +        private static final Class[] INHERITED_SIMPLE = {
  +                                                        Number.class, 
  +                                                        String.class,
  +                                                        Date.class,
  +                                                        java.sql.Date.class,
  +                                                        java.sql.Time.class,
  +                                                        java.sql.Timestamp.class,
  +                                                        java.math.BigDecimal.class,
  +                                                        java.math.BigInteger.class};
  +                                                        
  +        /**
  +         * Classes who are complex and whose subclasses are also complex
  +         */
  +        private static final Class[] INHERITED_COMPLEX = {
  +                                                                                    
         Throwable.class
  +                                                                     };
  +
  +        /**
            * Gets the binding type to be used for the given Java type.
            * This implementation recognizes all the usual Java primitive wrappers 
            * (plus a few more that will in most typical use cases be regarded in the 
same way). 
  @@ -153,15 +173,34 @@
               } else if ( type.equals( Object.class ) ) {
                   return false;
               }
  -            return type.getName().startsWith( "java.lang." )
  -                || Number.class.isAssignableFrom( type ) 
  -                || String.class.isAssignableFrom( type ) 
  -                || Date.class.isAssignableFrom( type ) 
  -                || java.sql.Date.class.isAssignableFrom( type ) 
  -                || java.sql.Time.class.isAssignableFrom( type ) 
  -                || java.sql.Timestamp.class.isAssignableFrom( type ) 
  -                || java.math.BigDecimal.class.isAssignableFrom( type ) 
  -                || java.math.BigInteger.class.isAssignableFrom( type );
  +            for ( int i=0, size=INHERITED_SIMPLE.length; i<size; i++ ) {
  +                if ( INHERITED_SIMPLE[i].equals( type ) ) {
  +                    return true;
  +                }
  +            }
  +    
  +            for ( int i=0, size=INHERITED_COMPLEX.length; i<size; i++ ) {
  +                if ( INHERITED_COMPLEX[i].equals( type ) ) {
  +                    return false;
  +                }
  +            }
  +            
  +            for ( int i=0, size=INHERITED_COMPLEX.length; i<size; i++ ) {
  +                if ( INHERITED_COMPLEX[i].isAssignableFrom( type ) ) {
  +                    return false;
  +                }
  +            }     
  +            
  +            if (type.getName().startsWith( "java.lang." )) {
  +                return true;
  +            }
  +            
  +            for ( int i=0, size=INHERITED_SIMPLE.length; i<size; i++ ) {
  +                if ( INHERITED_SIMPLE[i].isAssignableFrom( type ) ) {
  +                    return true;
  +                }
  +            }            
  +            return false;
           }
       }
   }
  
  
  
  1.3       +5 -1      
jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestSimpleTypeMapper.java
  
  Index: TestSimpleTypeMapper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestSimpleTypeMapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestSimpleTypeMapper.java 13 Jun 2004 21:32:49 -0000      1.2
  +++ TestSimpleTypeMapper.java 28 Sep 2004 22:21:20 -0000      1.3
  @@ -42,6 +42,10 @@
           super(name);
       }
       
  +    public void testDefaultExceptionType() throws Exception {
  +         assertEquals(TypeBindingStrategy.BindingType.COMPLEX, 
TypeBindingStrategy.DEFAULT.bindingType(RuntimeException.class));
  +    }
  +    
       public void testNewStrategy() throws Exception {
           XMLIntrospector introspector = new XMLIntrospector();
           introspector.getConfiguration().setSimpleTypeMapper(new 
StringsAsElementsSimpleTypeMapper());
  
  
  
  1.36      +5 -0      jakarta-commons/betwixt/xdocs/tasks.xml
  
  Index: tasks.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/tasks.xml,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- tasks.xml 23 Sep 2004 21:46:01 -0000      1.35
  +++ tasks.xml 28 Sep 2004 22:21:20 -0000      1.36
  @@ -196,6 +196,7 @@
               specified within a single document.</li>
               <li><strong>Improved support for derived beans</strong> bind time type
               population now supported and enabled by default</li>
  +            <li>All exceptions are now complex</li>
           </ul>
       </subsection>
       <subsection name='0.6'>
  @@ -448,6 +449,10 @@
   be populated by their bind time type (as opposed to their introspection time type).
   Most users should notice no negative effects from this change. The previous 
behaviour
   can be enabled by setting an introspection configuration property.
  +            </li>
  +            <li>
  +All exceptions are now complex types. This is now more consistent but the default
  +binding for exceptions in java.lang package have been changed from simple to 
complex.
               </li>
           </ul>
       </subsection>
  
  
  

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

Reply via email to