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