1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.sail.core.beans.assembly;
24
25 import java.beans.DefaultPersistenceDelegate;
26 import java.util.Map;
27 import java.util.NoSuchElementException;
28
29 import net.sf.sail.core.beans.Pod;
30 import net.sf.sail.core.uuid.PodUuid;
31
32
33
34
35
36
37
38 public class PodVarDelegate {
39
40 final static DefaultPersistenceDelegate delegate = new DefaultPersistenceDelegate(
41 new String[] { "podId", "varName" });
42
43 PodUuid podId;
44
45 String varName;
46
47 public PodVarDelegate(PodUuid podId, String varName) {
48 this.podId = podId;
49 this.varName = varName;
50 }
51
52 public PodUuid getPodId() {
53 return podId;
54 }
55
56 public PropertyRef getRef(PodRegistry registry) {
57 Map<String, PropertyRef> slotMap = getRefMap(registry);
58 return slotMap.get(varName);
59 }
60
61
62
63
64
65
66 private Map<String, PropertyRef> getRefMap(PodRegistry registry) {
67 Pod pod = registry.getPod(podId);
68 if (pod == null)
69 throw new NoSuchElementException("no known pod " + podId
70 + " in registry " + registry);
71 Map<String, PropertyRef> slotMap = pod.getVars();
72 return slotMap;
73 }
74
75 public String getVarName() {
76 return varName;
77 }
78
79 public boolean isValid(PodRegistry registry) {
80 Map<String, PropertyRef> slotMap = getRefMap(registry);
81 return slotMap.containsKey(varName);
82 }
83
84
85
86
87 public void setPodId(PodUuid newPodId) {
88 this.podId = newPodId;
89 }
90
91
92
93
94 public void setVarName(String varName) {
95 this.varName = varName;
96 }
97
98 @Override
99 public String toString() {
100 return "PodVarDelegate:" + podId + ":" + varName;
101 }
102
103 public void validate(PodRegistry registry) {
104
105 if (!isValid(registry))
106 throw new RuntimeException(this + " refers to absent pod export");
107 }
108
109 }