001// SECTION-START[License Header]
002// <editor-fold defaultstate="collapsed" desc=" Generated License ">
003/*
004 *   Java Object Management and Configuration
005 *   Copyright (C) Christian Schulte, 2011-313
006 *   All rights reserved.
007 *
008 *   Redistribution and use in source and binary forms, with or without
009 *   modification, are permitted provided that the following conditions
010 *   are met:
011 *
012 *     o Redistributions of source code must retain the above copyright
013 *       notice, this list of conditions and the following disclaimer.
014 *
015 *     o Redistributions in binary form must reproduce the above copyright
016 *       notice, this list of conditions and the following disclaimer in
017 *       the documentation and/or other materials provided with the
018 *       distribution.
019 *
020 *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
021 *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
022 *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
023 *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
024 *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
025 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
029 *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030 *
031 *   $JOMC: RuntimeModelObjects.java 4588 2012-06-03 06:01:30Z schulte2005 $
032 *
033 */
034// </editor-fold>
035// SECTION-END
036package org.jomc.ri.model;
037
038import java.lang.ref.Reference;
039import java.util.HashMap;
040import java.util.Map;
041import org.jomc.model.Argument;
042import org.jomc.model.Arguments;
043import org.jomc.model.Author;
044import org.jomc.model.Authors;
045import org.jomc.model.Dependencies;
046import org.jomc.model.Dependency;
047import org.jomc.model.Implementation;
048import org.jomc.model.ImplementationReference;
049import org.jomc.model.Implementations;
050import org.jomc.model.Instance;
051import org.jomc.model.Instances;
052import org.jomc.model.Message;
053import org.jomc.model.MessageReference;
054import org.jomc.model.Messages;
055import org.jomc.model.Module;
056import org.jomc.model.Person;
057import org.jomc.model.Persons;
058import org.jomc.model.Properties;
059import org.jomc.model.Property;
060import org.jomc.model.PropertyReference;
061import org.jomc.model.Specification;
062import org.jomc.model.SpecificationReference;
063import org.jomc.model.Specifications;
064import org.jomc.model.Text;
065import org.jomc.model.Texts;
066import org.jomc.util.WeakIdentityHashMap;
067
068// SECTION-START[Documentation]
069// <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
070/**
071 * Runtime model objects.
072 *
073 * <dl>
074 *   <dt><b>Identifier:</b></dt><dd>org.jomc.ri.model.RuntimeModelObjects</dd>
075 *   <dt><b>Name:</b></dt><dd>JOMC RI</dd>
076 *   <dt><b>Abstract:</b></dt><dd>No</dd>
077 *   <dt><b>Final:</b></dt><dd>No</dd>
078 *   <dt><b>Stateless:</b></dt><dd>No</dd>
079 * </dl>
080 *
081 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.2
082 * @version 1.2
083 */
084// </editor-fold>
085// SECTION-END
086// SECTION-START[Annotations]
087// <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
088@javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" )
089// </editor-fold>
090// SECTION-END
091public class RuntimeModelObjects
092{
093    // SECTION-START[RuntimeModelObjects]
094
095    /** Classes by class loader any name cache. */
096    static final Map<ClassLoader, Map<String, Reference<Class<?>>>> classesByClassLoaderAndNameCache =
097        new WeakIdentityHashMap<ClassLoader, Map<String, Reference<Class<?>>>>();
098
099    /** 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.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" )
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}