Coverage Report - org.apache.commons.betwixt.strategy.SimpleTypeMapper

Classes in this File Line Coverage Branch Coverage Complexity
SimpleTypeMapper
61% 
100% 
1.6

 1  
 /*
 2  
  * Copyright 2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */ 
 16  
 
 17  
 
 18  
 package org.apache.commons.betwixt.strategy;
 19  
 
 20  
 import org.apache.commons.betwixt.IntrospectionConfiguration;
 21  
 
 22  
 /**
 23  
  * Strategy for binding simple types.
 24  
  * Simple types (in xml) have no attributes or child elements.
 25  
  * For Betwixt, these are converted to and from strings
 26  
  * and these strings used to populate either attributes or element body's.
 27  
  * @author <a href='http://jakarta.apache.org/'>Apache Commons Team</a>
 28  
  * @version $Revision: 155402 $
 29  
  */
 30  4841
 public abstract class SimpleTypeMapper {
 31  
 
 32  
     /**
 33  
      * Enumerates binding options for simple types.
 34  
      * Simple types (in xml) have no attributes or child elements.
 35  
      * For Betwixt, these are converted to and from strings
 36  
      * and these strings used to populate either attributes or element body's.
 37  
      * @author <a href='http://jakarta.apache.org/'>Apache Commons Team</a>
 38  
      * @version $Revision: 155402 $
 39  
      */
 40  663
     public static class Binding {
 41  663
         public static final Binding ELEMENT = new Binding(1);
 42  663
         public static final Binding ATTRIBUTE = new Binding(2);
 43  
         
 44  
         private static final int ELEMENT_CODE = 1;
 45  
         private static final int ATTRIBUTE_CODE = 2;
 46  
         
 47  
         private int code;
 48  1326
         private Binding(int code) {
 49  1326
             this.code = code;
 50  1326
         }
 51  
         
 52  
         
 53  
         /**
 54  
          * Equals compatible with the enumeration.
 55  
          */
 56  
         public boolean equals( Object obj ) {
 57  10036
             boolean result = false;
 58  10036
             if ( obj == this ) {
 59  2886
                 result = true; 
 60  
             }
 61  10036
             return result;
 62  
         }
 63  
 
 64  
         /**
 65  
          * Implementation compatible with equals
 66  
          */
 67  
         public int hashCode() {
 68  0
             return code;
 69  
         }
 70  
 
 71  
         /**
 72  
          * Generate something appropriate for logging.
 73  
          */
 74  
         public String toString() {
 75  0
             String result = "[Binding]";
 76  0
             switch (code) {
 77  
                 case ELEMENT_CODE:
 78  0
                     result = "[Binding: ELEMENT]";
 79  0
                     break;
 80  
                     
 81  
                 case ATTRIBUTE_CODE:
 82  0
                     result = "[Binding: ATTRIBUTE]";
 83  
                     break;
 84  
             }   
 85  0
             return result;
 86  
         }
 87  
     }
 88  
     
 89  
     /**
 90  
      * <p>Specifies the binding of a simple type.
 91  
      * </p><p>
 92  
      * <strong>Note:</strong> the xml name to which this property will be bound
 93  
      * cannot be known at this stage (since it depends
 94  
      * </p>
 95  
      * @param propertyName the name of the property (to be bound)
 96  
      * @param propertyType the type of the property (to be bound)
 97  
      * @param configuration the current IntrospectionConfiguration
 98  
      */
 99  
     public abstract SimpleTypeMapper.Binding bind(
 100  
                                                 String propertyName, 
 101  
                                                 Class propertyType, 
 102  
                                                 IntrospectionConfiguration configuration);
 103  
 }