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: RuntimeArgument.java 4712 2013-01-02 13:56:12Z schulte $ 032 * 033 */ 034// </editor-fold> 035// SECTION-END 036package org.jomc.ri.model; 037 038import javax.xml.bind.annotation.XmlTransient; 039import org.jomc.model.Argument; 040import org.jomc.model.ArgumentType; 041import org.jomc.model.JavaTypeName; 042import org.jomc.model.ModelObjectException; 043 044// SECTION-START[Documentation] 045// <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 046/** 047 * Runtime {@code Argument}. 048 * 049 * <dl> 050 * <dt><b>Identifier:</b></dt><dd>org.jomc.ri.model.RuntimeArgument</dd> 051 * <dt><b>Name:</b></dt><dd>JOMC ⁑ RI ⁑ RuntimeArgument</dd> 052 * <dt><b>Specifications:</b></dt> 053 * <dd>org.jomc.ri.model.RuntimeModelObject @ 1.2</dd> 054 * <dt><b>Abstract:</b></dt><dd>No</dd> 055 * <dt><b>Final:</b></dt><dd>No</dd> 056 * <dt><b>Stateless:</b></dt><dd>No</dd> 057 * </dl> 058 * 059 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.2 060 * @version 1.2 061 */ 062// </editor-fold> 063// SECTION-END 064// SECTION-START[Annotations] 065// <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 066@javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 067// </editor-fold> 068// SECTION-END 069public class RuntimeArgument extends Argument implements RuntimeModelObject 070{ 071 // SECTION-START[RuntimeArgument] 072 073 /** Java type name. */ 074 @XmlTransient 075 private volatile JavaTypeName javaTypeName; 076 077 /** 078 * Creates a new {@code RuntimeArgument} instance by deeply copying a given {@code Argument} instance. 079 * 080 * @param argument The instance to copy. 081 * 082 * @throws NullPointerException if {@code argument} is {@code null}. 083 */ 084 public RuntimeArgument( final Argument argument ) 085 { 086 super( argument ); 087 088 if ( this.getAuthors() != null ) 089 { 090 this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) ); 091 } 092 if ( this.getDocumentation() != null ) 093 { 094 this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) ); 095 } 096 } 097 098 /** 099 * Gets the Java type name of the type referenced by the argument. 100 * <p>This method queries an internal cache for a result object to return. If no cached result object is available, 101 * this method queries the super-class for a result object to return and caches the outcome of that query for use on 102 * successive calls.</p> 103 * <p><b>Note:</b><br/>Method {@code clear()} must be used to synchronize the state of the internal cache with the 104 * state of the instance, should the state of the instance change.</p> 105 * 106 * @return The Java type name of the type referenced by the argument or {@code null}, if the argument does not 107 * reference a type. 108 * 109 * @throws ModelObjectException if compiling the name of the referenced type to a {@code JavaTypeName} fails. 110 * 111 * @since 1.4 112 * 113 * @see #getType() 114 * @see #clear() 115 */ 116 @Override 117 public JavaTypeName getJavaTypeName() throws ModelObjectException 118 { 119 if ( this.javaTypeName == null ) 120 { 121 this.javaTypeName = super.getJavaTypeName(); 122 } 123 124 return this.javaTypeName; 125 } 126 127 // SECTION-END 128 // SECTION-START[RuntimeModelObject] 129 public void gc() 130 { 131 this.gcOrClear( true, false ); 132 } 133 134 public void clear() 135 { 136 this.javaTypeName = null; 137 this.gcOrClear( false, true ); 138 } 139 140 private void gcOrClear( final boolean gc, final boolean clear ) 141 { 142 if ( this.getAuthors() instanceof RuntimeModelObject ) 143 { 144 if ( gc ) 145 { 146 ( (RuntimeModelObject) this.getAuthors() ).gc(); 147 } 148 if ( clear ) 149 { 150 ( (RuntimeModelObject) this.getAuthors() ).clear(); 151 } 152 } 153 if ( this.getDocumentation() instanceof RuntimeModelObject ) 154 { 155 if ( gc ) 156 { 157 ( (RuntimeModelObject) this.getDocumentation() ).gc(); 158 } 159 if ( clear ) 160 { 161 ( (RuntimeModelObject) this.getDocumentation() ).clear(); 162 } 163 } 164 } 165 166 // SECTION-END 167 // SECTION-START[Constructors] 168 // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> 169 /** Creates a new {@code RuntimeArgument} instance. */ 170 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.4", comments = "See http://www.jomc.org/jomc/1.4/jomc-tools-1.4" ) 171 public RuntimeArgument() 172 { 173 // SECTION-START[Default Constructor] 174 super(); 175 // SECTION-END 176 } 177 // </editor-fold> 178 // SECTION-END 179 // SECTION-START[Dependencies] 180 // SECTION-END 181 // SECTION-START[Properties] 182 // SECTION-END 183 // SECTION-START[Messages] 184 // SECTION-END 185}