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.Implementation;
41 import org.jomc.model.ImplementationReference;
42 import org.jomc.model.Implementations;
43 import org.jomc.model.ModelObjectException;
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 RuntimeImplementations extends Implementations implements RuntimeModelObject
72 {
73
74
75
76
77
78 @XmlTransient
79 private transient final Map<String, Implementation> implementationsByIdentifierCache = createMap();
80
81
82
83
84 @XmlTransient
85 private transient final Map<String, Implementation> implementationsByClassCache = createMap();
86
87
88
89
90 @XmlTransient
91 private transient final Map<String, Implementation> implementationsByNameCache = createMap();
92
93
94
95
96 @XmlTransient
97 private transient final Map<String, ImplementationReference> referencesByIdentifierCache = createMap();
98
99
100
101
102
103
104
105
106 public RuntimeImplementations( final Implementations implementations )
107 {
108 super( implementations );
109
110 if ( this.getAuthors() != null )
111 {
112 this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
113 }
114 if ( this.getDocumentation() != null )
115 {
116 this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
117 }
118
119 this.copyImplementations();
120 this.copyImplementationReferences();
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 @Override
146 public Implementation getImplementation( final String implementation )
147 {
148 if ( implementation == null )
149 {
150 throw new NullPointerException( "implementation" );
151 }
152
153 synchronized ( this.implementationsByIdentifierCache )
154 {
155 Implementation i = this.implementationsByIdentifierCache.get( implementation );
156
157 if ( i == null && !this.implementationsByIdentifierCache.containsKey( implementation ) )
158 {
159 i = super.getImplementation( implementation );
160 this.implementationsByIdentifierCache.put( implementation, i );
161 }
162
163 return i;
164 }
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191 @Override
192 public Implementation getImplementation( final Class<?> implementation ) throws ModelObjectException
193 {
194 if ( implementation == null )
195 {
196 throw new NullPointerException( "implementation" );
197 }
198
199 synchronized ( this.implementationsByClassCache )
200 {
201 Implementation i = this.implementationsByClassCache.get( implementation.getName() );
202
203 if ( i == null && !this.implementationsByClassCache.containsKey( implementation.getName() ) )
204 {
205 i = super.getImplementation( implementation );
206 this.implementationsByClassCache.put( implementation.getName(), i );
207 }
208
209 return i;
210 }
211 }
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 @Override
236 public Implementation getImplementationByName( final String name )
237 {
238 if ( name == null )
239 {
240 throw new NullPointerException( "name" );
241 }
242
243 synchronized ( this.implementationsByNameCache )
244 {
245 Implementation i = this.implementationsByNameCache.get( name );
246
247 if ( i == null && !this.implementationsByNameCache.containsKey( name ) )
248 {
249 i = super.getImplementationByName( name );
250 this.implementationsByNameCache.put( name, i );
251 }
252
253 return i;
254 }
255 }
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279 @Override
280 public ImplementationReference getReference( final String implementation )
281 {
282 if ( implementation == null )
283 {
284 throw new NullPointerException( "implementation" );
285 }
286
287 synchronized ( this.referencesByIdentifierCache )
288 {
289 ImplementationReference r = this.referencesByIdentifierCache.get( implementation );
290
291 if ( r == null && !this.referencesByIdentifierCache.containsKey( implementation ) )
292 {
293 r = super.getReference( implementation );
294 this.referencesByIdentifierCache.put( implementation, r );
295 }
296
297 return r;
298 }
299 }
300
301 private void copyImplementations()
302 {
303 for ( int i = 0, s0 = this.getImplementation().size(); i < s0; i++ )
304 {
305 final Implementation impl = this.getImplementation().get( i );
306 this.getImplementation().set( i, RuntimeModelObjects.getInstance().copyOf( impl ) );
307 }
308 }
309
310 private void copyImplementationReferences()
311 {
312 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
313 {
314 final ImplementationReference r = this.getReference().get( i );
315 this.getReference().set( i, RuntimeModelObjects.getInstance().copyOf( r ) );
316 }
317 }
318
319
320
321 public void gc()
322 {
323 this.gcOrClear( true, false );
324 }
325
326 public void clear()
327 {
328 synchronized ( this.implementationsByClassCache )
329 {
330 this.implementationsByClassCache.clear();
331 }
332 synchronized ( this.implementationsByIdentifierCache )
333 {
334 this.implementationsByIdentifierCache.clear();
335 }
336 synchronized ( this.implementationsByNameCache )
337 {
338 this.implementationsByNameCache.clear();
339 }
340 synchronized ( this.referencesByIdentifierCache )
341 {
342 this.referencesByIdentifierCache.clear();
343 }
344
345 this.gcOrClear( false, true );
346 }
347
348 private void gcOrClear( final boolean gc, final boolean clear )
349 {
350 if ( this.getAuthors() instanceof RuntimeModelObject )
351 {
352 if ( gc )
353 {
354 ( (RuntimeModelObject) this.getAuthors() ).gc();
355 }
356 if ( clear )
357 {
358 ( (RuntimeModelObject) this.getAuthors() ).clear();
359 }
360 }
361 if ( this.getDocumentation() instanceof RuntimeModelObject )
362 {
363 if ( gc )
364 {
365 ( (RuntimeModelObject) this.getDocumentation() ).gc();
366 }
367 if ( clear )
368 {
369 ( (RuntimeModelObject) this.getDocumentation() ).clear();
370 }
371 }
372
373 this.gcOrClearImplementationReferences( gc, clear );
374 this.gcOrClearImplementations( gc, clear );
375 }
376
377 private void gcOrClearImplementations( final boolean gc, final boolean clear )
378 {
379 for ( int i = 0, s0 = this.getImplementation().size(); i < s0; i++ )
380 {
381 final Implementation impl = this.getImplementation().get( i );
382 if ( impl instanceof RuntimeModelObject )
383 {
384 if ( gc )
385 {
386 ( (RuntimeModelObject) impl ).gc();
387 }
388 if ( clear )
389 {
390 ( (RuntimeModelObject) impl ).clear();
391 }
392 }
393 }
394 }
395
396 private void gcOrClearImplementationReferences( final boolean gc, final boolean clear )
397 {
398 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
399 {
400 final ImplementationReference r = this.getReference().get( i );
401 if ( r instanceof RuntimeModelObject )
402 {
403 if ( gc )
404 {
405 ( (RuntimeModelObject) r ).gc();
406 }
407 if ( clear )
408 {
409 ( (RuntimeModelObject) r ).clear();
410 }
411 }
412 }
413 }
414
415
416
417
418
419 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
420 public RuntimeImplementations()
421 {
422
423 super();
424
425 }
426
427
428
429
430
431
432
433
434
435 }