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: RuntimePersons.java 4381 2012-03-04 19:29:29Z schulte2005 $
032     *
033     */
034    // </editor-fold>
035    // SECTION-END
036    package org.jomc.ri.model;
037    
038    import org.jomc.model.Person;
039    import org.jomc.model.Persons;
040    
041    // SECTION-START[Documentation]
042    // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
043    /**
044     * Runtime {@code Persons}.
045     *
046     * <dl>
047     *   <dt><b>Identifier:</b></dt><dd>org.jomc.ri.model.RuntimePersons</dd>
048     *   <dt><b>Name:</b></dt><dd>JOMC RI RuntimePersons</dd>
049     *   <dt><b>Specifications:</b></dt>
050     *     <dd>org.jomc.ri.model.RuntimeModelObject @ 1.2</dd>
051     *   <dt><b>Abstract:</b></dt><dd>No</dd>
052     *   <dt><b>Final:</b></dt><dd>No</dd>
053     *   <dt><b>Stateless:</b></dt><dd>No</dd>
054     * </dl>
055     *
056     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.2
057     * @version 1.2
058     */
059    // </editor-fold>
060    // SECTION-END
061    // SECTION-START[Annotations]
062    // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
063    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
064    // </editor-fold>
065    // SECTION-END
066    public class RuntimePersons extends Persons implements RuntimeModelObject
067    {
068        // SECTION-START[RuntimePersons]
069    
070        /**
071         * Creates a new {@code RuntimePersons} instance by deeply copying a given {@code Persons} instance.
072         *
073         * @param persons The instance to copy.
074         *
075         * @throws NullPointerException if {@code persons} is {@code null}.
076         */
077        public RuntimePersons( final Persons persons )
078        {
079            super( persons );
080    
081            if ( this.getAuthors() != null )
082            {
083                this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
084            }
085            if ( this.getDocumentation() != null )
086            {
087                this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
088            }
089    
090            this.copyPersons();
091        }
092    
093        private void copyPersons()
094        {
095            for ( int i = 0, s0 = this.getPerson().size(); i < s0; i++ )
096            {
097                final Person p = this.getPerson().get( i );
098                this.getPerson().set( i, RuntimeModelObjects.getInstance().copyOf( p ) );
099            }
100        }
101    
102        // SECTION-END
103        // SECTION-START[RuntimeModelObject]
104        public void gc()
105        {
106            this.gcOrClear( true, false );
107        }
108    
109        public void clear()
110        {
111            this.gcOrClear( false, true );
112        }
113    
114        private void gcOrClear( final boolean gc, final boolean clear )
115        {
116            if ( this.getAuthors() instanceof RuntimeModelObject )
117            {
118                if ( gc )
119                {
120                    ( (RuntimeModelObject) this.getAuthors() ).gc();
121                }
122                if ( clear )
123                {
124                    ( (RuntimeModelObject) this.getAuthors() ).clear();
125                }
126            }
127            if ( this.getDocumentation() instanceof RuntimeModelObject )
128            {
129                if ( gc )
130                {
131                    ( (RuntimeModelObject) this.getDocumentation() ).gc();
132                }
133                if ( clear )
134                {
135                    ( (RuntimeModelObject) this.getDocumentation() ).clear();
136                }
137            }
138    
139            this.gcOrClearPersons( gc, clear );
140        }
141    
142        private void gcOrClearPersons( final boolean gc, final boolean clear )
143        {
144            for ( int i = this.getPerson().size() - 1; i >= 0; i-- )
145            {
146                final Person p = this.getPerson().get( i );
147                if ( p instanceof RuntimeModelObject )
148                {
149                    if ( gc )
150                    {
151                        ( (RuntimeModelObject) p ).gc();
152                    }
153                    if ( clear )
154                    {
155                        ( (RuntimeModelObject) p ).clear();
156                    }
157                }
158            }
159        }
160        // SECTION-END
161        // SECTION-START[Constructors]
162        // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
163        /** Creates a new {@code RuntimePersons} instance. */
164        @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
165        public RuntimePersons()
166        {
167            // SECTION-START[Default Constructor]
168            super();
169            // SECTION-END
170        }
171        // </editor-fold>
172        // SECTION-END
173        // SECTION-START[Dependencies]
174        // SECTION-END
175        // SECTION-START[Properties]
176        // SECTION-END
177        // SECTION-START[Messages]
178        // SECTION-END
179    }