1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 package org.jomc.ri.model;
37
38 import java.util.Map;
39 import javax.xml.bind.annotation.XmlTransient;
40 import org.jomc.model.Properties;
41 import org.jomc.model.Property;
42 import org.jomc.model.PropertyReference;
43 import static org.jomc.ri.model.RuntimeModelObjects.createMap;
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.6", comments = "See http://www.jomc.org/jomc/1.6/jomc-tools-1.6" )
68
69
70 public class RuntimeProperties extends Properties implements RuntimeModelObject
71 {
72
73
74
75 @XmlTransient
76 private transient final Map<String, Property> propertiesByNameCache = createMap();
77
78
79 @XmlTransient
80 private transient final Map<String, PropertyReference> referencesByNameCache = createMap();
81
82
83
84
85
86
87
88
89 public RuntimeProperties( final Properties properties )
90 {
91 super( properties );
92
93 if ( this.getAuthors() != null )
94 {
95 this.setAuthors( RuntimeModelObjects.getInstance().copyOf( this.getAuthors() ) );
96 }
97 if ( this.getDocumentation() != null )
98 {
99 this.setDocumentation( RuntimeModelObjects.getInstance().copyOf( this.getDocumentation() ) );
100 }
101
102 this.copyProperties();
103 this.copyReferences();
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 @Override
125 public Property getProperty( final String name )
126 {
127 if ( name == null )
128 {
129 throw new NullPointerException( "name" );
130 }
131
132 synchronized ( this.propertiesByNameCache )
133 {
134 Property p = this.propertiesByNameCache.get( name );
135
136 if ( p == null && !this.propertiesByNameCache.containsKey( name ) )
137 {
138 p = super.getProperty( name );
139 this.propertiesByNameCache.put( name, p );
140 }
141
142 return p;
143 }
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 @Override
165 public PropertyReference getReference( final String name )
166 {
167 if ( name == null )
168 {
169 throw new NullPointerException( "name" );
170 }
171
172 synchronized ( this.referencesByNameCache )
173 {
174 PropertyReference r = this.referencesByNameCache.get( name );
175
176 if ( r == null && !this.referencesByNameCache.containsKey( name ) )
177 {
178 r = super.getReference( name );
179 this.referencesByNameCache.put( name, r );
180 }
181
182 return r;
183 }
184 }
185
186 private void copyProperties()
187 {
188 for ( int i = 0, s0 = this.getProperty().size(); i < s0; i++ )
189 {
190 final Property p = this.getProperty().get( i );
191 this.getProperty().set( i, RuntimeModelObjects.getInstance().copyOf( p ) );
192 }
193 }
194
195 private void copyReferences()
196 {
197 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
198 {
199 final PropertyReference r = this.getReference().get( i );
200 this.getReference().set( i, RuntimeModelObjects.getInstance().copyOf( r ) );
201 }
202 }
203
204
205
206 public void gc()
207 {
208 this.gcOrClear( true, false );
209 }
210
211 public void clear()
212 {
213 synchronized ( this.propertiesByNameCache )
214 {
215 this.propertiesByNameCache.clear();
216 }
217 synchronized ( this.referencesByNameCache )
218 {
219 this.referencesByNameCache.clear();
220 }
221
222 this.gcOrClear( false, true );
223 }
224
225 private void gcOrClear( final boolean gc, final boolean clear )
226 {
227 if ( this.getAuthors() instanceof RuntimeModelObject )
228 {
229 if ( gc )
230 {
231 ( (RuntimeModelObject) this.getAuthors() ).gc();
232 }
233 if ( clear )
234 {
235 ( (RuntimeModelObject) this.getAuthors() ).clear();
236 }
237 }
238 if ( this.getDocumentation() instanceof RuntimeModelObject )
239 {
240 if ( gc )
241 {
242 ( (RuntimeModelObject) this.getDocumentation() ).gc();
243 }
244 if ( clear )
245 {
246 ( (RuntimeModelObject) this.getDocumentation() ).clear();
247 }
248 }
249
250 this.gcOrClearProperties( gc, clear );
251 this.gcOrClearReferences( gc, clear );
252 }
253
254 private void gcOrClearProperties( final boolean gc, final boolean clear )
255 {
256 for ( int i = 0, s0 = this.getProperty().size(); i < s0; i++ )
257 {
258 final Property p = this.getProperty().get( i );
259 if ( p instanceof RuntimeModelObject )
260 {
261 if ( gc )
262 {
263 ( (RuntimeModelObject) p ).gc();
264 }
265 if ( clear )
266 {
267 ( (RuntimeModelObject) p ).clear();
268 }
269 }
270 }
271 }
272
273 private void gcOrClearReferences( final boolean gc, final boolean clear )
274 {
275 for ( int i = 0, s0 = this.getReference().size(); i < s0; i++ )
276 {
277 final PropertyReference r = this.getReference().get( i );
278 if ( r instanceof RuntimeModelObject )
279 {
280 if ( gc )
281 {
282 ( (RuntimeModelObject) r ).gc();
283 }
284 if ( clear )
285 {
286 ( (RuntimeModelObject) r ).clear();
287 }
288 }
289 }
290 }
291
292
293
294
295
296 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.6", comments = "See http://www.jomc.org/jomc/1.6/jomc-tools-1.6" )
297 public RuntimeProperties()
298 {
299
300 super();
301
302 }
303
304
305
306
307
308
309
310
311 }