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 org.jbind.xml.base.AttributeOccurence;
|
13
|
|
import org.jbind.xml.base.IAttribute;
|
14
|
|
import org.jbind.xml.base.IBindingAttributes;
|
15
|
|
import org.jbind.xml.base.INamespaces;
|
16
|
|
import org.jbind.xml.base.ISymbolspace;
|
17
|
|
import org.jbind.xml.base.ISymbolspaces;
|
18
|
|
import org.jbind.xml.core.cmp.IComponent;
|
19
|
|
import org.jbind.xml.core.content.IAttrRefOrDecl;
|
20
|
|
import org.jbind.xml.core.type.IAnyType;
|
21
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
22
|
|
import org.jbind.xml.msg.XmlException;
|
23
|
|
import org.jbind.xml.msg.XmlMessages;
|
24
|
|
import org.jbind.xml.schema.cmp.AttrDecl;
|
25
|
|
import org.jbind.xml.schema.cmp.AttrRef;
|
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 AttributeDeclaration extends PartDeclaration implements IAttributeDeclaration {
|
33
|
|
|
34
|
|
private AttributeOccurence myOccurence = AttributeOccurence.OPTIONAL;
|
35
|
|
private ISimpleTypeDef mySimpleTypeDef = null;
|
36
|
|
|
37
|
723
|
public AttributeDeclaration(CreationParams aCreationParams, boolean anIsLocal) {
|
38
|
723
|
super(aCreationParams, anIsLocal);
|
39
|
|
}
|
40
|
|
|
41
|
70
|
protected IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
|
42
|
70
|
IElement res = null;
|
43
|
70
|
String componentName = NameUtil.getSchemaComponentName(aCreationParams);
|
44
|
70
|
if ("simpleType".equals(componentName)) {
|
45
|
46
|
res = new SimpleTypeDef(aCreationParams, getBoundName());
|
46
|
|
} else {
|
47
|
24
|
res = super.doCreateChild(aCreationParams);
|
48
|
|
}
|
49
|
70
|
return res;
|
50
|
|
}
|
51
|
|
|
52
|
1548
|
protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
|
53
|
1548
|
IAttribute res = null;
|
54
|
1548
|
String an = NameUtil.getSchemaAttributeName(anACParams);
|
55
|
1548
|
String upan = NameUtil.getBindingAttributeName(anACParams);
|
56
|
1548
|
if ("use".equals(an)) {
|
57
|
198
|
if (!getIsLocal()) {
|
58
|
1
|
throw new XmlException(XmlMessages.useAttributeNotAllowedAtTopLevel(this));
|
59
|
|
}
|
60
|
197
|
res = new Attribute(anACParams);
|
61
|
197
|
myOccurence = ConstantResolver.getOccurence(res.getStringValue(), this);
|
62
|
1350
|
} else if (IBindingAttributes.REFERENCED_TYPE.equals(upan)) {
|
63
|
0
|
res = new RefAttribute(anACParams, ISymbolspaces.TYPE);
|
64
|
|
} else {
|
65
|
1350
|
res = super.doCreateAttribute(anACParams);
|
66
|
|
}
|
67
|
1545
|
return res;
|
68
|
|
}
|
69
|
|
|
70
|
192
|
public ISimpleTypeDef getSimpleTypeDef() {
|
71
|
192
|
return mySimpleTypeDef;
|
72
|
|
}
|
73
|
|
|
74
|
0
|
public AttributeOccurence getOccurence() {
|
75
|
0
|
return myOccurence;
|
76
|
|
}
|
77
|
|
|
78
|
114
|
public ISymbolspace getSymbolSpace() {
|
79
|
114
|
return ISymbolspaces.ATTRIBUTE;
|
80
|
|
}
|
81
|
|
|
82
|
723
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
83
|
723
|
super.validateElement(aHelper, aViolations);
|
84
|
723
|
mySimpleTypeDef = (ISimpleTypeDef)getSubElement(ISimpleTypeDef.class, "duplicate type definition", aViolations);
|
85
|
723
|
if (((null != getRef()) && (null != getType())) || ((null != getRef()) && (null != mySimpleTypeDef)) || ((null != getType()) && (null != mySimpleTypeDef))) {
|
86
|
0
|
aViolations.add(XmlMessages.invalidAttributeDecl(this));
|
87
|
|
}
|
88
|
|
}
|
89
|
|
|
90
|
|
//
|
91
|
|
// Implementation of IComponentJobHelper
|
92
|
|
//
|
93
|
|
|
94
|
677
|
public void collectRefsForCreation(IJobRefs aJobRefs) {
|
95
|
677
|
if (null != getRef()) {
|
96
|
33
|
aJobRefs.add(getRef(), true, this);
|
97
|
|
}
|
98
|
677
|
if (null != getType()) {
|
99
|
497
|
aJobRefs.add(getType(), true, this);
|
100
|
|
}
|
101
|
|
}
|
102
|
|
|
103
|
1354
|
public void collectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
|
104
|
0
|
public void collectRefsForValidation(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
|
105
|
|
|
106
|
677
|
public IComponent createComponent(IElementHelper anElementHelper, IConstraintViolations aViolations) {
|
107
|
677
|
IAttrRefOrDecl res = null;
|
108
|
|
|
109
|
677
|
if (null != getRef()) {
|
110
|
33
|
IAttrRefOrDecl referencedDecl = (IAttrRefOrDecl)anElementHelper.getComponent(getRef(), true);
|
111
|
33
|
res = new AttrRef(this, myOccurence, referencedDecl);
|
112
|
|
|
113
|
|
} else {
|
114
|
644
|
FormType ft = null;
|
115
|
644
|
if (isTopLevelComponent()) {
|
116
|
69
|
ft = FormType.QUALIFIED;
|
117
|
|
} else {
|
118
|
575
|
ft = getFormType();
|
119
|
575
|
if (null == ft) {
|
120
|
573
|
ft = getSchemaElement().getAttributeFormDefault();
|
121
|
|
}
|
122
|
|
}
|
123
|
644
|
String namespace;
|
124
|
644
|
if (ft == FormType.QUALIFIED) {
|
125
|
98
|
namespace = getSchemaElement().getTargetNamespace();
|
126
|
|
} else {
|
127
|
546
|
namespace = INamespaces.NO;
|
128
|
|
}
|
129
|
|
|
130
|
644
|
final AttrDecl decl = new AttrDecl(this, myOccurence, namespace, getName());
|
131
|
644
|
res = decl;
|
132
|
|
|
133
|
644
|
if (null != getType()) {
|
134
|
497
|
decl.setType((IAnyType)anElementHelper.getComponent(getType(), true));
|
135
|
147
|
} else if (null != getSimpleTypeDef()) {
|
136
|
45
|
anElementHelper.addSubJob(getSimpleTypeDef(), new IComponentSetter() {
|
137
|
45
|
public void set(IComponent aComponent, IConstraintViolations aVls) {
|
138
|
45
|
IAnyType t = (IAnyType)aComponent;
|
139
|
45
|
decl.setType(t);
|
140
|
|
}
|
141
|
|
});
|
142
|
|
} else {
|
143
|
102
|
decl.setType(W3CTypes.anySimpleType);
|
144
|
102
|
decl.setHasDefaultType();
|
145
|
|
}
|
146
|
|
}
|
147
|
|
|
148
|
677
|
return res;
|
149
|
|
}
|
150
|
|
|
151
|
|
}
|
152
|
|
|