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: RuntimeAuthors.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.Author;
039    import org.jomc.model.Authors;
040    
041    // SECTION-START[Documentation]
042    // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
043    /**
044     * Runtime {@code Authors}.
045     *
046     * <dl>
047     *   <dt><b>Identifier:</b></dt><dd>org.jomc.ri.model.RuntimeAuthors</dd>
048     *   <dt><b>Name:</b></dt><dd>JOMC RI RuntimeAuthors</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 RuntimeAuthors extends Authors implements RuntimeModelObject
067    {
068        // SECTION-START[RuntimeAuthors]
069    
070        /**
071         * Creates a new {@code RuntimeAuthors} instance by deeply copying a given {@code Authors} instance.
072         *
073         * @param authors The instance to copy.
074         *
075         * @throws NullPointerException if {@code authors} is {@code null}.
076         */
077        public RuntimeAuthors( final Authors authors )
078        {
079            super( authors );
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.copyAuthors();
091        }
092    
093        private void copyAuthors()
094        {
095            for ( int i = 0, s0 = this.getAuthor().size(); i < s0; i++ )
096            {
097                final Author a = this.getAuthor().get( i );
098                this.getAuthor().set( i, RuntimeModelObjects.getInstance().copyOf( a ) );
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.gcOrClearAuthors( gc, clear );
140        }
141    
142        private void gcOrClearAuthors( final boolean gc, final boolean clear )
143        {
144            for ( int i = this.getAuthor().size() - 1; i >= 0; i-- )
145            {
146                final Author a = this.getAuthor().get( i );
147                if ( a instanceof RuntimeModelObject )
148                {
149                    if ( gc )
150                    {
151                        ( (RuntimeModelObject) a ).gc();
152                    }
153                    if ( clear )
154                    {
155                        ( (RuntimeModelObject) a ).clear();
156                    }
157                }
158            }
159        }
160    
161        // SECTION-END
162        // SECTION-START[Constructors]
163        // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
164        /** Creates a new {@code RuntimeAuthors} instance. */
165        @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" )
166        public RuntimeAuthors()
167        {
168            // SECTION-START[Default Constructor]
169            super();
170            // SECTION-END
171        }
172        // </editor-fold>
173        // SECTION-END
174        // SECTION-START[Dependencies]
175        // SECTION-END
176        // SECTION-START[Properties]
177        // SECTION-END
178        // SECTION-START[Messages]
179        // SECTION-END
180    }