1 16 package org.apache.commons.betwixt.io.read; 17 18 import org.apache.commons.betwixt.AttributeDescriptor; 19 import org.apache.commons.betwixt.ElementDescriptor; 20 import org.xml.sax.Attributes ; 21 22 29 public abstract class MappingAction { 30 31 32 public abstract MappingAction next( 33 String namespace, 34 String name, 35 Attributes attributes, 36 ReadContext context) 37 throws Exception ; 38 39 49 public abstract MappingAction begin( 50 String namespace, 51 String name, 52 Attributes attributes, 53 ReadContext context) 54 throws Exception ; 55 56 62 public abstract void body(String text, ReadContext context) 63 throws Exception ; 64 65 70 public abstract void end(ReadContext context) throws Exception ; 71 72 public static final MappingAction EMPTY = new MappingAction.Base(); 73 74 public static final MappingAction IGNORE = new MappingAction.Ignore(); 75 76 private static final class Ignore extends MappingAction { 77 78 public MappingAction next(String namespace, String name, Attributes attributes, ReadContext context) throws Exception { 79 return this; 80 } 81 82 public MappingAction begin(String namespace, String name, Attributes attributes, ReadContext context) throws Exception { 83 return this; 84 } 85 86 public void body(String text, ReadContext context) throws Exception { 87 } 89 90 public void end(ReadContext context) throws Exception { 91 } 93 94 } 95 96 102 public static class Base extends MappingAction { 103 104 public MappingAction next( 105 String namespace, 106 String name, 107 Attributes attributes, 108 ReadContext context) 109 throws Exception { 110 111 return context.getActionMappingStrategy().getMappingAction(namespace, name, attributes, context); 112 } 113 114 117 public MappingAction begin( 118 String namespace, 119 String name, 120 Attributes attributes, 121 ReadContext context) 122 throws Exception { 123 ElementDescriptor descriptor = context.getCurrentDescriptor(); 127 if (descriptor != null) { 128 129 AttributeDescriptor[] attributeDescriptors = 130 descriptor.getAttributeDescriptors(); 131 context.populateAttributes(attributeDescriptors, attributes); 132 } 133 return this; 134 } 135 136 139 public void body(String text, ReadContext context) throws Exception { 140 } 142 143 146 public void end(ReadContext context) throws Exception { 147 context.popElement(); 152 } 153 154 } 155 } 156 | Popular Tags |