1 package org.apache.torque.generator.configuration.mergepoint;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.ACTION_TAG;
23 import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.MERGEPOINT_NAME_ATTRIBUTE;
24 import static org.apache.torque.generator.configuration.mergepoint.MergepointConfigurationTags.MERGEPOINT_TAG;
25
26 import org.apache.torque.generator.configuration.ConfigurationHandlers;
27 import org.apache.torque.generator.configuration.ConfigurationProvider;
28 import org.apache.torque.generator.configuration.XMLConstants;
29 import org.apache.torque.generator.configuration.paths.ProjectPaths;
30 import org.xml.sax.Attributes;
31 import org.xml.sax.SAXException;
32
33
34
35
36 public class MergepointSaxHandler
37 {
38
39
40
41
42 private MergepointMapping mergepointMapping;
43
44
45
46
47 private ConfigurationProvider configurationProvider;
48
49
50
51
52 private ProjectPaths projectPaths;
53
54
55
56
57 private ConfigurationHandlers configurationHandlers;
58
59
60
61
62
63 private ActionSaxHandler delegateHandler;
64
65
66
67
68 private boolean finished = false;
69
70
71
72
73
74
75
76
77
78
79
80
81 public MergepointSaxHandler(
82 ConfigurationProvider configurationProvider,
83 ProjectPaths projectPaths,
84 ConfigurationHandlers configurationHandlers)
85 {
86 if (configurationProvider == null)
87 {
88 throw new NullPointerException(
89 "configurationProvider must not be null");
90 }
91 if (projectPaths == null)
92 {
93 throw new NullPointerException("projectPaths must not be null");
94 }
95 if (configurationHandlers == null)
96 {
97 throw new NullPointerException(
98 "configurationHandlers must not be null");
99 }
100 this.configurationProvider = configurationProvider;
101 this.projectPaths = projectPaths;
102 this.configurationHandlers = configurationHandlers;
103 }
104
105
106
107
108
109
110
111
112
113
114
115 public MergepointMapping getMergepointMapping()
116 {
117 if (!finished)
118 {
119 throw new IllegalStateException("not finished parsing");
120 }
121 return mergepointMapping;
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144 public void startElement(
145 String uri,
146 String localName,
147 String qName,
148 Attributes attributes)
149 throws SAXException
150 {
151 if (delegateHandler != null)
152 {
153 delegateHandler.startElement(uri, localName, qName, attributes);
154 }
155 else if (MERGEPOINT_TAG.equals(qName))
156 {
157 String name = attributes.getValue(MERGEPOINT_NAME_ATTRIBUTE);
158 if (name == null)
159 {
160 throw new SAXException("The tag "
161 + MERGEPOINT_TAG
162 + " needs to have the attribute "
163 + MERGEPOINT_NAME_ATTRIBUTE);
164 }
165 mergepointMapping = new MergepointMapping(name);
166 }
167 else if (ACTION_TAG.equals(qName))
168 {
169 String type = attributes.getValue(
170 XMLConstants.XSI_NAMESPACE,
171 XMLConstants.XSI_TYPE_ATTRBUTE_NAME);
172 if (type == null)
173 {
174 throw new SAXException("The tag " + ACTION_TAG
175 + " requires the attribute "
176 + XMLConstants.XSI_NAMESPACE
177 + ":"
178 + XMLConstants.XSI_TYPE_ATTRBUTE_NAME);
179 }
180
181 ActionSaxHandlerFactories actionSaxHandlerFactories
182 = configurationHandlers.getActionSaxHandlerFactories();
183 ActionSaxHandlerFactory handlerFactory
184 = actionSaxHandlerFactories.getActionSaxHandlerFactory(type);
185 if (handlerFactory == null)
186 {
187 throw new SAXException("No handler found for the action "
188 + "of type "
189 + type);
190 }
191
192 delegateHandler = handlerFactory.getActionSaxHandler(
193 uri,
194 localName,
195 qName,
196 attributes,
197 configurationProvider,
198 projectPaths);
199 }
200 else
201 {
202 throw new SAXException("unknown element : " + qName);
203 }
204 }
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223 public void endElement(String uri, String localName, String qName)
224 {
225 if (ACTION_TAG.equals(qName))
226 {
227 mergepointMapping.addAction(delegateHandler.getAction());
228 delegateHandler = null;
229 }
230 else if (MERGEPOINT_TAG.equals(qName))
231 {
232 finished = true;
233 }
234 }
235
236
237
238
239
240
241 public boolean isFinished()
242 {
243 return finished;
244 }
245 }