1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.io.read;
18
19 import org.apache.commons.betwixt.AttributeDescriptor;
20 import org.apache.commons.betwixt.ElementDescriptor;
21 import org.xml.sax.Attributes;
22
23
24
25
26
27
28
29
30 public abstract class MappingAction {
31
32
33 public abstract MappingAction next(
34 String namespace,
35 String name,
36 Attributes attributes,
37 ReadContext context)
38 throws Exception;
39
40
41
42
43
44
45
46
47
48
49
50 public abstract MappingAction begin(
51 String namespace,
52 String name,
53 Attributes attributes,
54 ReadContext context)
55 throws Exception;
56
57
58
59
60
61
62
63 public abstract void body(String text, ReadContext context)
64 throws Exception;
65
66
67
68
69
70
71 public abstract void end(ReadContext context) throws Exception;
72
73 public static final MappingAction EMPTY = new MappingAction.Base();
74
75 public static final MappingAction IGNORE = new MappingAction.Ignore();
76
77 private static final class Ignore extends MappingAction {
78
79 public MappingAction next(String namespace, String name, Attributes attributes, ReadContext context) throws Exception {
80 return this;
81 }
82
83 public MappingAction begin(String namespace, String name, Attributes attributes, ReadContext context) throws Exception {
84 return this;
85 }
86
87 public void body(String text, ReadContext context) throws Exception {
88
89 }
90
91 public void end(ReadContext context) throws Exception {
92
93 }
94
95 }
96
97
98
99
100
101
102
103 public static class Base extends MappingAction {
104
105 public MappingAction next(
106 String namespace,
107 String name,
108 Attributes attributes,
109 ReadContext context)
110 throws Exception {
111
112 return context.getActionMappingStrategy().getMappingAction(namespace, name, attributes, context);
113 }
114
115
116
117
118 public MappingAction begin(
119 String namespace,
120 String name,
121 Attributes attributes,
122 ReadContext context)
123 throws Exception {
124
125
126
127 ElementDescriptor descriptor = context.getCurrentDescriptor();
128 if (descriptor != null) {
129
130 AttributeDescriptor[] attributeDescriptors =
131 descriptor.getAttributeDescriptors();
132 context.populateAttributes(attributeDescriptors, attributes);
133 }
134 return this;
135 }
136
137
138
139
140 public void body(String text, ReadContext context) throws Exception {
141
142 }
143
144
145
146
147 public void end(ReadContext context) throws Exception {
148
149
150
151
152 context.popElement();
153 }
154
155 }
156 }