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