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 00022 #include "schemaparser/ComplexType.h" 00023 00024 namespace Schema { 00025 00026 ComplexType::ComplexType(const std::string & ns) 00027 :XSDType(ns), 00028 simpleContentTypeId_ (0), 00029 cm_(0), 00030 fwdElemRef_(false), 00031 fwdAttrRef_(false) 00032 { 00033 00034 setContentModel(Schema::Complex); 00035 } 00036 00037 void 00038 ComplexType::addAttribute(const Attribute& a, 00039 bool ref) 00040 { 00041 fwdAttrRef_=ref; 00042 00043 Attribute *at= (Attribute *)getAttribute(a.getName()); 00044 if(at){ 00045 *at=a; 00046 }else{ 00047 attList_.push_back(a); 00048 } 00049 } 00050 00051 00052 void 00053 ComplexType::addAttributeGroupName(const Qname & qn) 00054 { 00055 //TODO 00056 //store the attribute group and add all attributes later 00057 //by calling addAttribute() 00058 } 00059 00060 void 00061 ComplexType::matchElementRef(const std::string & name, Element & e) 00062 { 00063 if(cm_) { 00064 cm_->matchforwardRef(name,e); 00065 } 00066 } 00067 00068 void 00069 ComplexType::matchAttributeRef(const std::string & nam, 00070 Attribute & a) 00071 { 00072 if (fwdAttrRef_) { 00073 Attribute *at = (Attribute*)getAttribute(nam); 00074 if (at) 00075 *at = a; 00076 } 00077 } 00078 00079 const Attribute * 00080 ComplexType::getAttribute(const std::string & nam) const 00081 { 00082 std::list < Attribute >::const_iterator pAttr = attList_.begin(); 00083 while (pAttr != attList_.end()) 00084 { 00085 if (pAttr->getName() == nam) 00086 return &(*pAttr); 00087 pAttr++; 00088 } 00089 return 0; 00090 } 00091 00092 00093 void ComplexType::error(std::string msg) const 00094 { 00095 msg+="Complex Type "+ getName() +msg; 00096 SchemaParserException spe(msg); 00097 throw spe; 00098 return; 00099 } 00100 00101 const Attribute * 00102 ComplexType::getAttribute(int index) const 00103 { 00104 00105 int i=0; 00106 for (std::list<Attribute>::const_iterator ali=attList_.begin(); 00107 ali!=attList_.end();ali++,i++) { 00108 if(i==index) 00109 return &(*ali); 00110 } 00111 return 0; 00112 00113 } 00114 }