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

Classes in this File Line Coverage Branch Coverage Complexity
DefaultActionMappingStrategy
100% 
100% 
5

 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  
 package org.apache.commons.betwixt.strategy;
 18  
 
 19  
 import org.apache.commons.betwixt.ElementDescriptor;
 20  
 import org.apache.commons.betwixt.io.read.ArrayBindAction;
 21  
 import org.apache.commons.betwixt.io.read.BeanBindAction;
 22  
 import org.apache.commons.betwixt.io.read.MappingAction;
 23  
 import org.apache.commons.betwixt.io.read.ReadContext;
 24  
 import org.apache.commons.betwixt.io.read.SimpleTypeBindAction;
 25  
 import org.xml.sax.Attributes;
 26  
 
 27  
 /**
 28  
  * @author <a href='http://jakarta.apache.org/'>Apache Commons Team</a>
 29  
  * @version $Revision: 155402 $
 30  
  */
 31  526
 public class DefaultActionMappingStrategy extends ActionMappingStrategy {
 32  
     
 33  
     /**
 34  
      * Gets the mapping action to map the given element.
 35  
      * @param namespace not null
 36  
      * @param name not null
 37  
      * @param attributes <code>Attributes</code>, not null
 38  
      * @param context <code>ReadContext</code>, not null
 39  
      * @return <code>MappingAction</code>, not null
 40  
      * @throws Exception
 41  
      */
 42  
     public MappingAction getMappingAction(    
 43  
                             String namespace,
 44  
                             String name,
 45  
                             Attributes attributes,
 46  
                             ReadContext context)
 47  
         throws Exception {
 48  7799
         MappingAction result = MappingAction.EMPTY;
 49  
             
 50  7799
         ElementDescriptor activeDescriptor = context.getCurrentDescriptor();
 51  7799
         if (activeDescriptor != null) {
 52  7448
             if (activeDescriptor.isHollow()) {
 53  2825
                 if (isArrayDescriptor(activeDescriptor)) {
 54  104
                     result = ArrayBindAction.createMappingAction(activeDescriptor);
 55  
                 } else {
 56  2721
                     result = BeanBindAction.INSTANCE;
 57  
                 }
 58  
             }
 59  4623
             else if (activeDescriptor.isSimple())
 60  
             {
 61  3739
                 result = SimpleTypeBindAction.INSTANCE;
 62  
             }
 63  
             else
 64  
             {
 65  884
                 ElementDescriptor[] descriptors 
 66  884
                     = activeDescriptor.getElementDescriptors();
 67  884
                 if (descriptors.length == 1) {
 68  637
                     ElementDescriptor childDescriptor = descriptors[0];
 69  637
                     if (childDescriptor.isHollow() 
 70  442
                             && isArrayDescriptor(childDescriptor)) {
 71  39
                         result = ArrayBindAction.createMappingAction(childDescriptor);
 72  
                     }
 73  
                 }
 74  
             }
 75  
         }
 76  7799
         return result;
 77  
     }
 78  
     
 79  
     /**
 80  
      * Is the give
 81  
      * @param descriptor <code>ElementDescriptor</code>, possibly null
 82  
      * @return true if the descriptor describes an array property, if null returns false
 83  
      */
 84  
     private boolean isArrayDescriptor(ElementDescriptor descriptor) {
 85  3267
         boolean result = false;
 86  3267
         if (descriptor != null) {
 87  3267
             Class propertyType = descriptor.getPropertyType();
 88  3267
             if (propertyType != null) {
 89  3107
                 result = propertyType.isArray();
 90  
             }
 91  
         }
 92  3267
         return result;
 93  
     }
 94  
 }