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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM, 
  4           // The Open Group, Tivoli Systems
  5           //
  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           // 
 13           // 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 mike  1.2 //==============================================================================
 23           //
 24           // Author: Mike Brasher (mbrasher@bmc.com)
 25           //
 26           // Modified By:
 27           //
 28           //%/////////////////////////////////////////////////////////////////////////////
 29           
 30           #ifndef Pegasus_WQLParser_h
 31           #define Pegasus_WQLParser_h
 32           
 33           #include <Pegasus/Common/Config.h>
 34           #include <Pegasus/Common/Array.h>
 35           #include <Pegasus/WQL/Linkage.h>
 36           #include <Pegasus/WQL/WQLSelectStatement.h>
 37           
 38           PEGASUS_NAMESPACE_BEGIN
 39           
 40           /** This class is the main interface to the WQL parser used for parsing WQL1
 41               compliant SQL statements.
 42           
 43 mike  1.2     Here's an example which parses a SELECT statement:
 44           
 45               <pre>
 46           	const char TEXT[] = "SELECT X,Y FROM MyClass WHERE X > 10 AND Y < 3";
 47           
 48           	// Note that this array must be null-terminated (sizeof(TEXT) includes
 49           	// the null-terminator in the count).
 50           
 51           	Array<Sint8> text(TEXT, sizeof(TEXT));
 52           
 53           	WQLSelectStatement selectStatement;
 54           
 55           	WQLParser parser;
 56           
 57           	try
 58           	{
 59           	    parser.parse(text, selectStatement);
 60           	}
 61           	catch (ParseError&)
 62           	{
 63           	    ...
 64 mike  1.2 	}
 65           	catch (MissingNullTerminator&)
 66           	{
 67           	    ...
 68           	}
 69               </pre>
 70           
 71               Note that the text must be NULL terminated or else the MissingNullTerminator
 72               exception is thrown.
 73           
 74               The text is read and the result is left in the selectStatement output
 75               argument.
 76           
 77               At this point you might wish to peek at the contents of the selectStatement.
 78               This may be done by calling WQLSelectStatement::print() like this:
 79           
 80               <pre>
 81           	WQLSelectStatement selectStatement;
 82           	...
 83           	selectStatement.print();
 84               </pre>
 85 mike  1.2 
 86               For the above query text, the following is printed:
 87           
 88               <pre>
 89           	WQLSelectStatement
 90           	{
 91           	    _className: "MyClass"
 92           
 93           	    _propertyNames[0]: "X"
 94           	    _propertyNames[1]: "Y"
 95           
 96           	    _operations[0]: "WQL_GT"
 97           	    _operations[1]: "WQL_LT"
 98           	    _operations[2]: "WQL_AND"
 99           
100           	    _operands[0]: "PROPERTY_NAME: X"
101           	    _operands[1]: "INTEGER_VALUE: 10"
102           	    _operands[2]: "PROPERTY_NAME: Y"
103           	    _operands[3]: "INTEGER_VALUE: 3"
104           	}
105               </pre>
106 mike  1.2 
107               The WQLSelectStatement::evaluateWhereClause() method may be called to
108               determine whether a particular instance (whose properties are made 
109               available to he evaluateWhereClause() by a user implementation of the
110               WQLPropertySource class). This method returns true, if the where clause
111               matches this instance. Here is an example:
112           
113               <pre>
114           	WQLSelectStatement selectStatement;
115           	...
116           	WQLPropertySource* propertySource = new MyPropertySource(...);
117           
118           	if (selectStatement.evaluateWhereClause(propertySource))
119           	{
120           	    // It's a match!
121           	}
122               </pre>
123           
124               The evaluateWhereClause() method calls propertySource->getValue() to
125               obtain values for each of the properties referred to in where clause (X 
126               and Y in the above query example).
127 mike  1.2 
128               The implementer of the WQLPropertySource interface must provide the
129               implementation of getValue() to produce values for the target data
130               types. The WQL library makes no assumptions about the nature of the 
131               target data representation. This was done so that this libary could be
132               adapted to multiple data representations.
133           
134               For use with Pegasus CIMInstance objects, a CIMInstancePropertySource
135               class could be developed whose getValue() method fetches values from 
136               a CIMInstance. Here is an example of how it might be used.
137           
138               <pre>
139           	CIMInstancePropertySource* propertySource 
140           	    = new CIMInstancePropertySource(...);
141           
142           	CIMInstance instance;
143           
144           	while (instance = GetNextInstance(...))
145           	{
146           	    propertySource->setInstance(currentInstance);
147           
148 mike  1.2 	    if (selectStatement.evaluateWhereClause(propertySource))
149           	    {
150           		// It's a match!
151           	    }
152           	}
153               </pre>
154           
155               Of course the numeration of instances is left to the user of WQL.
156           */
157           class PEGASUS_WQL_LINKAGE WQLParser
158           {
159           public:
160           
161               /** Parse the SELECT statement given by the text parameter and initialize
162           	the statement parameter accordingly.
163           
164           	Please note that this method is not thread safe. It must be guarded 
165           	with mutexes by the caller.
166           
167 mike  1.3 	@param text null-terminated C-string which points to SQL statement.
168 mike  1.2 	@param statement object which holds the compiled version of the SELECT
169           	    statement upon return.
170           	@exception ParseError if text is not a valid SELECT statement.
171           	@exception MissingNullTerminator if text argument is not 
172           	    terminated with a null. 
173               */
174               static void parse(
175 mike  1.3 	const char* text,
176           	WQLSelectStatement& statement);
177           
178               /** Version of parse() taking an array of characters.
179               */
180               static void parse(
181 mike  1.2 	const Array<Sint8>& text,
182 mike  1.3 	WQLSelectStatement& statement);
183           
184               /** Version of parse() taking a string.
185               */
186               static void parse(
187           	const String& text,
188 mike  1.2 	WQLSelectStatement& statement);
189           
190           private:
191           
192               /** This method cleans up all the strings which were created by LEX and
193           	passed to YACC. These strings cannot be cleaned up by YACC actions
194           	since the actions that clean up certain strings are not always reached
195           	when errors occur.
196               */
197               static void cleanup();
198           
199               /** Private constructor to avoid user from creating instance of this class.
200               */
201               WQLParser() { }
202           };
203           
204           PEGASUS_NAMESPACE_END
205           
206           #endif /* Pegasus_WQLParser_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2