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.element;
|
11
|
|
|
12
|
|
import java.util.Set;
|
13
|
|
|
14
|
|
import org.jbind.xml.base.IAttribute;
|
15
|
|
import org.jbind.xml.base.IRef;
|
16
|
|
import org.jbind.xml.base.ISymbolspaces;
|
17
|
|
import org.jbind.xml.core.cmp.IComponent;
|
18
|
|
import org.jbind.xml.core.cmp.IComponentStore;
|
19
|
|
import org.jbind.xml.core.cmp.ISourceInfo;
|
20
|
|
import org.jbind.xml.core.type.IAnyType;
|
21
|
|
import org.jbind.xml.core.type.ISimpleType;
|
22
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
23
|
|
import org.jbind.xml.msg.XmlException;
|
24
|
|
import org.jbind.xml.msg.XmlMessages;
|
25
|
|
import org.jbind.xml.schema.cmp.ListType;
|
26
|
|
import org.jbind.xml.schema.cmp.W3CTypes;
|
27
|
|
import org.jbind.xml.schema.instantiation.IComponentSetter;
|
28
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
29
|
|
import org.jbind.xml.schema.instantiation.IElementHelper;
|
30
|
|
import org.jbind.xml.schema.instantiation.IJobRefs;
|
31
|
|
|
32
|
|
public class ListVariety extends Variety implements IListVariety {
|
33
|
|
|
34
|
|
private IRef myItemType = null;
|
35
|
|
private ISimpleTypeDef mySimpleTypeDef = null;
|
36
|
|
|
37
|
|
|
38
|
39
|
public ListVariety(CreationParams aCreationParams) {
|
39
|
39
|
super(aCreationParams);
|
40
|
|
}
|
41
|
|
|
42
|
|
|
43
|
75
|
public IRef getItemType() {
|
44
|
75
|
return myItemType;
|
45
|
|
}
|
46
|
|
|
47
|
|
|
48
|
4
|
public ISimpleTypeDef getSimpleTypeDef() {
|
49
|
4
|
return mySimpleTypeDef;
|
50
|
|
}
|
51
|
|
|
52
|
35
|
protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
|
53
|
35
|
IAttribute res = null;
|
54
|
35
|
String an = NameUtil.getSchemaAttributeName(anACParams);
|
55
|
35
|
if ("itemType".equals(an)) {
|
56
|
35
|
res = new RefAttribute(anACParams, ISymbolspaces.TYPE);
|
57
|
35
|
myItemType = res.getRef();
|
58
|
|
} else {
|
59
|
0
|
res = super.doCreateAttribute(anACParams);
|
60
|
|
}
|
61
|
35
|
return res;
|
62
|
|
}
|
63
|
|
|
64
|
4
|
protected IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
|
65
|
4
|
IElement res = null;
|
66
|
4
|
String componentName = NameUtil.getSchemaComponentName(aCreationParams);
|
67
|
4
|
if ("simpleType".equals(componentName)) {
|
68
|
4
|
res = new SimpleTypeDef(aCreationParams, "Item");
|
69
|
|
} else {
|
70
|
0
|
res = super.doCreateChild(aCreationParams);
|
71
|
|
}
|
72
|
4
|
return res;
|
73
|
|
}
|
74
|
|
|
75
|
39
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
76
|
39
|
super.validateElement(aHelper, aViolations);
|
77
|
39
|
mySimpleTypeDef = (ISimpleTypeDef)getSubElement(ISimpleTypeDef.class, "duplicate item type definition", aViolations);
|
78
|
39
|
if ((null != myItemType) && (null != mySimpleTypeDef)) {
|
79
|
0
|
aViolations.add(XmlMessages.itemTypeReferencedAndInlined(this));
|
80
|
|
}
|
81
|
39
|
if ((null == myItemType) && (null == mySimpleTypeDef)) {
|
82
|
0
|
aViolations.add(XmlMessages.missingItemType(this));
|
83
|
|
}
|
84
|
|
}
|
85
|
|
|
86
|
|
|
87
|
33
|
public void collectRefsForCreation(IJobRefs aJobRefs) {
|
88
|
33
|
IRef r = getItemType();
|
89
|
33
|
if (null != r) {
|
90
|
29
|
aJobRefs.add(r, true, this);
|
91
|
|
}
|
92
|
|
}
|
93
|
|
|
94
|
|
|
95
|
23
|
public IComponent createComponent(IElementHelper anElementHelper, ISourceInfo aSourceInfo, String aNamespace, String aName, String aRole, Set aFinalTypes, final IConstraintViolations aViolations) {
|
96
|
23
|
final ListType res = new ListType(aSourceInfo, aNamespace, aName, aRole, aFinalTypes);
|
97
|
|
|
98
|
|
// Set the item type. It is either referenced or defined.
|
99
|
23
|
if (null != getItemType()) {
|
100
|
19
|
IComponent c = anElementHelper.getComponent(getItemType(), true);
|
101
|
19
|
if (!(c instanceof ISimpleType)) {
|
102
|
0
|
aViolations.add(XmlMessages.itemTypeMustBeSimple(this));
|
103
|
|
}
|
104
|
19
|
ISimpleType t = (ISimpleType)c;
|
105
|
19
|
if (t == W3CTypes.notation) {
|
106
|
0
|
aViolations.add(XmlMessages.notationTypeMustNotBeUsedDirectly(this));
|
107
|
|
} else {
|
108
|
19
|
res.setItemType(t, aViolations);
|
109
|
|
}
|
110
|
|
} else {
|
111
|
4
|
anElementHelper.addSubJob(getSimpleTypeDef(), new IComponentSetter() {
|
112
|
4
|
public void set(IComponent aComponent, IConstraintViolations aVls) {
|
113
|
4
|
ISimpleType t = (ISimpleType)aComponent;
|
114
|
4
|
res.setItemType(t, aVls);
|
115
|
|
}
|
116
|
|
});
|
117
|
|
}
|
118
|
|
|
119
|
23
|
return res;
|
120
|
|
}
|
121
|
|
|
122
|
23
|
public void addSchemaData(IComponentStore aComponentStore, IComponent aComponent, IConstraintViolations aViolations) {}
|
123
|
|
|
124
|
9
|
public IRef getBaseRef() {
|
125
|
9
|
return W3CTypes.anyListType.getGlobalRef();
|
126
|
|
}
|
127
|
|
|
128
|
9
|
public void collectConstraints(IAnyType aType, IConstraintViolations aViolations) {}
|
129
|
|
|
130
|
|
}
|
131
|
|
|