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