Operation.h

Go to the documentation of this file.
00001 /* 
00002  * wsdlpull - A C++ parser  for Wsdl  (Web services description language)
00003  * Copyright (C) 2005-2007 Vivek Krishna
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  *
00019  *
00020  */
00021 #ifndef _OPERATIONH
00022 #define  _OPERATIONH
00023 
00024 #include "xmlpull/Qname.h"
00025 
00026 #include "wsdlparser/WsdlException.h"
00027 #include "wsdlparser/WsdlElement.h"
00028 #include "wsdlparser/Message.h"
00029 #include "xmlpull/wsdlpull_export.h"
00030 
00031 
00032 namespace WsdlPull {
00033 
00034 enum Optype{
00035   OP_NONE,
00036   OP_IN ,
00037   OP_OUT,
00038   OP_IN_OUT,
00039   OP_OUT_IN
00040 };
00041  
00042 enum MessageType{
00043 
00044   Input,
00045   Output,
00046   Fault
00047 };
00048 
00049 typedef std::list<const Message*> MessageList;
00050 typedef std::map<const Message *, std::string> MessageNameList;
00051 class PortType;
00052 //class for Wsdl operation element
00053 class WSDLPULL_EXPORT Operation:public WsdlElement
00054 {
00055  public:
00056   typedef std::vector<Operation*>::iterator OpIterator;
00057   typedef std::vector<Operation*>::const_iterator cOpIterator;
00058 
00059   Operation(WsdlParser& w,PortType * pt);
00060   ~Operation();
00063 
00069   const Message *getMessage(WsdlPull::MessageType type) const;
00070   //get the input/output/fault element's name
00071   std::string getMessageName(WsdlPull::MessageType type) const;
00072   std::list<const Message*>* getFaults()const;
00073   const Message* getFault(const std::string& name)const;
00078   Optype getType() const;
00079   
00084   const PortType* portType()const;
00085 
00087   void setMessage(const Message * message, WsdlPull::MessageType type,
00088                   const std::string & name = "");
00089   void addMessageExtensibility(WsdlPull::MessageType m,int ext);
00090   int getMessageExtension(WsdlPull::MessageType m);
00091 
00093   void print(std::ostream & out);
00094 
00095  private:
00096   PortType * pt_;
00097   Optype type_;
00098   const Message *inMessage_, *outMessage_;
00099   std::list<const Message*> *faultMessages_;
00100   MessageNameList messageNames_;
00101   int in_e,out_e,fault_e; //extensibility elements for <input>,<output>,<fault> elements
00102     
00103 };
00104 
00105 
00106 
00107 inline
00108 Operation::Operation(WsdlParser& w,PortType * p)
00109   :WsdlElement(w),
00110      pt_(p),
00111      type_(OP_NONE),
00112      inMessage_(0),
00113      outMessage_(0),
00114   faultMessages_(0),
00115   in_e(0),out_e(0),fault_e(0)
00116 {
00117 }
00118 
00119 inline
00120 Operation::~Operation()
00121 {
00122   
00123   delete faultMessages_;
00124 }
00125 
00126 inline
00127 const PortType* 
00128 Operation::portType()const
00129 {
00130   return pt_;
00131 }
00132 
00133 inline
00134 const Message *
00135 Operation::getMessage(WsdlPull::MessageType type) const     
00136 {
00137   if (type == Input)
00138     return inMessage_;
00139 
00140   else if (type == Output)
00141     return outMessage_;
00142 
00143   else if (type == Fault && faultMessages_)
00144     return faultMessages_->front();
00145 
00146   else
00147     return 0;
00148 }
00149 
00150 inline
00151 void 
00152 Operation::addMessageExtensibility(WsdlPull::MessageType type,int ext)
00153 {
00154  if (type == Input)
00155    in_e = ext;
00156 
00157   else if (type == Output)
00158     out_e = ext;
00159 
00160   else if (type == Fault)
00161     fault_e = ext;
00162   
00163  return;
00164 }
00165 inline
00166 int 
00167 Operation::getMessageExtension(WsdlPull::MessageType type)
00168 {
00169  if (type == Input)
00170    return in_e ;
00171 
00172   else if (type == Output)
00173     return out_e;
00174 
00175   else if (type == Fault)
00176     return fault_e;
00177 
00178  return 0;
00179 }
00180 inline  
00181 Optype
00182 Operation::getType() const                        
00183 {
00184   return type_;
00185 }
00186 
00187 
00188 inline
00189 void 
00190 Operation::setMessage(const Message * message,
00191                       WsdlPull::MessageType type,
00192                       const std::string &name)
00193 {
00194   if (message == 0)
00195     throw WsdlException("Invalid message name");
00196   if (type == Input) {
00197 
00198     inMessage_ = message;
00199     if (type_ == OP_NONE)
00200       type_ = OP_IN;
00201 
00202     else if (type_ == OP_OUT)
00203       type_ = OP_OUT_IN;
00204 
00205     else
00206       type_ = OP_NONE;
00207   }
00208   else if (type == Output){
00209     
00210     outMessage_ = message;
00211     if (type_ == OP_NONE)
00212       type_ = OP_OUT;
00213 
00214     else if (type_ == OP_IN)
00215       type_ = OP_IN_OUT;
00216 
00217     else
00218       type_ = OP_NONE;
00219   } 
00220   else if (type == Fault) {
00221       
00222     if (!faultMessages_)
00223       faultMessages_ = new std::list<const Message*>();
00224     
00225     faultMessages_->push_back(message);
00226   }
00227   //Save mesasge name
00228   messageNames_[message]=name;
00229 }
00230 
00231 inline
00232 void 
00233 Operation::print(std::ostream & out)
00234 {
00235   out << id_ << XmlUtils::dbsp << name_ << std::endl;
00236   out << type_ << std::endl;
00237   out << inMessage_ << XmlUtils::dbsp << outMessage_ << XmlUtils::dbsp <<std::endl;
00238   out << XmlUtils::blk;
00239 }
00240 
00241 inline
00242 std::list<const Message*>*
00243 Operation::getFaults()const
00244 {
00245 
00246   return faultMessages_;
00247 }
00248 inline
00249 const Message* 
00250 Operation::getFault(const std::string& name)const
00251 {
00252   for ( std::list<const Message*>::iterator mli = faultMessages_->begin();
00253         mli != faultMessages_->end();
00254         mli++) {
00255 
00256     if ((*mli)->getName() == name)
00257       return (*mli);
00258   }
00259   return 0;
00260 }
00261 
00262 inline
00263 std::string
00264 Operation::getMessageName(WsdlPull::MessageType type) const
00265 {
00266  std::string name("");
00267  const Message * pMessage = 0;
00268  MessageNameList::const_iterator it;
00269 
00270   if (type == Input)  {
00271 
00272     pMessage = inMessage_;
00273   }
00274   else if (type == Output)  {
00275 
00276     pMessage = outMessage_;
00277   }
00278   else if (type == Fault && faultMessages_)  {
00279 
00280     pMessage = faultMessages_->front();
00281   }
00282 
00283   it = messageNames_.find(pMessage);
00284 
00285   if (messageNames_.end() != it)
00286     name = it->second;
00287  
00288   return name;
00289 }
00290 
00291 }
00292 
00293 #endif                                            /*  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by  doxygen 1.6.2