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.IAttribute;
|
13
|
|
import org.jbind.xml.base.IBindingAttributes;
|
14
|
|
import org.jbind.xml.base.IRef;
|
15
|
|
import org.jbind.xml.base.Ref;
|
16
|
|
import org.jbind.xml.base.StringUtil;
|
17
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
18
|
|
import org.jbind.xml.msg.XmlException;
|
19
|
|
import org.jbind.xml.msg.XmlMessages;
|
20
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
21
|
|
import org.jbind.xml.schema.instantiation.IHasTopLevelJobs;
|
22
|
|
|
23
|
|
public abstract class Named extends Annotated implements INamed {
|
24
|
|
|
25
|
|
private String myName = null;
|
26
|
|
|
27
|
2641
|
public Named(CreationParams aCreationParams) {
|
28
|
2641
|
super(aCreationParams);
|
29
|
|
assert null != getParent_() : "missing parent";
|
30
|
|
}
|
31
|
|
|
32
|
2328
|
protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
|
33
|
2328
|
IAttribute res = null;
|
34
|
2328
|
String an = NameUtil.getSchemaAttributeName(anACParams);
|
35
|
2328
|
String upan = NameUtil.getBindingAttributeName(anACParams);
|
36
|
2328
|
if (IBindingAttributes.NAME.equals(upan)) {
|
37
|
2
|
res = new Attribute(anACParams);
|
38
|
2326
|
} else if ("name".equals(an)) {
|
39
|
2096
|
res = new Attribute(anACParams);
|
40
|
2096
|
myName = res.getStringValue();
|
41
|
|
} else {
|
42
|
230
|
res = super.doCreateAttribute(anACParams);
|
43
|
|
}
|
44
|
2328
|
return res;
|
45
|
|
}
|
46
|
|
|
47
|
2641
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
48
|
2641
|
super.validateElement(aHelper, aViolations);
|
49
|
2641
|
if ((null != myName) && !StringUtil.isValidNCName(myName)) {
|
50
|
3
|
aViolations.add(XmlMessages.invalidValueForNameAttribute(myName, this));
|
51
|
|
}
|
52
|
|
}
|
53
|
|
|
54
|
6299
|
public String getName() {
|
55
|
6299
|
return myName;
|
56
|
|
}
|
57
|
|
|
58
|
14
|
public void setName(String aName) {
|
59
|
14
|
myName = aName;
|
60
|
|
}
|
61
|
|
|
62
|
1082
|
public IRef getGlobalRef() {
|
63
|
|
assert null != getName() : "element has no name: " + this;
|
64
|
1082
|
SchemaElement se = getSchemaElement();
|
65
|
1082
|
return new Ref(se.getTargetNamespace(), getSymbolSpace(), getName());
|
66
|
|
}
|
67
|
|
|
68
|
967
|
public void createAndAddJob(IHasTopLevelJobs aSchemaJob) {
|
69
|
967
|
aSchemaJob.addComponentJob(this);
|
70
|
|
}
|
71
|
|
|
72
|
0
|
public String toString() {
|
73
|
0
|
if (null != getName()) {
|
74
|
0
|
return getGlobalRef().toString();
|
75
|
|
} else {
|
76
|
0
|
return "" + getSymbolSpace() + " at " + getLocation();
|
77
|
|
}
|
78
|
|
}
|
79
|
|
}
|
80
|
|
|