1 | // SECTION-START[License Header] |
2 | // <editor-fold defaultstate="collapsed" desc=" Generated License "> |
3 | /* |
4 | * Java Object Management and Configuration |
5 | * Copyright (C) Christian Schulte, 2011-313 |
6 | * All rights reserved. |
7 | * |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions |
10 | * are met: |
11 | * |
12 | * o Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. |
14 | * |
15 | * o Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in |
17 | * the documentation and/or other materials provided with the |
18 | * distribution. |
19 | * |
20 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
21 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
22 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
23 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, |
24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
29 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | * |
31 | * $JOMC: RuntimeInstance.java 4795 2013-04-21 09:09:02Z schulte $ |
32 | * |
33 | */ |
34 | // </editor-fold> |
35 | // SECTION-END |
36 | package org.jomc.ri.model; |
37 | |
38 | import java.lang.ref.Reference; |
39 | import java.lang.ref.WeakReference; |
40 | import java.lang.reflect.Constructor; |
41 | import java.lang.reflect.Method; |
42 | import java.util.Map; |
43 | import javax.xml.bind.annotation.XmlTransient; |
44 | import org.jomc.model.Instance; |
45 | import org.jomc.model.JavaTypeName; |
46 | import org.jomc.model.ModelObjectException; |
47 | import org.jomc.model.Specification; |
48 | import org.jomc.util.WeakIdentityHashMap; |
49 | import static org.jomc.ri.model.RuntimeModelObjects.BOOTSTRAP_CLASSLOADER_KEY; |
50 | import static org.jomc.ri.model.RuntimeModelObjects.classesByClassLoaderAndNameCache; |
51 | import static org.jomc.ri.model.RuntimeModelObjects.createMap; |
52 | |
53 | // SECTION-START[Documentation] |
54 | // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> |
55 | /** |
56 | * Runtime {@code Instance}. |
57 | * |
58 | * <dl> |
59 | * <dt><b>Identifier:</b></dt><dd>org.jomc.ri.model.RuntimeInstance</dd> |
60 | * <dt><b>Name:</b></dt><dd>JOMC ⁑ RI ⁑ RuntimeInstance</dd> |
61 | * <dt><b>Specifications:</b></dt> |
62 | * <dd>org.jomc.ri.model.RuntimeModelObject @ 1.2</dd> |
63 | * <dt><b>Abstract:</b></dt><dd>No</dd> |
64 | * <dt><b>Final:</b></dt><dd>No</dd> |
65 | * <dt><b>Stateless:</b></dt><dd>No</dd> |
66 | * </dl> |
67 | * |
68 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.2 |
69 | * @version 1.2 |
70 | */ |
71 | // </editor-fold> |
72 | // SECTION-END |
73 | // SECTION-START[Annotations] |
74 | // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> |
75 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" ) |
76 | // </editor-fold> |
77 | // SECTION-END |
78 | public class RuntimeInstance extends Instance implements RuntimeModelObject |
79 | { |
80 | // SECTION-START[RuntimeInstance] |
81 | |
82 | /** Classes by class loader any instance cache. */ |
83 | @XmlTransient |
84 | static final Map<ClassLoader, Map<String, Reference<Class<?>[]>>> classesByClassLoaderAndInstanceCache = |
85 | new WeakIdentityHashMap<ClassLoader, Map<String, Reference<Class<?>[]>>>(); |
86 | |
87 | /** Constructors by class loader any instance cache. */ |
88 | @XmlTransient |
89 | static final Map<ClassLoader, Map<String, Reference<Constructor<?>>>> constructorsByClassLoaderAndInstanceCache = |
90 | new WeakIdentityHashMap<ClassLoader, Map<String, Reference<Constructor<?>>>>(); |
91 | |
92 | /** Methods by class loader any instance cache. */ |
93 | @XmlTransient |
94 | static final Map<ClassLoader, Map<String, Reference<Method>>> methodsByClassLoaderAndInstanceCache = |
95 | new WeakIdentityHashMap<ClassLoader, Map<String, Reference<Method>>>(); |
96 | |
97 | /** Assignable flags by class loader any instance cache. */ |
98 | @XmlTransient |
99 | static final Map<ClassLoader, Map<String, Boolean>> assignableFlagsByClassLoaderAndInstanceCache = |
100 | new WeakIdentityHashMap<ClassLoader, Map<String, Boolean>>(); |
101 | |
102 | /** Proxy classes by class loader any instance cache. */ |
103 | @XmlTransient |
104 | static final Map<ClassLoader, Map<String, Reference<Class<?>>>> proxyClassesByClassLoaderAndInstanceCache = |
105 | new WeakIdentityHashMap<ClassLoader, Map<String, Reference<Class<?>>>>(); |
106 | |
107 | /** Method name. */ |
108 | @XmlTransient |
109 | private volatile String javaClassFactoryMethodName; |
110 | |
111 | /** Java type name. */ |
112 | @XmlTransient |
113 | private volatile JavaTypeName javaTypeName; |
114 | |
115 | /** |
116 | * Creates a new {@code RuntimeInstance} instance by deeply copying a given {@code Instance} instance. |
117 | * |
118 | * @param instance The instance to copy. |
119 | * |
120 | * @throws NullPointerException if {@code instance} is {@code null}. |
121 | */ |
122 | public RuntimeInstance( final Instance instance ) |
123 | { |
124 | super( instance ); |
125 | |
126 | if ( this.getAuthors() != null ) |
127 | { |
128 | this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) ); |
129 | } |
130 | if ( this.getDependencies() != null ) |
131 | { |
132 | this.setDependencies( RuntimeModelObjects.getInstance().copyOf( this.getDependencies() ) ); |
133 | } |
134 | if ( this.getDocumentation() != null ) |
135 | { |
136 | this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) ); |
137 | } |
138 | if ( this.getMessages() != null ) |
139 | { |
140 | this.setMessages( RuntimeModelObjects.getInstance().copyOf( this.getMessages() ) ); |
141 | } |
142 | if ( this.getProperties() != null ) |
143 | { |
144 | this.setProperties( RuntimeModelObjects.getInstance().copyOf( this.getProperties() ) ); |
145 | } |
146 | if ( this.getSpecifications() != null ) |
147 | { |
148 | this.setSpecifications( RuntimeModelObjects.getInstance().copyOf( this.getSpecifications() ) ); |
149 | } |
150 | } |
151 | |
152 | /** |
153 | * Gets the Java class of the instance for a given class loader. |
154 | * <p>This method queries an internal cache for a result object to return for the given argument values. If no |
155 | * cached result object is available, this method queries the super-class for a result object to return and caches |
156 | * the outcome of that query for use on successive calls.</p> |
157 | * <p><b>Note:</b><br/>Method {@code RuntimeModelObjects.clear()} must be used to synchronize the state of the |
158 | * internal cache with the state of the class loader, should the state of the class loader change.</p> |
159 | * |
160 | * @param classLoader The class loader to get the Java class from or {@code null}, to get the Java class from the |
161 | * platform's bootstrap class loader. |
162 | * |
163 | * @return The Java class of the instance. |
164 | * |
165 | * @throws ClassNotFoundException if the Java class is not found. |
166 | * @throws ModelObjectException if parsing the name of the referenced type fails. |
167 | * |
168 | * @see #getClazz() |
169 | * @see RuntimeModelObjects#clear() |
170 | */ |
171 | @Override |
172 | public Class<?> getJavaClass( final ClassLoader classLoader ) |
173 | throws ModelObjectException, ClassNotFoundException |
174 | { |
175 | Class<?> javaClass = null; |
176 | |
177 | if ( this.getJavaTypeName() != null ) |
178 | { |
179 | ClassLoader classLoaderKey = classLoader; |
180 | if ( classLoaderKey == null ) |
181 | { |
182 | classLoaderKey = BOOTSTRAP_CLASSLOADER_KEY; |
183 | } |
184 | |
185 | synchronized ( classesByClassLoaderAndNameCache ) |
186 | { |
187 | Map<String, Reference<Class<?>>> map = classesByClassLoaderAndNameCache.get( classLoaderKey ); |
188 | |
189 | if ( map == null ) |
190 | { |
191 | map = createMap(); |
192 | classesByClassLoaderAndNameCache.put( classLoaderKey, map ); |
193 | } |
194 | |
195 | final Reference<Class<?>> reference = map.get( this.getJavaTypeName().getClassName() ); |
196 | |
197 | if ( reference != null ) |
198 | { |
199 | javaClass = reference.get(); |
200 | } |
201 | |
202 | if ( javaClass == null ) |
203 | { |
204 | javaClass = super.getJavaClass( classLoader ); |
205 | map.put( this.getJavaTypeName().getClassName(), new WeakReference<Class<?>>( javaClass ) ); |
206 | } |
207 | } |
208 | } |
209 | |
210 | return javaClass; |
211 | } |
212 | |
213 | /** |
214 | * Gets the Java classes of all specifications of the instance for a given class loader. |
215 | * <p>This method queries an internal cache for a result object to return for the given argument values. If no |
216 | * cached result object is available, this method queries the super-class for a result object to return and caches |
217 | * the outcome of that query for use on successive calls.</p> |
218 | * <p><b>Note:</b><br/>Method {@code RuntimeModelObjects.clear()} must be used to synchronize the state of the |
219 | * internal cache with the state of the instance and class loader, should the state of the instance or class loader |
220 | * change.</p> |
221 | * |
222 | * @param classLoader The class loader to get the Java classes from or {@code null}, to get the Java classes from |
223 | * the platform's bootstrap class loader. |
224 | * |
225 | * @return The Java classes of all specifications of the instance. |
226 | * |
227 | * @throws ClassNotFoundException if a Java class is not found. |
228 | * @throws ModelObjectException if parsing a name of a referenced type fails. |
229 | * |
230 | * @see #getSpecifications() |
231 | * @see Specification#getClazz() |
232 | * @see RuntimeModelObjects#clear() |
233 | */ |
234 | @Override |
235 | public Class<?>[] getJavaClasses( final ClassLoader classLoader ) |
236 | throws ModelObjectException, ClassNotFoundException |
237 | { |
238 | ClassLoader classLoaderKey = classLoader; |
239 | if ( classLoaderKey == null ) |
240 | { |
241 | classLoaderKey = BOOTSTRAP_CLASSLOADER_KEY; |
242 | } |
243 | |
244 | synchronized ( classesByClassLoaderAndInstanceCache ) |
245 | { |
246 | Class<?>[] javaClasses = null; |
247 | Map<String, Reference<Class<?>[]>> map = classesByClassLoaderAndInstanceCache.get( classLoaderKey ); |
248 | |
249 | if ( map == null ) |
250 | { |
251 | map = createMap(); |
252 | classesByClassLoaderAndInstanceCache.put( classLoaderKey, map ); |
253 | } |
254 | |
255 | final Reference<Class<?>[]> reference = map.get( this.getIdentifier() ); |
256 | |
257 | if ( reference != null ) |
258 | { |
259 | javaClasses = reference.get(); |
260 | } |
261 | |
262 | if ( javaClasses == null && ( reference != null || !map.containsKey( this.getIdentifier() ) ) ) |
263 | { |
264 | javaClasses = super.getJavaClasses( classLoader ); |
265 | map.put( this.getIdentifier(), new WeakReference<Class<?>[]>( javaClasses ) ); |
266 | } |
267 | |
268 | return javaClasses; |
269 | } |
270 | } |
271 | |
272 | /** |
273 | * Gets the Java constructor to use for creating objects of the instance. |
274 | * <p>This method queries an internal cache for a result object to return for the given argument values. If no |
275 | * cached result object is available, this method queries the super-class for a result object to return and caches |
276 | * the outcome of that query for use on successive calls.</p> |
277 | * <p><b>Note:</b><br/>Method {@code RuntimeModelObjects.clear()} must be used to synchronize the state of the |
278 | * internal cache with the state of the instance and class loader, should the state of the instance or class loader |
279 | * change.</p> |
280 | * |
281 | * @param classLoader The class loader to get the Java class from or {@code null}, to get the Java class from the |
282 | * platform's bootstrap class loader. |
283 | * |
284 | * @return The public default Java constructor of the Java class of the instance or {@code null}, if that class |
285 | * does not declare such a constructor, is abstract or is not public. |
286 | * |
287 | * @throws ClassNotFoundException if the Java class is not found. |
288 | * @throws ModelObjectException if parsing the name of the type referenced by the instance fails. |
289 | * |
290 | * @see #getJavaClass(java.lang.ClassLoader) |
291 | * @see RuntimeModelObjects#clear() |
292 | */ |
293 | @Override |
294 | public Constructor<?> getJavaConstructor( final ClassLoader classLoader ) |
295 | throws ModelObjectException, ClassNotFoundException |
296 | { |
297 | ClassLoader classLoaderKey = classLoader; |
298 | if ( classLoaderKey == null ) |
299 | { |
300 | classLoaderKey = BOOTSTRAP_CLASSLOADER_KEY; |
301 | } |
302 | |
303 | synchronized ( constructorsByClassLoaderAndInstanceCache ) |
304 | { |
305 | Constructor<?> javaClassConstructor = null; |
306 | Map<String, Reference<Constructor<?>>> map = constructorsByClassLoaderAndInstanceCache.get( classLoaderKey ); |
307 | |
308 | if ( map == null ) |
309 | { |
310 | map = createMap(); |
311 | constructorsByClassLoaderAndInstanceCache.put( classLoaderKey, map ); |
312 | } |
313 | |
314 | final Reference<Constructor<?>> reference = map.get( this.getIdentifier() ); |
315 | |
316 | if ( reference != null ) |
317 | { |
318 | javaClassConstructor = reference.get(); |
319 | } |
320 | |
321 | if ( javaClassConstructor == null && ( reference != null || !map.containsKey( this.getIdentifier() ) ) ) |
322 | { |
323 | javaClassConstructor = super.getJavaConstructor( classLoader ); |
324 | map.put( this.getIdentifier(), new WeakReference<Constructor<?>>( javaClassConstructor ) ); |
325 | } |
326 | |
327 | return javaClassConstructor; |
328 | } |
329 | } |
330 | |
331 | /** |
332 | * Gets the name of the Java method to use for creating objects of the instance. |
333 | * <p>This method queries an internal cache for a result object to return. If no cached result object is available, |
334 | * this method queries the super-class for a result object to return and caches the outcome of that query for use on |
335 | * successive calls.</p> |
336 | * <p><b>Note:</b><br/>Method {@code clear()} must be used to synchronize the state of the internal cache with the |
337 | * state of the instance, should the state of the instance change.</p> |
338 | * |
339 | * @return The name of the Java method to use for creating objects of the instance or {@code null}, if no such |
340 | * method name is supported. |
341 | * |
342 | * @throws ModelObjectException if compiling the name of the instance to a {@code JavaIdentifier} fails. |
343 | * |
344 | * @see #getName() |
345 | * @see #clear() |
346 | */ |
347 | @Override |
348 | public String getJavaFactoryMethodName() throws ModelObjectException |
349 | { |
350 | if ( this.javaClassFactoryMethodName == null ) |
351 | { |
352 | this.javaClassFactoryMethodName = super.getJavaFactoryMethodName(); |
353 | } |
354 | |
355 | return this.javaClassFactoryMethodName; |
356 | } |
357 | |
358 | /** |
359 | * Gets the Java method to use for creating objects of the instance. |
360 | * <p>This method queries an internal cache for a result object to return for the given argument values. If no |
361 | * cached result object is available, this method queries the super-class for a result object to return and caches |
362 | * the outcome of that query for use on successive calls.</p> |
363 | * <p><b>Note:</b><br/>Method {@code RuntimeModelObjects.clear()} must be used to synchronize the state of the |
364 | * internal cache with the state of the instance and class loader, should the state of the instance or class loader |
365 | * change.</p> |
366 | * |
367 | * @param classLoader The class loader to get the Java class from or {@code null}, to get the Java class from the |
368 | * platform's bootstrap class loader. |
369 | * |
370 | * @return The public Java method of the Java class of the instance to use for creating objects of the instance or |
371 | * {@code null}, if that class does not declare such a method. |
372 | * |
373 | * @throws ClassNotFoundException if the Java class is not found. |
374 | * @throws ModelObjectException if parsing the name of the type referenced by the instance fails. |
375 | * |
376 | * @see #getJavaClass(java.lang.ClassLoader) |
377 | * @see #getJavaFactoryMethodName() |
378 | * @see RuntimeModelObjects#clear() |
379 | */ |
380 | @Override |
381 | public Method getJavaFactoryMethod( final ClassLoader classLoader ) |
382 | throws ModelObjectException, ClassNotFoundException |
383 | { |
384 | ClassLoader classLoaderKey = classLoader; |
385 | if ( classLoaderKey == null ) |
386 | { |
387 | classLoaderKey = BOOTSTRAP_CLASSLOADER_KEY; |
388 | } |
389 | |
390 | synchronized ( methodsByClassLoaderAndInstanceCache ) |
391 | { |
392 | Method javaClassFactoryMethod = null; |
393 | Map<String, Reference<Method>> map = methodsByClassLoaderAndInstanceCache.get( classLoaderKey ); |
394 | |
395 | if ( map == null ) |
396 | { |
397 | map = createMap(); |
398 | methodsByClassLoaderAndInstanceCache.put( classLoaderKey, map ); |
399 | } |
400 | |
401 | final Reference<Method> reference = map.get( this.getIdentifier() ); |
402 | |
403 | if ( reference != null ) |
404 | { |
405 | javaClassFactoryMethod = reference.get(); |
406 | } |
407 | |
408 | if ( javaClassFactoryMethod == null && ( reference != null || !map.containsKey( this.getIdentifier() ) ) ) |
409 | { |
410 | javaClassFactoryMethod = super.getJavaFactoryMethod( classLoader ); |
411 | map.put( this.getIdentifier(), new WeakReference<Method>( javaClassFactoryMethod ) ); |
412 | } |
413 | |
414 | return javaClassFactoryMethod; |
415 | } |
416 | } |
417 | |
418 | /** |
419 | * Gets a flag indicating the Java class of the instance is assignable to all Java classes of all specifications of |
420 | * the instance. |
421 | * <p>This method queries an internal cache for a result object to return for the given argument values. If no |
422 | * cached result object is available, this method queries the super-class for a result object to return and caches |
423 | * the outcome of that query for use on successive calls.</p> |
424 | * <p><b>Note:</b><br/>Method {@code RuntimeModelObjects.clear()} must be used to synchronize the state of the |
425 | * internal cache with the state of the instance and class loader, should the state of the instance or class loader |
426 | * change.</p> |
427 | * |
428 | * @param classLoader The class loader to get the Java classes from or {@code null}, to get the Java classes from |
429 | * the platform's bootstrap class loader. |
430 | * |
431 | * @return {@code true}, if the Java class of the instance is assignable to all Java classes of all specifications |
432 | * of the instance; {@code false}, if the Java class of the instance is not assignable to all Java classes of all |
433 | * specifications of the instance. |
434 | * |
435 | * @throws ClassNotFoundException if a Java class is not found. |
436 | * @throws ModelObjectException if parsing a name of a referenced type fails. |
437 | * |
438 | * @see #getJavaClass(java.lang.ClassLoader) |
439 | * @see #getJavaClasses(java.lang.ClassLoader) |
440 | * @see RuntimeModelObjects#clear() |
441 | */ |
442 | @Override |
443 | public boolean isJavaClassAssignable( final ClassLoader classLoader ) |
444 | throws ModelObjectException, ClassNotFoundException |
445 | { |
446 | ClassLoader classLoaderKey = classLoader; |
447 | if ( classLoaderKey == null ) |
448 | { |
449 | classLoaderKey = BOOTSTRAP_CLASSLOADER_KEY; |
450 | } |
451 | |
452 | synchronized ( assignableFlagsByClassLoaderAndInstanceCache ) |
453 | { |
454 | Map<String, Boolean> map = assignableFlagsByClassLoaderAndInstanceCache.get( classLoaderKey ); |
455 | |
456 | if ( map == null ) |
457 | { |
458 | map = createMap(); |
459 | assignableFlagsByClassLoaderAndInstanceCache.put( classLoaderKey, map ); |
460 | } |
461 | |
462 | Boolean javaClassAssignable = map.get( this.getIdentifier() ); |
463 | |
464 | if ( javaClassAssignable == null && !map.containsKey( this.getIdentifier() ) ) |
465 | { |
466 | javaClassAssignable = super.isJavaClassAssignable( classLoader ); |
467 | map.put( this.getIdentifier(), javaClassAssignable ); |
468 | } |
469 | |
470 | return javaClassAssignable == null ? false : javaClassAssignable; |
471 | } |
472 | } |
473 | |
474 | /** |
475 | * Gets the Java proxy class for a given class loader. |
476 | * <p>This method queries an internal cache for a result object to return for the given argument values. If no |
477 | * cached result object is available, this method queries the super-class for a result object to return and caches |
478 | * the outcome of that query for use on successive calls.</p> |
479 | * <p><b>Note:</b><br/>Method {@code RuntimeModelObjects.clear()} must be used to synchronize the state of the |
480 | * internal cache with the state of the instance and class loader, should the state of the instance or class loader |
481 | * change.</p> |
482 | * |
483 | * @param classLoader The class loader to get the Java proxy class for. |
484 | * |
485 | * @return The Java proxy class for {@code classLoader} or {@code null}, if the instance does not support a Java |
486 | * proxy class. |
487 | * |
488 | * @throws ClassNotFoundException if a Java class is not found. |
489 | * @throws ModelObjectException if parsing a name of a referenced type fails. |
490 | * |
491 | * @see #getJavaClasses(java.lang.ClassLoader) |
492 | * @see RuntimeModelObjects#clear() |
493 | */ |
494 | @Override |
495 | public Class<?> getJavaProxyClass( final ClassLoader classLoader ) |
496 | throws ModelObjectException, ClassNotFoundException |
497 | { |
498 | ClassLoader classLoaderKey = classLoader; |
499 | if ( classLoaderKey == null ) |
500 | { |
501 | classLoaderKey = BOOTSTRAP_CLASSLOADER_KEY; |
502 | } |
503 | |
504 | synchronized ( proxyClassesByClassLoaderAndInstanceCache ) |
505 | { |
506 | Class<?> javaProxyClass = null; |
507 | Map<String, Reference<Class<?>>> map = proxyClassesByClassLoaderAndInstanceCache.get( classLoaderKey ); |
508 | |
509 | if ( map == null ) |
510 | { |
511 | map = createMap(); |
512 | proxyClassesByClassLoaderAndInstanceCache.put( classLoaderKey, map ); |
513 | } |
514 | |
515 | final Reference<Class<?>> reference = map.get( this.getIdentifier() ); |
516 | |
517 | if ( reference != null ) |
518 | { |
519 | javaProxyClass = reference.get(); |
520 | } |
521 | |
522 | if ( javaProxyClass == null && ( reference != null || !map.containsKey( this.getIdentifier() ) ) ) |
523 | { |
524 | javaProxyClass = super.getJavaProxyClass( classLoader ); |
525 | map.put( this.getIdentifier(), new WeakReference<Class<?>>( javaProxyClass ) ); |
526 | } |
527 | |
528 | return javaProxyClass; |
529 | } |
530 | } |
531 | |
532 | /** |
533 | * Gets the Java type name of the type referenced by the instance. |
534 | * <p>This method queries an internal cache for a result object to return. If no cached result object is available, |
535 | * this method queries the super-class for a result object to return and caches the outcome of that query for use on |
536 | * successive calls.</p> |
537 | * <p><b>Note:</b><br/>Method {@code clear()} must be used to synchronize the state of the internal cache with the |
538 | * state of the instance, should the state of the instance change.</p> |
539 | * |
540 | * @return The Java type name of the type referenced by the instance or {@code null}, if the instance does not |
541 | * reference a type. |
542 | * |
543 | * @throws ModelObjectException if compiling the name of the referenced type to a {@code JavaTypeName} fails. |
544 | * |
545 | * @since 1.4 |
546 | * |
547 | * @see Instance#getJavaTypeName() |
548 | * @see #clear() |
549 | */ |
550 | @Override |
551 | public JavaTypeName getJavaTypeName() throws ModelObjectException |
552 | { |
553 | if ( this.javaTypeName == null ) |
554 | { |
555 | this.javaTypeName = super.getJavaTypeName(); |
556 | } |
557 | |
558 | return this.javaTypeName; |
559 | } |
560 | |
561 | // SECTION-END |
562 | // SECTION-START[RuntimeModelObject] |
563 | public void gc() |
564 | { |
565 | this.gcOrClear( true, false ); |
566 | } |
567 | |
568 | public void clear() |
569 | { |
570 | this.javaClassFactoryMethodName = null; |
571 | this.javaTypeName = null; |
572 | this.gcOrClear( false, true ); |
573 | } |
574 | |
575 | private void gcOrClear( final boolean gc, final boolean clear ) |
576 | { |
577 | if ( this.getAuthors() instanceof RuntimeModelObject ) |
578 | { |
579 | if ( gc ) |
580 | { |
581 | ( (RuntimeModelObject) this.getAuthors() ).gc(); |
582 | } |
583 | if ( clear ) |
584 | { |
585 | ( (RuntimeModelObject) this.getAuthors() ).clear(); |
586 | } |
587 | } |
588 | if ( this.getDependencies() instanceof RuntimeModelObject ) |
589 | { |
590 | if ( gc ) |
591 | { |
592 | ( (RuntimeModelObject) this.getDependencies() ).gc(); |
593 | } |
594 | if ( clear ) |
595 | { |
596 | ( (RuntimeModelObject) this.getDependencies() ).clear(); |
597 | } |
598 | } |
599 | if ( this.getDocumentation() instanceof RuntimeModelObject ) |
600 | { |
601 | if ( gc ) |
602 | { |
603 | ( (RuntimeModelObject) this.getDocumentation() ).gc(); |
604 | } |
605 | if ( clear ) |
606 | { |
607 | ( (RuntimeModelObject) this.getDocumentation() ).clear(); |
608 | } |
609 | } |
610 | if ( this.getMessages() instanceof RuntimeModelObject ) |
611 | { |
612 | if ( gc ) |
613 | { |
614 | ( (RuntimeModelObject) this.getMessages() ).gc(); |
615 | } |
616 | if ( clear ) |
617 | { |
618 | ( (RuntimeModelObject) this.getMessages() ).clear(); |
619 | } |
620 | } |
621 | if ( this.getProperties() instanceof RuntimeModelObject ) |
622 | { |
623 | if ( gc ) |
624 | { |
625 | ( (RuntimeModelObject) this.getProperties() ).gc(); |
626 | } |
627 | if ( clear ) |
628 | { |
629 | ( (RuntimeModelObject) this.getProperties() ).clear(); |
630 | } |
631 | } |
632 | if ( this.getSpecifications() instanceof RuntimeModelObject ) |
633 | { |
634 | if ( gc ) |
635 | { |
636 | ( (RuntimeModelObject) this.getSpecifications() ).gc(); |
637 | } |
638 | if ( clear ) |
639 | { |
640 | ( (RuntimeModelObject) this.getSpecifications() ).clear(); |
641 | } |
642 | } |
643 | } |
644 | |
645 | // SECTION-END |
646 | // SECTION-START[Constructors] |
647 | // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> |
648 | /** Creates a new {@code RuntimeInstance} instance. */ |
649 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" ) |
650 | public RuntimeInstance() |
651 | { |
652 | // SECTION-START[Default Constructor] |
653 | super(); |
654 | // SECTION-END |
655 | } |
656 | // </editor-fold> |
657 | // SECTION-END |
658 | // SECTION-START[Dependencies] |
659 | // SECTION-END |
660 | // SECTION-START[Properties] |
661 | // SECTION-END |
662 | // SECTION-START[Messages] |
663 | // SECTION-END |
664 | } |