PEP 55 Update license on source files to current license text and date
[tpot/pegasus/.git] / src / WMIMapper / WMIProvider / WMIAssociatorProvider.cpp
1 //%2003////////////////////////////////////////////////////////////////////////
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 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 // 
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Barbara Packard (barbara_packard@hp.com)
27 //
28 // Modified By:
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 // WMIAssociatorProvider.cpp: implementation of the WMIAssociatorProvider class.
33 //
34 //////////////////////////////////////////////////////////////////////
35
36 #include "stdafx.h"
37
38 #include "WMICollector.h"
39 #include "WMIBaseProvider.h"
40 #include "WMIClassProvider.h"
41 #include "WMIInstanceProvider.h"
42 #include "WMIAssociatorProvider.h"
43
44 #include "WMIProperty.h"
45 #include "WMIString.h"
46 #include "WMIValue.h"
47 #include "WMIQualifier.h"
48 #include "WMIQualifierSet.h"
49 #include "WMIType.h"
50 #include "WMIException.h"
51
52
53 //////////////////////////////////////////////////////////////////////////////
54 // WMIAssociatorProvider::
55 //
56 // ///////////////////////////////////////////////////////////////////////////
57 PEGASUS_NAMESPACE_BEGIN
58
59 /////////////////////////////////////////////////////////////////////
60 // Construction/Destruction
61 //////////////////////////////////////////////////////////////////////
62
63 WMIAssociatorProvider::WMIAssociatorProvider()
64 {
65         _collector = NULL;
66         m_bInitialized = false;
67 }
68
69 WMIAssociatorProvider::~WMIAssociatorProvider()
70 {
71         cleanup();
72 }
73
74 //////////////////////////////////////////////////////////////////////////////
75 // WMIAssociatorProvider::associators
76 //
77 //      NOTE:  This method sets up the query string and then calls
78 //              WMIBaseProvider::execCIMQuery
79 //////////////////////////////////////////////////////////////////////////////
80 Array<CIMObject> WMIAssociatorProvider::associators(
81         const String& nameSpace,
82         const String& userName,
83         const String& password,
84         const CIMObjectPath& objectName,
85         const String& assocClass,
86         const String& resultClass,
87         const String& role,
88         const String& resultRole,
89         Boolean includeQualifiers,
90         Boolean includeClassOrigin,
91         const CIMPropertyList& propertyList)
92 {
93         String sQuery;
94         String sQueryLanguage;
95
96         Array<CIMObject> objects;
97
98         PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIAssociatorProvider::associators()");
99
100         sQueryLanguage = qString(Q_WQL);
101         sQuery = getAssocQueryString(objectName, 
102                                 assocClass, 
103                                 resultClass, 
104                                 role, 
105                                 resultRole);
106
107         objects = execCIMQuery(nameSpace,
108                                 userName,
109                                 password,
110                                 sQueryLanguage, 
111                                 sQuery, 
112                                 propertyList,
113                                 includeQualifiers,
114                                 includeClassOrigin);
115
116         PEG_METHOD_EXIT();
117
118         return objects;
119 }
120
121 //////////////////////////////////////////////////////////////////////////////
122 // WMIAssociatorProvider::associatorNames
123 //
124 // ///////////////////////////////////////////////////////////////////////////
125 Array<CIMObjectPath> WMIAssociatorProvider::associatorNames(
126         const String& nameSpace,
127         const String& userName,
128         const String& password,
129         const CIMObjectPath& objectName,
130         const String& assocClass,
131         const String& resultClass,
132         const String& role,
133         const String& resultRole)
134 {
135         Array<CIMObject> objects;
136         Array<CIMObjectPath> objectNames;
137
138         PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIAssociatorProvider::associatorNames()");
139
140         // create an empty property list to save time...
141         Array<CIMName> propNames;
142         CIMPropertyList propertyList(propNames);
143
144         // now get the objects
145         objects = associators(  nameSpace,
146                                                         userName,
147                                                         password,
148                                                         objectName,
149                                                         assocClass,
150                                                         resultClass,
151                                                         role,
152                                                         resultRole,
153                                                         false,
154                                                         false,
155                                                         propertyList);
156
157         // now get the names from the object
158         Uint32 size = objects.size();
159         Uint32 i;
160
161         for (i=0; i<size; i++)
162         {
163                 CIMObjectPath objPath;
164
165                 objPath = objects[i].getPath();
166                 objectNames.append(objPath);
167         }
168
169         PEG_METHOD_EXIT();
170
171         return objectNames;
172 }
173
174 //////////////////////////////////////////////////////////////////////////////
175 // WMIAssociatorProvider
176 //              private methods
177 //
178 // ///////////////////////////////////////////////////////////////////////////
179
180 //////////////////////////////////////////////////////////////////////////////
181 // WMIAssociatorProvider::getAssocQueryString - calls the BaseProvider method 
182 //              to build the query string from the input parameters
183 //
184 // ///////////////////////////////////////////////////////////////////////////
185 String WMIAssociatorProvider::getAssocQueryString(const CIMObjectPath &objectName, 
186                 const String &assocClass, 
187                 const String &resultClass, 
188                 const String &role,
189                 const String &resultRole)
190 {
191         String sQuery;
192
193         sQuery = qString(Q_ASSOCIATORS);
194
195         return getQueryString(objectName, sQuery, assocClass, resultClass, role, resultRole);
196
197 }
198
199
200 PEGASUS_NAMESPACE_END