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.Iterator;
|
13
|
|
|
14
|
|
import org.jbind.xml.base.IRef;
|
15
|
|
import org.jbind.xml.base.ISymbolspace;
|
16
|
|
import org.jbind.xml.base.ISymbolspaces;
|
17
|
|
import org.jbind.xml.core.cmp.IComponent;
|
18
|
|
import org.jbind.xml.core.cmp.IComponentStore;
|
19
|
|
import org.jbind.xml.core.content.IAttrGroupDecl;
|
20
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
21
|
|
import org.jbind.xml.msg.XmlException;
|
22
|
|
import org.jbind.xml.msg.XmlMessages;
|
23
|
|
import org.jbind.xml.schema.cmp.AttrGroupDecl;
|
24
|
|
import org.jbind.xml.schema.instantiation.IElemValHelper;
|
25
|
|
import org.jbind.xml.schema.instantiation.IElementHelper;
|
26
|
|
import org.jbind.xml.schema.instantiation.IJobRefs;
|
27
|
|
import org.jbind.xml.schema.instantiation.ITopLevelElement;
|
28
|
|
|
29
|
|
public class AttributeGroupDeclaration extends GroupDeclaration implements IAttributeGroupDeclaration {
|
30
|
|
|
31
|
|
private IAttributeInfos myAttributeInfos = null;
|
32
|
|
|
33
|
67
|
public AttributeGroupDeclaration(CreationParams aCreationParams) {
|
34
|
67
|
super(aCreationParams);
|
35
|
67
|
myAttributeInfos = new AttributeInfos(this);
|
36
|
|
}
|
37
|
|
|
38
|
114
|
protected IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
|
39
|
114
|
IElement res = null;
|
40
|
114
|
String componentName = NameUtil.getSchemaComponentName(aCreationParams);
|
41
|
114
|
if ("attribute".equals(componentName)) {
|
42
|
84
|
res = new AttributeDeclaration(aCreationParams, true);
|
43
|
30
|
} else if ("attributeGroup".equals(componentName)) {
|
44
|
21
|
res = new AttributeGroupRef(aCreationParams);
|
45
|
9
|
} else if ("anyAttribute".equals(componentName)) {
|
46
|
0
|
res = new AnyAttribute(aCreationParams);
|
47
|
|
} else {
|
48
|
9
|
res = super.doCreateChild(aCreationParams);
|
49
|
|
}
|
50
|
113
|
return res;
|
51
|
|
}
|
52
|
|
|
53
|
0
|
public IAttributeInfos getAttributeInfos() {
|
54
|
0
|
return myAttributeInfos;
|
55
|
|
}
|
56
|
|
|
57
|
94
|
public ISymbolspace getSymbolSpace() {
|
58
|
94
|
return ISymbolspaces.ATTRIBUTE_GROUP;
|
59
|
|
}
|
60
|
|
|
61
|
67
|
public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
|
62
|
67
|
super.validateElement(aHelper, aViolations);
|
63
|
67
|
myAttributeInfos.validate(aViolations);
|
64
|
|
}
|
65
|
|
|
66
|
|
//
|
67
|
|
// Implementation of IComponentJobHelper
|
68
|
|
//
|
69
|
|
|
70
|
54
|
public void collectRefsForCreation(IJobRefs aJobRefs) {
|
71
|
54
|
myAttributeInfos.collectRefsForCreation(aJobRefs);
|
72
|
|
}
|
73
|
|
|
74
|
104
|
public void collectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
|
75
|
0
|
public void collectRefsForValidation(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
|
76
|
|
|
77
|
52
|
public IComponent createComponent(IElementHelper anElementHelper, IConstraintViolations aViolations) {
|
78
|
52
|
IAttrGroupDecl res = new AttrGroupDecl(this, getSchemaElement().getTargetNamespace(), getName());
|
79
|
52
|
myAttributeInfos.applyAttributes(anElementHelper, res, aViolations);
|
80
|
52
|
if (null != myRedefinedRef) {
|
81
|
|
// TODO validate that it is a valid redefinition
|
82
|
|
}
|
83
|
52
|
return res;
|
84
|
|
}
|
85
|
|
|
86
|
52
|
public void completeComponent(IElementHelper anElementHelper, IComponent aComponent, IConstraintViolations aViolations) {}
|
87
|
|
|
88
|
44
|
public void addSchemaData(IComponentStore aComponentStore, IComponent aComponent, IConstraintViolations aViolations) {}
|
89
|
|
|
90
|
5
|
public void redefine(ITopLevelElement aRedefinedElement, IConstraintViolations aViolations) {
|
91
|
5
|
boolean replaced = false;
|
92
|
5
|
for (Iterator i = myAttributeInfos.iterAttributeGroupRefs(); i.hasNext(); ) {
|
93
|
5
|
IAttributeGroupRef agr = (IAttributeGroupRef)i.next();
|
94
|
5
|
if (agr.getRef().equals(getGlobalRef())) {
|
95
|
5
|
if (!replaced) {
|
96
|
5
|
agr.setRef(aRedefinedElement.getGlobalRef());
|
97
|
5
|
replaced = true;
|
98
|
|
} else {
|
99
|
0
|
aViolations.add(XmlMessages.redefinedGroupCanOnlyBeReferencedOnce(this));
|
100
|
|
}
|
101
|
|
}
|
102
|
|
}
|
103
|
|
}
|
104
|
|
|
105
|
|
private IRef myRedefinedRef = null;
|
106
|
0
|
public IRef getRedefinedRef() {
|
107
|
0
|
return myRedefinedRef;
|
108
|
|
}
|
109
|
5
|
public void setRedefinedRef(IRef aRef) {
|
110
|
5
|
myRedefinedRef = aRef;
|
111
|
|
}
|
112
|
|
}
|
113
|
|
|