1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
package org.apache.hivemind.parse;
|
16
|
|
|
17
|
|
import java.io.BufferedInputStream;
|
18
|
|
import java.io.IOException;
|
19
|
|
import java.io.InputStream;
|
20
|
|
import java.util.Enumeration;
|
21
|
|
import java.util.HashMap;
|
22
|
|
import java.util.Iterator;
|
23
|
|
import java.util.Map;
|
24
|
|
import java.util.Properties;
|
25
|
|
|
26
|
|
import org.apache.commons.logging.Log;
|
27
|
|
import org.apache.commons.logging.LogFactory;
|
28
|
|
import org.apache.hivemind.ApplicationRuntimeException;
|
29
|
|
import org.apache.hivemind.Attribute;
|
30
|
|
import org.apache.hivemind.ClassResolver;
|
31
|
|
import org.apache.hivemind.ErrorHandler;
|
32
|
|
import org.apache.hivemind.Occurances;
|
33
|
|
import org.apache.hivemind.Resource;
|
34
|
|
import org.apache.hivemind.impl.AttributeImpl;
|
35
|
|
import org.apache.hivemind.impl.ElementImpl;
|
36
|
|
import org.apache.hivemind.internal.Visibility;
|
37
|
|
import org.apache.hivemind.schema.ElementModel;
|
38
|
|
import org.apache.hivemind.schema.Rule;
|
39
|
|
import org.apache.hivemind.schema.impl.AttributeModelImpl;
|
40
|
|
import org.apache.hivemind.schema.impl.ElementModelImpl;
|
41
|
|
import org.apache.hivemind.schema.impl.SchemaImpl;
|
42
|
|
import org.apache.hivemind.schema.rules.CreateObjectRule;
|
43
|
|
import org.apache.hivemind.schema.rules.InvokeParentRule;
|
44
|
|
import org.apache.hivemind.schema.rules.PushAttributeRule;
|
45
|
|
import org.apache.hivemind.schema.rules.ReadAttributeRule;
|
46
|
|
import org.apache.hivemind.schema.rules.ReadContentRule;
|
47
|
|
import org.apache.hivemind.schema.rules.SetModuleRule;
|
48
|
|
import org.apache.hivemind.schema.rules.SetParentRule;
|
49
|
|
import org.apache.hivemind.schema.rules.SetPropertyRule;
|
50
|
|
import org.apache.hivemind.util.IdUtils;
|
51
|
|
import org.apache.oro.text.regex.MalformedPatternException;
|
52
|
|
import org.apache.oro.text.regex.Pattern;
|
53
|
|
import org.apache.oro.text.regex.Perl5Compiler;
|
54
|
|
import org.apache.oro.text.regex.Perl5Matcher;
|
55
|
|
import org.xml.sax.Attributes;
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
|
|
65
|
|
public final class DescriptorParser extends AbstractParser
|
66
|
|
{
|
67
|
|
private static final String DEFAULT_SERVICE_MODEL = "singleton";
|
68
|
|
|
69
|
|
private static final Log LOG = LogFactory.getLog(DescriptorParser.class);
|
70
|
|
|
71
|
|
|
72
|
|
|
73
|
|
|
74
|
|
|
75
|
|
private static final int STATE_START = 0;
|
76
|
|
|
77
|
|
private static final int STATE_MODULE = 1;
|
78
|
|
|
79
|
|
|
80
|
|
private static final int STATE_CONFIGURATION_POINT = 3;
|
81
|
|
|
82
|
|
private static final int STATE_CONTRIBUTION = 4;
|
83
|
|
|
84
|
|
private static final int STATE_SERVICE_POINT = 5;
|
85
|
|
|
86
|
|
private static final int STATE_CREATE_INSTANCE = 6;
|
87
|
|
|
88
|
|
private static final int STATE_IMPLEMENTATION = 8;
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
|
private static final int STATE_SCHEMA = 9;
|
95
|
|
|
96
|
|
private static final int STATE_ELEMENT = 10;
|
97
|
|
|
98
|
|
private static final int STATE_RULES = 11;
|
99
|
|
|
100
|
|
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
private static final int STATE_COLLECT_SERVICE_PARAMETERS = 12;
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
|
109
|
|
|
110
|
|
private static final int STATE_CONVERSION = 13;
|
111
|
|
|
112
|
|
|
113
|
|
|
114
|
|
|
115
|
|
|
116
|
|
private static final int STATE_LWDOM = 100;
|
117
|
|
|
118
|
|
|
119
|
|
|
120
|
|
|
121
|
|
|
122
|
|
private static final int STATE_NO_CONTENT = 300;
|
123
|
|
|
124
|
|
private static final String SIMPLE_ID = "[a-zA-Z0-9_]+";
|
125
|
|
|
126
|
|
|
127
|
|
|
128
|
|
|
129
|
|
|
130
|
|
|
131
|
|
public static final String ID_PATTERN = "^" + SIMPLE_ID + "$";
|
132
|
|
|
133
|
|
|
134
|
|
|
135
|
|
|
136
|
|
|
137
|
|
public static final String MODULE_ID_PATTERN = "^" + SIMPLE_ID + "(\\." + SIMPLE_ID + ")*$";
|
138
|
|
|
139
|
|
public static final String VERSION_PATTERN = "[0-9]+(\\.[0-9]+){2}$";
|
140
|
|
|
141
|
|
|
142
|
|
|
143
|
|
|
144
|
|
private Map _attributes = new HashMap();
|
145
|
|
|
146
|
|
|
147
|
|
|
148
|
|
|
149
|
|
|
150
|
|
|
151
|
|
private Map _elementParseInfo = new HashMap();
|
152
|
|
|
153
|
|
private ModuleDescriptor _moduleDescriptor;
|
154
|
|
|
155
|
|
private ErrorHandler _errorHandler;
|
156
|
|
|
157
|
|
private ClassResolver _resolver;
|
158
|
|
|
159
|
|
private Perl5Compiler _compiler;
|
160
|
|
|
161
|
|
private Perl5Matcher _matcher;
|
162
|
|
|
163
|
|
private Map _compiledPatterns;
|
164
|
|
|
165
|
|
|
166
|
|
|
167
|
|
|
168
|
|
private final Map _ruleMap = new HashMap();
|
169
|
|
|
170
|
|
private final Map OCCURS_MAP = new HashMap();
|
171
|
|
|
172
|
|
{
|
173
|
241
|
OCCURS_MAP.put("0..1", Occurances.OPTIONAL);
|
174
|
241
|
OCCURS_MAP.put("1", Occurances.REQUIRED);
|
175
|
241
|
OCCURS_MAP.put("1..n", Occurances.ONE_PLUS);
|
176
|
241
|
OCCURS_MAP.put("0..n", Occurances.UNBOUNDED);
|
177
|
241
|
OCCURS_MAP.put("none", Occurances.NONE);
|
178
|
|
}
|
179
|
|
|
180
|
|
private final Map VISIBILITY_MAP = new HashMap();
|
181
|
|
|
182
|
|
{
|
183
|
241
|
VISIBILITY_MAP.put("public", Visibility.PUBLIC);
|
184
|
241
|
VISIBILITY_MAP.put("private", Visibility.PRIVATE);
|
185
|
|
}
|
186
|
|
|
187
|
241
|
public DescriptorParser(ErrorHandler errorHandler)
|
188
|
|
{
|
189
|
241
|
_errorHandler = errorHandler;
|
190
|
|
|
191
|
241
|
initializeFromPropertiesFile();
|
192
|
|
}
|
193
|
|
|
194
|
37335
|
public void begin(String elementName, Map attributes)
|
195
|
|
{
|
196
|
37335
|
_attributes = attributes;
|
197
|
|
|
198
|
37335
|
switch (getState())
|
199
|
|
{
|
200
|
|
case STATE_START:
|
201
|
|
|
202
|
253
|
beginStart(elementName);
|
203
|
253
|
break;
|
204
|
|
|
205
|
|
case STATE_MODULE:
|
206
|
|
|
207
|
4188
|
beginModule(elementName);
|
208
|
4188
|
break;
|
209
|
|
|
210
|
|
case STATE_CONFIGURATION_POINT:
|
211
|
|
|
212
|
674
|
beginConfigurationPoint(elementName);
|
213
|
674
|
break;
|
214
|
|
|
215
|
|
case STATE_CONTRIBUTION:
|
216
|
|
|
217
|
2692
|
beginContribution(elementName);
|
218
|
2692
|
break;
|
219
|
|
|
220
|
|
case STATE_LWDOM:
|
221
|
|
|
222
|
1069
|
beginLWDom(elementName);
|
223
|
1069
|
break;
|
224
|
|
|
225
|
|
case STATE_SERVICE_POINT:
|
226
|
|
|
227
|
2401
|
beginServicePoint(elementName);
|
228
|
2401
|
break;
|
229
|
|
|
230
|
|
case STATE_IMPLEMENTATION:
|
231
|
|
|
232
|
18
|
beginImplementation(elementName);
|
233
|
18
|
break;
|
234
|
|
|
235
|
|
case STATE_SCHEMA:
|
236
|
|
|
237
|
1216
|
beginSchema(elementName);
|
238
|
1215
|
break;
|
239
|
|
|
240
|
|
case STATE_ELEMENT:
|
241
|
|
|
242
|
10367
|
beginElement(elementName);
|
243
|
10366
|
break;
|
244
|
|
|
245
|
|
case STATE_RULES:
|
246
|
|
|
247
|
12600
|
beginRules(elementName);
|
248
|
12599
|
break;
|
249
|
|
|
250
|
|
case STATE_COLLECT_SERVICE_PARAMETERS:
|
251
|
|
|
252
|
1069
|
beginCollectServiceParameters(elementName);
|
253
|
1069
|
break;
|
254
|
|
|
255
|
|
case STATE_CONVERSION:
|
256
|
|
|
257
|
788
|
beginConversion(elementName);
|
258
|
788
|
break;
|
259
|
|
|
260
|
|
default:
|
261
|
|
|
262
|
0
|
unexpectedElement(elementName);
|
263
|
0
|
break;
|
264
|
|
}
|
265
|
|
}
|
266
|
|
|
267
|
|
|
268
|
|
|
269
|
|
|
270
|
|
|
271
|
|
|
272
|
|
|
273
|
|
|
274
|
1069
|
private void beginCollectServiceParameters(String elementName)
|
275
|
|
{
|
276
|
1069
|
ElementImpl element = buildLWDomElement(elementName);
|
277
|
|
|
278
|
1069
|
AbstractServiceInvocationDescriptor sid = (AbstractServiceInvocationDescriptor) peekObject();
|
279
|
|
|
280
|
1069
|
sid.addParameter(element);
|
281
|
|
|
282
|
1069
|
push(elementName, element, STATE_LWDOM, false);
|
283
|
|
}
|
284
|
|
|
285
|
|
|
286
|
|
|
287
|
|
|
288
|
674
|
private void beginConfigurationPoint(String elementName)
|
289
|
|
{
|
290
|
674
|
if (elementName.equals("schema"))
|
291
|
|
{
|
292
|
674
|
enterEmbeddedConfigurationPointSchema(elementName);
|
293
|
674
|
return;
|
294
|
|
}
|
295
|
|
|
296
|
0
|
unexpectedElement(elementName);
|
297
|
|
}
|
298
|
|
|
299
|
2692
|
private void beginContribution(String elementName)
|
300
|
|
{
|
301
|
|
|
302
|
|
|
303
|
2692
|
ElementImpl element = buildLWDomElement(elementName);
|
304
|
|
|
305
|
2692
|
ContributionDescriptor ed = (ContributionDescriptor) peekObject();
|
306
|
2692
|
ed.addElement(element);
|
307
|
|
|
308
|
2692
|
push(elementName, element, STATE_LWDOM, false);
|
309
|
|
}
|
310
|
|
|
311
|
788
|
private void beginConversion(String elementName)
|
312
|
|
{
|
313
|
788
|
if (elementName.equals("map"))
|
314
|
|
{
|
315
|
788
|
ConversionDescriptor cd = (ConversionDescriptor) peekObject();
|
316
|
|
|
317
|
788
|
AttributeMappingDescriptor amd = new AttributeMappingDescriptor();
|
318
|
|
|
319
|
788
|
push(elementName, amd, STATE_NO_CONTENT);
|
320
|
|
|
321
|
788
|
checkAttributes();
|
322
|
|
|
323
|
788
|
amd.setAttributeName(getAttribute("attribute"));
|
324
|
788
|
amd.setPropertyName(getAttribute("property"));
|
325
|
|
|
326
|
788
|
cd.addAttributeMapping(amd);
|
327
|
|
|
328
|
788
|
return;
|
329
|
|
}
|
330
|
|
|
331
|
0
|
unexpectedElement(elementName);
|
332
|
|
}
|
333
|
|
|
334
|
10367
|
private void beginElement(String elementName)
|
335
|
|
{
|
336
|
10367
|
if (elementName.equals("attribute"))
|
337
|
|
{
|
338
|
4479
|
enterAttribute(elementName);
|
339
|
4479
|
return;
|
340
|
|
}
|
341
|
|
|
342
|
5888
|
if (elementName.equals("conversion"))
|
343
|
|
{
|
344
|
461
|
enterConversion(elementName);
|
345
|
461
|
return;
|
346
|
|
}
|
347
|
|
|
348
|
5427
|
if (elementName.equals("rules"))
|
349
|
|
{
|
350
|
3084
|
enterRules(elementName);
|
351
|
3084
|
return;
|
352
|
|
}
|
353
|
|
|
354
|
|
|
355
|
|
|
356
|
2343
|
if (elementName.equals("element"))
|
357
|
|
{
|
358
|
2342
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
359
|
|
|
360
|
2342
|
elementModel.addElementModel(enterElement(elementName));
|
361
|
2342
|
return;
|
362
|
|
}
|
363
|
|
|
364
|
1
|
unexpectedElement(elementName);
|
365
|
|
}
|
366
|
|
|
367
|
2305
|
private void beginImplementation(String elementName)
|
368
|
|
{
|
369
|
|
|
370
|
2305
|
if (elementName.equals("create-instance"))
|
371
|
|
{
|
372
|
1063
|
enterCreateInstance(elementName);
|
373
|
1063
|
return;
|
374
|
|
}
|
375
|
|
|
376
|
1242
|
if (elementName.equals("invoke-factory"))
|
377
|
|
{
|
378
|
1176
|
enterInvokeFactory(elementName);
|
379
|
1176
|
return;
|
380
|
|
}
|
381
|
|
|
382
|
66
|
if (elementName.equals("interceptor"))
|
383
|
|
{
|
384
|
66
|
enterInterceptor(elementName);
|
385
|
66
|
return;
|
386
|
|
}
|
387
|
|
|
388
|
0
|
unexpectedElement(elementName);
|
389
|
|
}
|
390
|
|
|
391
|
1069
|
private void beginLWDom(String elementName)
|
392
|
|
{
|
393
|
1069
|
ElementImpl element = buildLWDomElement(elementName);
|
394
|
|
|
395
|
1069
|
ElementImpl parent = (ElementImpl) peekObject();
|
396
|
1069
|
parent.addElement(element);
|
397
|
|
|
398
|
1069
|
push(elementName, element, STATE_LWDOM, false);
|
399
|
|
}
|
400
|
|
|
401
|
|
|
402
|
|
|
403
|
|
|
404
|
4188
|
private void beginModule(String elementName)
|
405
|
|
{
|
406
|
4188
|
if (elementName.equals("configuration-point"))
|
407
|
|
{
|
408
|
964
|
enterConfigurationPoint(elementName);
|
409
|
|
|
410
|
964
|
return;
|
411
|
|
}
|
412
|
|
|
413
|
3224
|
if (elementName.equals("contribution"))
|
414
|
|
{
|
415
|
638
|
enterContribution(elementName);
|
416
|
638
|
return;
|
417
|
|
}
|
418
|
|
|
419
|
2586
|
if (elementName.equals("service-point"))
|
420
|
|
{
|
421
|
2255
|
enterServicePoint(elementName);
|
422
|
|
|
423
|
2255
|
return;
|
424
|
|
}
|
425
|
|
|
426
|
331
|
if (elementName.equals("implementation"))
|
427
|
|
{
|
428
|
16
|
enterImplementation(elementName);
|
429
|
|
|
430
|
16
|
return;
|
431
|
|
}
|
432
|
|
|
433
|
315
|
if (elementName.equals("schema"))
|
434
|
|
{
|
435
|
302
|
enterSchema(elementName);
|
436
|
302
|
return;
|
437
|
|
}
|
438
|
|
|
439
|
13
|
if (elementName.equals("sub-module"))
|
440
|
|
{
|
441
|
3
|
enterSubModule(elementName);
|
442
|
|
|
443
|
3
|
return;
|
444
|
|
}
|
445
|
|
|
446
|
10
|
if (elementName.equals("dependency"))
|
447
|
|
{
|
448
|
10
|
enterDependency(elementName);
|
449
|
|
|
450
|
10
|
return;
|
451
|
|
}
|
452
|
|
|
453
|
0
|
unexpectedElement(elementName);
|
454
|
|
}
|
455
|
|
|
456
|
12600
|
private void beginRules(String elementName)
|
457
|
|
{
|
458
|
|
|
459
|
12600
|
if (elementName.equals("create-object"))
|
460
|
|
{
|
461
|
3408
|
enterCreateObject(elementName);
|
462
|
3408
|
return;
|
463
|
|
}
|
464
|
|
|
465
|
9192
|
if (elementName.equals("invoke-parent"))
|
466
|
|
{
|
467
|
3740
|
enterInvokeParent(elementName);
|
468
|
3740
|
return;
|
469
|
|
}
|
470
|
|
|
471
|
5452
|
if (elementName.equals("read-attribute"))
|
472
|
|
{
|
473
|
2658
|
enterReadAttribute(elementName);
|
474
|
2658
|
return;
|
475
|
|
}
|
476
|
|
|
477
|
2794
|
if (elementName.equals("read-content"))
|
478
|
|
{
|
479
|
915
|
enterReadContent(elementName);
|
480
|
915
|
return;
|
481
|
|
}
|
482
|
|
|
483
|
1879
|
if (elementName.equals("set-module"))
|
484
|
|
{
|
485
|
10
|
enterSetModule(elementName);
|
486
|
10
|
return;
|
487
|
|
}
|
488
|
|
|
489
|
1869
|
if (elementName.equals("set-property"))
|
490
|
|
{
|
491
|
1521
|
enterSetProperty(elementName);
|
492
|
1521
|
return;
|
493
|
|
}
|
494
|
|
|
495
|
348
|
if (elementName.equals("push-attribute"))
|
496
|
|
{
|
497
|
334
|
enterPushAttribute(elementName);
|
498
|
334
|
return;
|
499
|
|
}
|
500
|
|
|
501
|
14
|
if (elementName.equals("set-parent"))
|
502
|
|
{
|
503
|
12
|
enterSetParent(elementName);
|
504
|
12
|
return;
|
505
|
|
}
|
506
|
|
|
507
|
2
|
if (elementName.equals("custom"))
|
508
|
|
{
|
509
|
2
|
enterCustom(elementName);
|
510
|
|
|
511
|
1
|
return;
|
512
|
|
}
|
513
|
|
|
514
|
0
|
unexpectedElement(elementName);
|
515
|
|
}
|
516
|
|
|
517
|
1216
|
private void beginSchema(String elementName)
|
518
|
|
{
|
519
|
1216
|
if (elementName.equals("element"))
|
520
|
|
{
|
521
|
1216
|
SchemaImpl schema = (SchemaImpl) peekObject();
|
522
|
|
|
523
|
1216
|
schema.addElementModel(enterElement(elementName));
|
524
|
1215
|
return;
|
525
|
|
}
|
526
|
|
|
527
|
0
|
unexpectedElement(elementName);
|
528
|
|
}
|
529
|
|
|
530
|
2401
|
private void beginServicePoint(String elementName)
|
531
|
|
{
|
532
|
2401
|
if (elementName.equals("parameters-schema"))
|
533
|
|
{
|
534
|
114
|
enterParametersSchema(elementName);
|
535
|
114
|
return;
|
536
|
|
}
|
537
|
|
|
538
|
|
|
539
|
|
|
540
|
2287
|
beginImplementation(elementName);
|
541
|
|
}
|
542
|
|
|
543
|
|
|
544
|
|
|
545
|
|
|
546
|
253
|
private void beginStart(String elementName)
|
547
|
|
{
|
548
|
253
|
if (!elementName.equals("module"))
|
549
|
0
|
throw new ApplicationRuntimeException(ParseMessages.notModule(
|
550
|
|
elementName,
|
551
|
|
getLocation()), getLocation(), null);
|
552
|
|
|
553
|
253
|
ModuleDescriptor md = new ModuleDescriptor(_resolver, _errorHandler);
|
554
|
|
|
555
|
253
|
push(elementName, md, STATE_MODULE);
|
556
|
|
|
557
|
253
|
checkAttributes();
|
558
|
|
|
559
|
253
|
md.setModuleId(getValidatedAttribute("id", MODULE_ID_PATTERN, "module-id-format"));
|
560
|
253
|
md.setVersion(getValidatedAttribute("version", VERSION_PATTERN, "version-format"));
|
561
|
|
|
562
|
253
|
String packageName = getAttribute("package");
|
563
|
253
|
if (packageName == null)
|
564
|
139
|
packageName = md.getModuleId();
|
565
|
|
|
566
|
253
|
md.setPackageName(packageName);
|
567
|
|
|
568
|
|
|
569
|
|
|
570
|
253
|
_moduleDescriptor = md;
|
571
|
|
}
|
572
|
|
|
573
|
32504
|
protected void push(String elementName, Object object, int state)
|
574
|
|
{
|
575
|
32504
|
if (object instanceof AnnotationHolder)
|
576
|
16337
|
super.push(elementName, object, state, false);
|
577
|
|
else
|
578
|
16167
|
super.push(elementName, object, state, true);
|
579
|
|
}
|
580
|
|
|
581
|
4830
|
private ElementImpl buildLWDomElement(String elementName)
|
582
|
|
{
|
583
|
4830
|
ElementImpl result = new ElementImpl();
|
584
|
4830
|
result.setElementName(elementName);
|
585
|
|
|
586
|
4830
|
Iterator i = _attributes.entrySet().iterator();
|
587
|
4830
|
while (i.hasNext())
|
588
|
|
{
|
589
|
8274
|
Map.Entry entry = (Map.Entry) i.next();
|
590
|
|
|
591
|
8274
|
String name = (String) entry.getKey();
|
592
|
8274
|
String value = (String) entry.getValue();
|
593
|
|
|
594
|
8274
|
Attribute a = new AttributeImpl(name, value);
|
595
|
|
|
596
|
8274
|
result.addAttribute(a);
|
597
|
|
}
|
598
|
|
|
599
|
4830
|
return result;
|
600
|
|
}
|
601
|
|
|
602
|
28746
|
private void checkAttributes()
|
603
|
|
{
|
604
|
28746
|
checkAttributes(peekElementName());
|
605
|
|
}
|
606
|
|
|
607
|
|
|
608
|
|
|
609
|
|
|
610
|
|
|
611
|
29420
|
private void checkAttributes(String elementName)
|
612
|
|
{
|
613
|
29420
|
Iterator i = _attributes.keySet().iterator();
|
614
|
|
|
615
|
29420
|
ElementParseInfo epi = (ElementParseInfo) _elementParseInfo.get(elementName);
|
616
|
|
|
617
|
|
|
618
|
|
|
619
|
29420
|
if (epi == null)
|
620
|
|
{
|
621
|
233
|
epi = new ElementParseInfo();
|
622
|
233
|
_elementParseInfo.put(elementName, epi);
|
623
|
|
}
|
624
|
|
|
625
|
|
|
626
|
|
|
627
|
29420
|
while (i.hasNext())
|
628
|
|
{
|
629
|
44691
|
String name = (String) i.next();
|
630
|
|
|
631
|
44691
|
if (!epi.isKnown(name))
|
632
|
1
|
_errorHandler.error(
|
633
|
|
LOG,
|
634
|
|
ParseMessages.unknownAttribute(name, getElementPath()),
|
635
|
|
getLocation(),
|
636
|
|
null);
|
637
|
|
}
|
638
|
|
|
639
|
|
|
640
|
|
|
641
|
29420
|
i = epi.getRequiredNames();
|
642
|
29420
|
while (i.hasNext())
|
643
|
|
{
|
644
|
34931
|
String name = (String) i.next();
|
645
|
|
|
646
|
34931
|
if (!_attributes.containsKey(name))
|
647
|
1
|
throw new ApplicationRuntimeException(ParseMessages.requiredAttribute(
|
648
|
|
name,
|
649
|
|
getElementPath(),
|
650
|
|
getLocation()));
|
651
|
|
}
|
652
|
|
|
653
|
|
}
|
654
|
|
|
655
|
37323
|
public void end(String elementName)
|
656
|
|
{
|
657
|
37323
|
switch (getState())
|
658
|
|
{
|
659
|
|
case STATE_LWDOM:
|
660
|
|
|
661
|
4830
|
endLWDom();
|
662
|
4830
|
break;
|
663
|
|
|
664
|
|
case STATE_CONVERSION:
|
665
|
|
|
666
|
461
|
endConversion();
|
667
|
461
|
break;
|
668
|
|
|
669
|
|
case STATE_SCHEMA:
|
670
|
|
|
671
|
1087
|
endSchema();
|
672
|
1087
|
break;
|
673
|
|
|
674
|
|
default:
|
675
|
|
|
676
|
30945
|
String content = peekContent();
|
677
|
|
|
678
|
30945
|
if (content != null && (peekObject() instanceof AnnotationHolder))
|
679
|
14917
|
((AnnotationHolder) peekObject()).setAnnotation(content);
|
680
|
|
|
681
|
30945
|
break;
|
682
|
|
}
|
683
|
|
|
684
|
|
|
685
|
|
|
686
|
37323
|
pop();
|
687
|
|
}
|
688
|
|
|
689
|
1087
|
private void endSchema()
|
690
|
|
{
|
691
|
1087
|
SchemaImpl schema = (SchemaImpl) peekObject();
|
692
|
|
|
693
|
1087
|
schema.setAnnotation(peekContent());
|
694
|
|
|
695
|
1087
|
try
|
696
|
|
{
|
697
|
1087
|
schema.validateKeyAttributes();
|
698
|
|
}
|
699
|
|
catch (ApplicationRuntimeException e)
|
700
|
|
{
|
701
|
1
|
_errorHandler.error(LOG, ParseMessages.invalidElementKeyAttribute(schema.getId(), e), e
|
702
|
|
.getLocation(), e);
|
703
|
|
}
|
704
|
|
}
|
705
|
|
|
706
|
461
|
private void endConversion()
|
707
|
|
{
|
708
|
461
|
ConversionDescriptor cd = (ConversionDescriptor) peekObject();
|
709
|
|
|
710
|
461
|
cd.addRulesForModel();
|
711
|
|
}
|
712
|
|
|
713
|
4830
|
private void endLWDom()
|
714
|
|
{
|
715
|
4830
|
ElementImpl element = (ElementImpl) peekObject();
|
716
|
4830
|
element.setContent(peekContent());
|
717
|
|
}
|
718
|
|
|
719
|
4479
|
private void enterAttribute(String elementName)
|
720
|
|
{
|
721
|
4479
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
722
|
|
|
723
|
4479
|
AttributeModelImpl attributeModel = new AttributeModelImpl();
|
724
|
|
|
725
|
4479
|
push(elementName, attributeModel, STATE_NO_CONTENT);
|
726
|
|
|
727
|
4479
|
checkAttributes();
|
728
|
|
|
729
|
4479
|
attributeModel.setName(getAttribute("name"));
|
730
|
4479
|
attributeModel.setRequired(getBooleanAttribute("required", false));
|
731
|
4479
|
attributeModel.setUnique(getBooleanAttribute("unique", false));
|
732
|
4479
|
attributeModel.setTranslator(getAttribute("translator", "smart"));
|
733
|
|
|
734
|
4479
|
elementModel.addAttributeModel(attributeModel);
|
735
|
|
}
|
736
|
|
|
737
|
964
|
private void enterConfigurationPoint(String elementName)
|
738
|
|
{
|
739
|
964
|
ModuleDescriptor md = (ModuleDescriptor) peekObject();
|
740
|
|
|
741
|
964
|
ConfigurationPointDescriptor cpd = new ConfigurationPointDescriptor();
|
742
|
|
|
743
|
964
|
push(elementName, cpd, STATE_CONFIGURATION_POINT);
|
744
|
|
|
745
|
964
|
checkAttributes();
|
746
|
|
|
747
|
964
|
cpd.setId(getValidatedAttribute("id", ID_PATTERN, "id-format"));
|
748
|
|
|
749
|
964
|
Occurances count = (Occurances) getEnumAttribute("occurs", OCCURS_MAP);
|
750
|
|
|
751
|
964
|
if (count != null)
|
752
|
24
|
cpd.setCount(count);
|
753
|
|
|
754
|
964
|
Visibility visibility = (Visibility) getEnumAttribute("visibility", VISIBILITY_MAP);
|
755
|
|
|
756
|
964
|
if (visibility != null)
|
757
|
2
|
cpd.setVisibility(visibility);
|
758
|
|
|
759
|
964
|
cpd.setContributionsSchemaId(getAttribute("schema-id"));
|
760
|
|
|
761
|
964
|
md.addConfigurationPoint(cpd);
|
762
|
|
}
|
763
|
|
|
764
|
638
|
private void enterContribution(String elementName)
|
765
|
|
{
|
766
|
638
|
ModuleDescriptor md = (ModuleDescriptor) peekObject();
|
767
|
|
|
768
|
638
|
ContributionDescriptor cd = new ContributionDescriptor();
|
769
|
|
|
770
|
638
|
push(elementName, cd, STATE_CONTRIBUTION);
|
771
|
|
|
772
|
638
|
checkAttributes();
|
773
|
|
|
774
|
638
|
cd.setConfigurationId(getAttribute("configuration-id"));
|
775
|
638
|
cd.setConditionalExpression(getAttribute("if"));
|
776
|
|
|
777
|
638
|
md.addContribution(cd);
|
778
|
|
}
|
779
|
|
|
780
|
461
|
private void enterConversion(String elementName)
|
781
|
|
{
|
782
|
461
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
783
|
|
|
784
|
461
|
ConversionDescriptor cd = new ConversionDescriptor(_errorHandler, elementModel);
|
785
|
|
|
786
|
461
|
push(elementName, cd, STATE_CONVERSION);
|
787
|
|
|
788
|
461
|
checkAttributes();
|
789
|
|
|
790
|
461
|
cd.setClassName(getAttribute("class"));
|
791
|
|
|
792
|
461
|
String methodName = getAttribute("parent-method");
|
793
|
|
|
794
|
461
|
if (methodName != null)
|
795
|
1
|
cd.setParentMethodName(methodName);
|
796
|
|
|
797
|
461
|
elementModel.addRule(cd);
|
798
|
|
}
|
799
|
|
|
800
|
1063
|
private void enterCreateInstance(String elementName)
|
801
|
|
{
|
802
|
1063
|
AbstractServiceDescriptor sd = (AbstractServiceDescriptor) peekObject();
|
803
|
1063
|
CreateInstanceDescriptor cid = new CreateInstanceDescriptor();
|
804
|
|
|
805
|
1063
|
push(elementName, cid, STATE_CREATE_INSTANCE);
|
806
|
|
|
807
|
1063
|
checkAttributes();
|
808
|
|
|
809
|
1063
|
cid.setInstanceClassName(getAttribute("class"));
|
810
|
|
|
811
|
1063
|
String model = getAttribute("model", DEFAULT_SERVICE_MODEL);
|
812
|
|
|
813
|
1063
|
cid.setServiceModel(model);
|
814
|
|
|
815
|
1063
|
sd.setInstanceBuilder(cid);
|
816
|
|
|
817
|
|
}
|
818
|
|
|
819
|
3408
|
private void enterCreateObject(String elementName)
|
820
|
|
{
|
821
|
3408
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
822
|
3408
|
CreateObjectRule rule = new CreateObjectRule();
|
823
|
3408
|
push(elementName, rule, STATE_NO_CONTENT);
|
824
|
|
|
825
|
3408
|
checkAttributes();
|
826
|
|
|
827
|
3408
|
rule.setClassName(getAttribute("class"));
|
828
|
|
|
829
|
3408
|
elementModel.addRule(rule);
|
830
|
|
}
|
831
|
|
|
832
|
2
|
private void enterCustom(String elementName)
|
833
|
|
{
|
834
|
2
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
835
|
|
|
836
|
|
|
837
|
|
|
838
|
2
|
push(elementName, null, STATE_NO_CONTENT);
|
839
|
|
|
840
|
2
|
checkAttributes();
|
841
|
|
|
842
|
2
|
String ruleClassName = getAttribute("class");
|
843
|
|
|
844
|
2
|
Rule rule = getCustomRule(ruleClassName);
|
845
|
|
|
846
|
1
|
elementModel.addRule(rule);
|
847
|
|
}
|
848
|
|
|
849
|
|
|
850
|
|
|
851
|
|
|
852
|
|
|
853
|
3558
|
private ElementModel enterElement(String elementName)
|
854
|
|
{
|
855
|
3558
|
ElementModelImpl result = new ElementModelImpl();
|
856
|
|
|
857
|
3558
|
push(elementName, result, STATE_ELEMENT);
|
858
|
|
|
859
|
3558
|
checkAttributes();
|
860
|
|
|
861
|
3557
|
result.setElementName(getAttribute("name"));
|
862
|
3557
|
result.setKeyAttribute(getAttribute("key-attribute"));
|
863
|
3557
|
result.setContentTranslator(getAttribute("content-translator"));
|
864
|
|
|
865
|
3557
|
return result;
|
866
|
|
}
|
867
|
|
|
868
|
674
|
private void enterEmbeddedConfigurationPointSchema(String elementName)
|
869
|
|
{
|
870
|
674
|
ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor) peekObject();
|
871
|
|
|
872
|
674
|
SchemaImpl schema = new SchemaImpl();
|
873
|
|
|
874
|
674
|
push(elementName, schema, STATE_SCHEMA);
|
875
|
|
|
876
|
674
|
if (cpd.getContributionsSchemaId() != null)
|
877
|
|
{
|
878
|
2
|
cpd.setContributionsSchemaId(null);
|
879
|
2
|
cpd.setContributionsSchema(schema);
|
880
|
2
|
_errorHandler.error(LOG, ParseMessages.multipleContributionsSchemas(cpd.getId(), schema
|
881
|
|
.getLocation()), schema.getLocation(), null);
|
882
|
|
}
|
883
|
|
else
|
884
|
672
|
cpd.setContributionsSchema(schema);
|
885
|
|
|
886
|
674
|
checkAttributes("schema{embedded}");
|
887
|
|
}
|
888
|
|
|
889
|
114
|
private void enterParametersSchema(String elementName)
|
890
|
|
{
|
891
|
114
|
ServicePointDescriptor spd = (ServicePointDescriptor) peekObject();
|
892
|
114
|
SchemaImpl schema = new SchemaImpl();
|
893
|
|
|
894
|
114
|
push(elementName, schema, STATE_SCHEMA);
|
895
|
|
|
896
|
114
|
checkAttributes();
|
897
|
|
|
898
|
114
|
if (spd.getParametersSchemaId() != null)
|
899
|
|
{
|
900
|
2
|
spd.setParametersSchemaId(null);
|
901
|
2
|
spd.setParametersSchema(schema);
|
902
|
2
|
_errorHandler.error(LOG, ParseMessages.multipleParametersSchemas(spd.getId(), schema
|
903
|
|
.getLocation()), schema.getLocation(), null);
|
904
|
|
}
|
905
|
|
else
|
906
|
112
|
spd.setParametersSchema(schema);
|
907
|
|
}
|
908
|
|
|
909
|
16
|
private void enterImplementation(String elementName)
|
910
|
|
{
|
911
|
16
|
ModuleDescriptor md = (ModuleDescriptor) peekObject();
|
912
|
|
|
913
|
16
|
ImplementationDescriptor id = new ImplementationDescriptor();
|
914
|
|
|
915
|
16
|
push(elementName, id, STATE_IMPLEMENTATION);
|
916
|
|
|
917
|
16
|
checkAttributes();
|
918
|
|
|
919
|
16
|
id.setServiceId(getAttribute("service-id"));
|
920
|
16
|
id.setConditionalExpression(getAttribute("if"));
|
921
|
|
|
922
|
16
|
md.addImplementation(id);
|
923
|
|
}
|
924
|
|
|
925
|
66
|
private void enterInterceptor(String elementName)
|
926
|
|
{
|
927
|
66
|
AbstractServiceDescriptor sd = (AbstractServiceDescriptor) peekObject();
|
928
|
66
|
InterceptorDescriptor id = new InterceptorDescriptor();
|
929
|
|
|
930
|
66
|
push(elementName, id, STATE_COLLECT_SERVICE_PARAMETERS);
|
931
|
|
|
932
|
66
|
checkAttributes();
|
933
|
|
|
934
|
66
|
id.setFactoryServiceId(getAttribute("service-id"));
|
935
|
|
|
936
|
66
|
id.setBefore(getAttribute("before"));
|
937
|
66
|
id.setAfter(getAttribute("after"));
|
938
|
66
|
id.setName(getAttribute("name" ));
|
939
|
66
|
sd.addInterceptor(id);
|
940
|
|
|
941
|
|
}
|
942
|
|
|
943
|
1176
|
private void enterInvokeFactory(String elementName)
|
944
|
|
{
|
945
|
1176
|
AbstractServiceDescriptor sd = (AbstractServiceDescriptor) peekObject();
|
946
|
1176
|
InvokeFactoryDescriptor ifd = new InvokeFactoryDescriptor();
|
947
|
|
|
948
|
1176
|
push(elementName, ifd, STATE_COLLECT_SERVICE_PARAMETERS);
|
949
|
|
|
950
|
1176
|
checkAttributes();
|
951
|
|
|
952
|
1176
|
ifd.setFactoryServiceId(getAttribute("service-id", "hivemind.BuilderFactory"));
|
953
|
|
|
954
|
1176
|
String model = getAttribute("model", DEFAULT_SERVICE_MODEL);
|
955
|
|
|
956
|
1176
|
ifd.setServiceModel(model);
|
957
|
|
|
958
|
|
|
959
|
|
|
960
|
1176
|
sd.setInstanceBuilder(ifd);
|
961
|
|
|
962
|
|
}
|
963
|
|
|
964
|
3740
|
private void enterInvokeParent(String elementName)
|
965
|
|
{
|
966
|
3740
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
967
|
3740
|
InvokeParentRule rule = new InvokeParentRule();
|
968
|
|
|
969
|
3740
|
push(elementName, rule, STATE_NO_CONTENT);
|
970
|
|
|
971
|
3740
|
checkAttributes();
|
972
|
|
|
973
|
3740
|
rule.setMethodName(getAttribute("method"));
|
974
|
|
|
975
|
3740
|
if (_attributes.containsKey("depth"))
|
976
|
2988
|
rule.setDepth(getIntAttribute("depth"));
|
977
|
|
|
978
|
3740
|
elementModel.addRule(rule);
|
979
|
|
}
|
980
|
|
|
981
|
2658
|
private void enterReadAttribute(String elementName)
|
982
|
|
{
|
983
|
2658
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
984
|
2658
|
ReadAttributeRule rule = new ReadAttributeRule();
|
985
|
|
|
986
|
2658
|
push(elementName, rule, STATE_NO_CONTENT);
|
987
|
|
|
988
|
2658
|
checkAttributes();
|
989
|
|
|
990
|
2658
|
rule.setPropertyName(getAttribute("property"));
|
991
|
2658
|
rule.setAttributeName(getAttribute("attribute"));
|
992
|
2658
|
rule.setSkipIfNull(getBooleanAttribute("skip-if-null", true));
|
993
|
2658
|
rule.setTranslator(getAttribute("translator"));
|
994
|
|
|
995
|
2658
|
elementModel.addRule(rule);
|
996
|
|
}
|
997
|
|
|
998
|
915
|
private void enterReadContent(String elementName)
|
999
|
|
{
|
1000
|
915
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
1001
|
915
|
ReadContentRule rule = new ReadContentRule();
|
1002
|
|
|
1003
|
915
|
push(elementName, rule, STATE_NO_CONTENT);
|
1004
|
|
|
1005
|
915
|
checkAttributes();
|
1006
|
|
|
1007
|
915
|
rule.setPropertyName(getAttribute("property"));
|
1008
|
|
|
1009
|
915
|
elementModel.addRule(rule);
|
1010
|
|
}
|
1011
|
|
|
1012
|
3084
|
private void enterRules(String elementName)
|
1013
|
|
{
|
1014
|
3084
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
1015
|
|
|
1016
|
3084
|
push(elementName, elementModel, STATE_RULES);
|
1017
|
|
|
1018
|
|
}
|
1019
|
|
|
1020
|
302
|
private void enterSchema(String elementName)
|
1021
|
|
{
|
1022
|
302
|
SchemaImpl schema = new SchemaImpl();
|
1023
|
|
|
1024
|
302
|
push(elementName, schema, STATE_SCHEMA);
|
1025
|
|
|
1026
|
302
|
checkAttributes();
|
1027
|
|
|
1028
|
302
|
String id = getValidatedAttribute("id", ID_PATTERN, "id-format");
|
1029
|
|
|
1030
|
302
|
schema.setId(id);
|
1031
|
|
|
1032
|
302
|
Visibility visibility = (Visibility) getEnumAttribute("visibility", VISIBILITY_MAP);
|
1033
|
|
|
1034
|
302
|
if (visibility != null)
|
1035
|
1
|
schema.setVisibility(visibility);
|
1036
|
|
|
1037
|
302
|
_moduleDescriptor.addSchema(schema);
|
1038
|
|
}
|
1039
|
|
|
1040
|
2255
|
private void enterServicePoint(String elementName)
|
1041
|
|
{
|
1042
|
2255
|
ModuleDescriptor md = (ModuleDescriptor) peekObject();
|
1043
|
|
|
1044
|
2255
|
ServicePointDescriptor spd = new ServicePointDescriptor();
|
1045
|
|
|
1046
|
2255
|
push(elementName, spd, STATE_SERVICE_POINT);
|
1047
|
|
|
1048
|
2255
|
checkAttributes();
|
1049
|
|
|
1050
|
2255
|
spd.setId(getValidatedAttribute("id", ID_PATTERN, "id-format"));
|
1051
|
|
|
1052
|
2255
|
String interfaceName = IdUtils.qualify(
|
1053
|
|
_moduleDescriptor.getPackageName(),
|
1054
|
|
getAttribute("interface"));
|
1055
|
2255
|
spd.setInterfaceClassName(interfaceName);
|
1056
|
|
|
1057
|
2255
|
spd.setParametersSchemaId(getAttribute("parameters-schema-id"));
|
1058
|
|
|
1059
|
2255
|
Occurances count = (Occurances) getEnumAttribute("parameters-occurs", OCCURS_MAP);
|
1060
|
|
|
1061
|
2255
|
if (count != null)
|
1062
|
108
|
spd.setParametersCount(count);
|
1063
|
|
|
1064
|
2255
|
Visibility visibility = (Visibility) getEnumAttribute("visibility", VISIBILITY_MAP);
|
1065
|
|
|
1066
|
2255
|
if (visibility != null)
|
1067
|
974
|
spd.setVisibility(visibility);
|
1068
|
|
|
1069
|
2255
|
md.addServicePoint(spd);
|
1070
|
|
}
|
1071
|
|
|
1072
|
10
|
private void enterSetModule(String elementName)
|
1073
|
|
{
|
1074
|
10
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
1075
|
10
|
SetModuleRule rule = new SetModuleRule();
|
1076
|
|
|
1077
|
10
|
push(elementName, rule, STATE_NO_CONTENT);
|
1078
|
|
|
1079
|
10
|
checkAttributes();
|
1080
|
|
|
1081
|
10
|
rule.setPropertyName(getAttribute("property"));
|
1082
|
|
|
1083
|
10
|
elementModel.addRule(rule);
|
1084
|
|
}
|
1085
|
|
|
1086
|
12
|
private void enterSetParent(String elementName)
|
1087
|
|
{
|
1088
|
12
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
1089
|
12
|
SetParentRule rule = new SetParentRule();
|
1090
|
|
|
1091
|
12
|
push(elementName, rule, STATE_NO_CONTENT);
|
1092
|
|
|
1093
|
12
|
checkAttributes();
|
1094
|
|
|
1095
|
12
|
rule.setPropertyName(getAttribute("property"));
|
1096
|
|
|
1097
|
12
|
elementModel.addRule(rule);
|
1098
|
|
}
|
1099
|
|
|
1100
|
1521
|
private void enterSetProperty(String elementName)
|
1101
|
|
{
|
1102
|
1521
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
1103
|
|
|
1104
|
1521
|
SetPropertyRule rule = new SetPropertyRule();
|
1105
|
|
|
1106
|
1521
|
push(elementName, rule, STATE_NO_CONTENT);
|
1107
|
|
|
1108
|
1521
|
checkAttributes();
|
1109
|
|
|
1110
|
1521
|
rule.setPropertyName(getAttribute("property"));
|
1111
|
1521
|
rule.setValue(getAttribute("value"));
|
1112
|
|
|
1113
|
1521
|
elementModel.addRule(rule);
|
1114
|
|
}
|
1115
|
|
|
1116
|
334
|
private void enterPushAttribute(String elementName)
|
1117
|
|
{
|
1118
|
334
|
ElementModelImpl elementModel = (ElementModelImpl) peekObject();
|
1119
|
|
|
1120
|
334
|
PushAttributeRule rule = new PushAttributeRule();
|
1121
|
|
|
1122
|
334
|
push(elementName, rule, STATE_NO_CONTENT);
|
1123
|
|
|
1124
|
334
|
checkAttributes();
|
1125
|
|
|
1126
|
334
|
rule.setAttributeName(getAttribute("attribute"));
|
1127
|
|
|
1128
|
334
|
elementModel.addRule(rule);
|
1129
|
|
}
|
1130
|
|
|
1131
|
3
|
private void enterSubModule(String elementName)
|
1132
|
|
{
|
1133
|
3
|
ModuleDescriptor md = (ModuleDescriptor) peekObject();
|
1134
|
|
|
1135
|
3
|
SubModuleDescriptor smd = new SubModuleDescriptor();
|
1136
|
|
|
1137
|
3
|
push(elementName, smd, STATE_NO_CONTENT);
|
1138
|
|
|
1139
|
3
|
checkAttributes();
|
1140
|
|
|
1141
|
3
|
Resource descriptor = getResource().getRelativeResource(getAttribute("descriptor"));
|
1142
|
|
|
1143
|
3
|
smd.setDescriptor(descriptor);
|
1144
|
|
|
1145
|
3
|
md.addSubModule(smd);
|
1146
|
|
}
|
1147
|
|
|
1148
|
10
|
private void enterDependency(String elementName)
|
1149
|
|
{
|
1150
|
10
|
ModuleDescriptor md = (ModuleDescriptor) peekObject();
|
1151
|
|
|
1152
|
10
|
DependencyDescriptor dd = new DependencyDescriptor();
|
1153
|
|
|
1154
|
10
|
push(elementName, dd, STATE_NO_CONTENT);
|
1155
|
|
|
1156
|
10
|
checkAttributes();
|
1157
|
|
|
1158
|
10
|
dd.setModuleId(getAttribute("module-id"));
|
1159
|
10
|
dd.setVersion(getAttribute("version"));
|
1160
|
|
|
1161
|
10
|
md.addDependency(dd);
|
1162
|
|
}
|
1163
|
|
|
1164
|
70841
|
private String getAttribute(String name)
|
1165
|
|
{
|
1166
|
70841
|
return (String) _attributes.get(name);
|
1167
|
|
}
|
1168
|
|
|
1169
|
7894
|
private String getAttribute(String name, String defaultValue)
|
1170
|
|
{
|
1171
|
7894
|
String result = (String) _attributes.get(name);
|
1172
|
|
|
1173
|
7894
|
if (result == null)
|
1174
|
6023
|
result = defaultValue;
|
1175
|
|
|
1176
|
7894
|
return result;
|
1177
|
|
}
|
1178
|
|
|
1179
|
4027
|
private String getValidatedAttribute(String name, String pattern, String formatKey)
|
1180
|
|
{
|
1181
|
4027
|
String result = getAttribute(name);
|
1182
|
|
|
1183
|
4027
|
if (!validateFormat(result, pattern))
|
1184
|
3
|
_errorHandler.error(LOG, ParseMessages.invalidAttributeFormat(
|
1185
|
|
name,
|
1186
|
|
result,
|
1187
|
|
getElementPath(),
|
1188
|
|
formatKey), getLocation(), null);
|
1189
|
|
|
1190
|
4027
|
return result;
|
1191
|
|
}
|
1192
|
|
|
1193
|
4027
|
private boolean validateFormat(String input, String pattern)
|
1194
|
|
{
|
1195
|
4027
|
if (_compiler == null)
|
1196
|
|
{
|
1197
|
240
|
_compiler = new Perl5Compiler();
|
1198
|
240
|
_matcher = new Perl5Matcher();
|
1199
|
240
|
_compiledPatterns = new HashMap();
|
1200
|
|
}
|
1201
|
|
|
1202
|
4027
|
Pattern compiled = (Pattern) _compiledPatterns.get(pattern);
|
1203
|
4027
|
if (compiled == null)
|
1204
|
|
{
|
1205
|
|
|
1206
|
712
|
try
|
1207
|
|
{
|
1208
|
712
|
compiled = _compiler.compile(pattern);
|
1209
|
|
}
|
1210
|
|
catch (MalformedPatternException ex)
|
1211
|
|
{
|
1212
|
0
|
throw new ApplicationRuntimeException(ex);
|
1213
|
|
}
|
1214
|
|
|
1215
|
712
|
_compiledPatterns.put(pattern, compiled);
|
1216
|
|
}
|
1217
|
|
|
1218
|
4027
|
return _matcher.matches(input, compiled);
|
1219
|
|
}
|
1220
|
|
|
1221
|
11616
|
private boolean getBooleanAttribute(String name, boolean defaultValue)
|
1222
|
|
{
|
1223
|
11616
|
String value = getAttribute(name);
|
1224
|
|
|
1225
|
11616
|
if (value == null)
|
1226
|
8531
|
return defaultValue;
|
1227
|
|
|
1228
|
3085
|
if (value.equals("true"))
|
1229
|
2637
|
return true;
|
1230
|
|
|
1231
|
448
|
if (value.equals("false"))
|
1232
|
448
|
return false;
|
1233
|
|
|
1234
|
0
|
_errorHandler.error(
|
1235
|
|
LOG,
|
1236
|
|
ParseMessages.booleanAttribute(value, name, getElementPath()),
|
1237
|
|
getLocation(),
|
1238
|
|
null);
|
1239
|
|
|
1240
|
0
|
return defaultValue;
|
1241
|
|
}
|
1242
|
|
|
1243
|
2
|
private Rule getCustomRule(String ruleClassName)
|
1244
|
|
{
|
1245
|
2
|
Rule result = (Rule) _ruleMap.get(ruleClassName);
|
1246
|
|
|
1247
|
2
|
if (result == null)
|
1248
|
|
{
|
1249
|
2
|
result = instantiateRule(ruleClassName);
|
1250
|
|
|
1251
|
1
|
_ruleMap.put(ruleClassName, result);
|
1252
|
|
}
|
1253
|
|
|
1254
|
1
|
return result;
|
1255
|
|
}
|
1256
|
|
|
1257
|
|
|
1258
|
|
|
1259
|
|
|
1260
|
|
|
1261
|
|
|
1262
|
6740
|
private Object getEnumAttribute(String name, Map translations)
|
1263
|
|
{
|
1264
|
6740
|
String value = getAttribute(name);
|
1265
|
|
|
1266
|
6740
|
if (value == null)
|
1267
|
5631
|
return null;
|
1268
|
|
|
1269
|
1109
|
Object result = translations.get(value);
|
1270
|
|
|
1271
|
1109
|
if (result == null)
|
1272
|
0
|
_errorHandler.error(LOG, ParseMessages.invalidAttributeValue(
|
1273
|
|
value,
|
1274
|
|
name,
|
1275
|
|
getElementPath()), getLocation(), null);
|
1276
|
|
|
1277
|
1109
|
return result;
|
1278
|
|
}
|
1279
|
|
|
1280
|
2988
|
private int getIntAttribute(String name)
|
1281
|
|
{
|
1282
|
2988
|
String value = getAttribute(name);
|
1283
|
|
|
1284
|
2988
|
try
|
1285
|
|
{
|
1286
|
2988
|
return Integer.parseInt(value);
|
1287
|
|
}
|
1288
|
|
catch (NumberFormatException ex)
|
1289
|
|
{
|
1290
|
0
|
_errorHandler.error(LOG, ParseMessages.invalidNumericValue(
|
1291
|
|
value,
|
1292
|
|
name,
|
1293
|
|
getElementPath()), getLocation(), ex);
|
1294
|
|
|
1295
|
0
|
return 0;
|
1296
|
|
}
|
1297
|
|
}
|
1298
|
|
|
1299
|
241
|
private void initializeFromProperties(Properties p)
|
1300
|
|
{
|
1301
|
241
|
Enumeration e = p.propertyNames();
|
1302
|
|
|
1303
|
241
|
while (e.hasMoreElements())
|
1304
|
|
{
|
1305
|
13014
|
String key = (String) e.nextElement();
|
1306
|
13014
|
String value = p.getProperty(key);
|
1307
|
|
|
1308
|
13014
|
initializeFromProperty(key, value);
|
1309
|
|
}
|
1310
|
|
}
|
1311
|
|
|
1312
|
|
|
1313
|
|
|
1314
|
|
|
1315
|
|
|
1316
|
241
|
private void initializeFromPropertiesFile()
|
1317
|
|
{
|
1318
|
241
|
Properties p = new Properties();
|
1319
|
|
|
1320
|
241
|
try
|
1321
|
|
{
|
1322
|
|
|
1323
|
241
|
InputStream propertiesIn = getClass()
|
1324
|
|
.getResourceAsStream("DescriptorParser.properties");
|
1325
|
241
|
InputStream bufferedIn = new BufferedInputStream(propertiesIn);
|
1326
|
|
|
1327
|
241
|
p.load(bufferedIn);
|
1328
|
|
|
1329
|
241
|
bufferedIn.close();
|
1330
|
|
}
|
1331
|
|
catch (IOException ex)
|
1332
|
|
{
|
1333
|
0
|
_errorHandler.error(LOG, ParseMessages.unableToInitialize(ex), null, ex);
|
1334
|
|
}
|
1335
|
|
|
1336
|
241
|
initializeFromProperties(p);
|
1337
|
|
}
|
1338
|
|
|
1339
|
13014
|
private void initializeFromProperty(String key, String value)
|
1340
|
|
{
|
1341
|
13014
|
if (key.startsWith("required."))
|
1342
|
|
{
|
1343
|
13014
|
initializeRequired(key, value);
|
1344
|
13014
|
return;
|
1345
|
|
}
|
1346
|
|
|
1347
|
|
}
|
1348
|
|
|
1349
|
13014
|
private void initializeRequired(String key, String value)
|
1350
|
|
{
|
1351
|
13014
|
boolean required = value.equals("true");
|
1352
|
|
|
1353
|
13014
|
int lastdotx = key.lastIndexOf('.');
|
1354
|
|
|
1355
|
13014
|
String elementName = key.substring(9, lastdotx);
|
1356
|
13014
|
String attributeName = key.substring(lastdotx + 1);
|
1357
|
|
|
1358
|
13014
|
ElementParseInfo epi = (ElementParseInfo) _elementParseInfo.get(elementName);
|
1359
|
|
|
1360
|
13014
|
if (epi == null)
|
1361
|
|
{
|
1362
|
5784
|
epi = new ElementParseInfo();
|
1363
|
5784
|
_elementParseInfo.put(elementName, epi);
|
1364
|
|
}
|
1365
|
|
|
1366
|
13014
|
epi.addAttribute(attributeName, required);
|
1367
|
|
}
|
1368
|
|
|
1369
|
2
|
private Rule instantiateRule(String ruleClassName)
|
1370
|
|
{
|
1371
|
2
|
try
|
1372
|
|
{
|
1373
|
2
|
Class ruleClass = _resolver.findClass(ruleClassName);
|
1374
|
|
|
1375
|
1
|
return (Rule) ruleClass.newInstance();
|
1376
|
|
}
|
1377
|
|
catch (Exception ex)
|
1378
|
|
{
|
1379
|
1
|
throw new ApplicationRuntimeException(ParseMessages.badRuleClass(
|
1380
|
|
ruleClassName,
|
1381
|
|
getLocation(),
|
1382
|
|
ex), getLocation(), ex);
|
1383
|
|
}
|
1384
|
|
}
|
1385
|
|
|
1386
|
|
|
1387
|
255
|
public void initialize(Resource resource, ClassResolver resolver)
|
1388
|
|
{
|
1389
|
255
|
initializeParser(resource, STATE_START);
|
1390
|
|
|
1391
|
255
|
_resolver = resolver;
|
1392
|
|
}
|
1393
|
|
|
1394
|
|
|
1395
|
250
|
public ModuleDescriptor getModuleDescriptor()
|
1396
|
|
{
|
1397
|
250
|
return _moduleDescriptor;
|
1398
|
|
}
|
1399
|
|
|
1400
|
|
|
1401
|
0
|
public void reset()
|
1402
|
|
{
|
1403
|
0
|
super.resetParser();
|
1404
|
|
|
1405
|
0
|
_moduleDescriptor = null;
|
1406
|
0
|
_attributes.clear();
|
1407
|
0
|
_resolver = null;
|
1408
|
|
}
|
1409
|
|
}
|