wsdlpull
1.23
|
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 _QNAMEH 00022 #define _QNAMEH 00023 #include <string> 00024 #include <iostream> 00025 #ifdef HAVE_CONFIG_H // 00026 #include <config.h> 00027 #endif 00028 #include "wsdlpull_export.h" 00029 00030 class WSDLPULL_EXPORT Qname 00031 { 00032 public: 00033 Qname (const std::string & name); 00034 Qname (const Qname & qn); 00035 Qname (); 00036 std::string getLocalName (void)const; 00037 std::string getPrefix (void) const; 00038 std::string getNamespace (void)const; 00039 void setNamespace (std::string uri); 00040 bool operator== (const Qname & qn)const; 00041 void operator= (const std::string & name); 00042 friend std::ostream & operator<<(std::ostream & os,const Qname& qn); 00043 private: 00044 void parse (const std::string & name); 00045 std::string namespaceUri, localname, prefix; 00046 }; 00047 00048 inline 00049 Qname::Qname (const std::string & name) 00050 { 00051 parse (name); 00052 } 00053 00054 inline 00055 Qname::Qname (const Qname & qn) 00056 { 00057 localname = qn.localname; 00058 prefix = qn.prefix; 00059 namespaceUri = qn.namespaceUri; 00060 } 00061 00062 inline 00063 Qname::Qname () 00064 { 00065 } 00066 00067 inline 00068 void 00069 Qname::operator= (const std::string & name) 00070 { 00071 parse (name); 00072 } 00073 00074 inline 00075 std::string 00076 Qname::getLocalName (void)const 00077 { 00078 return localname; 00079 } 00080 00081 inline 00082 std::string 00083 Qname::getPrefix (void) const 00084 { 00085 return prefix; 00086 } 00087 00088 inline 00089 std::string 00090 Qname::getNamespace (void)const 00091 { 00092 return namespaceUri; 00093 } 00094 00095 inline 00096 void 00097 Qname::setNamespace (std::string uri) 00098 { 00099 namespaceUri = uri; 00100 } 00101 00102 inline 00103 bool 00104 Qname::operator== (const Qname & qn)const 00105 { 00106 if (qn.getNamespace () == namespaceUri && qn.getLocalName () == localname) 00107 return true; 00108 else 00109 return false; 00110 } 00111 00112 inline 00113 void 00114 Qname::parse (const std::string & name) 00115 { 00116 int cut = -1; 00117 if (name.empty ()) 00118 return; 00119 cut = name.find (":"); 00120 if (cut == -1 || cut == 0) 00121 localname = name; 00122 00123 else 00124 00125 { 00126 localname = name.substr (cut + 1); 00127 prefix = name.substr (0, cut); 00128 } 00129 cut = localname.find ("[]"); 00130 if (cut > 0) 00131 localname = localname.substr (0, cut); 00132 } 00133 00134 inline 00135 std::ostream & 00136 operator<<(std::ostream & os,const Qname& qn) 00137 { 00138 os<<qn.getPrefix()<<"{"<<qn.getNamespace()<<"}:"<<qn.getLocalName(); 00139 return os; 00140 } 00141 #endif /* */