// ********************************************************************** // // Copyright (c) 2001 // Mutable Realms, Inc. // Huntsville, AL, USA // // All Rights Reserved // // ********************************************************************** #include #include #include // TODO: ??? #include using namespace std; using namespace Slice; using namespace IceUtil; static const string internalId = "_internal."; Slice::Gen::Gen(const string& name, const string& base, const string& include, const vector& includePaths, const string& dir) : _name(name), _base(base), _include(include), _includePaths(includePaths), _dir(dir) { _orgName = "http://www.noorg.org"; // TODO: argument! for(vector::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p) { if(p->length() && (*p)[p->length() - 1] != '/') { *p += '/'; } } string::size_type pos = _base.rfind('/'); if(pos != string::npos) { _base.erase(0, pos + 1); } } Slice::Gen::~Gen() { } bool Slice::Gen::visitClassDefStart(const ClassDefPtr& p) { XMLOutput O; //string fileO = _base + ".wsdl"; string fileO = containedToId(p) + p->name() + ".wsdl"; if(!_dir.empty()) { fileO = _dir + '/' + fileO; } O.open(fileO.c_str()); if(!O) { cerr << _name << ": can't open `" << fileO << "' for writing: " << strerror(errno) << endl; return false; } printHeader(O); O << "\n\n"; string scopeId = containedToId(p); // // TODO: It would be better if start() aligned the attributes // correctly. // ostringstream os; os << "wsdl:definitions name=\"" << scopeId << p->name() << "\"" << "\n xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\"" << "\n xmlns:xsd1=\"" << _orgName << "/schemas\"" << "\n xmlns:tns=\"" << _orgName << "/definitions\"" << "\n targetNamespace=\"" << _orgName << "/definitions\""; O << se(os.str()); // TODO: schemaLocation? O << sp << nl << ""; OperationList ops = p->allOperations(); for(OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q) { emitMessage(O, *q); } O << sp; os.str(""); os << "wsdl:portType name=\"" << scopeId << "PortType\""; O << se(os.str()); for(OperationList::const_iterator r = ops.begin(); r != ops.end(); ++r) { emitOperation(O, *r); } O << ee; // PortType O << ee; // definitions return false; } void Slice::Gen::emitMessage(XMLOutput& O, const OperationPtr& p) { O << sp; string scopeId = containedToId(p); ostringstream os; os << "wsdl:message name=\"input." << p->name() << "\""; O << se(os.str()); O << nl << "name() << "\"/>"; O << ee; // message os.str(""); os << "wsdl:message name=\"output." << p->name() << "\""; O << se(os.str()); O << nl << "name() << "\"/>"; O << ee; // message os.str(""); os << "wsdl:message name=\"metadata." << p->name() << "\""; O << se(os.str()); list metaData = p->getMetaData(); for(list::iterator iter = metaData.begin(); iter != metaData.end(); ++iter) { O << nl << ""; } O << ee; // message } void Slice::Gen::emitOperation(XMLOutput& O, const OperationPtr& p) { string scopeId = containedToId(p); ostringstream os; os << "wsdl:operation name=\"" << p->name() << "\""; O << se(os.str()); O << nl << "name() << "\"/>"; O << nl << "name() << "\"/>"; O << ee; // operation } void Slice::Gen::printHeader(XMLOutput& O) { static const char* header = "\n" ""; O.zeroIndent(); O << header; O << "\n"; O.restoreIndent(); } string Slice::Gen::containedToId(const ContainedPtr& contained) { assert(contained); string scoped = contained->scope(); if(scoped[0] == ':') { scoped.erase(0, 2); } string id; id.reserve(scoped.size()); for(unsigned int i = 0; i < scoped.size(); ++i) { if(scoped[i] == ':') { id += '.'; ++i; } else { id += scoped[i]; } } return id; }