1 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.4 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
|
4 kumpf 1.1 // 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.4 //
|
13 kumpf 1.1 // 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: Sushma Fernandes (sushma_fernandes@hp.com)
25 //
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29
30 ///////////////////////////////////////////////////////////////////////////////
31 //
32 // This file has implementation for the file system property owner class.
33 //
34 kumpf 1.1 ///////////////////////////////////////////////////////////////////////////////
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Tracer.h>
38 #include <Pegasus/Common/FileSystem.h>
39 #include <Pegasus/Common/Destroyer.h>
40 #include <Pegasus/Config/ConfigManager.h>
41 #include "FileSystemPropertyOwner.h"
42
43
44 PEGASUS_USING_STD;
45
46 PEGASUS_NAMESPACE_BEGIN
47
48 ///////////////////////////////////////////////////////////////////////////////
49 // FileSystemPropertyOwner
50 //
51 // When a new FileSystem property is added, make sure to add the property name
52 // and the default attributes of that property in the table below.
53 ///////////////////////////////////////////////////////////////////////////////
54
55 kumpf 1.1 static struct ConfigPropertyRow properties[] =
56 {
|
57 kumpf 1.6 {"repositoryDir", "repository", 0, 0, 0, 1},
58 {"providerDir", "lib", 0, 0, 0, 1},
|
59 kumpf 1.1 };
60
61 const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
62
63
64 /** Constructors */
65 FileSystemPropertyOwner::FileSystemPropertyOwner()
66 {
67 _repositoryDir = new ConfigProperty;
68 _providerDir = new ConfigProperty;
69 }
70
71 /** Destructor */
72 FileSystemPropertyOwner::~FileSystemPropertyOwner()
73 {
74 delete _repositoryDir;
75 delete _providerDir;
76 }
77
78 /**
79 Checks if the given directory is existing and writable
80 kumpf 1.1 */
81 Boolean isDirValid(const String& dirName)
82 {
83 if (FileSystem::isDirectory(dirName) && FileSystem::canWrite(dirName))
84 {
85 return true;
86 }
87 return false;
88 }
89
90 /**
91 Initialize the config properties.
92 */
93 void FileSystemPropertyOwner::initialize()
94 {
95 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
96 {
97 //
98 // Initialize the properties with default values
99 //
100 if (String::equalNoCase(properties[i].propertyName, "repositoryDir"))
101 kumpf 1.1 {
102 _repositoryDir->propertyName = properties[i].propertyName;
103 _repositoryDir->defaultValue = properties[i].defaultValue;
104 _repositoryDir->currentValue = properties[i].defaultValue;
105 _repositoryDir->plannedValue = properties[i].defaultValue;
106 _repositoryDir->dynamic = properties[i].dynamic;
107 _repositoryDir->domain = properties[i].domain;
108 _repositoryDir->domainSize = properties[i].domainSize;
|
109 kumpf 1.6 _repositoryDir->externallyVisible = properties[i].externallyVisible;
|
110 kumpf 1.1 }
111 else if (String::equalNoCase(properties[i].propertyName, "providerDir"
112 ))
113 {
114 _providerDir->propertyName = properties[i].propertyName;
115 _providerDir->defaultValue = properties[i].defaultValue;
116 _providerDir->currentValue = properties[i].defaultValue;
117 _providerDir->plannedValue = properties[i].defaultValue;
118 _providerDir->dynamic = properties[i].dynamic;
119 _providerDir->domain = properties[i].domain;
120 _providerDir->domainSize = properties[i].domainSize;
|
121 kumpf 1.6 _providerDir->externallyVisible = properties[i].externallyVisible;
|
122 kumpf 1.1 }
123 }
124 }
125
|
126 kumpf 1.3 struct ConfigProperty* FileSystemPropertyOwner::_lookupConfigProperty(
127 const String& name)
|
128 kumpf 1.1 {
129 if (String::equalNoCase(_repositoryDir->propertyName, name))
130 {
|
131 kumpf 1.3 return _repositoryDir;
|
132 kumpf 1.1 }
133 else if (String::equalNoCase(_providerDir->propertyName, name))
134 {
|
135 kumpf 1.3 return _providerDir;
|
136 kumpf 1.1 }
137 else
138 {
139 throw UnrecognizedConfigProperty(name);
140 }
141 }
142
|
143 kumpf 1.3 /**
144 Get information about the specified property.
|
145 kumpf 1.1 */
|
146 kumpf 1.3 void FileSystemPropertyOwner::getPropertyInfo(
147 const String& name,
148 Array<String>& propertyInfo)
|
149 kumpf 1.1 {
|
150 kumpf 1.3 propertyInfo.clear();
151
152 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
153
154 propertyInfo.append(configProperty->propertyName);
155 propertyInfo.append(configProperty->defaultValue);
156 propertyInfo.append(configProperty->currentValue);
157 propertyInfo.append(configProperty->plannedValue);
158 if (configProperty->dynamic)
|
159 kumpf 1.6 {
160 propertyInfo.append(STRING_TRUE);
161 }
162 else
163 {
164 propertyInfo.append(STRING_FALSE);
165 }
166 if (configProperty->externallyVisible)
|
167 kumpf 1.1 {
|
168 kumpf 1.3 propertyInfo.append(STRING_TRUE);
|
169 kumpf 1.1 }
170 else
171 {
|
172 kumpf 1.3 propertyInfo.append(STRING_FALSE);
|
173 kumpf 1.1 }
174 }
175
|
176 kumpf 1.3
177 /**
178 Get default value of the specified property.
179 */
180 const String FileSystemPropertyOwner::getDefaultValue(const String& name)
181 {
182 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
183 return configProperty->defaultValue;
184 }
185
|
186 kumpf 1.1 /**
187 Get current value of the specified property.
188 */
189 const String FileSystemPropertyOwner::getCurrentValue(const String& name)
190 {
|
191 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
192 return configProperty->currentValue;
|
193 kumpf 1.1 }
194
195 /**
196 Get planned value of the specified property.
197 */
198 const String FileSystemPropertyOwner::getPlannedValue(const String& name)
199 {
|
200 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
201 return configProperty->plannedValue;
|
202 kumpf 1.1 }
203
204 /**
205 Init current value of the specified property to the specified value.
206 */
207 void FileSystemPropertyOwner::initCurrentValue(
208 const String& name,
209 const String& value)
210 {
|
211 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
212 configProperty->currentValue = value;
|
213 kumpf 1.1 }
214
215
216 /**
217 Init planned value of the specified property to the specified value.
218 */
219 void FileSystemPropertyOwner::initPlannedValue(
220 const String& name,
221 const String& value)
222 {
|
223 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
224 configProperty->plannedValue = value;
|
225 kumpf 1.1 }
226
227 /**
228 Update current value of the specified property to the specified value.
229 */
230 void FileSystemPropertyOwner::updateCurrentValue(
231 const String& name,
232 const String& value)
233 {
234 //
235 // make sure the property is dynamic before updating the value.
236 //
237 if (!isDynamic(name))
238 {
239 throw NonDynamicConfigProperty(name);
240 }
|
241 kumpf 1.3
242 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
243 configProperty->currentValue = value;
|
244 kumpf 1.1 }
245
246
247 /**
248 Update planned value of the specified property to the specified value.
249 */
250 void FileSystemPropertyOwner::updatePlannedValue(
251 const String& name,
252 const String& value)
253 {
|
254 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
255 configProperty->plannedValue = value;
|
256 kumpf 1.1 }
257
258 /**
259 Checks to see if the given value is valid or not.
260 */
261 Boolean FileSystemPropertyOwner::isValid(const String& name, const String& value)
262 {
263 if (!isDirValid( value ))
264 {
265 throw InvalidPropertyValue(name, value);
266 }
267
268 return true;
269 }
270
271 /**
272 Checks to see if the specified property is dynamic or not.
273 */
274 Boolean FileSystemPropertyOwner::isDynamic(const String& name)
275 {
|
276 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
277 return configProperty->dynamic;
|
278 kumpf 1.1 }
279
280
281 PEGASUS_NAMESPACE_END
|