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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.8 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4           // The Open Group, Tivoli Systems
  5 mike  1.2 //
  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.8 // 
 13 mike  1.2 // 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: Chip Vincent (cvincent@us.ibm.com)
 25           //
 26           // Modified By:
 27           //
 28           //%/////////////////////////////////////////////////////////////////////////////
 29           
 30           #include "OperationContext.h"
 31 kumpf 1.10 #include "ArrayInternal.h"
 32 mike  1.2  
 33            PEGASUS_NAMESPACE_BEGIN
 34            
 35 chip  1.5  //
 36            // OperationContext
 37            //
 38 kumpf 1.7  class OperationContextRep
 39            {
 40            public:
 41                Array<OperationContext::Container *> containers;
 42            };
 43            
 44 chip  1.3  OperationContext::OperationContext(void)
 45 mike  1.2  {
 46 kumpf 1.7      _rep = new OperationContextRep;
 47 mike  1.2  }
 48            
 49 chip  1.4  OperationContext::OperationContext(const OperationContext & context)
 50            {
 51 kumpf 1.7      _rep = new OperationContextRep;
 52 chip  1.6      *this = context;
 53 chip  1.4  }
 54            
 55 chip  1.3  OperationContext::~OperationContext(void)
 56            {
 57 chip  1.5      clear();
 58 kumpf 1.7      delete _rep;
 59 chip  1.5  }
 60            
 61            OperationContext & OperationContext::operator=(const OperationContext & context)
 62            {
 63                if(this == &context)
 64                {
 65                    return(*this);
 66                }
 67            
 68                clear();
 69            
 70 kumpf 1.7      for(Uint32 i = 0, n = context._rep->containers.size(); i < n; i++)
 71 chip  1.5      {
 72 kumpf 1.7          _rep->containers.append(context._rep->containers[i]->clone());
 73 chip  1.5      }
 74            
 75                return(*this);
 76 chip  1.3  }
 77            
 78            void OperationContext::clear(void)
 79            {
 80 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
 81 chip  1.5      {
 82 kumpf 1.7          delete _rep->containers[i];
 83 chip  1.5      }
 84            
 85 kumpf 1.7      _rep->containers.clear();
 86 chip  1.3  }
 87            
 88 chip  1.5  const OperationContext::Container & OperationContext::get(const Uint32 key) const
 89 chip  1.3  {
 90 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
 91 chip  1.3      {
 92 kumpf 1.7          if(key == _rep->containers[i]->getKey())
 93 chip  1.3          {
 94 kumpf 1.7              Container * p = _rep->containers[i];
 95 chip  1.5  
 96                        return(*p);
 97 chip  1.3          }
 98                }
 99            
100                throw Exception("object not found");
101            }
102            
103            void OperationContext::set(const OperationContext::Container & container)
104            {
105 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
106 chip  1.3      {
107 kumpf 1.7          if(container.getKey() == _rep->containers[i]->getKey())
108 chip  1.3          {
109                        // delete previous container
110 kumpf 1.7              delete _rep->containers[i];
111                        _rep->containers.remove(i);
112 chip  1.3  
113                        // append current container
114 kumpf 1.7              _rep->containers.append(container.clone());
115 chip  1.3  
116                        return;
117                    }
118                }
119            
120                throw Exception("object not found");
121            }
122            
123            void OperationContext::insert(const OperationContext::Container & container)
124            {
125 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
126 chip  1.3      {
127 kumpf 1.7          if(container.getKey() == _rep->containers[i]->getKey())
128 chip  1.3          {
129                        throw Exception("object already exists.");
130                    }
131                }
132            
133 kumpf 1.7      _rep->containers.append(container.clone());
134 chip  1.3  }
135            
136            void OperationContext::remove(const Uint32 key)
137            {
138 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
139 chip  1.3      {
140 kumpf 1.7          if(key == _rep->containers[i]->getKey())
141 chip  1.3          {
142 kumpf 1.7              delete _rep->containers[i];
143                        _rep->containers.remove(i);
144 chip  1.3  
145                        return;
146                    }
147                }
148            
149                throw Exception("object not found");
150            }
151            
152 chip  1.5  //
153            // OperationContext::Container
154            //
155 chip  1.3  OperationContext::Container::Container(const Uint32 key) : _key(key)
156            {
157            }
158            
159            OperationContext::Container::~Container(void)
160            {
161            }
162            
163 kumpf 1.7  const Uint32 & OperationContext::Container::getKey(void) const
164            {
165                return(_key);
166            }
167            
168 chip  1.5  OperationContext::Container * OperationContext::Container::clone(void) const
169            {
170                return(new Container(*this));
171            }
172            
173            //
174 kumpf 1.7  // IdentityContainer
175 chip  1.5  //
176            IdentityContainer::IdentityContainer(const OperationContext::Container & container)
177            {
178                const IdentityContainer * p = dynamic_cast<const IdentityContainer *>(&container);
179            
180                if(p == 0)
181                {
182 kumpf 1.9          throw DynamicCastFailedException();
183 chip  1.5      }
184            
185                *this = *p;
186            }
187            
188 chip  1.3  IdentityContainer::IdentityContainer(const String & userName)
189                : OperationContext::Container(CONTEXT_IDENTITY), _userName(userName)
190            {
191            }
192            
193 chip  1.5  OperationContext::Container * IdentityContainer::clone(void) const
194 chip  1.3  {
195 chip  1.5      return(new IdentityContainer(*this));
196            }
197            
198            String IdentityContainer::getUserName(void) const
199            {
200                return(_userName);
201            }
202            
203            //
204            // LocaleContainer
205            //
206            LocaleContainer::LocaleContainer(const OperationContext::Container & container)
207            {
208                const LocaleContainer * p = dynamic_cast<const LocaleContainer *>(&container);
209            
210                if(p == 0)
211                {
212 kumpf 1.9          throw DynamicCastFailedException();
213 chip  1.5      }
214            
215                *this = *p;
216 mike  1.2  }
217            
218 chip  1.3  LocaleContainer::LocaleContainer(const String & languageId)
219                : OperationContext::Container(CONTEXT_LOCALE), _languageId(languageId)
220            {
221            }
222            
223 chip  1.5  OperationContext::Container * LocaleContainer::clone(void) const
224            {
225                return(new LocaleContainer(*this));
226            }
227            
228            String LocaleContainer::getLanguageId(void) const
229            {
230                return(_languageId);
231            }
232            
233            //
234            // ProviderIdContainer
235            //
236            ProviderIdContainer::ProviderIdContainer(const OperationContext::Container & container)
237            {
238                const ProviderIdContainer * p = dynamic_cast<const ProviderIdContainer *>(&container);
239            
240                if(p == 0)
241                {
242 kumpf 1.9          throw DynamicCastFailedException();
243 chip  1.5      }
244            
245                *this = *p;
246            }
247            
248            ProviderIdContainer::ProviderIdContainer(const CIMInstance & module, const CIMInstance & provider)
249                : OperationContext::Container(CONTEXT_PROVIDERID), _module(module), _provider(provider)
250            {
251            }
252            
253            OperationContext::Container * ProviderIdContainer::clone(void) const
254            {
255                return(new ProviderIdContainer(*this));
256            }
257            
258            CIMInstance ProviderIdContainer::getModule(void) const
259            {
260                return(_module);
261            }
262            
263            CIMInstance ProviderIdContainer::getProvider(void) const
264 chip  1.3  {
265 chip  1.5      return(_provider);
266 chip  1.3  }
267 mike  1.2  
268            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2