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.curnit;
24
25 import java.awt.Component;
26 import java.io.File;
27 import java.io.FileNotFoundException;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.HashSet;
31 import java.util.Set;
32
33 import net.sf.sail.common.beansupport.ITitleAware;
34 import net.sf.sail.core.beans.Pod;
35 import net.sf.sail.core.beans.SessionContext;
36 import net.sf.sail.core.beans.UnknownPodException;
37 import net.sf.sail.core.beans.assembly.PodRegistry;
38 import net.sf.sail.core.uuid.CurnitUuid;
39 import net.sf.sail.core.uuid.PodUuid;
40
41
42
43
44 public class Curnit implements ITitleAware, ICurnit {
45
46
47
48
49 private static final PodRegistry REGISTRY = PodRegistry
50 .getDefaultRegistry();
51
52 private static final long serialVersionUID = 1L;
53
54 {
55 PodArchiveResolver.getSystemResolver();
56 }
57
58 Pod rootPod;
59
60 Set<Pod> referencedPods = new HashSet<Pod>();
61
62 CurnitUuid curnitId;
63
64 String title = "undefined title";
65
66 private boolean assembled = false;
67
68
69
70 private PodUuid pendingLookup = null;
71
72 public CurnitUuid getCurnitId() {
73 return curnitId;
74 }
75
76 public void setCurnitId(CurnitUuid curnitId) {
77 this.curnitId = curnitId;
78 }
79
80 public String getTitle() {
81 return title;
82 }
83
84 public void setTitle(String curnitTitle) {
85 this.title = curnitTitle;
86 }
87
88 private void collectReferences(Pod pod) {
89 referencedPods.add(pod);
90 Set<PodUuid> childPodIds = pod.getChildPodIds();
91 for (PodUuid childPodId : childPodIds) {
92 Pod childPod = REGISTRY.getPod(childPodId);
93 collectReferences(childPod);
94 }
95 }
96
97 public void assemble() {
98 if (assembled)
99 throw new IllegalStateException("curnit already assembled");
100
101 refreshRootPod();
102
103 try {
104 rootPod.assemble(REGISTRY);
105 } catch (UnknownPodException e) {
106 e.printStackTrace();
107 throw new RuntimeException(e);
108 }
109 assembled = true;
110 }
111
112
113
114
115 private void refreshRootPod() {
116 if (rootPod == null) {
117
118 if (pendingLookup == null) {
119 throw new IllegalStateException(
120 "cannot assemble() before setRootPodId()");
121 } else {
122 rootPod = REGISTRY.getPod(pendingLookup);
123 pendingLookup = null;
124 }
125 }
126 }
127
128 public boolean isAssembled() {
129 return assembled;
130 }
131
132
133
134
135
136 private void refreshReferences() throws UnknownPodException {
137 referencedPods.clear();
138 refreshRootPod();
139 collectReferences(rootPod);
140 }
141
142 public Collection<Pod> getReferencedPods() {
143 try {
144 refreshReferences();
145 } catch (UnknownPodException e) {
146
147 e.printStackTrace();
148 }
149 return Collections.unmodifiableCollection(referencedPods);
150 }
151
152 public PodUuid getRootPodId() {
153 if (pendingLookup != null) {
154 return pendingLookup;
155 }
156 if (rootPod == null)
157 return null;
158 else
159 return rootPod.getPodId();
160 }
161
162 public void setRootPodId(PodUuid rootPodId) throws UnknownPodException {
163
164 this.rootPod = REGISTRY.getPod(rootPodId);
165
166 if (rootPod == null)
167 pendingLookup = rootPodId;
168 }
169
170
171
172
173 public Object getRootBean() {
174
175 PodUuid rootPodId = getRootPodId();
176 Pod rootPod = PodRegistry.getDefaultRegistry().getPod(rootPodId);
177
178 return rootPod;
179 }
180
181
182
183
184 public void initialize() {
185 if (!isAssembled()) {
186 assemble();
187 }
188 }
189
190 public void saveCurnit(File file) throws FileNotFoundException,
191 Exception {
192 }
193
194
195
196
197 public void setSessionContext(SessionContext sessionContext) {
198
199
200 }
201
202
203
204
205
206
207 public void previewCurnit(Component component) throws Exception {
208
209
210 }
211
212
213 }