BUG#: 5840
[tpot/pegasus/.git] / src / Pegasus / Common / CIMObjectRep.cpp
1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // 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 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
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 // 
21 // 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 #include "CIMObjectRep.h"
35
36 #include <Pegasus/Common/CIMName.h>
37 #include <Pegasus/Common/MessageLoader.h>
38
39 PEGASUS_NAMESPACE_BEGIN
40
41 PEGASUS_USING_STD;
42
43 CIMObjectRep::CIMObjectRep()
44 {
45 }
46
47 CIMObjectRep::CIMObjectRep(const CIMObjectRep& x)
48     : Sharable(), _reference(x._reference),
49     _resolved(x._resolved)
50 {
51     x._qualifiers.cloneTo(_qualifiers);
52
53     _properties.reserveCapacity(x._properties.size());
54
55     for (Uint32 i = 0, n = x._properties.size(); i < n; i++)
56     {
57         _properties.append(x._properties[i].clone());
58     }
59 }
60
61 CIMObjectRep::CIMObjectRep(const CIMObjectPath& reference)
62     : _resolved(false)
63 {
64     // ensure the class name is not null
65     if (reference.getClassName().isNull())
66     {
67         throw UninitializedObjectException();
68     }
69
70     _reference = reference;
71 }
72
73 CIMObjectRep::~CIMObjectRep()
74 {
75 }
76
77 void CIMObjectRep::addProperty(const CIMProperty& x)
78 {
79     if (x.isUninitialized())
80     {
81         throw UninitializedObjectException();
82     }
83
84     // Reject duplicate property names:
85
86     if (findProperty(x.getName()) != PEG_NOT_FOUND)
87     {
88         MessageLoaderParms parms(
89             "Common.CIMObjectRep.PROPERTY",
90             "property \"$0\"",
91             x.getName().getString());
92
93         throw AlreadyExistsException(parms);
94     }
95
96     // Append property:
97
98     _properties.append(x);
99 }
100
101 Uint32 CIMObjectRep::findProperty(const CIMName& name) const
102 {
103     for (Uint32 i = 0, n = _properties.size(); i < n; i++)
104     {
105         if (name.equal(_properties[i].getName()))
106         {
107             return i;
108         }
109     }
110
111     return PEG_NOT_FOUND;
112 }
113
114 CIMProperty CIMObjectRep::getProperty(Uint32 index)
115 {
116     if (index >= _properties.size())
117     {
118         throw IndexOutOfBoundsException();
119     }
120
121     return _properties[index];
122 }
123
124 void CIMObjectRep::removeProperty(Uint32 index)
125 {
126     if (index >= _properties.size())
127     {
128         throw IndexOutOfBoundsException();
129     }
130
131     _properties.remove(index);
132 }
133
134
135 Uint32 CIMObjectRep::getPropertyCount() const
136 {
137     return _properties.size();
138 }
139
140
141 Boolean CIMObjectRep::identical(const CIMObjectRep* x) const
142 {
143     if (!_reference.identical(x->_reference))
144     {
145         return false;
146     }
147
148     if (!_qualifiers.identical(x->_qualifiers))
149     {
150         return false;
151     }
152
153     // Compare properties:
154
155     {
156         const Array<CIMProperty>& tmp1 = _properties;
157         const Array<CIMProperty>& tmp2 = x->_properties;
158
159         if (tmp1.size() != tmp2.size())
160         {
161             return false;
162         }
163
164         for (Uint32 i = 0, n = tmp1.size(); i < n; i++)
165         {
166             if (!tmp1[i].identical(tmp2[i]))
167             {
168                 return false;
169             }
170         }
171     }
172
173     if (_resolved != x->_resolved)
174     {
175         return false;
176     }
177
178     return true;
179 }
180
181 void CIMObjectRep::setPath(const CIMObjectPath& path)
182 {
183     // ensure the class name is not null
184     if (path.getClassName().isNull())
185     {
186         throw UninitializedObjectException();
187     }
188
189     // prevent changing the class name (type) in when updating the object path
190     if (!_reference.getClassName().equal(path.getClassName()))
191     {
192         throw TypeMismatchException();
193     }
194
195     _reference = path;
196 }
197
198 PEGASUS_NAMESPACE_END