1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.schema.cmp;
|
11
|
|
|
12
|
|
import org.jbind.xml.base.BlockType;
|
13
|
|
import org.jbind.xml.base.IHasLocation;
|
14
|
|
import org.jbind.xml.core.bridge.IDataImpl;
|
15
|
|
import org.jbind.xml.core.content.IDataDesc;
|
16
|
|
import org.jbind.xml.core.data.IAnyTypeData;
|
17
|
|
import org.jbind.xml.core.data.ISimpleData;
|
18
|
|
import org.jbind.xml.core.type.IAnyType;
|
19
|
|
import org.jbind.xml.msg.XmlException;
|
20
|
|
import org.jbind.xml.msg.XmlMessages;
|
21
|
|
|
22
|
|
public class DataDescHelper {
|
23
|
|
|
24
|
4056
|
private static void checkOverloadingType(IDataDesc aDecl, IAnyType anOverloadingType, IHasLocation aHasLocation) throws XmlException {
|
25
|
4056
|
IAnyType declaredType = aDecl.getType();
|
26
|
4056
|
if (null != anOverloadingType) {
|
27
|
146
|
if (!declaredType.canBeOverloadedBy(anOverloadingType)) {
|
28
|
33
|
throw new XmlException(XmlMessages.overloadingTypeInvalidInstanceType(anOverloadingType, declaredType, aHasLocation));
|
29
|
|
}
|
30
|
113
|
boolean extensionBlocked = false;
|
31
|
113
|
boolean restrictionBlocked = false;
|
32
|
|
// TODO which alternative is correct?
|
33
|
113
|
if (false) {
|
34
|
0
|
for (IAnyType t = ((IAnyType)anOverloadingType).getBaseType();
|
35
|
0
|
!(extensionBlocked && restrictionBlocked) && declaredType.isBaseType(t);
|
36
|
|
t = t.getBaseType()) {
|
37
|
0
|
extensionBlocked |= t.isActive(BlockType.EXTENSION);
|
38
|
0
|
restrictionBlocked |= t.isActive(BlockType.RESTRICTION);
|
39
|
|
}
|
40
|
|
} else {
|
41
|
113
|
extensionBlocked = declaredType.isActive(BlockType.EXTENSION);
|
42
|
113
|
restrictionBlocked = declaredType.isActive(BlockType.RESTRICTION);
|
43
|
|
}
|
44
|
113
|
if (extensionBlocked && anOverloadingType.isExtension(declaredType)) {
|
45
|
4
|
throw new XmlException(XmlMessages.typeBlockedForExtension(aHasLocation));
|
46
|
|
}
|
47
|
109
|
if (restrictionBlocked && anOverloadingType.isRestriction(declaredType)) {
|
48
|
0
|
throw new XmlException(XmlMessages.typeBlockedForRestriction(aHasLocation));
|
49
|
|
}
|
50
|
109
|
if (aDecl.isActive(BlockType.EXTENSION) && anOverloadingType.isExtension(declaredType)) {
|
51
|
12
|
throw new XmlException(XmlMessages.elementBlockedForExtension(aHasLocation));
|
52
|
|
}
|
53
|
97
|
if (aDecl.isActive(BlockType.RESTRICTION) && anOverloadingType.isRestriction(declaredType)) {
|
54
|
0
|
throw new XmlException(XmlMessages.elementBlockedForRestriction(aHasLocation));
|
55
|
|
}
|
56
|
|
}
|
57
|
|
}
|
58
|
|
|
59
|
4040
|
public static IAnyTypeData createData(IDataDesc aDecl, IDataImpl anImpl, IAnyType anOverloadingType, IHasLocation aHasLocation) throws XmlException {
|
60
|
4040
|
checkOverloadingType(aDecl, anOverloadingType, aHasLocation);
|
61
|
|
|
62
|
3991
|
IAnyType type = (null != anOverloadingType) ? anOverloadingType : aDecl.getType();
|
63
|
|
|
64
|
3991
|
IAnyTypeData data = type.createData(anImpl);
|
65
|
3971
|
data.setDataDesc_(aDecl);
|
66
|
3971
|
aDecl.checkValueConstraints(data);
|
67
|
|
|
68
|
3964
|
return data;
|
69
|
|
|
70
|
|
}
|
71
|
|
|
72
|
16
|
public static IAnyTypeData createUncheckedData(IDataDesc aDecl, IDataImpl anImpl, IAnyType anOverloadingType, IHasLocation aHasLocation) throws XmlException {
|
73
|
16
|
checkOverloadingType(aDecl, anOverloadingType, aHasLocation);
|
74
|
|
|
75
|
16
|
IAnyType type = (null != anOverloadingType) ? anOverloadingType : aDecl.getType();
|
76
|
|
|
77
|
16
|
IAnyTypeData data = type.createUncheckedData(anImpl);
|
78
|
16
|
data.setDataDesc_(aDecl);
|
79
|
|
|
80
|
16
|
return data;
|
81
|
|
}
|
82
|
|
|
83
|
0
|
public static IAnyTypeData createEmptyData(IDataDesc aDecl, IDataImpl anImpl, IAnyType anOverloadingType, IHasLocation aHasLocation) throws XmlException {
|
84
|
0
|
checkOverloadingType(aDecl, anOverloadingType, aHasLocation);
|
85
|
|
|
86
|
0
|
IAnyType type = (null != anOverloadingType) ? anOverloadingType : aDecl.getType();
|
87
|
|
|
88
|
0
|
IAnyTypeData data = type.createEmptyData(anImpl);
|
89
|
0
|
data.setDataDesc_(aDecl);
|
90
|
|
|
91
|
0
|
return data;
|
92
|
|
}
|
93
|
|
|
94
|
3971
|
public static void checkValueConstraints(IDataDesc aDesc, IAnyTypeData aData) throws XmlException {
|
95
|
3971
|
ISimpleData fixed = aDesc.getFixed();
|
96
|
3971
|
if ((null != fixed) && !fixed.simpleStorageValueEquals(aData)) {
|
97
|
7
|
throw new XmlException(XmlMessages.dataDoesNotMatchFixed(aData, fixed, aData.getImpl_()));
|
98
|
|
}
|
99
|
|
}
|
100
|
|
|
101
|
0
|
private DataDescHelper() {}
|
102
|
|
|
103
|
|
}
|
104
|
|
|