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