1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.settings;
14
15 import java.util.HashSet;
16 import java.util.Set;
17
18 import com.eviware.soapui.model.settings.Settings;
19 import com.eviware.soapui.model.settings.SettingsListener;
20 import com.eviware.soapui.support.types.StringToStringMap;
21
22 /***
23 * Default Settings implementation
24 *
25 * @author Ole.Matzura
26 */
27
28 public class SettingsImpl implements Settings
29 {
30 private final Settings parent;
31 private final StringToStringMap values = new StringToStringMap();
32 private final Set<SettingsListener> listeners = new HashSet<SettingsListener>();
33
34 public SettingsImpl()
35 {
36 this( null );
37 }
38
39 public SettingsImpl( Settings parent )
40 {
41 this.parent = parent;
42 }
43
44 public boolean isSet( String id )
45 {
46 return values.containsKey( id );
47 }
48
49 public String getString( String id, String defaultValue )
50 {
51 if( values.containsKey( id ) )
52 return values.get( id );
53 return parent == null ? defaultValue : parent.getString( id, defaultValue );
54 }
55
56 public void setString( String id, String value )
57 {
58 String oldValue = getString( id, null );
59 values.put( id, value );
60
61 for( SettingsListener listener : listeners )
62 {
63 listener.settingChanged( id, value, oldValue );
64 }
65 }
66
67 public void reloadSettings()
68 {
69 for( SettingsListener listener : listeners )
70 {
71 listener.settingsReloaded();
72 }
73 }
74
75 public boolean getBoolean( String id )
76 {
77 if( values.containsKey( id ) )
78 return Boolean.parseBoolean( values.get( id ) );
79 return parent == null ? false : parent.getBoolean( id );
80 }
81
82 public void setBoolean( String id, boolean value )
83 {
84 String oldValue = getString( id, null );
85 values.put( id, Boolean.toString( value ) );
86
87 for( SettingsListener listener : listeners )
88 {
89 listener.settingChanged( id, Boolean.toString( value ), oldValue );
90 }
91 }
92
93 public long getLong( String id, long defaultValue )
94 {
95 if( values.containsKey( id ) )
96 {
97 try
98 {
99 return Long.parseLong( values.get( id ) );
100 }
101 catch( NumberFormatException e )
102 {
103 }
104 }
105
106 return defaultValue;
107 }
108
109 public void addSettingsListener( SettingsListener listener )
110 {
111 listeners.add( listener );
112 }
113
114 public void removeSettingsListener( SettingsListener listener )
115 {
116 listeners.remove( listener );
117 }
118
119 public void clearSetting( String id )
120 {
121 values.remove( id );
122 }
123
124 public void setLong( String id, long value )
125 {
126 values.put( id, Long.toString( value ) );
127 }
128 }