XMPSchemaGenerator.java
29.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.xmp.schema.model.ArrayType
* com.adobe.xmp.schema.model.ArrayType$ArrayForm
* com.adobe.xmp.schema.model.PropertyDescription
* com.adobe.xmp.schema.model.PropertyType
* com.adobe.xmp.schema.model.SchemaDescription
* com.adobe.xmp.schema.model.SchemaModelFactory
* com.adobe.xmp.schema.model.SimpleType
* com.adobe.xmp.schema.model.SimpleType$BasicType
* com.adobe.xmp.schema.model.StructType
* com.adobe.xmp.schema.model.TypeRegistry
* com.adobe.xmp.schema.model.TypeRule
* com.adobe.xmp.schema.model.TypeRule$ComparisonOperator
* com.adobe.xmp.schema.model.TypeRule$LogicalOperator
* com.adobe.xmp.schema.model.XMPSchemaException
* com.adobe.xmp.schema.model.rules.BooleanRule
* com.adobe.xmp.schema.model.rules.ClosedChoice
* com.adobe.xmp.schema.model.rules.DateRule
* com.adobe.xmp.schema.model.rules.IntegerRule
* com.adobe.xmp.schema.model.rules.LengthRule
* com.adobe.xmp.schema.model.rules.LogicalRule
* com.adobe.xmp.schema.model.rules.OpenChoice
* com.adobe.xmp.schema.model.rules.PatternRule
* com.adobe.xmp.schema.model.rules.RealRule
* com.adobe.xmp.schema.model.rules.Vocable
* com.adobe.xmp.schema.model.rules.Vocable$Type
*/
package com.adobe.xmp.schema.rng.parser.generator;
import com.adobe.xmp.schema.model.ArrayType;
import com.adobe.xmp.schema.model.PropertyDescription;
import com.adobe.xmp.schema.model.PropertyType;
import com.adobe.xmp.schema.model.SchemaDescription;
import com.adobe.xmp.schema.model.SchemaModelFactory;
import com.adobe.xmp.schema.model.SimpleType;
import com.adobe.xmp.schema.model.StructType;
import com.adobe.xmp.schema.model.TypeRegistry;
import com.adobe.xmp.schema.model.TypeRule;
import com.adobe.xmp.schema.model.XMPSchemaException;
import com.adobe.xmp.schema.model.rules.BooleanRule;
import com.adobe.xmp.schema.model.rules.ClosedChoice;
import com.adobe.xmp.schema.model.rules.DateRule;
import com.adobe.xmp.schema.model.rules.IntegerRule;
import com.adobe.xmp.schema.model.rules.LengthRule;
import com.adobe.xmp.schema.model.rules.LogicalRule;
import com.adobe.xmp.schema.model.rules.OpenChoice;
import com.adobe.xmp.schema.model.rules.PatternRule;
import com.adobe.xmp.schema.model.rules.RealRule;
import com.adobe.xmp.schema.model.rules.Vocable;
import com.adobe.xmp.schema.rng.model.DatatypeInfo;
import com.adobe.xmp.schema.rng.model.ParamInfo;
import com.adobe.xmp.schema.rng.model.ParamInfoGroup;
import com.adobe.xmp.schema.rng.model.ParamInfoImpl;
import com.adobe.xmp.schema.rng.model.PropertyInfo;
import com.adobe.xmp.schema.rng.parser.annotation.RNGDecorationAnnotation;
import com.adobe.xmp.schema.rng.parser.constants.RNGSymbol;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGParseException;
import com.adobe.xmp.schema.rng.parser.utils.RNGUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.namespace.QName;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class XMPSchemaGenerator {
public static final Map<String, SimpleType.BasicType> kBasicTypes = new HashMap<String, SimpleType.BasicType>();
private final String mNS;
private final String mLabel;
private final String mDescription;
private final ArrayList<PropertyInfo> mProperties;
private TypeRegistry mTypeRegistry;
private SchemaDescription mSchema;
public XMPSchemaGenerator(String ns, String label, String description, ArrayList<PropertyInfo> properties) {
this.mNS = ns;
this.mLabel = label;
this.mDescription = description;
this.mProperties = properties;
this.setTypeRegistry(null);
this.mSchema = null;
}
public SchemaDescription getModel() throws XMPSchemaException {
if (this.mSchema == null) {
this.generateModel();
}
return this.mSchema;
}
public void setTypeRegistry(TypeRegistry mTypeRegistry) {
this.mTypeRegistry = mTypeRegistry;
}
public TypeRegistry getTypeRegistry() {
if (this.mTypeRegistry == null) {
this.mTypeRegistry = SchemaModelFactory.createTypeRegistry();
}
return this.mTypeRegistry;
}
private void generateModel() throws XMPSchemaException {
this.mSchema = SchemaModelFactory.createSchema((String)this.mNS);
this.mSchema.setLabel(this.mLabel);
this.mSchema.setDescription(this.mDescription);
for (PropertyInfo property : this.mProperties) {
PropertyDescription propertyDescription = this.createPropertyDescription(property);
this.mSchema.addProperty(propertyDescription);
}
}
private PropertyDescription createPropertyDescription(PropertyInfo property) throws XMPSchemaException {
PropertyType propertyType = this.createPropertyType(property);
propertyType = this.addConstraints(property, propertyType);
PropertyDescription propertyDescription = SchemaModelFactory.createProperty((String)property.getNS(), (String)property.getName(), (PropertyType)propertyType);
propertyDescription.setDeprecated(property.isDeprecated());
propertyDescription.setDescription(property.getDescription());
propertyDescription.setLabel(property.getLabel());
propertyDescription.setMandatory(property.isMandatory());
propertyDescription.setReadOnly(property.getAccess() != RNGDecorationAnnotation.ACCESS.readwrite);
this.addQualifier(property, propertyDescription);
this.addDecorators(property, propertyDescription);
return propertyDescription;
}
private void addDecorators(PropertyInfo property, PropertyDescription propertyDescription) {
if (!property.hasDecorators()) {
return;
}
for (Map.Entry<QName, Map<String, String>> entry : property.getDecoratorStore().entrySet()) {
QName qname = entry.getKey();
propertyDescription.getDecorator(qname.getNamespaceURI(), qname.getLocalPart()).putAll(entry.getValue());
}
}
private void addQualifier(PropertyInfo property, PropertyDescription propertyDescription) throws XMPSchemaException {
for (PropertyInfo info : property.getQualifiers()) {
PropertyType qualifierType = this.createPropertyType(info);
PropertyDescription qualifierDescription = SchemaModelFactory.createProperty((String)info.getNS(), (String)info.getName(), (PropertyType)qualifierType);
qualifierDescription.setDeprecated(info.isDeprecated());
qualifierDescription.setDescription(info.getDescription());
qualifierDescription.setLabel(info.getLabel());
qualifierDescription.setMandatory(info.isMandatory());
qualifierDescription.setReadOnly(property.getAccess() != RNGDecorationAnnotation.ACCESS.readwrite);
PropertyType propertyType = propertyDescription.getType();
if (info.isArrayItemQualifier() && propertyType instanceof ArrayType) {
((ArrayType)propertyType).addItemQualifier(qualifierDescription);
continue;
}
propertyDescription.addQualifier(qualifierDescription);
}
}
private PropertyType addConstraints(PropertyInfo property, PropertyType propertyType) throws XMPSchemaException {
ParamInfoGroup params = property.getParamInfos();
if (params != null && !params.empty()) {
if (propertyType instanceof StructType) {
throw new RNGParseException("defect rng: no constraints for structs allowed");
}
if (propertyType instanceof ArrayType) {
PropertyType itemType;
TypeRule rules;
TypeRule arrRules = this.createRules(params, propertyType, property);
if (arrRules != null && this.isLengthRule(arrRules)) {
((ArrayType)propertyType).setRule(arrRules);
}
if ((rules = this.createRules(params, itemType = ((ArrayType)propertyType).getItemType(), property)) != null) {
itemType.setRule(rules);
}
} else {
TypeRule rule = this.createRules(params, propertyType, property);
if (rule != null) {
ClosedChoice choiceRule;
if (rule instanceof ClosedChoice && (choiceRule = (ClosedChoice)rule).getVocabulary().size() > 0) {
Vocable vocable = (Vocable)choiceRule.getVocabulary().get(0);
Object xmpValue = vocable.getXmpValue();
if (xmpValue instanceof Integer || xmpValue instanceof Long) {
propertyType = this.getTypeRegistry().createDerivedType(SimpleType.BasicType.INTEGER);
} else if (xmpValue instanceof Float || xmpValue instanceof Double) {
propertyType = this.getTypeRegistry().createDerivedType(SimpleType.BasicType.REAL);
} else if (xmpValue instanceof Boolean) {
propertyType = this.getTypeRegistry().createDerivedType(SimpleType.BasicType.BOOLEAN);
}
}
propertyType.setRule(rule);
}
}
}
return propertyType;
}
private TypeRule createRules(ParamInfoGroup params, PropertyType type, PropertyInfo property) throws XMPSchemaException {
TypeRule ret = null;
if (params.isChoice() && this.isPureChoice(params, property)) {
ret = this.createPureChoiceRule(params, type, property);
} else {
LogicalRule group = new LogicalRule(params.getOperator() == ParamInfoGroup.Operator.kAND ? TypeRule.LogicalOperator.AND : TypeRule.LogicalOperator.OR);
Stack<ParamInfo> paramStack = params.getParams();
int numSibling = paramStack.size();
for (ParamInfo param : paramStack) {
TypeRule rule = null;
rule = param instanceof ParamInfoGroup ? this.createRules((ParamInfoGroup)param, type, property) : (this.isChoiceIParamInfo(param, property, numSibling) ? this.createChoiceRule((ParamInfoImpl)param, property) : this.createRule((ParamInfoImpl)param, type));
if (rule == null) continue;
group.addOperand(rule);
}
List rules = group.getOperands();
if (rules != null && !rules.isEmpty()) {
ret = rules.size() > 1 ? group : (TypeRule)rules.toArray()[0];
}
}
return ret;
}
private TypeRule createRule(ParamInfoImpl param, PropertyType type) {
TypeRule rule = null;
if (!(type instanceof StructType)) {
if (type instanceof ArrayType) {
rule = this.createArrayRule(param);
} else {
switch (((SimpleType)type).getBasicType()) {
case TEXT: {
rule = this.createTextRule(param);
break;
}
case REAL: {
rule = this.createRealRule(param);
break;
}
case INTEGER: {
rule = this.createIntegerRule(param);
break;
}
case BOOLEAN: {
rule = this.createBooleanRule(param);
break;
}
case DATE: {
rule = this.createDateRule(param);
}
}
}
}
return rule;
}
private TypeRule createArrayRule(ParamInfoImpl param) {
LengthRule rule = null;
try {
TypeRule.ComparisonOperator op;
int value = Integer.parseInt(param.getStringValue());
switch (param.getType()) {
case arrayLength: {
op = TypeRule.ComparisonOperator.EQUALS;
break;
}
case maxArrayLength: {
op = TypeRule.ComparisonOperator.LESS_EQUALS;
break;
}
case minArrayLength: {
op = TypeRule.ComparisonOperator.GREATER_EQUALS;
break;
}
default: {
op = null;
}
}
if (op != null) {
rule = new LengthRule(op, value);
}
}
catch (NumberFormatException e) {
// empty catch block
}
return rule;
}
private TypeRule createTextRule(ParamInfoImpl param) {
PatternRule rule = null;
if (param.getType() == RNGSymbol.pattern) {
rule = new PatternRule(param.getStringValue());
} else {
try {
TypeRule.ComparisonOperator op = null;
switch (param.getType()) {
case length: {
op = TypeRule.ComparisonOperator.EQUALS;
break;
}
case maxLength: {
op = TypeRule.ComparisonOperator.LESS_EQUALS;
break;
}
case minLength: {
op = TypeRule.ComparisonOperator.GREATER_EQUALS;
break;
}
default: {
return new LengthRule(TypeRule.ComparisonOperator.LESS_EQUALS, Integer.MAX_VALUE);
}
}
if (op != null) {
int value = Integer.parseInt(param.getStringValue());
rule = new LengthRule(op, value);
}
}
catch (NumberFormatException e) {
// empty catch block
}
}
return rule;
}
private TypeRule createIntegerRule(ParamInfoImpl param) {
IntegerRule rule = null;
try {
TypeRule.ComparisonOperator op = null;
switch (param.getType()) {
case constValue: {
op = TypeRule.ComparisonOperator.EQUALS;
break;
}
case maxInclusive: {
op = TypeRule.ComparisonOperator.LESS_EQUALS;
break;
}
case minInclusive: {
op = TypeRule.ComparisonOperator.GREATER_EQUALS;
break;
}
case maxExclusive: {
op = TypeRule.ComparisonOperator.LESS;
break;
}
case minExclusive: {
op = TypeRule.ComparisonOperator.GREATER;
}
}
if (op != null) {
long value = Long.parseLong(param.getStringValue());
rule = new IntegerRule(op, value);
}
}
catch (NumberFormatException e) {
// empty catch block
}
return rule;
}
private TypeRule createRealRule(ParamInfoImpl param) {
RealRule rule = null;
try {
TypeRule.ComparisonOperator op = null;
switch (param.getType()) {
case constValue: {
op = TypeRule.ComparisonOperator.EQUALS;
break;
}
case maxInclusive: {
op = TypeRule.ComparisonOperator.LESS_EQUALS;
break;
}
case minInclusive: {
op = TypeRule.ComparisonOperator.GREATER_EQUALS;
break;
}
case maxExclusive: {
op = TypeRule.ComparisonOperator.LESS;
break;
}
case minExclusive: {
op = TypeRule.ComparisonOperator.GREATER;
}
}
if (op != null) {
double value = Double.parseDouble(param.getStringValue());
rule = new RealRule(op, value);
}
}
catch (NumberFormatException e) {
// empty catch block
}
return rule;
}
private TypeRule createDateRule(ParamInfoImpl param) {
DateRule rule = null;
TypeRule.ComparisonOperator op = null;
switch (param.getType()) {
case constValue: {
op = TypeRule.ComparisonOperator.EQUALS;
break;
}
case pattern: {
break;
}
case maxInclusive: {
op = TypeRule.ComparisonOperator.LESS_EQUALS;
break;
}
case minInclusive: {
op = TypeRule.ComparisonOperator.GREATER_EQUALS;
break;
}
case maxExclusive: {
op = TypeRule.ComparisonOperator.LESS;
break;
}
case minExclusive: {
op = TypeRule.ComparisonOperator.GREATER;
}
}
if (op != null) {
rule = new DateRule(op, param.getStringValue());
}
return rule;
}
private TypeRule createBooleanRule(ParamInfoImpl param) {
BooleanRule rule = null;
boolean value = param.getStringValue().equalsIgnoreCase("true") || param.getValue().equals("1");
switch (param.getType()) {
case constValue: {
rule = new BooleanRule(value);
break;
}
case pattern: {
Pattern p = Pattern.compile(param.getStringValue().toLowerCase());
boolean matchesTrue = p.matcher("true").matches();
boolean matchesFalse = p.matcher("false").matches();
if (matchesTrue && matchesFalse) break;
rule = new BooleanRule(matchesTrue || !matchesFalse);
}
}
return rule;
}
private boolean isPureChoice(ParamInfoGroup params, PropertyInfo property) {
Stack<ParamInfo> paramsStack = params.getParams();
int numSiblings = paramsStack.size();
for (ParamInfo info : paramsStack) {
if (this.isChoiceIParamInfo(info, property, numSiblings)) continue;
return false;
}
return true;
}
private boolean isChoiceIParamInfo(ParamInfo info, PropertyInfo property, int numSiblings) {
if (!(info instanceof ParamInfoImpl)) {
return false;
}
ParamInfoImpl param = (ParamInfoImpl)info;
if ((param == ParamInfoImpl.PARAM_ALL_BOOLEAN || param == ParamInfoImpl.PARAM_ALL_DOUBLE || param == ParamInfoImpl.PARAM_ALL_INTEGER || param == ParamInfoImpl.PARAM_ALL_TEXT) && numSiblings > 1) {
return true;
}
return param.getType() == RNGSymbol.constValue && (property.getDataType() == null && property.getRawDataType().getName().equals("Text") || property.getDataType() != null && property.getDataType().getName().equals("Text"));
}
private boolean isLengthRule(TypeRule rule) {
if (rule instanceof LengthRule) {
return true;
}
if (rule instanceof LogicalRule) {
LogicalRule lRule = (LogicalRule)rule;
List rules = lRule.getOperands();
if (rules != null) {
for (TypeRule cRule : rules) {
if (cRule == null || this.isLengthRule(cRule)) continue;
return false;
}
return true;
}
return false;
}
return false;
}
private TypeRule createChoiceRule(ParamInfoImpl param, PropertyInfo property) throws XMPSchemaException {
Vocable.Type type = this.getVocableType(param.getValue());
ClosedChoice choice = this.createEmptyChoiceRule(property, type);
if (param != null) {
choice.addVocable(param.getValue(), param.getLabel());
}
return choice;
}
private Vocable.Type getVocableType(Object xmpValue) {
if (xmpValue instanceof String) {
return Vocable.Type.TEXT;
}
if (xmpValue instanceof Integer) {
return Vocable.Type.INTEGER;
}
if (xmpValue instanceof Double) {
return Vocable.Type.REAL;
}
if (xmpValue instanceof Boolean) {
return Vocable.Type.BOOLEAN;
}
if (xmpValue instanceof Date) {
return Vocable.Type.DATE;
}
if (xmpValue instanceof Integer[]) {
return Vocable.Type.ARRAY_OF_INTEGER;
}
throw new RNGParseException("Unsupported value type found as a vocable.");
}
private TypeRule createPureChoiceRule(ParamInfoGroup params, PropertyType type, PropertyInfo property) throws XMPSchemaException {
boolean closedChoice = property.getChoice() != RNGDecorationAnnotation.CHOICE.open;
Vocable.Type vocableType = null;
HashMap<ParamInfo, Object> choiceValues = new HashMap<ParamInfo, Object>();
String dataType = null;
boolean wildcardFound = false;
for (ParamInfo paramInfo : params.getParams()) {
if (!(paramInfo instanceof ParamInfoImpl)) continue;
ParamInfoImpl param = (ParamInfoImpl)paramInfo;
if (dataType == null) {
dataType = param.getXMPValueType();
}
if (param.getValue() instanceof Integer[]) {
vocableType = Vocable.Type.ARRAY_OF_INTEGER;
choiceValues.put(paramInfo, param.getValue());
continue;
}
if (param == ParamInfoImpl.PARAM_ALL_TEXT) {
vocableType = Vocable.Type.TEXT;
wildcardFound = true;
continue;
}
if (param == ParamInfoImpl.PARAM_ALL_DOUBLE && "Real".equals(dataType)) {
vocableType = Vocable.Type.REAL;
wildcardFound = true;
continue;
}
if (param == ParamInfoImpl.PARAM_ALL_INTEGER && "Integer".equals(dataType)) {
vocableType = Vocable.Type.INTEGER;
wildcardFound = true;
continue;
}
if (param == ParamInfoImpl.PARAM_ALL_BOOLEAN && "Boolean".equals(dataType)) {
vocableType = Vocable.Type.BOOLEAN;
wildcardFound = true;
continue;
}
Object value = this.convertSimpleRawValue(param, dataType);
if (value == null) continue;
choiceValues.put(paramInfo, value);
}
if (wildcardFound) {
if (property.getChoice() == RNGDecorationAnnotation.CHOICE.closed) {
throw new RNGParseException("Values such as <rng:text/> which can allow multiple values, are not allowed for closed choice.");
}
closedChoice = false;
}
if (vocableType == null) {
SimpleType.BasicType basicType = kBasicTypes.get(dataType.toLowerCase());
vocableType = Vocable.Type.valueOf((String)basicType.name());
}
ClosedChoice choice = this.createEmptyChoiceRule(property, vocableType, closedChoice);
for (ParamInfo info : params.getParams()) {
ParamInfoImpl param = info instanceof ParamInfoImpl ? (ParamInfoImpl)info : null;
if (param == null) continue;
if (choiceValues != null) {
if (!choiceValues.containsKey(info)) continue;
choice.addVocable(choiceValues.get(info), param.getLabel());
continue;
}
choice.addVocable(param.getValue(), param.getLabel());
}
return choice;
}
private Object convertSimpleRawValue(ParamInfoImpl param, String xmpDataType) {
if (param == null || xmpDataType == null) {
return null;
}
return RNGUtils.convertSimpleRawValue(param.getStringValue(), xmpDataType.toLowerCase());
}
private ClosedChoice createEmptyChoiceRule(PropertyInfo property, Vocable.Type type) {
RNGDecorationAnnotation.CHOICE choice = property.getChoice();
if (choice == RNGDecorationAnnotation.CHOICE.open) {
return new OpenChoice(type);
}
return new ClosedChoice(type);
}
private ClosedChoice createEmptyChoiceRule(PropertyInfo property, Vocable.Type type, boolean closedChoice) {
if (closedChoice) {
return new ClosedChoice(type);
}
return new OpenChoice(type);
}
private PropertyType createPropertyType(PropertyInfo property) throws XMPSchemaException {
return this.createPropertyType(property, false);
}
private PropertyType createPropertyType(PropertyInfo property, boolean arrayItemType) throws XMPSchemaException {
PropertyType propertyType = null;
propertyType = !arrayItemType && property.getArrayForm() != null ? this.createArrayType(property) : (this.isStruct(property) ? this.createStructType(property) : this.createSimpleType(property));
return propertyType;
}
private PropertyType createSimpleType(PropertyInfo property) throws XMPSchemaException {
PropertyType propertyType = null;
TypeRegistry typeRegistry = this.getTypeRegistry();
String typeName = this.getTypeName(property);
if (typeName != null) {
SimpleType baseType;
boolean isBasicType = kBasicTypes.containsKey(typeName.toLowerCase());
if (isBasicType && !property.getParamInfos().empty()) {
propertyType = typeRegistry.createDerivedType(kBasicTypes.get(typeName.toLowerCase()));
} else {
propertyType = typeRegistry.getType(typeName);
if (propertyType != null) {
property.getParamInfos().getParams().clear();
}
}
if (propertyType == null && (baseType = this.getBaseType(property)) != null) {
propertyType = typeRegistry.createDerivedType(baseType);
typeRegistry.registerType(typeName, propertyType);
}
}
return propertyType;
}
private PropertyType createArrayType(PropertyInfo property) throws XMPSchemaException {
ArrayType propertyType = null;
TypeRegistry typeRegistry = this.getTypeRegistry();
ArrayType.ArrayForm form = property.getArrayForm();
if (form != null) {
propertyType = typeRegistry.createArray(form, this.createPropertyType(property, true));
}
return propertyType;
}
private PropertyType createStructType(PropertyInfo property) throws XMPSchemaException {
StructType propertyType = null;
TypeRegistry typeRegistry = this.getTypeRegistry();
if (this.isStruct(property)) {
String typeName = this.getTypeName(property);
String ns = this.getStructNS(property);
if (typeName != null && typeName.length() > 0 && (propertyType = typeRegistry.getType(typeName)) != null && !(propertyType instanceof StructType)) {
propertyType = null;
}
if (propertyType == null) {
propertyType = typeRegistry.createStruct(ns);
if (typeName != null && typeName.length() > 0 && !kBasicTypes.containsKey(typeName.toLowerCase())) {
typeRegistry.registerType(typeName, (PropertyType)propertyType);
}
Stack<PropertyInfo> children = property.getFields();
for (PropertyInfo child : children) {
propertyType.addField(this.createPropertyDescription(child));
}
}
}
return propertyType;
}
private boolean isStruct(PropertyInfo property) {
Stack<PropertyInfo> children = property.getFields();
return !children.isEmpty();
}
private String getStructNS(PropertyInfo property) {
String ns = null;
if (this.isStruct(property)) {
ns = property.getFields().get(0).getNS();
}
return ns;
}
private String getTypeName(PropertyInfo property) {
String name = "";
DatatypeInfo type = property.getDataType();
if (type != null) {
name = type.getName();
} else if (!this.isStruct(property)) {
name = property.getRawDataType().getName();
}
return name;
}
private SimpleType getBaseType(PropertyInfo property) {
DatatypeInfo dType = property.getDataType();
PropertyType type = null;
if (dType != null) {
type = this.getTypeRegistry().getType(dType.getName());
}
if (type == null) {
type = this.getTypeRegistry().getType(property.getRawDataType().getName());
}
SimpleType ret = null;
if (type instanceof SimpleType) {
ret = (SimpleType)type;
}
return ret;
}
static {
kBasicTypes.put("Boolean".toLowerCase(), SimpleType.BasicType.BOOLEAN);
kBasicTypes.put("Date".toLowerCase(), SimpleType.BasicType.DATE);
kBasicTypes.put("Integer".toLowerCase(), SimpleType.BasicType.INTEGER);
kBasicTypes.put("Real".toLowerCase(), SimpleType.BasicType.REAL);
kBasicTypes.put("Text".toLowerCase(), SimpleType.BasicType.TEXT);
}
}