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, 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 4948 2014-03-26 00:59:29Z 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.7", comments = "See http://www.jomc.org/jomc/1.7/jomc-tools-1.7" )
66  // </editor-fold>
67  // SECTION-END
68  public class RuntimeArgument extends Argument implements RuntimeModelObject
69  {
70      // SECTION-START[RuntimeArgument]
71  
72      /** Java type name. */
73      @XmlTransient
74      private volatile JavaTypeName javaTypeName;
75  
76      /**
77       * Creates a new {@code RuntimeArgument} instance by deeply copying a given {@code Argument} instance.
78       *
79       * @param argument The instance to copy.
80       *
81       * @throws NullPointerException if {@code argument} is {@code null}.
82       */
83      public RuntimeArgument( final Argument argument )
84      {
85          super( argument );
86  
87          if ( this.getAuthors() != null )
88          {
89              this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
90          }
91          if ( this.getDocumentation() != null )
92          {
93              this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
94          }
95      }
96  
97      /**
98       * Gets the Java type name of the type referenced by the argument.
99       * <p>This method queries an internal cache for a result object to return. If no cached result object is available,
100      * this method queries the super-class for a result object to return and caches the outcome of that query for use on
101      * successive calls.</p>
102      * <p><b>Note:</b><br/>Method {@code clear()} must be used to synchronize the state of the internal cache with the
103      * state of the instance, should the state of the instance change.</p>
104      *
105      * @return The Java type name of the type referenced by the argument or {@code null}, if the argument does not
106      * reference a type.
107      *
108      * @throws ModelObjectException if compiling the name of the referenced type to a {@code JavaTypeName} fails.
109      *
110      * @since 1.4
111      *
112      * @see #getType()
113      * @see #clear()
114      */
115     @Override
116     public JavaTypeName getJavaTypeName() throws ModelObjectException
117     {
118         if ( this.javaTypeName == null )
119         {
120             this.javaTypeName = super.getJavaTypeName();
121         }
122 
123         return this.javaTypeName;
124     }
125 
126     // SECTION-END
127     // SECTION-START[RuntimeModelObject]
128     public void gc()
129     {
130         this.gcOrClear( true, false );
131     }
132 
133     public void clear()
134     {
135         this.javaTypeName = null;
136         this.gcOrClear( false, true );
137     }
138 
139     private void gcOrClear( final boolean gc, final boolean clear )
140     {
141         if ( this.getAuthors() instanceof RuntimeModelObject )
142         {
143             if ( gc )
144             {
145                 ( (RuntimeModelObject) this.getAuthors() ).gc();
146             }
147             if ( clear )
148             {
149                 ( (RuntimeModelObject) this.getAuthors() ).clear();
150             }
151         }
152         if ( this.getDocumentation() instanceof RuntimeModelObject )
153         {
154             if ( gc )
155             {
156                 ( (RuntimeModelObject) this.getDocumentation() ).gc();
157             }
158             if ( clear )
159             {
160                 ( (RuntimeModelObject) this.getDocumentation() ).clear();
161             }
162         }
163     }
164 
165     // SECTION-END
166     // SECTION-START[Constructors]
167     // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
168     /** Creates a new {@code RuntimeArgument} instance. */
169     @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.7", comments = "See http://www.jomc.org/jomc/1.7/jomc-tools-1.7" )
170     public RuntimeArgument()
171     {
172         // SECTION-START[Default Constructor]
173         super();
174         // SECTION-END
175     }
176     // </editor-fold>
177     // SECTION-END
178     // SECTION-START[Dependencies]
179     // SECTION-END
180     // SECTION-START[Properties]
181     // SECTION-END
182     // SECTION-START[Messages]
183     // SECTION-END
184 }