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.ModelObjectException;
41 import org.jomc.model.Specification;
42 import org.jomc.model.SpecificationReference;
43 import org.jomc.model.Specifications;
44 import static org.jomc.ri.model.RuntimeModelObjects.createMap;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
69
70
71 public class RuntimeSpecifications extends Specifications implements RuntimeModelObject
72 {
73
74
75
76
77
78 @XmlTransient
79 private transient final Map<String, Specification> specificationsByIdentifierCache = createMap();
80
81
82
83
84 @XmlTransient
85 private transient final Map<String, Specification> specificationsByClassCache = createMap();
86
87
88
89
90 @XmlTransient
91 private transient final Map<String, SpecificationReference> referencesByIdentifierCache = createMap();
92
93
94
95
96
97
98
99
100 public RuntimeSpecifications( final Specifications specifications )
101 {
102 super( specifications );
103
104 if ( this.getAuthors() != null )
105 {
106 this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
107 }
108 if ( this.getDocumentation() != null )
109 {
110 this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
111 }
112
113 this.copySpecifications();
114 this.copyReferences();
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 @Override
140 public Specification getSpecification( final String specification )
141 {
142 if ( specification == null )
143 {
144 throw new NullPointerException( "specification" );
145 }
146
147 synchronized ( this.specificationsByIdentifierCache )
148 {
149 Specification s = this.specificationsByIdentifierCache.get( specification );
150
151 if ( s == null && !this.specificationsByIdentifierCache.containsKey( specification ) )
152 {
153 s = super.getSpecification( specification );
154 this.specificationsByIdentifierCache.put( specification, s );
155 }
156
157 return s;
158 }
159 }
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 @Override
186 public Specification getSpecification( final Class<?> specification ) throws ModelObjectException
187 {
188 if ( specification == null )
189 {
190 throw new NullPointerException( "specification" );
191 }
192
193 synchronized ( this.specificationsByClassCache )
194 {
195 Specification s = this.specificationsByClassCache.get( specification.getName() );
196
197 if ( s == null && !this.specificationsByClassCache.containsKey( specification.getName() ) )
198 {
199 s = super.getSpecification( specification );
200 this.specificationsByClassCache.put( specification.getName(), s );
201 }
202
203 return s;
204 }
205 }
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 @Override
230 public SpecificationReference getReference( final String specification )
231 {
232 if ( specification == null )
233 {
234 throw new NullPointerException( "specification" );
235 }
236
237 synchronized ( this.referencesByIdentifierCache )
238 {
239 SpecificationReference r = this.referencesByIdentifierCache.get( specification );
240
241 if ( r == null && !this.referencesByIdentifierCache.containsKey( specification ) )
242 {
243 r = super.getReference( specification );
244 this.referencesByIdentifierCache.put( specification, r );
245 }
246
247 return r;
248 }
249 }
250
251 private void copySpecifications()
252 {
253 for ( int i = 0, s0 = this.getSpecification().size(); i < s0; i++ )
254 {
255 final Specification s = this.getSpecification().get( i );
256 this.getSpecification().set( i, RuntimeModelObjects.getInstance().copyOf( s ) );
257 }
258 }
259
260 private void copyReferences()
261 {
262 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
263 {
264 final SpecificationReference r = this.getReference().get( i );
265 this.getReference().set( i, RuntimeModelObjects.getInstance().copyOf( r ) );
266 }
267 }
268
269
270
271 public void gc()
272 {
273 this.gcOrClear( true, false );
274 }
275
276 public void clear()
277 {
278 synchronized ( this.specificationsByClassCache )
279 {
280 this.specificationsByClassCache.clear();
281 }
282 synchronized ( this.specificationsByIdentifierCache )
283 {
284 this.specificationsByIdentifierCache.clear();
285 }
286 synchronized ( this.referencesByIdentifierCache )
287 {
288 this.referencesByIdentifierCache.clear();
289 }
290
291 this.gcOrClear( false, true );
292 }
293
294 private void gcOrClear( final boolean gc, final boolean clear )
295 {
296 if ( this.getAuthors() instanceof RuntimeModelObject )
297 {
298 if ( gc )
299 {
300 ( (RuntimeModelObject) this.getAuthors() ).gc();
301 }
302 if ( clear )
303 {
304 ( (RuntimeModelObject) this.getAuthors() ).clear();
305 }
306 }
307 if ( this.getDocumentation() instanceof RuntimeModelObject )
308 {
309 if ( gc )
310 {
311 ( (RuntimeModelObject) this.getDocumentation() ).gc();
312 }
313 if ( clear )
314 {
315 ( (RuntimeModelObject) this.getDocumentation() ).clear();
316 }
317 }
318
319 this.gcOrClearReferences( gc, clear );
320 this.gcOrClearSpecifications( gc, clear );
321 }
322
323 private void gcOrClearSpecifications( final boolean gc, final boolean clear )
324 {
325 for ( int i = 0, s0 = this.getSpecification().size(); i < s0; i++ )
326 {
327 final Specification s = this.getSpecification().get( i );
328 if ( s instanceof RuntimeModelObject )
329 {
330 if ( gc )
331 {
332 ( (RuntimeModelObject) s ).gc();
333 }
334 if ( clear )
335 {
336 ( (RuntimeModelObject) s ).clear();
337 }
338 }
339 }
340 }
341
342 private void gcOrClearReferences( final boolean gc, final boolean clear )
343 {
344 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
345 {
346 final SpecificationReference r = this.getReference().get( i );
347 if ( r instanceof RuntimeModelObject )
348 {
349 if ( gc )
350 {
351 ( (RuntimeModelObject) r ).gc();
352 }
353 if ( clear )
354 {
355 ( (RuntimeModelObject) r ).clear();
356 }
357 }
358 }
359 }
360
361
362
363
364
365 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
366 public RuntimeSpecifications()
367 {
368
369 super();
370
371 }
372
373
374
375
376
377
378
379
380
381 }