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 {"repositoryDir", "repository", 0, 0, 0},
58 {"providerDir", "lib", 0, 0, 0},
59 };
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 kumpf 1.1 }
77
78 /**
79 Checks if the given directory is existing and writable
80 */
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 kumpf 1.1 //
98 // Initialize the properties with default values
99 //
100 if (String::equalNoCase(properties[i].propertyName, "repositoryDir"))
101 {
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 }
110 else if (String::equalNoCase(properties[i].propertyName, "providerDir"
111 ))
112 {
113 _providerDir->propertyName = properties[i].propertyName;
114 _providerDir->defaultValue = properties[i].defaultValue;
115 _providerDir->currentValue = properties[i].defaultValue;
116 _providerDir->plannedValue = properties[i].defaultValue;
117 _providerDir->dynamic = properties[i].dynamic;
118 kumpf 1.1 _providerDir->domain = properties[i].domain;
119 _providerDir->domainSize = properties[i].domainSize;
120 }
121 }
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 kumpf 1.3 return _repositoryDir;
|
130 kumpf 1.1 }
131 else if (String::equalNoCase(_providerDir->propertyName, name))
132 {
|
133 kumpf 1.3 return _providerDir;
|
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.1 {
|
158 kumpf 1.3 propertyInfo.append(STRING_TRUE);
|
159 kumpf 1.1 }
160 else
161 {
|
162 kumpf 1.3 propertyInfo.append(STRING_FALSE);
|
163 kumpf 1.1 }
164 }
165
|
166 kumpf 1.3
167 /**
168 Get default value of the specified property.
169 */
170 const String FileSystemPropertyOwner::getDefaultValue(const String& name)
171 {
172 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
173 return configProperty->defaultValue;
174 }
175
|
176 kumpf 1.1 /**
177 Get current value of the specified property.
178 */
179 const String FileSystemPropertyOwner::getCurrentValue(const String& name)
180 {
|
181 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
182 return configProperty->currentValue;
|
183 kumpf 1.1 }
184
185 /**
186 Get planned value of the specified property.
187 */
188 const String FileSystemPropertyOwner::getPlannedValue(const String& name)
189 {
|
190 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
191 return configProperty->plannedValue;
|
192 kumpf 1.1 }
193
194 /**
195 Init current value of the specified property to the specified value.
196 */
197 void FileSystemPropertyOwner::initCurrentValue(
198 const String& name,
199 const String& value)
200 {
|
201 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
202 configProperty->currentValue = value;
|
203 kumpf 1.1 }
204
205
206 /**
207 Init planned value of the specified property to the specified value.
208 */
209 void FileSystemPropertyOwner::initPlannedValue(
210 const String& name,
211 const String& value)
212 {
|
213 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
214 configProperty->plannedValue = value;
|
215 kumpf 1.1 }
216
217 /**
218 Update current value of the specified property to the specified value.
219 */
220 void FileSystemPropertyOwner::updateCurrentValue(
221 const String& name,
222 const String& value)
223 {
224 //
225 // make sure the property is dynamic before updating the value.
226 //
227 if (!isDynamic(name))
228 {
229 throw NonDynamicConfigProperty(name);
230 }
|
231 kumpf 1.3
232 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
233 configProperty->currentValue = value;
|
234 kumpf 1.1 }
235
236
237 /**
238 Update planned value of the specified property to the specified value.
239 */
240 void FileSystemPropertyOwner::updatePlannedValue(
241 const String& name,
242 const String& value)
243 {
|
244 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
245 configProperty->plannedValue = value;
|
246 kumpf 1.1 }
247
248 /**
249 Checks to see if the given value is valid or not.
250 */
251 Boolean FileSystemPropertyOwner::isValid(const String& name, const String& value)
252 {
253 if (!isDirValid( value ))
254 {
255 throw InvalidPropertyValue(name, value);
256 }
257
258 return true;
259 }
260
261 /**
262 Checks to see if the specified property is dynamic or not.
263 */
264 Boolean FileSystemPropertyOwner::isDynamic(const String& name)
265 {
|
266 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
267 return configProperty->dynamic;
|
268 kumpf 1.1 }
269
270
271 PEGASUS_NAMESPACE_END
|