(file) Return to WQLParser.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / WQL

  1 martin 1.13 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.14 //
  3 martin 1.13 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.14 //
 10 martin 1.13 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.14 //
 17 martin 1.13 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.14 //
 20 martin 1.13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.14 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.13 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.14 //
 28 martin 1.13 //////////////////////////////////////////////////////////////////////////
 29 mike   1.2  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             #ifndef Pegasus_WQLParser_h
 33             #define Pegasus_WQLParser_h
 34             
 35             #include <Pegasus/Common/Config.h>
 36 kumpf  1.5  #include <Pegasus/Common/ArrayInternal.h>
 37 mike   1.2  #include <Pegasus/WQL/Linkage.h>
 38             #include <Pegasus/WQL/WQLSelectStatement.h>
 39 mike   1.10 #include <Pegasus/Common/Buffer.h>
 40 mike   1.2  
 41             PEGASUS_NAMESPACE_BEGIN
 42             
 43             /** This class is the main interface to the WQL parser used for parsing WQL1
 44                 compliant SQL statements.
 45             
 46                 Here's an example which parses a SELECT statement:
 47             
 48                 <pre>
 49 karl   1.12     const char TEXT[] = "SELECT X,Y FROM MyClass WHERE X > 10 AND Y < 3";
 50 mike   1.2  
 51 karl   1.12     // Note that this array must be null-terminated (sizeof(TEXT) includes
 52                 // the null-terminator in the count).
 53 mike   1.2  
 54 karl   1.12     Buffer text(TEXT, sizeof(TEXT));
 55 mike   1.2  
 56 karl   1.12     WQLSelectStatement selectStatement;
 57 mike   1.2  
 58 karl   1.12     WQLParser parser;
 59             
 60                 try
 61                 {
 62                     parser.parse(text, selectStatement);
 63                 }
 64                 catch (ParseError&)
 65                 {
 66                     ...
 67                 }
 68                 catch (MissingNullTerminator&)
 69                 {
 70                     ...
 71                 }
 72 mike   1.2      </pre>
 73             
 74                 Note that the text must be NULL terminated or else the MissingNullTerminator
 75                 exception is thrown.
 76             
 77                 The text is read and the result is left in the selectStatement output
 78                 argument.
 79             
 80                 At this point you might wish to peek at the contents of the selectStatement.
 81                 This may be done by calling WQLSelectStatement::print() like this:
 82             
 83                 <pre>
 84 karl   1.12     WQLSelectStatement selectStatement;
 85                 ...
 86                 selectStatement.print();
 87 mike   1.2      </pre>
 88             
 89                 For the above query text, the following is printed:
 90             
 91                 <pre>
 92 karl   1.12     WQLSelectStatement
 93                 {
 94                     _className: "MyClass"
 95             
 96                     _propertyNames[0]: "X"
 97                     _propertyNames[1]: "Y"
 98             
 99                     _operations[0]: "WQL_GT"
100                     _operations[1]: "WQL_LT"
101                     _operations[2]: "WQL_AND"
102             
103                     _operands[0]: "PROPERTY_NAME: X"
104                     _operands[1]: "INTEGER_VALUE: 10"
105                     _operands[2]: "PROPERTY_NAME: Y"
106                     _operands[3]: "INTEGER_VALUE: 3"
107                 }
108 mike   1.2      </pre>
109             
110                 The WQLSelectStatement::evaluateWhereClause() method may be called to
111 kumpf  1.15     determine whether a particular instance (whose properties are made
112 mike   1.2      available to he evaluateWhereClause() by a user implementation of the
113                 WQLPropertySource class). This method returns true, if the where clause
114                 matches this instance. Here is an example:
115             
116                 <pre>
117 karl   1.12     WQLSelectStatement selectStatement;
118                 ...
119                 WQLPropertySource* propertySource = new MyPropertySource(...);
120             
121                 if (selectStatement.evaluateWhereClause(propertySource))
122                 {
123                     // It's a match!
124                 }
125 mike   1.2      </pre>
126             
127                 The evaluateWhereClause() method calls propertySource->getValue() to
128 kumpf  1.15     obtain values for each of the properties referred to in where clause (X
129 mike   1.2      and Y in the above query example).
130             
131                 The implementer of the WQLPropertySource interface must provide the
132                 implementation of getValue() to produce values for the target data
133 kumpf  1.15     types. The WQL library makes no assumptions about the nature of the
134 mike   1.2      target data representation. This was done so that this libary could be
135                 adapted to multiple data representations.
136             
137                 For use with Pegasus CIMInstance objects, a CIMInstancePropertySource
138 kumpf  1.15     class could be developed whose getValue() method fetches values from
139 mike   1.2      a CIMInstance. Here is an example of how it might be used.
140             
141                 <pre>
142 kumpf  1.15     CIMInstancePropertySource* propertySource
143 karl   1.12         = new CIMInstancePropertySource(...);
144 mike   1.2  
145 karl   1.12     CIMInstance instance;
146 mike   1.2  
147 karl   1.12     while (instance = GetNextInstance(...))
148                 {
149                     propertySource->setInstance(currentInstance);
150             
151                     if (selectStatement.evaluateWhereClause(propertySource))
152                     {
153                     // It's a match!
154                     }
155                 }
156 mike   1.2      </pre>
157             
158                 Of course the numeration of instances is left to the user of WQL.
159             */
160             class PEGASUS_WQL_LINKAGE WQLParser
161             {
162             public:
163             
164                 /** Parse the SELECT statement given by the text parameter and initialize
165 karl   1.12     the statement parameter accordingly.
166 mike   1.2  
167 kumpf  1.15     Please note that this method is not thread safe. It must be guarded
168 karl   1.12     with mutexes by the caller.
169 mike   1.2  
170 karl   1.12     @param text null-terminated C-string which points to SQL statement.
171                 @param statement object which holds the compiled version of the SELECT
172                     statement upon return.
173                 @exception ParseError if text is not a valid SELECT statement.
174 kumpf  1.15     @exception MissingNullTerminator if text argument is not
175                     terminated with a null.
176 mike   1.2      */
177                 static void parse(
178 karl   1.12     const char* text,
179                 WQLSelectStatement& statement);
180 mike   1.3  
181                 /** Version of parse() taking an array of characters.
182                 */
183                 static void parse(
184 karl   1.12     const Buffer& text,
185                 WQLSelectStatement& statement);
186 mike   1.3  
187                 /** Version of parse() taking a string.
188                 */
189                 static void parse(
190 karl   1.12     const String& text,
191                 WQLSelectStatement& statement);
192 mike   1.2  
193             private:
194             
195                 /** This method cleans up all the strings which were created by LEX and
196 karl   1.12         passed to YACC. These strings cannot be cleaned up by YACC actions
197                     since the actions that clean up certain strings are not always reached
198                     when errors occur.
199 mike   1.2      */
200                 static void cleanup();
201             
202                 /** Private constructor to avoid user from creating instance of this class.
203                 */
204                 WQLParser() { }
205             };
206             
207             PEGASUS_NAMESPACE_END
208             
209             #endif /* Pegasus_WQLParser_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2