ServiceBase
#include "ServiceBase.hpp"
#include "jliball.hpp"
#include "jlog.hpp"
#include "jptree.hpp"
ServiceBase
extern "C" int on(const char* CtxStr, const char* ReqStr, StringBuffer& RespStr)
{
Owned<> service = createServiceObj();
return service->(CtxStr, ReqStr, RespStr);
}
class UnSerializer : public CInterface, implements IInterface
{
public:
IMPLEMENT_IINTERFACE;
UnSerializer()
{
}
int unserialize(EsdlContext* obj, IPropertyTree* ptree)
{
if (!obj || !ptree)
return 0;
if (ptree->hasProp("username"))
obj->username.setown(new PString(ptree->queryProp("username")));
if (ptree->hasProp("clientMajorVersion"))
obj->clientMajorVersion.setown(new Integer(ptree->getPropInt("clientMajorVersion")));
if (ptree->hasProp("clientMinorVersion"))
obj->clientMinorVersion.setown(new Integer(ptree->getPropInt("clientMinorVersion")));
}
};
int ::(const char* CtxStr, const char* ReqStr, StringBuffer& RespStr)
{
Owned<UnSerializer> UnSe = new UnSerializer();
Owned<EsdlContext> ctx = new EsdlContext();
if (CtxStr && *CtxStr)
{
Owned<IPropertyTree> ptree = createPTreeFromXMLString(CtxStr);
UnSe->unserialize(ctx.get(), ptree.get());
}
Owned<> service = createServiceObj();
Owned<> req = new ();
Owned<IPropertyTree> ptree;
ptree.setown(createPTreeFromXMLString(ReqStr));
UnSe->unserialize(req.get(), ptree.get());
Owned<> resp = service->(ctx.get(), req.get());
RespStr = "<Response><Results><Result><Dataset name=\"\"><Row>";
UnSe->serialize(resp.get(), RespStr);
RespStr.append("</Row></Dataset></Result></Results></Response>");
return 0;
}
int unserialize(* obj, IPropertyTree* ptree)
{
if (!obj || !ptree)
return 0;
IPropertyTree* subtree = nullptr;
subtree = ptree->queryPropTree("");
if (subtree != nullptr)
{
obj->.setown(new ());
unserialize(obj->.get(), subtree);
}
if (ptree->hasProp(""))
obj->.setown(new PString(ptree->queryProp("")));
if (ptree->hasProp(""))
obj->.setown(new Integer(ptree->getPropInt("")));
if (ptree->hasProp(""))
obj->.setown(new Integer64(ptree->getPropInt64("")));
if (ptree->hasProp(""))
obj->.setown(new Boolean(ptree->getPropBool("")));
if (ptree->hasProp(""))
obj->.setown(new Float(atof(ptree->queryProp(""))));
if (ptree->hasProp(""))
obj->.setown(new Double(atof(ptree->queryProp(""))));
subtree = ptree->queryPropTree("");
if (subtree != nullptr)
{
Owned<IPropertyTreeIterator> itr = subtree->getElements("");
ForEach (*itr)
{
IPropertyTree* onetree = &itr->query();
Owned<> oneobj(new ());
unserialize(oneobj.get(), onetree);
obj->.append(*oneobj.getClear());
obj->.append(*(new PString(onetree->queryProp("."))));
obj->.append(*(new Integer(onetree->getPropInt("."))));
obj->.append(*(new Integer64(onetree->getPropInt64("."))));
obj->.append(*(new Boolean(onetree->getPropBool("."))));
obj->.append(*(new Float(atof(onetree->queryProp(".")))));
obj->.append(*(new Double(atof(onetree->queryProp(".")))));
}
}
if (ptree->hasProp(""))
obj-> = EnumHandler::fromString(ptree->queryProp(""));
return 0;
}
int serialize(* obj, StringBuffer& buf)
{
if (!obj)
return 0;
if (obj->)
{
buf.append("<>");
serialize(obj->, buf);
buf.append(obj->->str());
buf.append("</>");
}
if (obj->.length() > 0)
{
buf.append("<>");
ForEachItemIn(i, obj->)
{
& oneitem = obj->.item(i);
buf.append("<>");
serialize(&oneitem, buf);
buf.append("</>");
& oneitem = obj->.item(i);
buf.append("<>").append(oneitem.str()).append("</>");
}
buf.append("</>");
}
if (obj-> != ::UNSET)
buf.append("<>").append(EnumHandler::toString(obj->)).append("</>");
return 0;
}