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.lang.ref.Reference;
39 import java.lang.ref.WeakReference;
40 import java.net.URI;
41 import java.util.Map;
42 import javax.xml.bind.annotation.XmlTransient;
43 import org.jomc.model.Implementation;
44 import org.jomc.model.JavaTypeName;
45 import org.jomc.model.ModelObjectException;
46 import static org.jomc.ri.model.RuntimeModelObjects.BOOTSTRAP_CLASSLOADER_KEY;
47 import static org.jomc.ri.model.RuntimeModelObjects.classesByClassLoaderAndNameCache;
48 import static org.jomc.ri.model.RuntimeModelObjects.createMap;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
73
74
75 public class RuntimeImplementation extends Implementation implements RuntimeModelObject
76 {
77
78
79
80 private volatile URI locationUri;
81
82
83 @XmlTransient
84 private volatile JavaTypeName javaTypeName;
85
86
87
88
89
90
91
92
93 public RuntimeImplementation( final Implementation implementation )
94 {
95 super( implementation );
96
97 if ( this.getAuthors() != null )
98 {
99 this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
100 }
101 if ( this.getDependencies() != null )
102 {
103 this.setDependencies( RuntimeModelObjects.getInstance().copyOf( this.getDependencies() ) );
104 }
105 if ( this.getDocumentation() != null )
106 {
107 this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
108 }
109 if ( this.getImplementations() != null )
110 {
111 this.setImplementations( RuntimeModelObjects.getInstance().copyOf( this.getImplementations() ) );
112 }
113 if ( this.getMessages() != null )
114 {
115 this.setMessages( RuntimeModelObjects.getInstance().copyOf( this.getMessages() ) );
116 }
117 if ( this.getProperties() != null )
118 {
119 this.setProperties( RuntimeModelObjects.getInstance().copyOf( this.getProperties() ) );
120 }
121 if ( this.getSpecifications() != null )
122 {
123 this.setSpecifications( RuntimeModelObjects.getInstance().copyOf( this.getSpecifications() ) );
124 }
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 @Override
144 public URI getLocationUri() throws ModelObjectException
145 {
146 if ( this.locationUri == null )
147 {
148 this.locationUri = super.getLocationUri();
149 }
150
151 return this.locationUri;
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 Class<?> getJavaClass( final ClassLoader classLoader )
175 throws ModelObjectException, ClassNotFoundException
176 {
177 Class<?> javaClass = null;
178
179 if ( this.getJavaTypeName() != null )
180 {
181 ClassLoader classLoaderKey = classLoader;
182 if ( classLoaderKey == null )
183 {
184 classLoaderKey = BOOTSTRAP_CLASSLOADER_KEY;
185 }
186
187 synchronized ( classesByClassLoaderAndNameCache )
188 {
189 Map<String, Reference<Class<?>>> map = classesByClassLoaderAndNameCache.get( classLoaderKey );
190
191 if ( map == null )
192 {
193 map = createMap();
194 classesByClassLoaderAndNameCache.put( classLoaderKey, map );
195 }
196
197 final Reference<Class<?>> reference = map.get( this.getJavaTypeName().getClassName() );
198
199 if ( reference != null )
200 {
201 javaClass = reference.get();
202 }
203
204 if ( javaClass == null )
205 {
206 javaClass = super.getJavaClass( classLoader );
207 map.put( this.getJavaTypeName().getClassName(), new WeakReference<Class<?>>( javaClass ) );
208 }
209 }
210 }
211
212 return javaClass;
213 }
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233 @Override
234 public JavaTypeName getJavaTypeName() throws ModelObjectException
235 {
236 if ( this.javaTypeName == null )
237 {
238 this.javaTypeName = super.getJavaTypeName();
239 }
240
241 return this.javaTypeName;
242 }
243
244
245
246 public void gc()
247 {
248 this.gcOrClear( true, false );
249 }
250
251 public void clear()
252 {
253 this.locationUri = null;
254 this.javaTypeName = null;
255 this.gcOrClear( false, true );
256 }
257
258 private void gcOrClear( final boolean gc, final boolean clear )
259 {
260 if ( this.getAuthors() instanceof RuntimeModelObject )
261 {
262 if ( gc )
263 {
264 ( (RuntimeModelObject) this.getAuthors() ).gc();
265 }
266 if ( clear )
267 {
268 ( (RuntimeModelObject) this.getAuthors() ).clear();
269 }
270 }
271 if ( this.getDependencies() instanceof RuntimeModelObject )
272 {
273 if ( gc )
274 {
275 ( (RuntimeModelObject) this.getDependencies() ).gc();
276 }
277 if ( clear )
278 {
279 ( (RuntimeModelObject) this.getDependencies() ).clear();
280 }
281 }
282 if ( this.getDocumentation() instanceof RuntimeModelObject )
283 {
284 if ( gc )
285 {
286 ( (RuntimeModelObject) this.getDocumentation() ).gc();
287 }
288 if ( clear )
289 {
290 ( (RuntimeModelObject) this.getDocumentation() ).clear();
291 }
292 }
293 if ( this.getImplementations() instanceof RuntimeModelObject )
294 {
295 if ( gc )
296 {
297 ( (RuntimeModelObject) this.getImplementations() ).gc();
298 }
299 if ( clear )
300 {
301 ( (RuntimeModelObject) this.getImplementations() ).clear();
302 }
303 }
304 if ( this.getMessages() instanceof RuntimeModelObject )
305 {
306 if ( gc )
307 {
308 ( (RuntimeModelObject) this.getMessages() ).gc();
309 }
310 if ( clear )
311 {
312 ( (RuntimeModelObject) this.getMessages() ).clear();
313 }
314 }
315 if ( this.getProperties() instanceof RuntimeModelObject )
316 {
317 if ( gc )
318 {
319 ( (RuntimeModelObject) this.getProperties() ).gc();
320 }
321 if ( clear )
322 {
323 ( (RuntimeModelObject) this.getProperties() ).clear();
324 }
325 }
326 if ( this.getSpecifications() instanceof RuntimeModelObject )
327 {
328 if ( gc )
329 {
330 ( (RuntimeModelObject) this.getSpecifications() ).gc();
331 }
332 if ( clear )
333 {
334 ( (RuntimeModelObject) this.getSpecifications() ).clear();
335 }
336 }
337 }
338
339
340
341
342
343 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
344 public RuntimeImplementation()
345 {
346
347 super();
348
349 }
350
351
352
353
354
355
356
357
358 }