1 mike 1.2 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.10 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
|
4 mike 1.2 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
|
12 kumpf 1.10 //
|
13 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Nag Boranna (nagaraja_boranna@hp.com)
25 //
26 // Modified By: Yi Zhou (yi_zhou@hp.com)
|
27 kumpf 1.14 // Warren Otsuka (warren.otsuka@hp.com)
|
28 mike 1.2 //
29 //%/////////////////////////////////////////////////////////////////////////////
30
31
32 ///////////////////////////////////////////////////////////////////////////////
33 //
34 // This file has implementation for the default property owner class.
35 //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 #include "DefaultPropertyOwner.h"
39
40
41 PEGASUS_USING_STD;
42
43 PEGASUS_NAMESPACE_BEGIN
44
45
46 ///////////////////////////////////////////////////////////////////////////////
47 // DefaultPropertyOwner
48 //
49 mike 1.2 // When a new property is added with the default owner, make sure to add
50 // the property name and the default attributes of that property in
51 // the table below.
52 ///////////////////////////////////////////////////////////////////////////////
53
54 static struct ConfigPropertyRow properties[] =
55 {
|
56 kumpf 1.14 #include "DefaultPropertyTable.h"
|
57 mike 1.2 };
58
59 const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
60
61
62 /** Constructors */
63 DefaultPropertyOwner::DefaultPropertyOwner()
64 {
65 _configProperties = new ConfigProperty[NUM_PROPERTIES];
66 }
67
68 /** Destructor */
69 DefaultPropertyOwner::~DefaultPropertyOwner()
70 {
|
71 kumpf 1.5 delete [] _configProperties;
|
72 mike 1.2 }
73
74 /**
75 Initialize the config properties.
76 */
77 void DefaultPropertyOwner::initialize()
78 {
79 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
80 {
81 _configProperties[i].propertyName = properties[i].propertyName;
82 _configProperties[i].defaultValue = properties[i].defaultValue;
83 _configProperties[i].currentValue = properties[i].defaultValue;
84 _configProperties[i].plannedValue = properties[i].defaultValue;
85 _configProperties[i].dynamic = properties[i].dynamic;
86 _configProperties[i].domain = properties[i].domain;
87 _configProperties[i].domainSize = properties[i].domainSize;
88 }
89 }
90
91
92 /**
93 mike 1.2 Get information about the specified property.
94 */
95 void DefaultPropertyOwner::getPropertyInfo(
96 const String& name,
97 Array<String>& propertyInfo)
98 {
99 propertyInfo.clear();
100
101 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
102 {
103 if (String::equalNoCase(_configProperties[i].propertyName, name))
104 {
105 propertyInfo.append(_configProperties[i].propertyName);
106 propertyInfo.append(_configProperties[i].defaultValue);
107 propertyInfo.append(_configProperties[i].currentValue);
108 propertyInfo.append(_configProperties[i].plannedValue);
109 if (_configProperties[i].dynamic)
110 {
111 propertyInfo.append(STRING_TRUE);
112 }
113 else
114 mike 1.2 {
115 propertyInfo.append(STRING_FALSE);
116 }
117 return;
118 }
119 }
120
121 //
122 // specified property name is not found
123 //
124 throw UnrecognizedConfigProperty(name);
125 }
126
127 /**
128 Get default value of the specified property
129 */
130 const String DefaultPropertyOwner::getDefaultValue(const String& name)
131 {
132 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
133 {
134 if (String::equalNoCase(_configProperties[i].propertyName, name))
135 mike 1.2 {
136 return (_configProperties[i].defaultValue);
137 }
138 }
139
140 //
141 // Specified property name could not be found
142 //
143 throw UnrecognizedConfigProperty(name);
144 }
145
146 /**
147 Get current value of the specified property
148 */
149 const String DefaultPropertyOwner::getCurrentValue(const String& name)
150 {
151 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
152 {
153 if (String::equalNoCase(_configProperties[i].propertyName, name))
154 {
155 return (_configProperties[i].currentValue);
156 mike 1.2 }
157 }
158
159 //
160 // Specified property name could not be found
161 //
162 throw UnrecognizedConfigProperty(name);
163 }
164
165 /**
166 Get planned value of the specified property
167 */
168 const String DefaultPropertyOwner::getPlannedValue(const String& name)
169 {
170 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
171 {
172 if (String::equalNoCase(_configProperties[i].propertyName, name))
173 {
174 return (_configProperties[i].plannedValue);
175 }
176 }
177 mike 1.2
178 //
179 // Specified property name could not be found
180 //
181 throw UnrecognizedConfigProperty(name);
182 }
183
184 /**
185 Init current value of the specified property to the specified value
186 */
187 void DefaultPropertyOwner::initCurrentValue(
188 const String& name,
189 const String& value)
190 {
191 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
192 {
193 if (String::equalNoCase(_configProperties[i].propertyName, name))
194 {
195 _configProperties[i].currentValue = value;
196 return;
197 }
198 mike 1.2 }
199
200 //
201 // Specified property name could not be found
202 //
203 throw UnrecognizedConfigProperty(name);
204 }
205
206
207 /**
208 Init planned value of the specified property to the specified value
209 */
210 void DefaultPropertyOwner::initPlannedValue(
211 const String& name,
212 const String& value)
213 {
214 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
215 {
216 if (String::equalNoCase(_configProperties[i].propertyName, name))
217 {
218 _configProperties[i].plannedValue = value;
219 mike 1.2 return;
220 }
221 }
222
223 //
224 // Specified property name could not be found
225 //
226 throw UnrecognizedConfigProperty(name);
227 }
228
229 /**
230 Update current value of the specified property to the specified value
231 */
232 void DefaultPropertyOwner::updateCurrentValue(
233 const String& name,
234 const String& value)
235 {
236 //
237 // make sure the property is dynamic before updating the value.
238 //
239 if (!isDynamic(name))
240 mike 1.2 {
241 throw NonDynamicConfigProperty(name);
242 }
243
244 //
245 // Since the validations done in initCurrrentValue are sufficient and
246 // no additional validations required for update, we shall call
247 // initCurrrentValue.
248 //
249 initCurrentValue(name, value);
250 }
251
252
253 /**
254 Update planned value of the specified property to the specified value
255 */
256 void DefaultPropertyOwner::updatePlannedValue(
257 const String& name,
258 const String& value)
259 {
260 //
261 mike 1.2 // Since the validations done in initPlannedValue are sufficient and
262 // no additional validations required for update, we shall call
263 // initPlannedValue.
264 //
265 initPlannedValue(name, value);
266 }
267
268
269 /**
270 Checks to see if the given value is valid or not.
271 */
272 Boolean DefaultPropertyOwner::isValid(const String& name, const String& value)
273 {
274 //
275 // By default, no validation is done. It can optionally be added here
276 // per property.
277 //
278 return 1;
279 }
280
281 /**
282 mike 1.2 Checks to see if the specified property is dynamic or not.
283 */
284 Boolean DefaultPropertyOwner::isDynamic(const String& name)
285 {
286 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
287 {
288 if (String::equalNoCase(_configProperties[i].propertyName, name))
289 {
290 return (_configProperties[i].dynamic);
291 }
292 }
293
294 //
295 // Specified property name could not be found
296 //
297 throw UnrecognizedConfigProperty(name);
298 }
299
300
301 PEGASUS_NAMESPACE_END
|