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