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 #include "xmlpull/XmlUtils.h" 00021 #include "wsdlparser/Message.h" 00022 00023 using namespace std; 00024 00025 namespace WsdlPull { 00026 int 00027 Message::getPartIndex(string & nam) const 00028 { 00029 for (size_t i = 0; i < parts.size(); i++) 00030 { 00031 if (parts[i].name() == nam) 00032 return i; 00033 } 00034 return -1; 00035 } 00036 00037 Part::PartRefType 00038 Message::getPartRefType(int index) const 00039 { 00040 return parts[index].refType(); 00041 } 00042 00043 Part::PartRefType 00044 Message::getPartRefType(const string & nam) const 00045 { 00046 const Part* p=getMessagePart(nam); 00047 if(p) 00048 return p->refType(); 00049 else 00050 return Part::None; 00051 } 00052 00053 00054 const Part* 00055 Message::getMessagePart(const std::string & nam)const 00056 { 00057 for (size_t i = 0; i < parts.size(); i++) 00058 if (parts[i].name() == nam) 00059 return &parts[i]; 00060 return 0; 00061 } 00062 00063 int 00064 Message::getPartType(const std::string & nam) const 00065 { 00066 const Part* p=getMessagePart(nam); 00067 if(p) 00068 return p->type(); 00069 else 00070 return 0; 00071 } 00072 00073 00074 int 00075 Message::getPartContentSchemaId(const std::string & nam) const 00076 { 00077 const Part* p=getMessagePart(nam); 00078 if(p) 00079 return p->schemaId(); 00080 else 00081 return 0; 00082 } 00083 00084 const Part* 00085 Message::getMessagePart(size_t index)const 00086 { 00087 if(index>=0 && index < parts.size()) 00088 return &(parts[index]); 00089 else 00090 return 0; 00091 } 00092 00093 void 00094 Message::addPart(string pname, 00095 Part::PartRefType reftype, 00096 void* d, 00097 int schema_id) 00098 { 00099 Part p(pname); 00100 if(reftype==Part::Elem) { 00101 p.setPartElement((Element*)d,schema_id); 00102 }else { 00103 p.setPartType(*((int*)d),schema_id); 00104 } 00105 parts.push_back(p); 00106 } 00107 00108 void 00109 Part::setPartType(int typeId,int schema) 00110 { 00111 discriminator=Part::Type; 00112 type_id=typeId; 00113 schema_id=schema; 00114 } 00115 00116 void 00117 Part::setPartElement(const Element* el,int schema) 00118 { 00119 discriminator=Part::Elem; 00120 this->e=el; 00121 schema_id=schema; 00122 } 00123 00124 00125 int 00126 Part::type()const 00127 { 00128 if(discriminator==Part::Type) 00129 return type_id; 00130 else if(e!=0) 00131 return e->getType(); 00132 else 00133 return 0; 00134 } 00135 00136 const Element* 00137 Part::element()const 00138 { 00139 if(discriminator==Part::Elem) 00140 return e; 00141 else 00142 return 0; 00143 } 00144 }