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.reader;
|
11
|
|
|
12
|
|
import org.jbind.xml.base.IRef;
|
13
|
|
import org.jbind.xml.core.cmp.IComponent;
|
14
|
|
import org.jbind.xml.msg.IConstraintViolations;
|
15
|
|
import org.jbind.xml.schema.instantiation.IComponentJobHelper;
|
16
|
|
import org.jbind.xml.schema.instantiation.IComponentSetter;
|
17
|
|
import org.jbind.xml.schema.instantiation.IJobRefs;
|
18
|
|
|
19
|
|
public class ComponentJob extends Job implements IComponentJob {
|
20
|
|
|
21
|
|
/**
|
22
|
|
* The component that is created by this job.
|
23
|
|
*/
|
24
|
|
private IComponent myComponent = null;
|
25
|
|
|
26
|
|
private IComponentJobHelper myHelper = null;
|
27
|
|
private IComponentSetter myAfterCreation = null;
|
28
|
|
private IComponentSetter myAfterValidation = null;
|
29
|
|
|
30
|
|
|
31
|
3551
|
public ComponentJob(IComponentJobHelper aHelper, IComponentSetter anAfterCreation, IComponentSetter anAfterValidation) {
|
32
|
3551
|
super(aHelper);
|
33
|
3551
|
myHelper = aHelper;
|
34
|
3551
|
myAfterCreation = anAfterCreation;
|
35
|
3551
|
myAfterValidation = anAfterValidation;
|
36
|
|
}
|
37
|
|
|
38
|
24180
|
public IInstantiator getInstantiator() {
|
39
|
24180
|
return getParent().getInstantiator();
|
40
|
|
}
|
41
|
|
|
42
|
21115
|
private IComponentJobHelper getComponentJobHelper() {
|
43
|
21115
|
return (IComponentJobHelper)myHelper;
|
44
|
|
}
|
45
|
|
|
46
|
|
|
47
|
3551
|
protected void collectRefsForCreation(IJobRefs aJobRefs) {
|
48
|
3551
|
getComponentJobHelper().collectRefsForCreation(aJobRefs);
|
49
|
|
}
|
50
|
|
|
51
|
|
|
52
|
7017
|
protected void collectRefsForCompletion(IJobRefs aJobRefs) {
|
53
|
7017
|
getComponentJobHelper().collectRefsForCompletion(this, aJobRefs);
|
54
|
|
}
|
55
|
|
|
56
|
0
|
protected void collectRefsForValidation(IJobRefs aJobRefs) {
|
57
|
0
|
getComponentJobHelper().collectRefsForValidation(this, aJobRefs);
|
58
|
|
}
|
59
|
|
|
60
|
|
|
61
|
3525
|
public void doExecuteCreation(IConstraintViolations aViolations) {
|
62
|
3525
|
myComponent = getComponentJobHelper().createComponent(this, aViolations);
|
63
|
|
// TODO
|
64
|
|
// System.out.println("created component '" + myComponent.getName() + "': " + myComponent.getLocation());
|
65
|
3525
|
if (null != myAfterCreation) {
|
66
|
946
|
myAfterCreation.set(myComponent, aViolations);
|
67
|
|
}
|
68
|
|
// After all components are instantiated the instantiator will provide the
|
69
|
|
// components with their bindings and will init their data creation
|
70
|
|
// capabilities. Then the instantiator will add schema data to the components
|
71
|
|
// by calling the addSchemaData method of the component job helper.
|
72
|
3525
|
getInstantiator().addSchemaDataAddition(myComponent, getComponentJobHelper());
|
73
|
|
}
|
74
|
|
|
75
|
3497
|
public void doExecuteCompletion(IConstraintViolations aViolations) {
|
76
|
3497
|
getComponentJobHelper().completeComponent(this, myComponent, aViolations);
|
77
|
|
}
|
78
|
|
|
79
|
3493
|
public void doExecuteValidation(IConstraintViolations aViolations) {
|
80
|
3493
|
myComponent.validate(aViolations);
|
81
|
|
|
82
|
3493
|
if (null != myAfterValidation) {
|
83
|
3493
|
myAfterValidation.set(myComponent, aViolations);
|
84
|
|
}
|
85
|
|
}
|
86
|
|
|
87
|
|
|
88
|
|
//
|
89
|
|
// implementation of IElementHelper
|
90
|
|
//
|
91
|
|
|
92
|
4056
|
public IComponent getComponent(IRef aGlobalRef, boolean aMustBeValidated) {
|
93
|
4056
|
return getInstantiator().getComponent(new JobRef(aGlobalRef, aMustBeValidated, null));
|
94
|
|
}
|
95
|
|
|
96
|
2584
|
public void addSubJob(IComponentJobHelper aHelper, final IComponentSetter aComponentSetter) {
|
97
|
2584
|
IComponentSetter setter = new IComponentSetter() {
|
98
|
2560
|
public void set(IComponent aComponent, IConstraintViolations aViolations) {
|
99
|
2560
|
myComponent.addSubComponent(aComponent);
|
100
|
2560
|
aComponent.setParentComponent(myComponent);
|
101
|
2560
|
aComponentSetter.set(aComponent, aViolations);
|
102
|
|
}
|
103
|
|
};
|
104
|
2584
|
addSubJob(new ComponentJob(aHelper, null, setter));
|
105
|
|
}
|
106
|
|
|
107
|
82
|
public String getDescription() {
|
108
|
82
|
return "componentJob: " + getLocation();
|
109
|
|
}
|
110
|
|
|
111
|
|
}
|
112
|
|
|