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