(file) Return to CQLIdentifierRep.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / CQL

  1 karl  1.13 //%2006////////////////////////////////////////////////////////////////////////
  2 chuck 1.2  //
  3 karl  1.9  // 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 chuck 1.2  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.9  // 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 karl  1.13 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 chuck 1.2  //
 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 chuck 1.2  //#include "CQLIdentifier.h"
 35            #include "CQLIdentifierRep.h"
 36            #include <Pegasus/Query/QueryCommon/QueryIdentifierRep.h>
 37            #include <Pegasus/Query/QueryCommon/QueryException.h>
 38 humberto 1.3  #include <Pegasus/Common/Tracer.h>
 39 chuck    1.2  PEGASUS_NAMESPACE_BEGIN
 40               
 41               
 42 chuck    1.10 Char16 CQLIdentifierRep::STAR = '*';
 43               Char16 CQLIdentifierRep::HASH = '#';
 44               Char16 CQLIdentifierRep::RBRKT = ']';
 45               Char16 CQLIdentifierRep::LBRKT = '[';
 46               const char CQLIdentifierRep::SCOPE[] = "::";
 47 chuck    1.2  
 48               CQLIdentifierRep::CQLIdentifierRep(): 
 49 karl     1.14     QueryIdentifierRep()
 50 chuck    1.2  {
 51               
 52               }
 53               
 54 aruran.ms 1.12 CQLIdentifierRep::CQLIdentifierRep(const String& identifier): 
 55 karl      1.14     QueryIdentifierRep()
 56 chuck     1.2  {
 57 karl      1.14     _isWildcard = false;
 58                    _isSymbolicConstant = false;
 59                    parse(identifier);
 60 chuck     1.2  }
 61                
 62                CQLIdentifierRep::CQLIdentifierRep(const CQLIdentifierRep* rep):
 63 karl      1.14     QueryIdentifierRep()
 64 chuck     1.2  {
 65 karl      1.14     _symbolicConstant = rep->_symbolicConstant;
 66                    _scope = rep->_scope;
 67                    _indices = rep->_indices;
 68                    _name = rep->_name;
 69                    _isWildcard = rep->_isWildcard;
 70                    _isSymbolicConstant = rep->_isSymbolicConstant;
 71 chuck     1.2  }
 72                
 73                CQLIdentifierRep::~CQLIdentifierRep()
 74                {
 75                
 76                }
 77                
 78                CQLIdentifierRep& CQLIdentifierRep::operator=(const CQLIdentifierRep& rhs)
 79                {
 80 karl      1.14     _symbolicConstant = rhs._symbolicConstant;
 81                    _scope = rhs._scope;
 82                    _indices = rhs._indices; 
 83                    _name = rhs._name;
 84                    _isWildcard = rhs._isWildcard;
 85                    _isSymbolicConstant = rhs._isSymbolicConstant;
 86                    return *this;
 87 chuck     1.2  }
 88                
 89                void CQLIdentifierRep::parse(String identifier)
 90                {
 91 karl      1.14     PEG_METHOD_ENTER(TRC_CQL, "CQLIdentifierRep::parse");
 92                    /*
 93                     - Parse for the following:
 94 chuck     1.2           1. A::<scoped string>
 95 karl      1.14      (a)  property name
 96 chuck     1.2           (b)  property[3]     e.g. an array index
 97                         (c)  property#'OK'    e.g. a symbolic constant
 98                         (d)  *   (wildcard)
 99 karl      1.14      (e)  class name
100                     (f)  embedded object
101                     (g)  namespace
102                    */
103                
104                    Uint32 index;
105                    Boolean hasCIMName = true;
106                    if(identifier == String::EMPTY)
107                    {
108                        _name = CIMName();
109                        return; 
110                    }
111                    // basic error check
112                    if((index = identifier.find(HASH)) != PEG_NOT_FOUND)
113                    {
114                        if(((index = identifier.find(RBRKT)) != PEG_NOT_FOUND) || 
115                            ((index = identifier.find(LBRKT)) != PEG_NOT_FOUND))    
116                        {
117                            //error
118                            MessageLoaderParms parms(
119                                String("CQL.CQLIdentifier.HASH_ARRAY_SYMBOL_MISMATCH"),
120 karl      1.14                 String("The identifier contains a mismatched symbolic"
121                                    " constant symbol and an array symbol: $0"),
122                                identifier);
123                            throw CQLIdentifierParseException(parms);
124                        }
125                    }
126                
127                    String _SCOPE(SCOPE);
128                    if((index = identifier.find(_SCOPE)) != PEG_NOT_FOUND)
129                    {
130                        _scope = identifier.subString(0,index);
131                        identifier = identifier.subString(index+2);
132                    }
133                
134                    if((index = identifier.find(RBRKT)) != PEG_NOT_FOUND)
135                    {
136                        if((index = identifier.find(LBRKT)) != PEG_NOT_FOUND)
137                        {
138                            // found array index, parse for ','
139                            String range = identifier.subString(index);
140                            // remove left and right bracket
141 karl      1.14             range = range.subString(1,range.size()-2);
142                            while(index != PEG_NOT_FOUND){
143                            if((index = range.find(',')) != PEG_NOT_FOUND)
144                            {
145                                // Basic query error
146                                MessageLoaderParms parms(
147                                    String("CQL.CQLIdentifier.TOO_MANY_ARRAY_INDICES"),
148                                    String("The identifier contains one or more commas which"
149                                        " is not allowed in CQL Basic query: $0"),
150                                    identifier);
151                                throw CQLIdentifierParseException(parms);
152                                // 
153                                // For basic query the following lines are disabled
154                                // An exception is thrown if we have ',' in the array range
155                                //
156                                //_indices.append(SubRange(range.subString(0,index)));
157                                //range = range.subString(index+1);
158                            }else
159                            {
160                                _indices.append(SubRange(range));
161                            }
162 karl      1.14           }
163                          // remove ranges from identifier
164                          identifier = identifier.subString(0,identifier.find(LBRKT));
165                        }
166                        else
167                        {
168                          // error
169                            MessageLoaderParms parms(
170                                String("CQL.CQLIdentifier.ARRAY_SYMBOL_MISMATCH"),
171                                String("The identifier contains a mismatched array symbol: $0"),
172                                identifier);
173                            throw CQLIdentifierParseException(parms);
174                        }
175                    }
176                    else if((index = identifier.find(STAR)) != PEG_NOT_FOUND)
177                    {
178                        // wildcard
179                        _isWildcard = true;
180                    }
181                    else if((index = identifier.find(HASH)) != PEG_NOT_FOUND)
182                    {
183 karl      1.14         // symbolic constant
184                
185                        // check if only have a symbolic constant without a leading identifier
186                        if(index == 0) hasCIMName = false;
187                
188                        _isSymbolicConstant = true;
189                        _symbolicConstant = identifier.subString(index+1);
190                        identifier = identifier.subString(0,index);
191                    }
192                
193                    // name
194                    if(!_isWildcard)
195                    {
196                        try
197                        {
198                            if(hasCIMName)
199                                _name = CIMName(identifier);
200                        }
201                        catch(Exception e)
202                        {
203                            MessageLoaderParms parms(
204 karl      1.14                 String("CQL.CQLIdentifier.INVALID_CIMNAME"),
205                                String("The identifier contains an invalid CIMName: $0."),
206                                identifier);
207                            throw CQLIdentifierParseException(parms);
208                        }
209                    }
210                    
211 humberto  1.3  PEG_METHOD_EXIT();
212 chuck     1.2  }
213                
214                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2