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.Collections;
|
13
|
|
import java.util.Iterator;
|
14
|
|
|
15
|
|
import org.jbind.xml.base.IAttribute;
|
16
|
|
import org.jbind.xml.base.StringUtil;
|
17
|
|
import org.jbind.xml.core.cmp.IAnnotation;
|
18
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
19
|
|
import org.jbind.xml.msg.XmlException;
|
20
|
|
import org.jbind.xml.msg.XmlMessages;
|
21
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
22
|
|
|
23
|
|
public abstract class Annotated extends OpenAttributes implements IAnnotated {
|
24
|
|
|
25
|
|
private IAnnotationElement myAnnotationElement = null;
|
26
|
|
private String myId = null;
|
27
|
|
|
28
|
5111
|
public Annotated(CreationParams aCreationParams) {
|
29
|
5111
|
super(aCreationParams);
|
30
|
|
}
|
31
|
|
|
32
|
0
|
public IAnnotationElement getAnnotationElement() {
|
33
|
0
|
return myAnnotationElement;
|
34
|
|
}
|
35
|
|
|
36
|
0
|
public String getId() {
|
37
|
0
|
return myId;
|
38
|
|
}
|
39
|
|
|
40
|
337
|
protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
|
41
|
337
|
IAttribute res = null;
|
42
|
337
|
String an = NameUtil.getSchemaAttributeName(anACParams);
|
43
|
337
|
if ("id".equals(an)) {
|
44
|
285
|
res = new Attribute(anACParams);
|
45
|
285
|
myId = res.getStringValue();
|
46
|
|
} else {
|
47
|
52
|
res = super.doCreateAttribute(anACParams);
|
48
|
|
}
|
49
|
337
|
return res;
|
50
|
|
}
|
51
|
|
|
52
|
308
|
protected IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
|
53
|
308
|
IElement res = null;
|
54
|
308
|
String componentName = NameUtil.getSchemaComponentName(aCreationParams);
|
55
|
308
|
if ("annotation".equals(componentName)) {
|
56
|
305
|
if (hasChildren()) {
|
57
|
4
|
throw new XmlException(XmlMessages.notAllowedHere("Annotation", aCreationParams.myLocation));
|
58
|
|
}
|
59
|
301
|
myAnnotationElement = new AnnotationElement(aCreationParams);
|
60
|
301
|
res = myAnnotationElement;
|
61
|
|
} else {
|
62
|
3
|
res = super.doCreateChild(aCreationParams);
|
63
|
|
}
|
64
|
304
|
return res;
|
65
|
|
}
|
66
|
|
|
67
|
4499
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
68
|
4499
|
super.validateElement(aHelper, aViolations);
|
69
|
4499
|
if (null != myId) {
|
70
|
285
|
if (!StringUtil.isValidNCName(myId)) {
|
71
|
5
|
aViolations.add(XmlMessages.invalidValueForIdAttribute(myId, this));
|
72
|
|
} else {
|
73
|
280
|
if (!getSchemaElement().addElementId(myId)) {
|
74
|
3
|
aViolations.add(XmlMessages.valueOfIdAttributeNotUnique(myId, this));
|
75
|
|
}
|
76
|
|
}
|
77
|
|
}
|
78
|
|
}
|
79
|
|
|
80
|
936
|
protected Iterator iterAppInfos() {
|
81
|
936
|
Iterator res = null;
|
82
|
936
|
if (myAnnotationElement != null) {
|
83
|
92
|
res = myAnnotationElement.iterAppInfos();
|
84
|
|
} else {
|
85
|
844
|
res = Collections.EMPTY_LIST.iterator();
|
86
|
|
}
|
87
|
936
|
return res;
|
88
|
|
}
|
89
|
|
|
90
|
2257
|
public IAnnotation getAnnotation() {
|
91
|
2257
|
return myAnnotationElement;
|
92
|
|
}
|
93
|
|
|
94
|
|
}
|
95
|
|
|