1 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 31 public class DefaultActionMappingStrategy extends ActionMappingStrategy { 32 33 42 public MappingAction getMappingAction( 43 String namespace, 44 String name, 45 Attributes attributes, 46 ReadContext context) 47 throws Exception { 48 MappingAction result = MappingAction.EMPTY; 49 50 ElementDescriptor activeDescriptor = context.getCurrentDescriptor(); 51 if (activeDescriptor != null) { 52 if (activeDescriptor.isHollow()) { 53 if (isArrayDescriptor(activeDescriptor)) { 54 result = ArrayBindAction.createMappingAction(activeDescriptor); 55 } else { 56 result = BeanBindAction.INSTANCE; 57 } 58 } 59 else if (activeDescriptor.isSimple()) 60 { 61 result = SimpleTypeBindAction.INSTANCE; 62 } 63 else 64 { 65 ElementDescriptor[] descriptors 66 = activeDescriptor.getElementDescriptors(); 67 if (descriptors.length == 1) { 68 ElementDescriptor childDescriptor = descriptors[0]; 69 if (childDescriptor.isHollow() 70 && isArrayDescriptor(childDescriptor)) { 71 result = ArrayBindAction.createMappingAction(childDescriptor); 72 } 73 } 74 } 75 } 76 return result; 77 } 78 79 84 private boolean isArrayDescriptor(ElementDescriptor descriptor) { 85 boolean result = false; 86 if (descriptor != null) { 87 Class propertyType = descriptor.getPropertyType(); 88 if (propertyType != null) { 89 result = propertyType.isArray(); 90 } 91 } 92 return result; 93 } 94 } 95 | Popular Tags |