1:
31: package ;
32:
33: import ;
34:
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43:
44:
49: public class SectionReadHandler extends AbstractElementReadHandler
50: {
51: private Section section;
52: private StringBuffer textBuffer;
53: private ArrayList nodes;
54: private ArrayList operationsAfter;
55: private ArrayList operationsBefore;
56: private String repeat;
57:
58: public SectionReadHandler()
59: {
60: nodes = new ArrayList();
61: operationsAfter = new ArrayList();
62: operationsBefore = new ArrayList();
63: }
64:
65:
66: public SectionReadHandler(final Section section)
67: {
68: this();
69: this.section = section;
70: }
71:
72: protected Element getElement()
73: {
74: if (section == null)
75: {
76: section = new Section();
77: }
78: return section;
79: }
80:
81:
87: protected void startParsing(final Attributes attrs) throws SAXException
88: {
89: super.startParsing(attrs);
90:
91: final String repeatValue = attrs.getValue(getUri(), "repeat");
92: if (repeatValue != null)
93: {
94: repeat = repeatValue;
95: }
96:
97: if (FlowReportFactoryModule.NAMESPACE.equals(getUri()) == false)
98: {
99: final Element element = getElement();
100: final int attrLength = attrs.getLength();
101: for (int i = 0; i < attrLength; i++)
102: {
103: final String uri = attrs.getURI(i);
104: final String local = attrs.getLocalName(i);
105: if (FlowReportFactoryModule.NAMESPACE.equals(uri) == false)
106: {
107: element.setAttribute(uri, local, attrs.getValue(i));
108: }
109: }
110: }
111: }
112:
113: protected void configureElement(final Element e)
114: {
115: super.configureElement(e);
116:
117: final Section section = (Section) e;
118: if (repeat != null)
119: {
120: section.setRepeat("true".equals(repeat));
121: }
122: }
123:
124:
132: protected XmlReadHandler getHandlerForChild(final String uri,
133: final String tagName,
134: final Attributes atts)
135: throws SAXException
136: {
137: if (textBuffer != null)
138: {
139: nodes.add(new StaticText(textBuffer.toString()));
140: textBuffer = null;
141: }
142:
143: final XmlReadHandler elementTypeHanders =
144: super.getHandlerForChild(uri, tagName, atts);
145: if (elementTypeHanders != null)
146: {
147: return elementTypeHanders;
148: }
149:
150: if (FlowReportFactoryModule.NAMESPACE.equals(uri))
151: {
152: if ("operation-after".equals(tagName))
153: {
154: final FlowOperationReadHandler frh = new FlowOperationReadHandler();
155: operationsAfter.add(frh);
156: return frh;
157: }
158: else if ("operation-before".equals(tagName))
159: {
160: final FlowOperationReadHandler frh = new FlowOperationReadHandler();
161: operationsBefore.add(frh);
162: return frh;
163: }
164: }
165:
166: final NodeReadHandlerFactory factory = NodeReadHandlerFactory.getInstance();
167: final NodeReadHandler handler = (NodeReadHandler) factory.getHandler(uri, tagName);
168: if (handler != null)
169: {
170: nodes.add(handler);
171: return handler;
172: }
173: return null;
174: }
175:
176:
181: protected void doneParsing() throws SAXException
182: {
183: if (textBuffer != null)
184: {
185: nodes.add(new StaticText(textBuffer.toString()));
186: textBuffer = null;
187: }
188:
189: final Section section = (Section) getElement();
190: configureElement(section);
191:
192: for (int i = 0; i < nodes.size(); i++)
193: {
194: final Object wrapper = nodes.get(i);
195: if (wrapper instanceof StaticText)
196: {
197: section.addNode((StaticText) wrapper);
198: }
199: else if (wrapper instanceof NodeReadHandler)
200: {
201: final NodeReadHandler nr = (NodeReadHandler) wrapper;
202: section.addNode(nr.getNode());
203: }
204: }
205: for (int i = 0; i < operationsAfter.size(); i++)
206: {
207: final FlowOperationReadHandler handler =
208: (FlowOperationReadHandler) operationsAfter.get(i);
209: section.addOperationAfter(handler.getOperation());
210: }
211: for (int i = 0; i < operationsBefore.size(); i++)
212: {
213: final FlowOperationReadHandler handler =
214: (FlowOperationReadHandler) operationsBefore.get(i);
215: section.addOperationBefore(handler.getOperation());
216: }
217: }
218:
219:
220:
221:
229: public void characters(final char[] ch, final int start, final int length)
230: throws SAXException
231: {
232: if (textBuffer == null)
233: {
234: textBuffer = new StringBuffer();
235: }
236: textBuffer.append(ch, start, length);
237: }
238:
239: }