wsdlpull 1.23
Operation.h
Go to the documentation of this file.
1/*
2 * wsdlpull - A C++ parser for Wsdl (Web services description language)
3 * Copyright (C) 2005-2007 Vivek Krishna
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *
20 */
21#ifndef _OPERATIONH
22#define _OPERATIONH
23
24#include "xmlpull/Qname.h"
25
28#include "wsdlparser/Message.h"
30
31
32namespace WsdlPull {
33
34enum Optype{
40};
41
43
46 Fault
47};
48
49typedef std::list<const Message*> MessageList;
50typedef std::map<const Message *, std::string> MessageNameList;
51class PortType;
52//class for Wsdl operation element
54{
55 public:
56 typedef std::vector<Operation*>::iterator OpIterator;
57 typedef std::vector<Operation*>::const_iterator cOpIterator;
58
60 ~Operation();
63
69 const Message *getMessage(WsdlPull::MessageType type) const;
70 //get the input/output/fault element's name
71 std::string getMessageName(WsdlPull::MessageType type) const;
72 std::list<const Message*>* getFaults()const;
73 const Message* getFault(const std::string& name)const;
78 Optype getType() const;
79
84 const PortType* portType()const;
85
87 void setMessage(const Message * message, WsdlPull::MessageType type,
88 const std::string & name = "");
89 void addMessageExtensibility(WsdlPull::MessageType m,int ext);
90 int getMessageExtension(WsdlPull::MessageType m);
91
93 void print(std::ostream & out);
94
95 private:
96 PortType * pt_;
97 Optype type_;
98 const Message *inMessage_, *outMessage_;
99 std::list<const Message*> *faultMessages_;
100 MessageNameList messageNames_;
101 int in_e,out_e,fault_e; //extensibility elements for <input>,<output>,<fault> elements
102
103};
104
105
106
107inline
109 :WsdlElement(w),
110 pt_(p),
111 type_(OP_NONE),
112 inMessage_(0),
113 outMessage_(0),
114 faultMessages_(0),
115 in_e(0),out_e(0),fault_e(0)
116{
117}
118
119inline
121{
122
123 delete faultMessages_;
124}
125
126inline
127const PortType*
129{
130 return pt_;
131}
132
133inline
134const Message *
136{
137 if (type == Input)
138 return inMessage_;
139
140 else if (type == Output)
141 return outMessage_;
142
143 else if (type == Fault && faultMessages_)
144 return faultMessages_->front();
145
146 else
147 return 0;
148}
149
150inline
151void
153{
154 if (type == Input)
155 in_e = ext;
156
157 else if (type == Output)
158 out_e = ext;
159
160 else if (type == Fault)
161 fault_e = ext;
162
163 return;
164}
165inline
166int
168{
169 if (type == Input)
170 return in_e ;
171
172 else if (type == Output)
173 return out_e;
174
175 else if (type == Fault)
176 return fault_e;
177
178 return 0;
179}
180inline
181Optype
183{
184 return type_;
185}
186
187
188inline
189void
192 const std::string &name)
193{
194 if (message == 0)
195 throw WsdlException("Invalid message name");
196 if (type == Input) {
197
198 inMessage_ = message;
199 if (type_ == OP_NONE)
200 type_ = OP_IN;
201
202 else if (type_ == OP_OUT)
203 type_ = OP_OUT_IN;
204
205 else
206 type_ = OP_NONE;
207 }
208 else if (type == Output){
209
210 outMessage_ = message;
211 if (type_ == OP_NONE)
212 type_ = OP_OUT;
213
214 else if (type_ == OP_IN)
215 type_ = OP_IN_OUT;
216
217 else
218 type_ = OP_NONE;
219 }
220 else if (type == Fault) {
221
222 if (!faultMessages_)
223 faultMessages_ = new std::list<const Message*>();
224
225 faultMessages_->push_back(message);
226 }
227 //Save mesasge name
228 messageNames_[message]=name;
229}
230
231inline
232void
233Operation::print(std::ostream & out)
234{
235 out << id_ << XmlUtils::dbsp << name_ << std::endl;
236 out << type_ << std::endl;
237 out << inMessage_ << XmlUtils::dbsp << outMessage_ << XmlUtils::dbsp <<std::endl;
238 out << XmlUtils::blk;
239}
240
241inline
242std::list<const Message*>*
244{
245
246 return faultMessages_;
247}
248inline
249const Message*
250Operation::getFault(const std::string& name)const
251{
252 for ( std::list<const Message*>::iterator mli = faultMessages_->begin();
253 mli != faultMessages_->end();
254 mli++) {
255
256 if ((*mli)->getName() == name)
257 return (*mli);
258 }
259 return 0;
260}
261
262inline
263std::string
265{
266 std::string name("");
267 const Message * pMessage = 0;
268 MessageNameList::const_iterator it;
269
270 if (type == Input) {
271
272 pMessage = inMessage_;
273 }
274 else if (type == Output) {
275
276 pMessage = outMessage_;
277 }
278 else if (type == Fault && faultMessages_) {
279
280 pMessage = faultMessages_->front();
281 }
282
283 it = messageNames_.find(pMessage);
284
285 if (messageNames_.end() != it)
286 name = it->second;
287
288 return name;
289}
290
291}
292
293#endif /* */
std::vector< Operation * >::const_iterator cOpIterator
Definition: Operation.h:57
std::vector< Operation * >::iterator OpIterator
Definition: Operation.h:56
std::string getMessageName(WsdlPull::MessageType type) const
Definition: Operation.h:264
const Message * getFault(const std::string &name) const
Definition: Operation.h:250
Operation(WsdlParser &w, PortType *pt)
Definition: Operation.h:108
int getMessageExtension(WsdlPull::MessageType m)
Definition: Operation.h:167
void setMessage(const Message *message, WsdlPull::MessageType type, const std::string &name="")
Definition: Operation.h:190
const Message * getMessage(WsdlPull::MessageType type) const
Definition: Operation.h:135
std::list< const Message * > * getFaults() const
Definition: Operation.h:243
Optype getType() const
Definition: Operation.h:182
void addMessageExtensibility(WsdlPull::MessageType m, int ext)
Definition: Operation.h:152
void print(std::ostream &out)
Definition: Operation.h:233
const PortType * portType() const
Definition: Operation.h:128
@ Output
Definition: Operation.h:45
std::map< const Message *, std::string > MessageNameList
Definition: Operation.h:50
std::list< const Message * > MessageList
Definition: Operation.h:49
@ OP_NONE
Definition: Operation.h:35
@ OP_IN_OUT
Definition: Operation.h:38
@ OP_OUT_IN
Definition: Operation.h:39
@ OP_OUT
Definition: Operation.h:37
std::ostream & blk(std::ostream &str)
Definition: XmlUtils.cpp:97
std::ostream & dbsp(std::ostream &str)
Definition: XmlUtils.cpp:90
#define WSDLPULL_EXPORT