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: RuntimeModelObjects.java 4881 2014-02-20 22:55:53Z 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.util.HashMap; |
40 | import java.util.Map; |
41 | import org.jomc.model.Argument; |
42 | import org.jomc.model.Arguments; |
43 | import org.jomc.model.Author; |
44 | import org.jomc.model.Authors; |
45 | import org.jomc.model.Dependencies; |
46 | import org.jomc.model.Dependency; |
47 | import org.jomc.model.Implementation; |
48 | import org.jomc.model.ImplementationReference; |
49 | import org.jomc.model.Implementations; |
50 | import org.jomc.model.Instance; |
51 | import org.jomc.model.Instances; |
52 | import org.jomc.model.Message; |
53 | import org.jomc.model.MessageReference; |
54 | import org.jomc.model.Messages; |
55 | import org.jomc.model.Module; |
56 | import org.jomc.model.Person; |
57 | import org.jomc.model.Persons; |
58 | import org.jomc.model.Properties; |
59 | import org.jomc.model.Property; |
60 | import org.jomc.model.PropertyReference; |
61 | import org.jomc.model.Specification; |
62 | import org.jomc.model.SpecificationReference; |
63 | import org.jomc.model.Specifications; |
64 | import org.jomc.model.Text; |
65 | import org.jomc.model.Texts; |
66 | import org.jomc.util.WeakIdentityHashMap; |
67 | |
68 | // SECTION-START[Documentation] |
69 | // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> |
70 | /** |
71 | * Runtime model objects. |
72 | * |
73 | * <dl> |
74 | * <dt><b>Identifier:</b></dt><dd>org.jomc.ri.model.RuntimeModelObjects</dd> |
75 | * <dt><b>Name:</b></dt><dd>JOMC ⁑ RI ⁑ RuntimeModelObjects</dd> |
76 | * <dt><b>Abstract:</b></dt><dd>No</dd> |
77 | * <dt><b>Final:</b></dt><dd>No</dd> |
78 | * <dt><b>Stateless:</b></dt><dd>No</dd> |
79 | * </dl> |
80 | * |
81 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.2 |
82 | * @version 1.2 |
83 | */ |
84 | // </editor-fold> |
85 | // SECTION-END |
86 | // SECTION-START[Annotations] |
87 | // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> |
88 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.6", comments = "See http://www.jomc.org/jomc/1.6/jomc-tools-1.6" ) |
89 | // </editor-fold> |
90 | // SECTION-END |
91 | public class RuntimeModelObjects |
92 | { |
93 | // SECTION-START[RuntimeModelObjects] |
94 | |
95 | /** Classes by class loader any name cache. */ |
96 | static final Map<ClassLoader, Map<String, Reference<Class<?>>>> classesByClassLoaderAndNameCache = |
97 | new WeakIdentityHashMap<ClassLoader, Map<String, Reference<Class<?>>>>(); |
98 | |
99 | /** Singleton instance. */ |
100 | private static final RuntimeModelObjects instance = new RuntimeModelObjects(); |
101 | |
102 | /** Cache key for the bootstrap class loader. */ |
103 | static final ClassLoader BOOTSTRAP_CLASSLOADER_KEY = new ClassLoader() |
104 | { |
105 | }; |
106 | |
107 | /** |
108 | * Gets the {@code RuntimeModelObjects} singleton instance. |
109 | * |
110 | * @return The {@code RuntimeModelObjects} singleton instance. |
111 | */ |
112 | public static RuntimeModelObjects getInstance() |
113 | { |
114 | return instance; |
115 | } |
116 | |
117 | /** |
118 | * Creates a copy of a given object. |
119 | * |
120 | * @param o The object to copy. |
121 | * |
122 | * @return {@code new RuntimePropertyReference( o )} |
123 | */ |
124 | public PropertyReference copyOf( final PropertyReference o ) |
125 | { |
126 | return new RuntimePropertyReference( o ); |
127 | } |
128 | |
129 | /** |
130 | * Creates a copy of a given object. |
131 | * |
132 | * @param o The object to copy. |
133 | * |
134 | * @return {@code new RuntimeImplementationReference( o )} |
135 | */ |
136 | public ImplementationReference copyOf( final ImplementationReference o ) |
137 | { |
138 | return new RuntimeImplementationReference( o ); |
139 | } |
140 | |
141 | /** |
142 | * Creates a copy of a given object. |
143 | * |
144 | * @param o The object to copy. |
145 | * |
146 | * @return {@code new RuntimeDependencies( o )} |
147 | */ |
148 | public Dependencies copyOf( final Dependencies o ) |
149 | { |
150 | return new RuntimeDependencies( o ); |
151 | } |
152 | |
153 | /** |
154 | * Creates a copy of a given object. |
155 | * |
156 | * @param o The object to copy. |
157 | * |
158 | * @return {@code new RuntimeInstances( o )} |
159 | */ |
160 | public Instances copyOf( final Instances o ) |
161 | { |
162 | return new RuntimeInstances( o ); |
163 | } |
164 | |
165 | /** |
166 | * Creates a copy of a given object. |
167 | * |
168 | * @param o The object to copy. |
169 | * |
170 | * @return {@code new RuntimeAuthors( o )} |
171 | */ |
172 | public Authors copyOf( final Authors o ) |
173 | { |
174 | return new RuntimeAuthors( o ); |
175 | } |
176 | |
177 | /** |
178 | * Creates a copy of a given object. |
179 | * |
180 | * @param o The object to copy. |
181 | * |
182 | * @return {@code new RuntimeSpecification( o )} |
183 | */ |
184 | public Specification copyOf( final Specification o ) |
185 | { |
186 | return new RuntimeSpecification( o ); |
187 | } |
188 | |
189 | /** |
190 | * Creates a copy of a given object. |
191 | * |
192 | * @param o The object to copy. |
193 | * |
194 | * @return {@code new RuntimeMessage( o )} |
195 | */ |
196 | public Message copyOf( final Message o ) |
197 | { |
198 | return new RuntimeMessage( o ); |
199 | } |
200 | |
201 | /** |
202 | * Creates a copy of a given object. |
203 | * |
204 | * @param o The object to copy. |
205 | * |
206 | * @return {@code new RuntimeInstance( o )} |
207 | */ |
208 | public Instance copyOf( final Instance o ) |
209 | { |
210 | return new RuntimeInstance( o ); |
211 | } |
212 | |
213 | /** |
214 | * Creates a copy of a given object. |
215 | * |
216 | * @param o The object to copy. |
217 | * |
218 | * @return {@code new RuntimeImplementations( o )} |
219 | */ |
220 | public Implementations copyOf( final Implementations o ) |
221 | { |
222 | return new RuntimeImplementations( o ); |
223 | } |
224 | |
225 | /** |
226 | * Creates a copy of a given object. |
227 | * |
228 | * @param o The object to copy. |
229 | * |
230 | * @return {@code new RuntimeTexts( o )} |
231 | */ |
232 | public Texts copyOf( final Texts o ) |
233 | { |
234 | return new RuntimeTexts( o ); |
235 | } |
236 | |
237 | /** |
238 | * Creates a copy of a given object. |
239 | * |
240 | * @param o The object to copy. |
241 | * |
242 | * @return {@code new RuntimeImplementation( o )} |
243 | */ |
244 | public Implementation copyOf( final Implementation o ) |
245 | { |
246 | return new RuntimeImplementation( o ); |
247 | } |
248 | |
249 | /** |
250 | * Creates a copy of a given object. |
251 | * |
252 | * @param o The object to copy. |
253 | * |
254 | * @return {@code new RuntimeModule( o )} |
255 | */ |
256 | public Module copyOf( final Module o ) |
257 | { |
258 | return new RuntimeModule( o ); |
259 | } |
260 | |
261 | /** |
262 | * Creates a copy of a given object. |
263 | * |
264 | * @param o The object to copy. |
265 | * |
266 | * @return {@code new RuntimeArgument( o )} |
267 | */ |
268 | public Argument copyOf( final Argument o ) |
269 | { |
270 | return new RuntimeArgument( o ); |
271 | } |
272 | |
273 | /** |
274 | * Creates a copy of a given object. |
275 | * |
276 | * @param o The object to copy. |
277 | * |
278 | * @return {@code new RuntimeText( o )} |
279 | */ |
280 | public Text copyOf( final Text o ) |
281 | { |
282 | return new RuntimeText( o ); |
283 | } |
284 | |
285 | /** |
286 | * Creates a copy of a given object. |
287 | * |
288 | * @param o The object to copy. |
289 | * |
290 | * @return {@code new RuntimeProperties( o )} |
291 | */ |
292 | public Properties copyOf( final Properties o ) |
293 | { |
294 | return new RuntimeProperties( o ); |
295 | } |
296 | |
297 | /** |
298 | * Creates a copy of a given object. |
299 | * |
300 | * @param o The object to copy. |
301 | * |
302 | * @return {@code new RuntimePerson( o )} |
303 | */ |
304 | public Person copyOf( final Person o ) |
305 | { |
306 | return new RuntimePerson( o ); |
307 | } |
308 | |
309 | /** |
310 | * Creates a copy of a given object. |
311 | * |
312 | * @param o The object to copy. |
313 | * |
314 | * @return {@code new RuntimeSpecificationReference( o )} |
315 | */ |
316 | public SpecificationReference copyOf( final SpecificationReference o ) |
317 | { |
318 | return new RuntimeSpecificationReference( o ); |
319 | } |
320 | |
321 | /** |
322 | * Creates a copy of a given object. |
323 | * |
324 | * @param o The object to copy. |
325 | * |
326 | * @return {@code new RuntimeAuthor( o )} |
327 | */ |
328 | public Author copyOf( final Author o ) |
329 | { |
330 | return new RuntimeAuthor( o ); |
331 | } |
332 | |
333 | /** |
334 | * Creates a copy of a given object. |
335 | * |
336 | * @param o The object to copy. |
337 | * |
338 | * @return {@code new RuntimeProperty( o )} |
339 | */ |
340 | public Property copyOf( final Property o ) |
341 | { |
342 | return new RuntimeProperty( o ); |
343 | } |
344 | |
345 | /** |
346 | * Creates a copy of a given object. |
347 | * |
348 | * @param o The object to copy. |
349 | * |
350 | * @return {@code new RuntimeArguments( o )} |
351 | */ |
352 | public Arguments copyOf( final Arguments o ) |
353 | { |
354 | return new RuntimeArguments( o ); |
355 | } |
356 | |
357 | /** |
358 | * Creates a copy of a given object. |
359 | * |
360 | * @param o The object to copy. |
361 | * |
362 | * @return {@code new RuntimeDependency( o )} |
363 | */ |
364 | public Dependency copyOf( final Dependency o ) |
365 | { |
366 | return new RuntimeDependency( o ); |
367 | } |
368 | |
369 | /** |
370 | * Creates a copy of a given object. |
371 | * |
372 | * @param o The object to copy. |
373 | * |
374 | * @return {@code new RuntimeSpecifications( o )} |
375 | */ |
376 | public Specifications copyOf( final Specifications o ) |
377 | { |
378 | return new RuntimeSpecifications( o ); |
379 | } |
380 | |
381 | /** |
382 | * Creates a copy of a given object. |
383 | * |
384 | * @param o The object to copy. |
385 | * |
386 | * @return {@code new RuntimeMessages( o )} |
387 | */ |
388 | public Messages copyOf( final Messages o ) |
389 | { |
390 | return new RuntimeMessages( o ); |
391 | } |
392 | |
393 | /** |
394 | * Creates a copy of a given object. |
395 | * |
396 | * @param o The object to copy. |
397 | * |
398 | * @return {@code new RuntimePersons( o )} |
399 | */ |
400 | public Persons copyOf( final Persons o ) |
401 | { |
402 | return new RuntimePersons( o ); |
403 | } |
404 | |
405 | /** |
406 | * Creates a copy of a given object. |
407 | * |
408 | * @param o The object to copy. |
409 | * |
410 | * @return {@code new RuntimeMessageReference( o )} |
411 | */ |
412 | public MessageReference copyOf( final MessageReference o ) |
413 | { |
414 | return new RuntimeMessageReference( o ); |
415 | } |
416 | |
417 | /** Handles shared runtime state. */ |
418 | public void gc() |
419 | { |
420 | synchronized ( classesByClassLoaderAndNameCache ) |
421 | { |
422 | classesByClassLoaderAndNameCache.size(); |
423 | } |
424 | synchronized ( RuntimeInstance.assignableFlagsByClassLoaderAndInstanceCache ) |
425 | { |
426 | RuntimeInstance.assignableFlagsByClassLoaderAndInstanceCache.size(); |
427 | } |
428 | synchronized ( RuntimeInstance.classesByClassLoaderAndInstanceCache ) |
429 | { |
430 | RuntimeInstance.classesByClassLoaderAndInstanceCache.size(); |
431 | } |
432 | synchronized ( RuntimeInstance.constructorsByClassLoaderAndInstanceCache ) |
433 | { |
434 | RuntimeInstance.constructorsByClassLoaderAndInstanceCache.size(); |
435 | } |
436 | synchronized ( RuntimeInstance.methodsByClassLoaderAndInstanceCache ) |
437 | { |
438 | RuntimeInstance.methodsByClassLoaderAndInstanceCache.size(); |
439 | } |
440 | synchronized ( RuntimeInstance.proxyClassesByClassLoaderAndInstanceCache ) |
441 | { |
442 | RuntimeInstance.proxyClassesByClassLoaderAndInstanceCache.size(); |
443 | } |
444 | } |
445 | |
446 | /** Clears shared runtime state. */ |
447 | public void clear() |
448 | { |
449 | synchronized ( classesByClassLoaderAndNameCache ) |
450 | { |
451 | classesByClassLoaderAndNameCache.clear(); |
452 | } |
453 | synchronized ( RuntimeInstance.assignableFlagsByClassLoaderAndInstanceCache ) |
454 | { |
455 | RuntimeInstance.assignableFlagsByClassLoaderAndInstanceCache.clear(); |
456 | } |
457 | synchronized ( RuntimeInstance.classesByClassLoaderAndInstanceCache ) |
458 | { |
459 | RuntimeInstance.classesByClassLoaderAndInstanceCache.clear(); |
460 | } |
461 | synchronized ( RuntimeInstance.constructorsByClassLoaderAndInstanceCache ) |
462 | { |
463 | RuntimeInstance.constructorsByClassLoaderAndInstanceCache.clear(); |
464 | } |
465 | synchronized ( RuntimeInstance.methodsByClassLoaderAndInstanceCache ) |
466 | { |
467 | RuntimeInstance.methodsByClassLoaderAndInstanceCache.clear(); |
468 | } |
469 | synchronized ( RuntimeInstance.proxyClassesByClassLoaderAndInstanceCache ) |
470 | { |
471 | RuntimeInstance.proxyClassesByClassLoaderAndInstanceCache.clear(); |
472 | } |
473 | } |
474 | |
475 | /** |
476 | * Creates a new {@code Map} instance. |
477 | * |
478 | * @param <K> The type of the keys to maintain by the new map. |
479 | * @param <V> The type of the values to map. |
480 | * |
481 | * @return A new {@code Map} instance. |
482 | */ |
483 | static <K, V> Map<K, V> createMap() |
484 | { |
485 | return new HashMap<K, V>( 128 ); |
486 | } |
487 | |
488 | // SECTION-END |
489 | // SECTION-START[Constructors] |
490 | // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> |
491 | /** Creates a new {@code RuntimeModelObjects} instance. */ |
492 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.6", comments = "See http://www.jomc.org/jomc/1.6/jomc-tools-1.6" ) |
493 | public RuntimeModelObjects() |
494 | { |
495 | // SECTION-START[Default Constructor] |
496 | super(); |
497 | // SECTION-END |
498 | } |
499 | // </editor-fold> |
500 | // SECTION-END |
501 | // SECTION-START[Dependencies] |
502 | // SECTION-END |
503 | // SECTION-START[Properties] |
504 | // SECTION-END |
505 | // SECTION-START[Messages] |
506 | // SECTION-END |
507 | } |