1 mike 1.2 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.2 //
23 // Author: Chip Vincent (cvincent@us.ibm.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include "OperationContext.h"
30
31 PEGASUS_NAMESPACE_BEGIN
32
|
33 chip 1.5 //
34 // OperationContext
35 //
|
36 chip 1.3 OperationContext::OperationContext(void)
|
37 mike 1.2 {
38 }
39
|
40 chip 1.4 OperationContext::OperationContext(const OperationContext & context)
41 : _containers(context._containers)
42 {
43 }
44
|
45 chip 1.3 OperationContext::~OperationContext(void)
46 {
|
47 chip 1.5 clear();
48 }
49
50 OperationContext & OperationContext::operator=(const OperationContext & context)
51 {
52 if(this == &context)
53 {
54 return(*this);
55 }
56
57 clear();
58
59 for(Uint32 i = 0, n = context._containers.size(); i < n; i++)
60 {
61 _containers.append(context._containers[i]->clone());
62 }
63
64 return(*this);
|
65 chip 1.3 }
66
67 void OperationContext::clear(void)
68 {
|
69 chip 1.5 for(Uint32 i = 0, n = _containers.size(); i < n; i++)
70 {
71 delete _containers[i];
72 }
73
|
74 chip 1.3 _containers.clear();
75 }
76
|
77 chip 1.5 const OperationContext::Container & OperationContext::get(const Uint32 key) const
|
78 chip 1.3 {
79 for(Uint32 i = 0, n = _containers.size(); i < n; i++)
80 {
|
81 chip 1.5 if(key == _containers[i]->getKey())
|
82 chip 1.3 {
|
83 chip 1.5 Container * p = _containers[i];
84
85 return(*p);
|
86 chip 1.3 }
87 }
88
89 throw Exception("object not found");
90 }
91
92 void OperationContext::set(const OperationContext::Container & container)
93 {
94 for(Uint32 i = 0, n = _containers.size(); i < n; i++)
95 {
|
96 chip 1.5 if(container.getKey() == _containers[i]->getKey())
|
97 chip 1.3 {
98 // delete previous container
99 _containers.remove(i);
100
101 // append current container
|
102 chip 1.5 _containers.append(container.clone());
|
103 chip 1.3
104 return;
105 }
106 }
107
108 throw Exception("object not found");
109 }
110
111 void OperationContext::insert(const OperationContext::Container & container)
112 {
113 for(Uint32 i = 0, n = _containers.size(); i < n; i++)
114 {
|
115 chip 1.5 if(container.getKey() == _containers[i]->getKey())
|
116 chip 1.3 {
117 throw Exception("object already exists.");
118 }
119 }
120
|
121 chip 1.5 _containers.append(container.clone());
|
122 chip 1.3 }
123
124 void OperationContext::remove(const Uint32 key)
125 {
126 for(Uint32 i = 0, n = _containers.size(); i < n; i++)
127 {
|
128 chip 1.5 if(key == _containers[i]->getKey())
|
129 chip 1.3 {
130 _containers.remove(i);
131
132 return;
133 }
134 }
135
136 throw Exception("object not found");
137 }
138
|
139 chip 1.5 //
140 // OperationContext::Container
141 //
|
142 chip 1.3 OperationContext::Container::Container(const Uint32 key) : _key(key)
143 {
144 }
145
146 OperationContext::Container::~Container(void)
147 {
148 }
149
|
150 chip 1.5 OperationContext::Container * OperationContext::Container::clone(void) const
151 {
152 return(new Container(*this));
153 }
154
155 //
156 // IdentitiyContainer
157 //
158 IdentityContainer::IdentityContainer(const OperationContext::Container & container)
159 {
160 const IdentityContainer * p = dynamic_cast<const IdentityContainer *>(&container);
161
162 if(p == 0)
163 {
164 throw DynamicCastFailed();
165 }
166
167 *this = *p;
168 }
169
|
170 chip 1.3 IdentityContainer::IdentityContainer(const String & userName)
171 : OperationContext::Container(CONTEXT_IDENTITY), _userName(userName)
172 {
173 }
174
|
175 chip 1.5 OperationContext::Container * IdentityContainer::clone(void) const
|
176 chip 1.3 {
|
177 chip 1.5 return(new IdentityContainer(*this));
178 }
179
180 String IdentityContainer::getUserName(void) const
181 {
182 return(_userName);
183 }
184
185 //
186 // LocaleContainer
187 //
188 LocaleContainer::LocaleContainer(const OperationContext::Container & container)
189 {
190 const LocaleContainer * p = dynamic_cast<const LocaleContainer *>(&container);
191
192 if(p == 0)
193 {
194 throw DynamicCastFailed();
195 }
196
197 *this = *p;
|
198 mike 1.2 }
199
|
200 chip 1.3 LocaleContainer::LocaleContainer(const String & languageId)
201 : OperationContext::Container(CONTEXT_LOCALE), _languageId(languageId)
202 {
203 }
204
|
205 chip 1.5 OperationContext::Container * LocaleContainer::clone(void) const
206 {
207 return(new LocaleContainer(*this));
208 }
209
210 String LocaleContainer::getLanguageId(void) const
211 {
212 return(_languageId);
213 }
214
215 //
216 // ProviderIdContainer
217 //
218 ProviderIdContainer::ProviderIdContainer(const OperationContext::Container & container)
219 {
220 const ProviderIdContainer * p = dynamic_cast<const ProviderIdContainer *>(&container);
221
222 if(p == 0)
223 {
224 throw DynamicCastFailed();
225 }
226 chip 1.5
227 *this = *p;
228 }
229
230 ProviderIdContainer::ProviderIdContainer(const CIMInstance & module, const CIMInstance & provider)
231 : OperationContext::Container(CONTEXT_PROVIDERID), _module(module), _provider(provider)
232 {
233 }
234
235 OperationContext::Container * ProviderIdContainer::clone(void) const
236 {
237 return(new ProviderIdContainer(*this));
238 }
239
240 CIMInstance ProviderIdContainer::getModule(void) const
241 {
242 return(_module);
243 }
244
245 CIMInstance ProviderIdContainer::getProvider(void) const
|
246 chip 1.3 {
|
247 chip 1.5 return(_provider);
|
248 chip 1.3 }
|
249 mike 1.2
250 PEGASUS_NAMESPACE_END
|