(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 kumpf 1.11 // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 27 mike  1.2  //
 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.11 
 39 kumpf 1.7  class OperationContextRep
 40            {
 41            public:
 42                Array<OperationContext::Container *> containers;
 43            };
 44            
 45 chip  1.3  OperationContext::OperationContext(void)
 46 mike  1.2  {
 47 kumpf 1.7      _rep = new OperationContextRep;
 48 mike  1.2  }
 49            
 50 chip  1.4  OperationContext::OperationContext(const OperationContext & context)
 51            {
 52 kumpf 1.7      _rep = new OperationContextRep;
 53 chip  1.6      *this = context;
 54 chip  1.4  }
 55            
 56 chip  1.3  OperationContext::~OperationContext(void)
 57            {
 58 chip  1.5      clear();
 59 kumpf 1.7      delete _rep;
 60 chip  1.5  }
 61            
 62            OperationContext & OperationContext::operator=(const OperationContext & context)
 63            {
 64                if(this == &context)
 65                {
 66                    return(*this);
 67                }
 68            
 69                clear();
 70            
 71 kumpf 1.7      for(Uint32 i = 0, n = context._rep->containers.size(); i < n; i++)
 72 chip  1.5      {
 73 kumpf 1.7          _rep->containers.append(context._rep->containers[i]->clone());
 74 chip  1.5      }
 75            
 76                return(*this);
 77 chip  1.3  }
 78            
 79            void OperationContext::clear(void)
 80            {
 81 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
 82 chip  1.5      {
 83 kumpf 1.11         _rep->containers[i]->destroy();
 84 chip  1.5      }
 85            
 86 kumpf 1.7      _rep->containers.clear();
 87 chip  1.3  }
 88            
 89 kumpf 1.11 const OperationContext::Container & OperationContext::get(
 90                const String& containerName) const
 91            {
 92                for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
 93                {
 94                    if(containerName == _rep->containers[i]->getName())
 95                    {
 96                        Container * p = _rep->containers[i];
 97            
 98                        return(*p);
 99                    }
100                }
101            
102                throw Exception("object not found");
103            }
104            
105            #ifndef PEGASUS_REMOVE_DEPRECATED
106 chip  1.5  const OperationContext::Container & OperationContext::get(const Uint32 key) const
107 chip  1.3  {
108 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
109 chip  1.3      {
110 kumpf 1.7          if(key == _rep->containers[i]->getKey())
111 chip  1.3          {
112 kumpf 1.7              Container * p = _rep->containers[i];
113 chip  1.5  
114                        return(*p);
115 chip  1.3          }
116                }
117            
118                throw Exception("object not found");
119            }
120 kumpf 1.11 #endif
121 chip  1.3  
122            void OperationContext::set(const OperationContext::Container & container)
123            {
124 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
125 chip  1.3      {
126 kumpf 1.11         if(container.getName() == _rep->containers[i]->getName())
127 chip  1.3          {
128                        // delete previous container
129 kumpf 1.11             _rep->containers[i]->destroy();
130 kumpf 1.7              _rep->containers.remove(i);
131 chip  1.3  
132                        // append current container
133 kumpf 1.7              _rep->containers.append(container.clone());
134 chip  1.3  
135                        return;
136                    }
137                }
138            
139                throw Exception("object not found");
140            }
141            
142            void OperationContext::insert(const OperationContext::Container & container)
143            {
144 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
145 chip  1.3      {
146 kumpf 1.11         if(container.getName() == _rep->containers[i]->getName())
147 chip  1.3          {
148                        throw Exception("object already exists.");
149                    }
150                }
151            
152 kumpf 1.7      _rep->containers.append(container.clone());
153 chip  1.3  }
154            
155 kumpf 1.11 void OperationContext::remove(const String& containerName)
156            {
157                for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
158                {
159                    if(containerName == _rep->containers[i]->getName())
160                    {
161                        _rep->containers[i]->destroy();
162                        _rep->containers.remove(i);
163            
164                        return;
165                    }
166                }
167            
168                throw Exception("object not found");
169            }
170            
171            #ifndef PEGASUS_REMOVE_DEPRECATED
172 chip  1.3  void OperationContext::remove(const Uint32 key)
173            {
174 kumpf 1.7      for(Uint32 i = 0, n = _rep->containers.size(); i < n; i++)
175 chip  1.3      {
176 kumpf 1.7          if(key == _rep->containers[i]->getKey())
177 chip  1.3          {
178 kumpf 1.7              delete _rep->containers[i];
179                        _rep->containers.remove(i);
180 chip  1.3  
181                        return;
182                    }
183                }
184            
185                throw Exception("object not found");
186            }
187 kumpf 1.11 #endif
188 chip  1.3  
189 chip  1.5  //
190            // OperationContext::Container
191            //
192 kumpf 1.11 
193            #ifndef PEGASUS_REMOVE_DEPRECATED
194 chip  1.3  OperationContext::Container::Container(const Uint32 key) : _key(key)
195            {
196            }
197 kumpf 1.11 #endif
198 chip  1.3  
199            OperationContext::Container::~Container(void)
200            {
201            }
202            
203 kumpf 1.11 #ifndef PEGASUS_REMOVE_DEPRECATED
204 kumpf 1.7  const Uint32 & OperationContext::Container::getKey(void) const
205            {
206                return(_key);
207            }
208 kumpf 1.11 #endif
209 chip  1.5  
210            //
211 kumpf 1.7  // IdentityContainer
212 chip  1.5  //
213            
214 kumpf 1.11 class IdentityContainerRep
215 chip  1.3  {
216 kumpf 1.11 public:
217                String userName;
218            };
219 chip  1.3  
220 kumpf 1.11 const String IdentityContainer::NAME = "IdentityContainer";
221 chip  1.5  
222 kumpf 1.11 IdentityContainer::IdentityContainer(const OperationContext::Container & container)
223 kumpf 1.12 #ifndef PEGASUS_REMOVE_DEPRECATED
224                : OperationContext::Container(container.getKey())
225            #endif
226 chip  1.5  {
227 kumpf 1.11     const IdentityContainer * p = dynamic_cast<const IdentityContainer *>(&container);
228 chip  1.5  
229                if(p == 0)
230                {
231 kumpf 1.9          throw DynamicCastFailedException();
232 chip  1.5      }
233            
234 kumpf 1.11     _rep = new IdentityContainerRep();
235                _rep->userName = p->_rep->userName;
236 mike  1.2  }
237            
238 kumpf 1.13 IdentityContainer::IdentityContainer(const IdentityContainer & container)
239            {
240                _rep = new IdentityContainerRep();
241                _rep->userName = container._rep->userName;
242            }
243            
244 kumpf 1.11 IdentityContainer::IdentityContainer(const String & userName)
245            #ifndef PEGASUS_REMOVE_DEPRECATED
246                : OperationContext::Container(CONTEXT_IDENTITY)
247            #endif
248 chip  1.3  {
249 kumpf 1.11     _rep = new IdentityContainerRep();
250                _rep->userName = userName;
251 chip  1.3  }
252            
253 kumpf 1.11 IdentityContainer::~IdentityContainer(void)
254 chip  1.5  {
255 kumpf 1.11     delete _rep;
256 kumpf 1.13 }
257            
258            IdentityContainer & IdentityContainer::operator=(
259                const IdentityContainer & container)
260            {
261                if (this == &container)
262                {
263                    return (*this);
264                }
265            
266                _rep->userName = container._rep->userName;
267            
268                return (*this);
269 chip  1.5  }
270            
271 kumpf 1.11 String IdentityContainer::getName(void) const
272 chip  1.5  {
273 kumpf 1.11     return(NAME);
274 chip  1.5  }
275            
276 kumpf 1.11 OperationContext::Container * IdentityContainer::clone(void) const
277 chip  1.5  {
278 kumpf 1.11     return(new IdentityContainer(_rep->userName));
279 chip  1.5  }
280            
281 kumpf 1.11 void IdentityContainer::destroy(void)
282 chip  1.5  {
283 kumpf 1.11     delete this;
284 chip  1.5  }
285            
286 kumpf 1.11 String IdentityContainer::getUserName(void) const
287 chip  1.3  {
288 kumpf 1.11     return(_rep->userName);
289 chip  1.3  }
290 mike  1.2  
291            PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2