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.IRef;
|
14
|
|
import org.jbind.xml.base.ISymbolspaces;
|
15
|
|
import org.jbind.xml.core.cmp.IComponent;
|
16
|
|
import org.jbind.xml.core.constraint.ITypeInstanceConstraint;
|
17
|
|
import org.jbind.xml.core.type.IAnyType;
|
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.constraint.TypeKeyRefConstraint;
|
22
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
23
|
|
import org.jbind.xml.schema.instantiation.IElementHelper;
|
24
|
|
import org.jbind.xml.schema.instantiation.IJobRefs;
|
25
|
|
|
26
|
|
public class TypeKeyRefConstraintElement extends TypeIdentityConstraintElement implements IKeyRefConstraintElement {
|
27
|
|
|
28
|
|
private IRef myRefer = null;
|
29
|
|
|
30
|
8
|
public TypeKeyRefConstraintElement(CreationParams aCreationParams) {
|
31
|
8
|
super(aCreationParams);
|
32
|
|
}
|
33
|
|
|
34
|
0
|
public IRef getRefer() {
|
35
|
0
|
return myRefer;
|
36
|
|
}
|
37
|
|
|
38
|
16
|
protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
|
39
|
16
|
IAttribute res = null;
|
40
|
16
|
String an = NameUtil.getSchemaAttributeName(anACParams);
|
41
|
16
|
String upan = NameUtil.getBindingAttributeName(anACParams);
|
42
|
16
|
if ("refer".equals(an)) {
|
43
|
8
|
res = new RefAttribute(anACParams, ISymbolspaces.IDENTITY_CONSTRAINT);
|
44
|
8
|
myRefer = res.getRef();
|
45
|
|
} else {
|
46
|
8
|
res = super.doCreateAttribute(anACParams);
|
47
|
|
}
|
48
|
16
|
return res;
|
49
|
|
}
|
50
|
|
|
51
|
8
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
52
|
8
|
super.validateElement(aHelper, aViolations);
|
53
|
8
|
if (null == myRefer) {
|
54
|
0
|
aViolations.add(XmlMessages.missingAttribute("refer", this));
|
55
|
|
}
|
56
|
|
}
|
57
|
|
|
58
|
16
|
protected void doCollectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {
|
59
|
16
|
aJobRefs.add(myRefer, true, this);
|
60
|
|
}
|
61
|
|
|
62
|
8
|
public IComponent createComponent(IElementHelper anElementHelper, IConstraintViolations aViolations) {
|
63
|
8
|
return new TypeKeyRefConstraint(this, getTargetNamespace(), getName());
|
64
|
|
}
|
65
|
|
|
66
|
8
|
public void completeComponent(IElementHelper anElementHelper, IComponent aComponent, IConstraintViolations aViolations) {
|
67
|
8
|
super.completeComponent(anElementHelper, aComponent, aViolations);
|
68
|
8
|
TypeKeyRefConstraint krc = (TypeKeyRefConstraint)aComponent;
|
69
|
8
|
IComponent referredComponent = anElementHelper.getComponent(myRefer, true);
|
70
|
8
|
if (!(referredComponent instanceof ITypeInstanceConstraint)) {
|
71
|
0
|
aViolations.add(XmlMessages.referencedConstraintMustBeKeyOrUnique(this));
|
72
|
|
} else {
|
73
|
8
|
ITypeInstanceConstraint referredConstraint = (ITypeInstanceConstraint)referredComponent;
|
74
|
8
|
if (krc.getNbFields() != referredConstraint.getNbFields()) {
|
75
|
0
|
aViolations.add(XmlMessages.numberOfkeyRefFieldsDoNotMatchKeyFields(this));
|
76
|
|
}
|
77
|
8
|
krc.setReferredConstraint(referredConstraint);
|
78
|
8
|
IAnyType referredDataType = referredConstraint.getDataType();
|
79
|
8
|
if (null == krc.getDataType()) {
|
80
|
8
|
krc.setDataType(referredDataType);
|
81
|
|
} else {
|
82
|
0
|
if (!referredDataType.isBaseType(krc.getDataType())) {
|
83
|
0
|
aViolations.add(XmlMessages.typeOfRefMustBeSubType(this));
|
84
|
|
}
|
85
|
|
}
|
86
|
|
}
|
87
|
|
}
|
88
|
|
|
89
|
|
}
|
90
|
|
|