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