1 chuck 1.2 //%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 chuck 1.2 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Authors: David Rosckes (rosckes@us.ibm.com)
27 // 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 #include <Pegasus/CQL/CQLTerm.h>
36 #include <Pegasus/CQL/CQLTermRep.h>
37 #include <Pegasus/CQL/CQLFactory.h>
38 #include <Pegasus/Query/QueryCommon/QueryContext.h>
39 #include <Pegasus/Query/QueryCommon/QueryException.h>
40 #include <Pegasus/Common/Tracer.h>
41
42 PEGASUS_NAMESPACE_BEGIN
43 chuck 1.2
44 CQLTermRep::CQLTermRep(){}
45
46 CQLTermRep::CQLTermRep(const CQLFactor& theFactor)
47 {
48 PEG_METHOD_ENTER(TRC_CQL,"CQLTermRep:CQLTermRep()");
49
50 _Factors.append(theFactor);
51
52 PEG_METHOD_EXIT();
53 }
54
55 CQLTermRep::CQLTermRep(const CQLTermRep& rep){
56 _Factors = rep._Factors;
57 _FactorOperators = rep._FactorOperators;
58 }
59
60 CQLTermRep::~CQLTermRep(){
61 }
62
63 CQLValue CQLTermRep::resolveValue(const CIMInstance& CI, const QueryContext& QueryCtx)
64 chuck 1.2 {
65 PEG_METHOD_ENTER(TRC_CQL,"CQLTermRep:resolveValue()");
66 CQLValue returnVal = _Factors[0].resolveValue(CI,QueryCtx);
67
68 for(Uint32 i = 0; i < _FactorOperators.size(); ++i)
69 {
70 switch(_FactorOperators[i])
71 {/*
72 case mult:
73 returnVal = returnVal *
74 _Factors[i+1].resolveValue(CI,QueryCtx);
75 break;
76 case divide:
77 returnVal = returnVal /
78 _Factors[i+1].resolveValue(CI,QueryCtx);
79 break;
80 */
81 case concat:
82 returnVal = returnVal +
83 _Factors[i+1].resolveValue(CI,QueryCtx);
84 break;
85 chuck 1.2
86 default:
87 MessageLoaderParms mload(String("CQL.CQLTermRep.OPERATION_NOT_SUPPORTED"),
88 String("Operation is not supported."));
89 throw CQLSyntaxErrorException(mload);
90 }
91 }
92
93 PEG_METHOD_EXIT();
94 return returnVal;
95 }
96
97 void CQLTermRep::appendOperation(FactorOpType inFactorOpType, CQLFactor inFactor)
98 {
99 PEG_METHOD_ENTER(TRC_CQL,"CQLTermRep::appendOperation()");
100
101 _FactorOperators.append(inFactorOpType);
102 _Factors.append(inFactor);
103
104 PEG_METHOD_EXIT();
105 }
106 chuck 1.2
107 String CQLTermRep::toString()const
108 {
109 PEG_METHOD_ENTER(TRC_CQL,"CQLTermRep::toString()");
110
111 String returnStr;
112
113 returnStr.append(_Factors[0].toString());
114
115 for(Uint32 i = 0; i < _FactorOperators.size(); ++i)
116 {
117 returnStr.append(_FactorOperators[i] ==
118 mult ? String(" * ") : divide ? String(" / ") : String(" concat "));
119 returnStr.append(_Factors[i+1].toString());
120 }
121
122 PEG_METHOD_EXIT();
123 return returnStr;
124 }
125
126 Boolean CQLTermRep::isSimple()const
127 chuck 1.2 {
128 return (_Factors.size() == 1);
129 }
130
131 Boolean CQLTermRep::isSimpleValue()const
132 {
133 PEG_METHOD_ENTER(TRC_CQL,"CQLTermRep::isSimpleValue()");
134 if(_Factors.size() == 1)
135 {
136 PEG_METHOD_EXIT();
137 return _Factors[0].isSimpleValue();
138 }
139
140 PEG_METHOD_EXIT();
141 return false;
142 }
143
144 Array<CQLFactor> CQLTermRep::getFactors()const
145 {
146 return _Factors;
147 }
148 chuck 1.2
149 Array<FactorOpType> CQLTermRep::getOperators()const
150 {
151 return _FactorOperators;
152 }
153
154 void CQLTermRep::applyContext(QueryContext& inContext,
155 CQLChainedIdentifier& inCid)
156 {
157 PEG_METHOD_ENTER(TRC_CQL,"CQLTermRep::applyContext()");
158
159 for(Uint32 i = 0; i < _Factors.size(); ++i)
160 {
161 _Factors[i].applyContext(inContext, inCid);
162 }
163
164 PEG_METHOD_EXIT();
165 }
166
167 Boolean CQLTermRep::operator==(const CQLTermRep& rhs)const
168 {
169 chuck 1.2 PEG_METHOD_ENTER(TRC_CQL,"CQLTermRep::operator==()");
170
171 for(Uint32 i = 0; i < _FactorOperators.size(); ++i)
172 {
173 if(_FactorOperators[i] != rhs._FactorOperators[i])
174 {
175 PEG_METHOD_EXIT();
176 return false;
177 }
178 }
179
180 for(Uint32 i = 0; i < _Factors.size(); ++i)
181 {
182 if(_Factors[i] != rhs._Factors[i])
183 {
184 PEG_METHOD_EXIT();
185 return false;
186 }
187 }
188
189 PEG_METHOD_EXIT();
190 chuck 1.2 return true;
191 }
192
193 Boolean CQLTermRep::operator!=(const CQLTermRep& rhs)const
194 {
195 return (!operator==(rhs));
196 }
197
198 PEGASUS_NAMESPACE_END
|