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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2