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: RuntimeArgument.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 javax.xml.bind.annotation.XmlTransient;
39  import org.jomc.model.Argument;
40  import org.jomc.model.JavaTypeName;
41  import org.jomc.model.ModelObjectException;
42  
43  // SECTION-START[Documentation]
44  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
45  /**
46   * Runtime {@code Argument}.
47   *
48   * <dl>
49   *   <dt><b>Identifier:</b></dt><dd>org.jomc.ri.model.RuntimeArgument</dd>
50   *   <dt><b>Name:</b></dt><dd>JOMC ⁑ RI ⁑ RuntimeArgument</dd>
51   *   <dt><b>Specifications:</b></dt>
52   *     <dd>org.jomc.ri.model.RuntimeModelObject @ 1.2</dd>
53   *   <dt><b>Abstract:</b></dt><dd>No</dd>
54   *   <dt><b>Final:</b></dt><dd>No</dd>
55   *   <dt><b>Stateless:</b></dt><dd>No</dd>
56   * </dl>
57   *
58   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.2
59   * @version 1.2
60   */
61  // </editor-fold>
62  // SECTION-END
63  // SECTION-START[Annotations]
64  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
65  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
66  // </editor-fold>
67  // SECTION-END
68  public class RuntimeArgument extends Argument implements RuntimeModelObject
69  {
70      // SECTION-START[RuntimeArgument]
71  
72      /**
73       * Java type name.
74       */
75      @XmlTransient
76      private volatile JavaTypeName javaTypeName;
77  
78      /**
79       * Creates a new {@code RuntimeArgument} instance by deeply copying a given {@code Argument} instance.
80       *
81       * @param argument The instance to copy.
82       *
83       * @throws NullPointerException if {@code argument} is {@code null}.
84       */
85      public RuntimeArgument( final Argument argument )
86      {
87          super( argument );
88  
89          if ( this.getAuthors() != null )
90          {
91              this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
92          }
93          if ( this.getDocumentation() != null )
94          {
95              this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
96          }
97      }
98  
99      /**
100      * Gets the Java type name of the type referenced by the argument.
101      * <p>
102      * This method queries an internal cache for a result object to return. If no cached result object is available,
103      * this method queries the super-class for a result object to return and caches the outcome of that query for use on
104      * successive calls.
105      * </p>
106      * <p>
107      * <b>Note:</b><br/>Method {@code clear()} must be used to synchronize the state of the internal cache with the
108      * state of the instance, should the state of the instance change.
109      * </p>
110      *
111      * @return The Java type name of the type referenced by the argument or {@code null}, if the argument does not
112      * reference a type.
113      *
114      * @throws ModelObjectException if compiling the name of the referenced type to a {@code JavaTypeName} fails.
115      *
116      * @since 1.4
117      *
118      * @see #getType()
119      * @see #clear()
120      */
121     @Override
122     public JavaTypeName getJavaTypeName() throws ModelObjectException
123     {
124         if ( this.javaTypeName == null )
125         {
126             this.javaTypeName = super.getJavaTypeName();
127         }
128 
129         return this.javaTypeName;
130     }
131 
132     // SECTION-END
133     // SECTION-START[RuntimeModelObject]
134     public void gc()
135     {
136         this.gcOrClear( true, false );
137     }
138 
139     public void clear()
140     {
141         this.javaTypeName = null;
142         this.gcOrClear( false, true );
143     }
144 
145     private void gcOrClear( final boolean gc, final boolean clear )
146     {
147         if ( this.getAuthors() instanceof RuntimeModelObject )
148         {
149             if ( gc )
150             {
151                 ( (RuntimeModelObject) this.getAuthors() ).gc();
152             }
153             if ( clear )
154             {
155                 ( (RuntimeModelObject) this.getAuthors() ).clear();
156             }
157         }
158         if ( this.getDocumentation() instanceof RuntimeModelObject )
159         {
160             if ( gc )
161             {
162                 ( (RuntimeModelObject) this.getDocumentation() ).gc();
163             }
164             if ( clear )
165             {
166                 ( (RuntimeModelObject) this.getDocumentation() ).clear();
167             }
168         }
169     }
170 
171     // SECTION-END
172     // SECTION-START[Constructors]
173     // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
174     /** Creates a new {@code RuntimeArgument} instance. */
175     @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.9", comments = "See http://www.jomc.org/jomc/1.9/jomc-tools-1.9" )
176     public RuntimeArgument()
177     {
178         // SECTION-START[Default Constructor]
179         super();
180         // SECTION-END
181     }
182     // </editor-fold>
183     // SECTION-END
184     // SECTION-START[Dependencies]
185     // SECTION-END
186     // SECTION-START[Properties]
187     // SECTION-END
188     // SECTION-START[Messages]
189     // SECTION-END
190 
191 }