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 java.util.Iterator;
|
13
|
|
|
14
|
|
import org.jbind.xml.base.BlockType;
|
15
|
|
import org.jbind.xml.base.FinalType;
|
16
|
|
import org.jbind.xml.base.IAttribute;
|
17
|
|
import org.jbind.xml.base.IRange;
|
18
|
|
import org.jbind.xml.core.cmp.IComponentVisitor;
|
19
|
|
import org.jbind.xml.core.cmp.ISourceInfo;
|
20
|
|
import org.jbind.xml.core.content.IElemDecl;
|
21
|
|
import org.jbind.xml.core.content.IElemRef;
|
22
|
|
import org.jbind.xml.core.content.IElemRefOrDecl;
|
23
|
|
import org.jbind.xml.core.data.ISimpleData;
|
24
|
|
import org.jbind.xml.core.type.IAnyType;
|
25
|
|
import org.jbind.xml.instance.data.StringDataImpl;
|
26
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
27
|
|
import org.jbind.xml.msg.XmlException;
|
28
|
|
import org.jbind.xml.msg.XmlMessages;
|
29
|
|
|
30
|
|
public class ElemRef extends ElemRefOrDecl implements IElemRef {
|
31
|
|
|
32
|
|
private IElemRefOrDecl myElemRefOrDecl;
|
33
|
|
|
34
|
214
|
public ElemRef(ISourceInfo aSourceInfo, IRange aRange, IElemRefOrDecl anElemRefOrDecl) {
|
35
|
214
|
super(aSourceInfo, anElemRefOrDecl.getNamespace(), anElemRefOrDecl.getName(), aRange);
|
36
|
214
|
myElemRefOrDecl = anElemRefOrDecl;
|
37
|
|
}
|
38
|
|
|
39
|
489
|
ElemRef(IElemRefOrDecl anElemRefOrDecl, IRange aNewRange) {
|
40
|
489
|
super(anElemRefOrDecl, anElemRefOrDecl.getNamespace(), anElemRefOrDecl.getName(), aNewRange);
|
41
|
489
|
myElemRefOrDecl = anElemRefOrDecl;
|
42
|
489
|
myDefault = anElemRefOrDecl.getDefault();
|
43
|
489
|
myFixed = anElemRefOrDecl.getFixed();
|
44
|
|
}
|
45
|
|
|
46
|
444
|
public void accept(IComponentVisitor aVisitor) throws XmlException {
|
47
|
444
|
aVisitor.visitElemRefStart(this);
|
48
|
444
|
visitSubComponents(aVisitor);
|
49
|
444
|
aVisitor.visitElemRefEnd(this);
|
50
|
|
}
|
51
|
|
|
52
|
0
|
public String getDesc() {
|
53
|
0
|
return myElemRefOrDecl.getDesc();
|
54
|
|
}
|
55
|
|
|
56
|
15
|
private void addSimpleValueConstraints(String aDefault, String aFixed, IConstraintViolations aViolations) {
|
57
|
15
|
try {
|
58
|
15
|
myDefault = (null != aDefault) ? (ISimpleData)getType().createData(new StringDataImpl(aDefault, getPrefixToNamespaceMapping(), this)) : null;
|
59
|
15
|
myFixed = (null != aFixed) ? (ISimpleData)getType().createData(new StringDataImpl(aFixed, getPrefixToNamespaceMapping(), this)) : null;
|
60
|
15
|
if (null == myDefault) {
|
61
|
13
|
myDefault = myElemRefOrDecl.getDefault();
|
62
|
|
}
|
63
|
15
|
if (null == myFixed) {
|
64
|
13
|
myFixed = myElemRefOrDecl.getFixed();
|
65
|
|
}
|
66
|
15
|
if ((null != myFixed) && (null != myElemRefOrDecl.getFixed()) && !myFixed.equals(myElemRefOrDecl.getFixed())) {
|
67
|
0
|
aViolations.add(XmlMessages.fixedValueMustNotBeChanged(this));
|
68
|
|
}
|
69
|
15
|
if ((null != myDefault) && (null != myElemRefOrDecl.getFixed()) && !myDefault.equals(myElemRefOrDecl.getFixed())) {
|
70
|
0
|
aViolations.add(XmlMessages.defaultValueMustMatchFixed(this));
|
71
|
|
}
|
72
|
15
|
if (null != myFixed) {
|
73
|
4
|
myDefault = myFixed;
|
74
|
|
}
|
75
|
|
} catch (XmlException e) {
|
76
|
0
|
aViolations.add(e.getXmlMessage());
|
77
|
|
}
|
78
|
|
}
|
79
|
|
|
80
|
210
|
public void addValueConstraints(String aDefault, String aFixed, IConstraintViolations aViolations) {
|
81
|
210
|
IAnyType type = getType();
|
82
|
210
|
if (!type.isSimple()) {
|
83
|
195
|
if (null != aFixed) {
|
84
|
0
|
aViolations.add(XmlMessages.fixedNotAllowedForComplexType(this));
|
85
|
|
}
|
86
|
195
|
if (type.getContentModel().canContainText()) {
|
87
|
18
|
myDefaultTextContent = aDefault;
|
88
|
18
|
if (null == myDefaultTextContent) {
|
89
|
18
|
myDefaultTextContent = myElemRefOrDecl.getDefaultTextContent();
|
90
|
|
}
|
91
|
177
|
} else if (null != aDefault) {
|
92
|
0
|
aViolations.add(XmlMessages.defaultNotAllowedForNonMixedComplexType(this));
|
93
|
|
}
|
94
|
|
} else {
|
95
|
15
|
addSimpleValueConstraints(aDefault, aFixed, aViolations);
|
96
|
|
}
|
97
|
|
}
|
98
|
|
|
99
|
2028
|
public IElemRefOrDecl getSubstitute(String aNamespace, String aName) {
|
100
|
2028
|
return myElemRefOrDecl.getSubstitute(aNamespace, aName);
|
101
|
|
}
|
102
|
|
|
103
|
9475
|
public IAnyType getType() {
|
104
|
9475
|
return myElemRefOrDecl.getType();
|
105
|
|
}
|
106
|
905
|
public boolean isAbstract() {
|
107
|
905
|
return myElemRefOrDecl.isAbstract();
|
108
|
|
}
|
109
|
598
|
public boolean isNillable() {
|
110
|
598
|
return myElemRefOrDecl.isNillable();
|
111
|
|
}
|
112
|
|
|
113
|
1796
|
public boolean isActive(BlockType aBlockType) {
|
114
|
1796
|
return myElemRefOrDecl.isActive(aBlockType);
|
115
|
|
}
|
116
|
0
|
public boolean isActive(FinalType aFinalType) {
|
117
|
0
|
return myElemRefOrDecl.isActive(aFinalType);
|
118
|
|
}
|
119
|
|
|
120
|
220
|
public Iterator iterSubstitutes() {
|
121
|
220
|
return myElemRefOrDecl.iterSubstitutes();
|
122
|
|
}
|
123
|
|
|
124
|
218
|
public boolean isReference() {
|
125
|
218
|
return true;
|
126
|
|
}
|
127
|
|
|
128
|
0
|
public IElemDecl getSubstitutionGroup() {
|
129
|
0
|
return myElemRefOrDecl.getSubstitutionGroup();
|
130
|
|
}
|
131
|
|
|
132
|
3115
|
public IAttribute getBindingAttribute(String aName) {
|
133
|
3115
|
IAttribute a = super.getBindingAttribute(aName);
|
134
|
3115
|
return (null != a) ? a : myElemRefOrDecl.getBindingAttribute(aName);
|
135
|
|
}
|
136
|
1313
|
public IAttribute getLocalBindingAttribute(String aName) {
|
137
|
1313
|
IAttribute a = super.getLocalBindingAttribute(aName);
|
138
|
1313
|
return (null != a) ? a : myElemRefOrDecl.getLocalBindingAttribute(aName);
|
139
|
|
}
|
140
|
0
|
public IAttribute getDefaultedLocalBindingAttribute(String aName) {
|
141
|
0
|
IAttribute a = super.getLocalBindingAttribute(aName);
|
142
|
0
|
return (null != a) ? a : myElemRefOrDecl.getLocalBindingAttribute(aName);
|
143
|
|
}
|
144
|
|
|
145
|
|
}
|
146
|
|
|