summaryrefslogtreecommitdiff
path: root/cpp/src/slice2wsdl/Gen.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2002-01-25 16:56:52 +0000
committerMatthew Newhook <matthew@zeroc.com>2002-01-25 16:56:52 +0000
commitccb36bbe1463c2b4760f793ec5611b24caa6c09f (patch)
tree0fb6ecc7d0ba90c6b82606b46b3621f5fbcd238a /cpp/src/slice2wsdl/Gen.cpp
parentChanged Gen.cpp to fix a minor bug that prevented compiling in VC++. Added (diff)
downloadice-ccb36bbe1463c2b4760f793ec5611b24caa6c09f.tar.bz2
ice-ccb36bbe1463c2b4760f793ec5611b24caa6c09f.tar.xz
ice-ccb36bbe1463c2b4760f793ec5611b24caa6c09f.zip
Use visitor pattern. Add ability to generate WSDL definitions for all types
in a file.
Diffstat (limited to 'cpp/src/slice2wsdl/Gen.cpp')
-rw-r--r--cpp/src/slice2wsdl/Gen.cpp175
1 files changed, 41 insertions, 134 deletions
diff --git a/cpp/src/slice2wsdl/Gen.cpp b/cpp/src/slice2wsdl/Gen.cpp
index 29f6f879c53..57aeb726592 100644
--- a/cpp/src/slice2wsdl/Gen.cpp
+++ b/cpp/src/slice2wsdl/Gen.cpp
@@ -12,6 +12,7 @@
#include <Slice/CPlusPlusUtil.h> // TODO: ???
#include <Gen.h>
+#include <Slice/OutputUtil.h>
using namespace std;
using namespace Slice;
@@ -19,12 +20,12 @@ using namespace Slice;
static const string internalId = "_internal.";
Slice::Gen::Gen(const string& name, const string& base, const string& include,
- const vector<string>& includePaths, const string& dir,
- const ClassDefPtr& classDef) :
+ const vector<string>& includePaths, const string& dir) :
+ _name(name),
_base(base),
_include(include),
_includePaths(includePaths),
- _classDef(classDef)
+ _dir(dir)
{
_orgName = "http://www.noorg.org"; // TODO: argument!
for (vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
@@ -40,85 +41,79 @@ Slice::Gen::Gen(const string& name, const string& base, const string& include,
{
_base.erase(0, pos + 1);
}
+}
+
+Slice::Gen::~Gen()
+{
+}
+
+bool
+Slice::Gen::visitClassDefStart(const ClassDefPtr& p)
+{
+ Output O;
//string fileO = _base + ".wsdl";
- string fileO = containedToId(classDef) + classDef->name() + ".wsdl";
- if (!dir.empty())
+ string fileO = containedToId(p) + p->name() + ".wsdl";
+ if (!_dir.empty())
{
- fileO = dir + '/' + fileO;
+ fileO = _dir + '/' + fileO;
}
O.open(fileO.c_str());
if (!O)
{
- cerr << name << ": can't open `" << fileO << "' for writing: " << strerror(errno) << endl;
- return;
+ cerr << _name << ": can't open `" << fileO << "' for writing: " << strerror(errno) << endl;
+ return false;
}
- printHeader();
+ printHeader(O);
O << "\n<!-- Generated from file `" << changeInclude(_base, _includePaths) << ".ice' -->\n";
-}
-Slice::Gen::~Gen()
-{
-}
-
-bool
-Slice::Gen::operator!() const
-{
- return !O;
-}
-
-void
-Slice::Gen::generate(const UnitPtr& unit)
-{
- unit->mergeModules();
-
- string scopeId = containedToId(_classDef);
+ string scopeId = containedToId(p);
//
// TODO: It would be better if start() aligned the attributes
// correctly.
//
ostringstream os;
- os << "wsdl:definitions name=\"" << scopeId << _classDef->name() << "\""
+ 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\"";
- start(os.str());
+ start(O, os.str());
// TODO: schemaLocation?
O << sp << nl << "<wsdl:import namespace=\"" << _orgName << "/schemas\" location=\"" << _base << ".xsd\"/>";
- OperationList ops = _classDef->allOperations();
+ OperationList ops = p->allOperations();
for (OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q)
{
- emitMessage(*q);
+ emitMessage(O, *q);
}
O << sp;
os.str("");
os << "wsdl:portType name=\"" << scopeId << "PortType\"";
- start(os.str());
+ start(O, os.str());
for (OperationList::const_iterator r = ops.begin(); r != ops.end(); ++r)
{
- emitOperation(*r);
+ emitOperation(O, *r);
}
- end(); // PortType
+ end(O); // PortType
- end(); // definitions
+ end(O); // definitions
- O << nl;
+ return false;
}
void
-Slice::Gen::emitMessage(const OperationPtr& p)
+Slice::Gen::emitMessage(Output& O, const OperationPtr& p)
{
O << sp;
@@ -126,38 +121,38 @@ Slice::Gen::emitMessage(const OperationPtr& p)
ostringstream os;
os << "wsdl:message name=\"input." << p->name() << "\"";
- start(os.str());
+ start(O, os.str());
O << nl << "<wsdl:part name=\"body\" element=\"xsd1:" << scopeId << "request." << p->name() << "\"/>";
- end(); // message
+ end(O); // message
os.str("");
os << "wsdl:message name=\"output." << p->name() << "\"";
- start(os.str());
+ start(O, os.str());
O << nl << "<wsdl:part name=\"body\" element=\"xsd1:" << scopeId << "request." << p->name() << "\"/>";
- end(); // message
+ end(O); // message
}
void
-Slice::Gen::emitOperation(const OperationPtr& p)
+Slice::Gen::emitOperation(Output& O, const OperationPtr& p)
{
string scopeId = containedToId(p);
ostringstream os;
os << "wsdl:operation name=\"" << p->name() << "\"";
- start(os.str());
+ start(O, os.str());
O << nl << "<wsdl:input message=\"tns:input." << p->name() << "\">";
O << nl << "<wsdl:output message=\"tns:output." << p->name() << "\">";
- end(); // operation
+ end(O); // operation
}
void
-Slice::Gen::printHeader()
+Slice::Gen::printHeader(Output& O)
{
static const char* header =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@@ -181,7 +176,7 @@ Slice::Gen::printHeader()
void
-Slice::Gen::start(const std::string& element)
+Slice::Gen::start(Output& O, const std::string& element)
{
O << nl << '<' << element << '>';
O.inc();
@@ -198,7 +193,7 @@ Slice::Gen::start(const std::string& element)
}
void
-Slice::Gen::end()
+Slice::Gen::end(Output& O)
{
string element = _elementStack.top();
_elementStack.pop();
@@ -237,91 +232,3 @@ Slice::Gen::containedToId(const ContainedPtr& contained)
return id;
}
-
-string
-Slice::Gen::toString(const SyntaxTreeBasePtr& p)
-{
- string tag;
- string linkend;
- string s;
-
- static const char* builtinTable[] =
- {
- "xs:byte",
- "xs:boolean",
- "xs;short",
- "xs:int",
- "xs:long",
- "xs:float",
- "xs:double",
- "xs:string",
- "ice:_internal.reference", /* Object */
- "ice:_internal.proxyType", /* Object* */
- "???" /* LocalObject */
- };
-
- BuiltinPtr builtin = BuiltinPtr::dynamicCast(p);
- if (builtin)
- {
- s = builtinTable[builtin->kind()];
- //tag = "type";
- }
-
- ProxyPtr proxy = ProxyPtr::dynamicCast(p);
- if (proxy)
- {
- s = "ice:_internal.proxyType";
- }
-
- ClassDeclPtr cl = ClassDeclPtr::dynamicCast(p);
- if (cl)
- {
- string scopeId = containedToId(cl);
- //s = "tns:" + internalId + scopeId + cl->name() + "Type";
- s = "ice:_internal.reference";
- }
-
- ExceptionPtr ex = ExceptionPtr::dynamicCast(p);
- if (ex)
- {
- string scopeId = containedToId(ex);
- s = "tns:" + internalId + scopeId + ex->name() + "Type";
- }
-
- StructPtr st = StructPtr::dynamicCast(p);
- if (st)
- {
- string scopeId = containedToId(st);
- s = "tns:" + internalId + scopeId + st->name() + "Type";
- }
-
- EnumeratorPtr en = EnumeratorPtr::dynamicCast(p);
- if (en)
- {
- string scopeId = containedToId(en);
- s = "tns:" + internalId + scopeId + en->name() + "Type";
- }
-
- SequencePtr sq = SequencePtr::dynamicCast(p);
- if (sq)
- {
- string scopeId = containedToId(sq);
- s = "tns:" + internalId + scopeId + sq->name() + "Type";
- }
-
- DictionaryPtr di = DictionaryPtr::dynamicCast(p);
- if (di)
- {
- string scopeId = containedToId(di);
- s = "tns:" + internalId + scopeId + di->name() + "Type";
- }
-
- EnumPtr em = EnumPtr::dynamicCast(p);
- if (em)
- {
- string scopeId = containedToId(em);
- s = "tns:" + internalId + scopeId + em->name() + "Type";
- }
-
- return s;
-}