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