23 #include "ComponentGen.h"
25 ComponentGen::ComponentGen() {
26 logger = Logger::getLogger(
"ComponentGen");
29 ComponentGen::~ComponentGen() {
33 string convertfrom(
string val)
35 StringUtil::toUpper(val);
42 throw "Conversion exception";
47 string ComponentGen::generateComponentCU(
string fileName,
string &cudata,
string &cuheader,
string &curemote,
string &curemoteheaders)
54 string initheaders,cuinithdrs,name;
68 propMap srprps = pread.getProperties(fileName);
73 name = srprps[
"@CMP_NAME"];
75 throw "Component Name must be specified";
76 file = (
"Component_"+name);
78 StringUtil::toUpper(cudef);
79 initheaders =
"#ifndef "+cudef+
"_H\n#define "+cudef+
"_H\n";
80 cuinithdrs =
"#ifndef "+cudef+
"_REMOTE_H\n#define "+cudef+
"_REMOTE_H\n";
81 initheaders +=
"#include \"Component.h\"\n";
82 initheaders +=
"#include \"AppContext.h\"\n";
83 cuheader =
"class "+file +
": public Component \n{\n";
84 curemote =
"#include \""+file+
"_Remote.h\"\n";
85 curemoteheaders =
"#include \"RemoteComponent.h\"\n";
86 curemoteheaders +=
"class "+file +
"_Remote : public RemoteComponent \n{\n";
88 curemoteheaders +=
"public:\n";
89 curemoteheaders +=
"~"+file+
"_Remote();\n";
90 curemoteheaders += file+
"_Remote();\n";
92 cudata =
"#include \""+file+
".h\"\n\n";
95 string servs,servsh,rsrvs;
96 cuheader +=
"public:\n";
97 cuheader +=
"~"+file+
"();\n";
98 cuheader += file+
"();\n";
99 cudata += file+
"::~"+file+
"()\n{}\n";
100 cudata += file+
"::"+file+
"()\n{\n";
101 cudata +=
"AppContext::lookup(\""+name+
"\");\n;";
103 curemote += file+
"_Remote::~"+file+
"_Remote()\n{}\n";
104 curemote += file+
"_Remote::"+file+
"_Remote()\n{\n";
105 curemote += (
"this->setBeanName(\""+name+
"\");\n");
107 cudata+= (
"this->setName(\""+name+
"\");\n");
109 string desc = srprps[
"@CMP_DESC"];
110 cudata+= (
"this->setDesc(\""+desc+
"\");\n");
112 cudata+= (
"this->setAjaxAvail("+convertfrom(srprps[
"@AJAX_AVAIL"])+
");\n");
114 cudata+= (
"this->setWebsAvail("+convertfrom(srprps[
"@WEBS_AVAIL"])+
");\n");
116 cudata+= (
"this->setMethinvAvail("+convertfrom(srprps[
"@MINV_AVAIL"])+
");\n");
118 cudata+= (
"this->setAutoTranx("+convertfrom(srprps[
"@AUTO_TRANS"])+
");\n");
120 cudata+= (
"this->setSession("+convertfrom(srprps[
"@SESSION"])+
");\n");
122 cudata+= (
"this->setThrdPerReq("+convertfrom(srprps[
"@THRD_PER_REQ"])+
");\n");
124 cudata+= (
"this->setThrdPoolSize("+srprps[
"@THRD_POOL_NUM"]+
");\n");
126 cudata+= (
"this->setAuthMode("+convertfrom(srprps[
"@AUTH_ALL"])+
");\n");
128 string alwd = srprps[
"@USR_GRP_ALWD"];
130 StringUtil::split(alwdls, alwd, (
","));
131 for (
unsigned int var = 0; var < alwdls.size(); var++)
133 cudata+= (
"this->getAllwList().push_back(\""+alwdls.at(var)+
"\");\n");
136 string blkd = srprps[
"@BLOCK_USERS"];
138 StringUtil::split(blkls, blkd, (
","));
139 for (
unsigned int var = 0; var < blkls.size(); var++)
141 cudata+= (
"this->getBlkdList().push_back(\""+blkls.at(var)+
"\");\n");
144 string prots = srprps[
"@PROTO_ALWD"];
146 StringUtil::split(protls, prots, (
","));
147 for (
unsigned int var = 0; var < protls.size(); var++)
149 cudata+= (
"this->getProtocols().push_back(\""+protls.at(var)+
"\");\n");
153 consts.mode = srprps[
"@AUTH_DETS"];
154 cudata += (
"ConnectionSettings conset(");
155 cudata+= (
"\""+srprps[
"@AUTH_DETS"]+
"\",");
156 consts.source = srprps[
"@AUTH_CONN_SRC"];
157 cudata+= (
"\""+srprps[
"@AUTH_CONN_SRC"]+
"\",");
158 consts.username = srprps[
"@AUTH_USR_NAME"];
159 cudata+= (
"\""+srprps[
"@AUTH_USR_NAME"]+
"\",");
160 consts.passwd = srprps[
"@AUTH_USR_PASS"];
161 cudata+= (
"\""+srprps[
"@AUTH_USR_PASS"]+
"\",");
162 consts.address = srprps[
"@AUTH_ADD"];
163 cudata+= (
"\""+srprps[
"@AUTH_ADD"]+
"\");\n");
164 cudata+= (
"this->setAuthDets(conset);\n");
166 cudata+= (
"this->setDbconpoolSize("+srprps[
"@DB_CONN_POOL_NUM"]+
");\n");
169 while(srprps[
"@SERVICE"+CastUtil::lexical_cast<string>(cnt)]!=
"")
171 string srvc = srprps[
"@SERVICE"+CastUtil::lexical_cast<
string>(cnt++)];
173 if(srvc.find(
"@USR_GRP_ALWD(")!=string::npos)
175 int st = srvc.find(
"@USR_GRP_ALWD(");
176 string temp = srvc.substr(st+14);
177 size_t sp = temp.find_first_of(
" ");
178 size_t cl = temp.find_first_of(
")");
179 if((sp!=string::npos && sp<cl) || cl==string::npos)
181 throw "No spaces allowed between in value";
185 string temtem = temp.substr(0,cl);
186 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
187 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
188 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
189 temtem.find(
"@SRV_RET")!=string::npos ||
190 temtem.find(
"@USERS_ALWD")!=string::npos ||
191 temtem.find(
"@NAME")!=string::npos ||
192 temtem.find(
"@ARGS")!=string::npos ||
193 temtem.find(
"@SIGNATURE")!=string::npos)
195 throw "Invalid start of property within another property";
200 StringUtil::split(alwd, temtem, (
","));
204 if(srvc.find(
"@BLOCK_USERS(")!=string::npos)
206 int st = srvc.find(
"@BLOCK_USERS(");
207 string temp = srvc.substr(st+13);
208 size_t sp = temp.find_first_of(
" ");
209 size_t cl = temp.find_first_of(
")");
210 if((sp!=string::npos && sp<cl) || cl==string::npos)
212 throw "No spaces allowed between in value";
216 string temtem = temp.substr(0,cl);
217 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
218 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
219 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
220 temtem.find(
"@SRV_RET")!=string::npos ||
221 temtem.find(
"@USERS_ALWD")!=string::npos ||
222 temtem.find(
"@NAME")!=string::npos ||
223 temtem.find(
"@ARGS")!=string::npos ||
224 temtem.find(
"@SIGNATURE")!=string::npos)
226 throw "Invalid start of property within another property";
231 StringUtil::split(alwd, temtem, (
","));
235 if(srvc.find(
"@BLOCK_USR_GRPS(")!=string::npos)
237 int st = srvc.find(
"@BLOCK_USR_GRPS(");
238 string temp = srvc.substr(st+16);
239 size_t sp = temp.find_first_of(
" ");
240 size_t cl = temp.find_first_of(
")");
241 if((sp!=string::npos && sp<cl) || cl==string::npos)
243 throw "No spaces allowed between in value";
247 string temtem = temp.substr(0,cl);
248 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
249 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
250 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
251 temtem.find(
"@SRV_RET")!=string::npos ||
252 temtem.find(
"@USERS_ALWD")!=string::npos ||
253 temtem.find(
"@NAME")!=string::npos ||
254 temtem.find(
"@ARGS")!=string::npos ||
255 temtem.find(
"@SIGNATURE")!=string::npos)
257 throw "Invalid start of property within another property";
262 StringUtil::split(alwd, temtem, (
","));
266 string srvret =
"void";
267 if(srvc.find(
"@SRV_RET(")!=string::npos)
269 int st = srvc.find(
"@SRV_RET(");
270 string temp = srvc.substr(st+9);
271 size_t sp = temp.find_first_of(
" ");
272 size_t cl = temp.find_first_of(
")");
273 if((sp!=string::npos && sp<cl) || cl==string::npos)
275 throw "No spaces allowed between in value";
279 string temtem = temp.substr(0,cl);
280 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
281 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
282 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
283 temtem.find(
"@SRV_RET")!=string::npos ||
284 temtem.find(
"@USERS_ALWD")!=string::npos ||
285 temtem.find(
"@NAME")!=string::npos ||
286 temtem.find(
"@ARGS")!=string::npos ||
287 temtem.find(
"@SIGNATURE")!=string::npos)
289 throw "Invalid start of property within another property";
293 cmps.retType = temtem;
298 if(srvc.find(
"@USERS_ALWD(")!=string::npos)
300 int st = srvc.find(
"@USERS_ALWD(");
301 string temp = srvc.substr(st+12);
302 size_t sp = temp.find_first_of(
" ");
303 size_t cl = temp.find_first_of(
")");
304 if((sp!=string::npos && sp<cl) || cl==string::npos)
306 throw "No spaces allowed between in value";
310 string temtem = temp.substr(0,cl);
311 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
312 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
313 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
314 temtem.find(
"@SRV_RET")!=string::npos ||
315 temtem.find(
"@USERS_ALWD")!=string::npos ||
316 temtem.find(
"@NAME")!=string::npos ||
317 temtem.find(
"@ARGS")!=string::npos ||
318 temtem.find(
"@SIGNATURE")!=string::npos)
320 throw "Invalid start of property within another property";
325 StringUtil::split(alwd, temtem, (
","));
329 string srvcls,srvmeth;
330 if(srvc.find(
"@SIGNATURE(")!=string::npos)
332 int st = srvc.find(
"@SIGNATURE(");
333 string temp = srvc.substr(st+11);
334 size_t sp = temp.find_first_of(
" ");
335 size_t cl = temp.find_first_of(
")");
336 if((sp!=string::npos && sp<cl) || cl==string::npos)
338 throw "No spaces allowed between in value";
342 string temtem = temp.substr(0,cl);
343 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
344 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
345 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
346 temtem.find(
"@SRV_RET")!=string::npos ||
347 temtem.find(
"@USERS_ALWD")!=string::npos ||
348 temtem.find(
"@NAME")!=string::npos ||
349 temtem.find(
"@ARGS")!=string::npos ||
350 temtem.find(
"@SIGNATURE")!=string::npos)
352 throw "Invalid start of property within another property";
357 StringUtil::split(alwd, temtem, (
"."));
361 srvmeth = alwd.at(1);
362 cmps.classn = alwd.at(0);
363 cmps.methName = alwd.at(1);
367 throw "Invalid Service Signature";
373 if(srvc.find(
"@NAME(")!=string::npos)
375 int st = srvc.find(
"@NAME(");
376 string temp = srvc.substr(st+6);
377 size_t sp = temp.find_first_of(
" ");
378 size_t cl = temp.find_first_of(
")");
379 if((sp!=string::npos && sp<cl) || cl==string::npos)
381 throw "No spaces allowed between in value";
385 string temtem = temp.substr(0,cl);
386 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
387 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
388 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
389 temtem.find(
"@SRV_RET")!=string::npos ||
390 temtem.find(
"@USERS_ALWD")!=string::npos ||
391 temtem.find(
"@NAME")!=string::npos ||
392 temtem.find(
"@ARGS")!=string::npos ||
393 temtem.find(
"@SIGNATURE")!=string::npos)
395 throw "Invalid start of property within another property";
403 string srvargs,srvmcarg,srvmcargremote,srvmcargremotevec=
"vector<Object> _vec;\n";
404 if(srvc.find(
"@ARGS(")!=string::npos)
406 int st = srvc.find(
"@ARGS(");
407 string temp = srvc.substr(st+6);
408 size_t sp = temp.find_first_of(
" ");
409 size_t cl = temp.find_first_of(
")");
410 if((sp!=string::npos && sp<cl) || cl==string::npos)
412 throw "No spaces allowed between in value";
416 string temtem = temp.substr(0,cl);
417 if(temtem.find(
"@BLOCK_USERS")!=string::npos ||
418 temtem.find(
"@USR_GRP_ALWD")!=string::npos ||
419 temtem.find(
"@BLOCK_USR_GRPS")!=string::npos ||
420 temtem.find(
"@SRV_RET")!=string::npos ||
421 temtem.find(
"@USERS_ALWD")!=string::npos ||
422 temtem.find(
"@NAME")!=string::npos ||
423 temtem.find(
"@ARGS")!=string::npos ||
424 temtem.find(
"@SIGNATURE")!=string::npos)
426 throw "Invalid start of property within another property";
435 StringUtil::split(alwd, temtem, (
","));
436 for (
unsigned int var = 0; var < alwd.size(); ++var)
438 if(alwd.at(var)!=
"" && alwd.at(var).find(
"*")==string::npos && alwd.at(var).find(
"&")==string::npos)
441 srvmcarg +=
"_"+CastUtil::lexical_cast<
string>(var+1)+
"";
442 srvargs += alwd.at(var)+
" _"+CastUtil::lexical_cast<
string>(var+1);
443 srvmcargremote += alwd.at(var)+
" &_"+CastUtil::lexical_cast<
string>(var+1);
444 srvmcargremotevec +=
"Object __"+CastUtil::lexical_cast<
string>(var+1)+
";\n";
445 srvmcargremotevec +=
"__"+CastUtil::lexical_cast<
string>(var+1)+
" << _"+CastUtil::lexical_cast<string>(var+1)+
";\n";
446 srvmcargremotevec +=
"_vec.push_back(__"+CastUtil::lexical_cast<
string>(var+1)+
");\n";
447 if(var!=alwd.size()-1)
450 srvmcargremote +=
",";
456 throw "Invalid service arguments";
463 cuinithdrs +=
"#include \""+srvcls+
".h\"\n";
464 initheaders +=
"#include \""+srvcls+
".h\"\n";
465 servsh += srvret+
" "+srvname+
"("+srvargs+
");\n";
466 servs += srvret+
" "+file+
"::"+srvname+
"("+srvargs+
")\n{\n";
467 servs += srvcls +
" _serviceImpl;\n";
468 if(srvret!=
"" && srvret!=
"void")
469 servs += srvret +
" _retvalue;\n";
471 if(convertfrom(srprps[
"@AUTO_TRANS"])==
"true")
472 servs +=
"this->startTransaction();\n";
473 if(srvret!=
"" && srvret!=
"void")
474 servs +=
"_retvalue = _serviceImpl."+srvmeth+
"("+srvmcarg+
");\n}\n";
476 servs +=
"_serviceImpl."+srvmeth+
"("+srvmcarg+
");\n}\n";
477 servs +=
"catch(...){\n";
478 if(convertfrom(srprps[
"@AUTO_TRANS"])==
"true")
479 servs +=
"this->rollback();\n";
481 if(convertfrom(srprps[
"@AUTO_TRANS"])==
"true")
482 servs +=
"this->endTransaction();\n";
483 if(srvret!=
"" && srvret!=
"void")
484 servs +=
"return _retvalue;\n}\n\n";
487 curemoteheaders += srvret+
" "+srvname+
"("+srvmcargremote+
");\n";
488 rsrvs += srvret+
" "+file+
"_Remote::"+srvname+
"("+srvmcargremote+
")\n{\n";
489 rsrvs += srvmcargremotevec;
490 if(srvret!=
"" && srvret!=
"void")
492 rsrvs +=
"*("+srvret+
"*)this->invoke(\""+srvname+
"\",_vec,\""+srvret+
"\");\n";
495 curemoteheaders +=
"};\n";
496 cudata +=
"}\n"+servs;
497 curemote +=
"}\n"+rsrvs;
498 cuheader += servsh +
"};\n";
499 cuheader = initheaders + cuheader+
"#endif";
500 curemoteheaders = cuinithdrs + curemoteheaders+
"#endif";
510 catch(
const char* ex)
513 logger <<
"Exception occurred" << flush;
518 throw "Error Parsing Component";