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.core.cmp.IComponent;
|
15
|
|
import org.jbind.xml.core.cmp.IComponentStore;
|
16
|
|
import org.jbind.xml.core.content.IContentDesc;
|
17
|
|
import org.jbind.xml.core.content.IElemGroupDecl;
|
18
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
19
|
|
import org.jbind.xml.msg.XmlException;
|
20
|
|
import org.jbind.xml.schema.instantiation.IComponentSetter;
|
21
|
|
import org.jbind.xml.schema.instantiation.IElementHelper;
|
22
|
|
import org.jbind.xml.schema.instantiation.IHasTopLevelJobs;
|
23
|
|
import org.jbind.xml.schema.instantiation.IJobRefs;
|
24
|
|
|
25
|
|
public abstract class ModelGroup extends Particle implements IModelGroup {
|
26
|
|
|
27
|
381
|
public ModelGroup(CreationParams aCreationParams) {
|
28
|
381
|
super(aCreationParams);
|
29
|
|
}
|
30
|
|
|
31
|
777
|
protected IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
|
32
|
777
|
IElement res = null;
|
33
|
777
|
String componentName = NameUtil.getSchemaComponentName(aCreationParams);
|
34
|
777
|
if ("element".equals(componentName)) {
|
35
|
620
|
res = new ElementDeclaration(aCreationParams, true);
|
36
|
157
|
} else if ("any".equals(componentName)) {
|
37
|
42
|
res = new AnyElement(aCreationParams);
|
38
|
115
|
} else if ("group".equals(componentName)) {
|
39
|
61
|
res = new ModelGroupRef(aCreationParams);
|
40
|
54
|
} else if ("choice".equals(componentName)) {
|
41
|
28
|
res = new ChoiceModelGroup(aCreationParams);
|
42
|
26
|
} else if ("sequence".equals(componentName)) {
|
43
|
8
|
res = new SequenceModelGroup(aCreationParams);
|
44
|
18
|
} else if ("all".equals(componentName)) {
|
45
|
8
|
res = new AllModelGroup(aCreationParams);
|
46
|
|
} else {
|
47
|
10
|
res = super.doCreateChild(aCreationParams);
|
48
|
|
}
|
49
|
777
|
return res;
|
50
|
|
}
|
51
|
|
|
52
|
1626
|
public Iterator iterParticles() {
|
53
|
1626
|
return iterChildrenByClass(IParticle.class);
|
54
|
|
}
|
55
|
|
|
56
|
423
|
public void collectRefsForCreation(IJobRefs aJobRefs) {
|
57
|
423
|
for (Iterator i = iterParticles(); i.hasNext(); ) {
|
58
|
881
|
IParticle p = (IParticle)i.next();
|
59
|
881
|
p.collectRefsForCreation(aJobRefs);
|
60
|
|
}
|
61
|
|
}
|
62
|
|
|
63
|
835
|
public void collectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {
|
64
|
835
|
for (Iterator i = iterParticles(); i.hasNext(); ) {
|
65
|
1751
|
IParticle p = (IParticle)i.next();
|
66
|
1751
|
p.collectRefsForCompletion(anElementHelper, aJobRefs);
|
67
|
|
}
|
68
|
|
}
|
69
|
0
|
public void collectRefsForValidation(IElementHelper anElementHelper, IJobRefs aJobRefs) {
|
70
|
0
|
for (Iterator i = iterParticles(); i.hasNext(); ) {
|
71
|
0
|
IParticle p = (IParticle)i.next();
|
72
|
0
|
p.collectRefsForValidation(anElementHelper, aJobRefs);
|
73
|
|
}
|
74
|
|
}
|
75
|
|
|
76
|
329
|
public IComponent createComponent(IElementHelper aHelper, IConstraintViolations aViolations) {
|
77
|
329
|
return createComponent(aHelper, aViolations, null, null);
|
78
|
|
}
|
79
|
|
|
80
|
365
|
protected void doAddSubJobs(final IElemGroupDecl aContent, IElementHelper aHelper, IConstraintViolations aViolations) {
|
81
|
365
|
int idx = 0;
|
82
|
365
|
for (Iterator i = iterParticles(); i.hasNext(); ) {
|
83
|
749
|
IParticle p = (IParticle)i.next();
|
84
|
|
// Index of the particle. It is important that the sub content has the
|
85
|
|
// same sequence as the particles.
|
86
|
749
|
final int index = idx++;
|
87
|
749
|
aHelper.addSubJob(p, new IComponentSetter() {
|
88
|
746
|
public void set(IComponent aComponent, IConstraintViolations aVls) {
|
89
|
746
|
aContent.setSubContent(index, (IContentDesc)aComponent);
|
90
|
|
}
|
91
|
|
});
|
92
|
|
}
|
93
|
|
}
|
94
|
|
|
95
|
342
|
public void addSchemaData(IComponentStore aStore, IComponent aComponent, IConstraintViolations aViolations) {}
|
96
|
0
|
public void createAndAddJob(IHasTopLevelJobs aHasTopLevelJobs) {}
|
97
|
|
|
98
|
|
}
|
99
|
|
|