(file) Return to FileSystemPropertyOwner.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Config

  1 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
  4           // 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           //
 13           // 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 kumpf 1.1 //==============================================================================
 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           ///////////////////////////////////////////////////////////////////////////////
 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 kumpf 1.1 
 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           static struct ConfigPropertyRow properties[] =
 56           {
 57               {"repositoryDir", "repository", 0, 0, 0},
 58               {"providerDir", "lib", 0, 0, 0},
 59               {"consumerDir", "", 0, 0, 0}
 60           };
 61           
 62           const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
 63           
 64 kumpf 1.1 
 65           /** Constructors  */
 66           FileSystemPropertyOwner::FileSystemPropertyOwner()
 67           {
 68               _repositoryDir = new ConfigProperty;
 69               _providerDir = new ConfigProperty;
 70               _consumerDir = new ConfigProperty;
 71           }
 72           
 73           /** Destructor  */
 74           FileSystemPropertyOwner::~FileSystemPropertyOwner()
 75           {
 76               delete _repositoryDir;
 77               delete _providerDir;
 78               delete _consumerDir;
 79           }
 80           
 81           /**
 82           Checks if the given directory is existing and writable
 83           */
 84           Boolean isDirValid(const String& dirName)
 85 kumpf 1.1 {
 86               if (FileSystem::isDirectory(dirName) && FileSystem::canWrite(dirName))
 87               {
 88                   return true;
 89               }
 90               return false;
 91           }
 92            
 93           /**
 94           Initialize the config properties.
 95           */
 96           void FileSystemPropertyOwner::initialize()
 97           {
 98               for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
 99               {
100                   //
101                   // Initialize the properties with default values
102                   //
103                   if (String::equalNoCase(properties[i].propertyName, "repositoryDir"))
104                   {
105                       _repositoryDir->propertyName = properties[i].propertyName;
106 kumpf 1.1             _repositoryDir->defaultValue = properties[i].defaultValue;
107                       _repositoryDir->currentValue = properties[i].defaultValue;
108                       _repositoryDir->plannedValue = properties[i].defaultValue;
109                       _repositoryDir->dynamic = properties[i].dynamic;
110                       _repositoryDir->domain = properties[i].domain;
111                       _repositoryDir->domainSize = properties[i].domainSize;
112                   }
113                   else if (String::equalNoCase(properties[i].propertyName, "providerDir"
114           ))
115                   {
116                       _providerDir->propertyName = properties[i].propertyName;
117                       _providerDir->defaultValue = properties[i].defaultValue;
118                       _providerDir->currentValue = properties[i].defaultValue;
119                       _providerDir->plannedValue = properties[i].defaultValue;
120                       _providerDir->dynamic = properties[i].dynamic;
121                       _providerDir->domain = properties[i].domain;
122                       _providerDir->domainSize = properties[i].domainSize;
123                   }
124                   else if (String::equalNoCase(properties[i].propertyName, "consumerDir"
125           ))
126                   {
127 kumpf 1.1             _consumerDir->propertyName = properties[i].propertyName;
128                       _consumerDir->defaultValue = properties[i].defaultValue;
129                       _consumerDir->currentValue = properties[i].defaultValue;
130                       _consumerDir->plannedValue = properties[i].defaultValue;
131                       _consumerDir->dynamic = properties[i].dynamic;
132                       _consumerDir->domain = properties[i].domain;
133                       _consumerDir->domainSize = properties[i].domainSize;
134                   }
135               }
136           }
137           
138           /** 
139           Get information about the specified property.
140           */
141           void FileSystemPropertyOwner::getPropertyInfo(
142               const String& name, 
143               Array<String>& propertyInfo)
144           {
145               propertyInfo.clear();
146           
147               if (String::equalNoCase(_repositoryDir->propertyName, name))
148 kumpf 1.1     {
149                   propertyInfo.append(_repositoryDir->propertyName);
150                   propertyInfo.append(_repositoryDir->defaultValue);
151                   propertyInfo.append(_repositoryDir->currentValue);
152                   propertyInfo.append(_repositoryDir->plannedValue);
153                   if (_repositoryDir->dynamic)
154                   {
155                       propertyInfo.append(STRING_TRUE);
156                   }
157                   else
158                   {
159                       propertyInfo.append(STRING_FALSE);
160                   }
161               }
162               else if (String::equalNoCase(_providerDir->propertyName, name))
163               {
164                   propertyInfo.append(_providerDir->propertyName);
165                   propertyInfo.append(_providerDir->defaultValue);
166                   propertyInfo.append(_providerDir->currentValue);
167                   propertyInfo.append(_providerDir->plannedValue);
168                   if (_providerDir->dynamic)
169 kumpf 1.1         {
170                       propertyInfo.append(STRING_TRUE);
171                   }
172                   else
173                   {
174                       propertyInfo.append(STRING_FALSE);
175                   }
176               }
177               else if (String::equalNoCase(_consumerDir->propertyName, name))
178               {
179                   propertyInfo.append(_consumerDir->propertyName);
180                   propertyInfo.append(_consumerDir->defaultValue);
181                   propertyInfo.append(_consumerDir->currentValue);
182                   propertyInfo.append(_consumerDir->plannedValue);
183                   if (_consumerDir->dynamic)
184                   {
185                       propertyInfo.append(STRING_TRUE);
186                   }
187                   else
188                   {
189                       propertyInfo.append(STRING_FALSE);
190 kumpf 1.1         }
191               }
192               else
193               {
194                   throw UnrecognizedConfigProperty(name);
195               }
196           }
197           
198           
199           /**
200           Get default value of the specified property.
201           */
202           const String FileSystemPropertyOwner::getDefaultValue(const String& name)
203           {
204               if (String::equalNoCase(_repositoryDir->propertyName, name))
205               {
206                   return (_repositoryDir->defaultValue);
207               }
208               else if (String::equalNoCase(_providerDir->propertyName, name))
209               {
210                   return (_providerDir->defaultValue);
211 kumpf 1.1     }
212               else if (String::equalNoCase(_consumerDir->propertyName, name))
213               {
214                   return (_consumerDir->defaultValue);
215               }
216               else
217               {
218                   throw UnrecognizedConfigProperty(name);
219               }
220           }
221           
222           /** 
223           Get current value of the specified property.
224           */
225           const String FileSystemPropertyOwner::getCurrentValue(const String& name)
226           {
227               if (String::equalNoCase(_repositoryDir->propertyName, name))
228               {
229                   return (_repositoryDir->currentValue);
230               }
231               else if (String::equalNoCase(_providerDir->propertyName, name))
232 kumpf 1.1     {
233                   return (_providerDir->currentValue);
234               }
235               else if (String::equalNoCase(_consumerDir->propertyName, name))
236               {
237                   return (_consumerDir->currentValue);
238               }
239               else
240               {
241                   throw UnrecognizedConfigProperty(name);
242               }
243           }
244           
245           /** 
246           Get planned value of the specified property.
247           */
248           const String FileSystemPropertyOwner::getPlannedValue(const String& name)
249           {
250               if (String::equalNoCase(_repositoryDir->propertyName, name))
251               {
252                   return (_repositoryDir->plannedValue);
253 kumpf 1.1     }
254               else if (String::equalNoCase(_providerDir->propertyName, name))
255               {
256                   return (_providerDir->plannedValue);
257               }
258               else if (String::equalNoCase(_consumerDir->propertyName, name))
259               {
260                   return (_consumerDir->plannedValue);
261               }
262               else
263               {
264                   throw UnrecognizedConfigProperty(name);
265               }
266           }
267           
268           /** 
269           Init current value of the specified property to the specified value.
270           */
271           void FileSystemPropertyOwner::initCurrentValue(
272               const String& name, 
273               const String& value)
274 kumpf 1.1 {
275               // Perform validation
276               if (String::equal(value, EMPTY_VALUE))
277               {
278                       throw InvalidPropertyValue(name,value);
279               }
280               
281               if (String::equalNoCase(_repositoryDir->propertyName, name))
282               {
283                   _repositoryDir->currentValue = value;
284               }
285               else if (String::equalNoCase(_providerDir->propertyName, name))
286               {
287                   _providerDir->currentValue = value;
288               }
289               else if (String::equalNoCase(_consumerDir->propertyName, name))
290               {
291                   _consumerDir->currentValue = value;
292               }
293               else
294               {
295 kumpf 1.1         throw UnrecognizedConfigProperty(name);
296               }
297           }
298           
299           
300           /** 
301           Init planned value of the specified property to the specified value.
302           */
303           void FileSystemPropertyOwner::initPlannedValue(
304               const String& name, 
305               const String& value)
306           {
307               // Perform validation
308               if (String::equal(value, EMPTY_VALUE))
309               {
310                   throw InvalidPropertyValue(name,value);
311               }
312           
313               if (String::equalNoCase(_repositoryDir->propertyName, name))
314               {
315                   _repositoryDir->plannedValue = value;
316 kumpf 1.1     }
317               else if (String::equalNoCase(_providerDir->propertyName, name))
318               {
319                   _providerDir->plannedValue = value;
320               }
321               else if (String::equalNoCase(_consumerDir->propertyName, name))
322               {
323                   _consumerDir->plannedValue = value;
324               }
325               else
326               {
327                   throw UnrecognizedConfigProperty(name);
328               }
329           }
330           
331           /** 
332           Update current value of the specified property to the specified value.
333           */
334           void FileSystemPropertyOwner::updateCurrentValue(
335               const String& name, 
336               const String& value) 
337 kumpf 1.1 {
338               //
339               // Validate the specified value
340               //
341               if (!isValid(name, value))
342               {
343                   throw InvalidPropertyValue(name, value);
344               }
345           
346               //
347               // make sure the property is dynamic before updating the value.
348               //
349               if (!isDynamic(name))
350               {
351                   throw NonDynamicConfigProperty(name); 
352               }
353           }
354           
355           
356           /** 
357           Update planned value of the specified property to the specified value.
358 kumpf 1.1 */
359           void FileSystemPropertyOwner::updatePlannedValue(
360               const String& name, 
361               const String& value)
362           {
363               //
364               // Validate the specified value
365               //
366               if (!isValid(name, value))
367               {
368                   throw InvalidPropertyValue(name, value);
369               }
370           
371               if (String::equalNoCase(_repositoryDir->propertyName, name))
372               {
373                   _repositoryDir->plannedValue = value;
374               }
375               else if (String::equalNoCase(_providerDir->propertyName, name))
376               {
377                   _providerDir->plannedValue = value;
378               }
379 kumpf 1.1     else if (String::equalNoCase(_consumerDir->propertyName, name))
380               {
381                   _consumerDir->plannedValue = value;
382               }
383               else
384               {
385                   throw UnrecognizedConfigProperty(name);
386               }
387           }
388           
389           /** 
390           Checks to see if the given value is valid or not.
391           */
392           Boolean FileSystemPropertyOwner::isValid(const String& name, const String& value)
393           {
394               Boolean retVal = false;
395           
396               if (String::equal(value, EMPTY_VALUE))
397               {
398                   throw InvalidPropertyValue(name, value);
399               }
400 kumpf 1.1 
401               if (!isDirValid( value ))
402               {
403                   throw InvalidPropertyValue(name, value);
404               }
405            
406               return true;
407           }
408           
409           /** 
410           Checks to see if the specified property is dynamic or not.
411           */
412           Boolean FileSystemPropertyOwner::isDynamic(const String& name)
413           {
414               if (String::equalNoCase(_repositoryDir->propertyName, name))
415               {
416                   return (_repositoryDir->dynamic);
417               }
418               else if (String::equalNoCase(_providerDir->propertyName, name))
419               {
420                   return (_providerDir->dynamic);
421 kumpf 1.1     }
422               else if (String::equalNoCase(_consumerDir->propertyName, name))
423               {
424                   return (_consumerDir->dynamic);
425               }
426               else
427               {
428                   throw UnrecognizedConfigProperty(name);
429               }
430           }
431           
432           
433           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2