1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 package org.jomc.ri.model;
37
38 import java.util.Map;
39 import javax.xml.bind.annotation.XmlTransient;
40 import org.jomc.model.Message;
41 import org.jomc.model.MessageReference;
42 import org.jomc.model.Messages;
43 import static org.jomc.ri.model.RuntimeModelObjects.createMap;
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
68
69
70 public class RuntimeMessages extends Messages implements RuntimeModelObject
71 {
72
73
74
75
76
77 @XmlTransient
78 private transient final Map<String, Message> messagesByNameCache = createMap();
79
80
81
82
83 @XmlTransient
84 private transient final Map<String, MessageReference> referencesByNameCache = createMap();
85
86
87
88
89
90
91
92
93 public RuntimeMessages( final Messages messages )
94 {
95 super( messages );
96
97 if ( this.getAuthors() != null )
98 {
99 this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
100 }
101 if ( this.getDocumentation() != null )
102 {
103 this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
104 }
105
106 this.copyMessages();
107 this.copyMessageReferences();
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 @Override
133 public Message getMessage( final String name )
134 {
135 if ( name == null )
136 {
137 throw new NullPointerException( "name" );
138 }
139
140 synchronized ( this.messagesByNameCache )
141 {
142 Message m = this.messagesByNameCache.get( name );
143
144 if ( m == null && !this.messagesByNameCache.containsKey( name ) )
145 {
146 m = super.getMessage( name );
147 this.messagesByNameCache.put( name, m );
148 }
149
150 return m;
151 }
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 @Override
177 public MessageReference getReference( final String name )
178 {
179 if ( name == null )
180 {
181 throw new NullPointerException( "name" );
182 }
183
184 synchronized ( this.referencesByNameCache )
185 {
186 MessageReference r = this.referencesByNameCache.get( name );
187
188 if ( r == null && !this.referencesByNameCache.containsKey( name ) )
189 {
190 r = super.getReference( name );
191 this.referencesByNameCache.put( name, r );
192 }
193
194 return r;
195 }
196 }
197
198 private void copyMessages()
199 {
200 for ( int i = 0, s0 = this.getMessage().size(); i < s0; i++ )
201 {
202 final Message m = this.getMessage().get( i );
203 this.getMessage().set( i, RuntimeModelObjects.getInstance().copyOf( m ) );
204 }
205 }
206
207 private void copyMessageReferences()
208 {
209 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
210 {
211 final MessageReference r = this.getReference().get( i );
212 this.getReference().set( i, RuntimeModelObjects.getInstance().copyOf( r ) );
213 }
214 }
215
216
217
218 public void gc()
219 {
220 this.gcOrClear( true, false );
221 }
222
223 public void clear()
224 {
225 synchronized ( this.messagesByNameCache )
226 {
227 this.messagesByNameCache.clear();
228 }
229 synchronized ( this.referencesByNameCache )
230 {
231 this.referencesByNameCache.clear();
232 }
233
234 this.gcOrClear( false, true );
235 }
236
237 private void gcOrClear( final boolean gc, final boolean clear )
238 {
239 if ( this.getAuthors() instanceof RuntimeModelObject )
240 {
241 if ( gc )
242 {
243 ( (RuntimeModelObject) this.getAuthors() ).gc();
244 }
245 if ( clear )
246 {
247 ( (RuntimeModelObject) this.getAuthors() ).clear();
248 }
249 }
250 if ( this.getDocumentation() instanceof RuntimeModelObject )
251 {
252 if ( gc )
253 {
254 ( (RuntimeModelObject) this.getDocumentation() ).gc();
255 }
256 if ( clear )
257 {
258 ( (RuntimeModelObject) this.getDocumentation() ).clear();
259 }
260 }
261
262 this.gcOrClearMessageReferences( gc, clear );
263 this.gcOrClearMessages( gc, clear );
264 }
265
266 private void gcOrClearMessages( final boolean gc, final boolean clear )
267 {
268 for ( int i = 0, s0 = this.getMessage().size(); i < s0; i++ )
269 {
270 final Message m = this.getMessage().get( i );
271 if ( m instanceof RuntimeModelObject )
272 {
273 if ( gc )
274 {
275 ( (RuntimeModelObject) m ).gc();
276 }
277 if ( clear )
278 {
279 ( (RuntimeModelObject) m ).clear();
280 }
281 }
282 }
283 }
284
285 private void gcOrClearMessageReferences( final boolean gc, final boolean clear )
286 {
287 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
288 {
289 final MessageReference r = this.getReference().get( i );
290 if ( r instanceof RuntimeModelObject )
291 {
292 if ( gc )
293 {
294 ( (RuntimeModelObject) r ).gc();
295 }
296 if ( clear )
297 {
298 ( (RuntimeModelObject) r ).clear();
299 }
300 }
301 }
302 }
303
304
305
306
307
308 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
309 public RuntimeMessages()
310 {
311
312 super();
313
314 }
315
316
317
318
319
320
321
322
323
324 }