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

  1 chuck 1.1.2.6 //%2003////////////////////////////////////////////////////////////////////////
  2 chuck 1.1.2.3 //
  3               // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
  4               // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
  5 chuck 1.1.2.7 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
  6 chuck 1.1.2.3 // 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               // Authors: David Rosckes (rosckes@us.ibm.com)
 27 chuck 1.1.2.3 //          Bert Rivero (hurivero@us.ibm.com)
 28               //          Chuck Carmack (carmack@us.ibm.com)
 29               //          Brian Lucier (lucier@us.ibm.com)
 30               //
 31               // Modified By: 
 32               //
 33               //%/////////////////////////////////////////////////////////////////////////////
 34               
 35 humberto 1.1.2.1 #include "QueryContext.h"
 36                  #include <Pegasus/Common/System.h>
 37                  
 38 chuck    1.1.2.8 #include <iostream>
 39                  
 40 chuck    1.1.2.3 PEGASUS_NAMESPACE_BEGIN
 41                                  
 42                  QueryContext::QueryContext(CIMNamespaceName& inNS)
 43                    :_NS(inNS)
 44                  {
 45                  }
 46                  
 47                  QueryContext::QueryContext(const QueryContext& ctx)
 48                    :_NS(ctx._NS),
 49                     _AliasClassTable(ctx._AliasClassTable),
 50                     _fromList(ctx._fromList)
 51                  {
 52 chuck    1.1.2.8 
 53 chuck    1.1.2.3 }
 54                  
 55                  QueryContext::~QueryContext()
 56                  {
 57 humberto 1.1.2.1 }
 58                  
 59 chuck    1.1.2.3 QueryContext& QueryContext::operator=(const QueryContext& rhs)
 60                  {
 61                    if (this == &rhs)
 62                      return *this;
 63                  
 64                    _NS = rhs._NS;
 65                    _fromList = rhs._fromList;
 66                    _AliasClassTable = rhs._AliasClassTable;
 67                  
 68                    return *this;
 69                  }
 70                  
 71                  String QueryContext::getHost(Boolean fullyQualified)
 72                  {
 73 humberto 1.1.2.1 	if(fullyQualified) return System::getFullyQualifiedHostName();
 74                  	return System::getHostName();
 75                  }
 76                  
 77 chuck    1.1.2.3 CIMNamespaceName QueryContext::getNamespace() const
 78                  {
 79 humberto 1.1.2.1 	return _NS;
 80                  }
 81                  
 82 chuck    1.1.2.3 void QueryContext::insertClassPath(const CQLIdentifier& inIdentifier, String inAlias)
 83                  {
 84 chuck    1.1.2.8   CQLIdentifier _class;  
 85                  
 86                    if (inIdentifier.getName().getString() == String::EMPTY)
 87                    {
 88                      throw Exception("TEMP MSG QueryContext: not allowed to add empty class name");
 89                    }
 90                  
 91                    if ((inAlias != String::EMPTY) &&
 92                        (String::equalNoCase(inAlias,inIdentifier.getName().getString())))
 93                    {
 94                      inAlias = String::EMPTY;
 95                    }
 96                   
 97                    if (_AliasClassTable.contains(inIdentifier.getName().getString()))
 98                    {
 99                      throw Exception("TEMP MSG QueryContext: classname is already an alias");
100                    }
101                  
102                    Boolean found = false;
103                    for (Uint32 i = 0; i < _fromList.size(); i++)
104                    {
105 chuck    1.1.2.8     if ((inAlias != String::EMPTY) && 
106                  	(String::equalNoCase(inAlias, _fromList[i].getName().getString())))
107                      {
108                        throw Exception("TEMP MSG QueryContext: alias is already a classname");
109                      }
110                  
111                      if (_fromList[i].getName() == inIdentifier.getName())
112                      {
113                        found = true;
114                      }
115                    }
116                  
117                    if (!found)
118                    {  
119                      _fromList.append(inIdentifier);
120                    }
121                  
122                    if(inAlias != String::EMPTY)
123                    {
124                      if (!_AliasClassTable.insert(inAlias, inIdentifier))
125                      {  
126 chuck    1.1.2.8       // Alias already exists
127                        if (_AliasClassTable.lookup(inAlias, _class))
128                        {	
129                  	if (!_class.getName().equal(inIdentifier.getName()))
130 chuck    1.1.2.3 	{
131 chuck    1.1.2.8 	  throw Exception("TEMP MSG QueryContext: attempted to add conflicting aliases");
132 humberto 1.1.2.1 	}
133 chuck    1.1.2.8       }
134                      }
135                    }
136 humberto 1.1.2.1 }
137                  
138 chuck    1.1.2.10 CQLIdentifier QueryContext::findClass(const String& inAlias) const
139 chuck    1.1.2.3  {
140 humberto 1.1.2.1  	// look for alias match
141                   	CQLIdentifier _class;
142                   	if(_AliasClassTable.lookup(inAlias, _class)) return _class;
143                   
144                   	// look if inAlias is really a class name
145                   	_class = CQLIdentifier(inAlias);
146                   	Array<CQLIdentifier> _identifiers = getFromList();
147                   	for(Uint32 i = 0; i < _identifiers.size(); i++){
148 humberto 1.1.2.5  		if(_class == _identifiers[i].getName()) return _identifiers[i];
149 humberto 1.1.2.1  	}	
150                   
151                   	// could not find inAlias
152                   	return CQLIdentifier("");
153 chuck    1.1.2.3  }
154                   
155                   Array<CQLIdentifier> QueryContext::getFromList() const 
156                   {
157 humberto 1.1.2.1  	return _fromList;
158                   }
159                   
160 chuck    1.1.2.8  String QueryContext::getFromString() const
161                   {
162                     Array<CQLIdentifier> aliasedClasses;
163                     Array<String> aliases;
164                     for (HT_Alias_Class::Iterator i = _AliasClassTable.start(); i; i++)
165                     {  
166                       aliases.append(i.key());
167                       aliasedClasses.append(i.value());
168                     }
169                   
170                     String result("FROM ");
171                     for (Uint32 i = 0; i < _fromList.size(); i++)
172                     {
173                       Boolean hasAlias = false;
174                       for (Uint32 j = 0; j < aliasedClasses.size(); j++)
175                       {
176                         if (_fromList[i].getName() == aliasedClasses[j].getName())
177                         {
178                   	result.append(_fromList[i].getName().getString());
179                   	result.append(" AS ");
180                   	result.append(aliases[j]);     
181 chuck    1.1.2.8  	hasAlias = true;
182                         }
183                       }
184                   
185                       if (!hasAlias)
186                       {
187                         result.append(_fromList[i].getName().getString());      
188                       }
189                   
190                       if (i < _fromList.size() - 1)
191                       {
192                         result.append(" , ");
193                       }
194                       else
195                       {
196                         result.append(" ");
197                       }
198                     }
199                   
200                     return result;
201                   }
202 chuck    1.1.2.8  
203 chuck    1.1.2.4  void QueryContext::clear(){
204 chuck    1.1.2.8    _fromList.clear();
205                      _AliasClassTable.clear();
206 chuck    1.1.2.4  }
207                   
208 humberto 1.1.2.1  PEGASUS_NAMESPACE_END
209                   

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2