23 #include "FFEADContext.h"
25 FFEADContext::FFEADContext(
string depFile)
28 Element root = parser.getDocument(depFile).getRootElement();
29 ElementList eles = root.getChildElements();
30 vector<string> beanchk;
31 if(eles.size()>0 && root.getTagName()==
"beans")
33 for (
unsigned int var = 0; var < eles.size(); var++)
36 if(ele.getTagName()==
"bean")
39 bean.name = ele.getAttribute(
"name");
40 bean.value = ele.getAttribute(
"value");
41 bean.inbuilt = ele.getAttribute(
"inbuilt");
42 if(ele.getAttribute(
"bean")!=
"")
43 throw "Invalid attribute";
44 bean.bean = ele.getAttribute(
"bean");
45 bean.clas = ele.getAttribute(
"class");
46 bean.intfType = ele.getAttribute(
"intfType");
47 bean.injectAs = ele.getAttribute(
"injectAs");
49 ElementList eleeles = ele.getChildElements();
56 for (
unsigned int var1 = 0; var1 < eleeles.size(); var1++)
58 Element ele1 = eleeles.at(var1);
59 if(ele1.getTagName()==
"inject")
61 if(ele1.getAttribute(
"bean")!=
"")
63 beanchk.push_back(ele1.getAttribute(
"bean"));
64 bean.injs.push_back(ele1.getAttribute(
"bean"));
65 if(ele1.getAttribute(
"name")!=
"")
66 bean.names.push_back(ele1.getAttribute(
"name"));
68 bean.names.push_back(ele1.getAttribute(
"bean"));
69 bean.types.push_back(ele1.getAttribute(
"intfType"));
74 beanc.name = ele1.getAttribute(
"name");
75 beanc.value = ele1.getAttribute(
"value");
76 beanc.inbuilt = ele1.getAttribute(
"inbuilt");
77 beanc.clas = ele1.getAttribute(
"class");
78 beanc.intfType = ele1.getAttribute(
"intfType");
79 beanc.realbean =
false;
80 injbns[beanc.name] = beanc;
81 bean.injs.push_back(beanc.name);
82 bean.names.push_back(beanc.name);
91 beans[bean.name] = bean;
101 FFEADContext::~FFEADContext()
106 void* FFEADContext::getBean(
Bean bean)
110 if(bean.inbuilt!=
"" && bean.value!=
"")
113 if(bean.inbuilt==
"string")
115 string *in =
new string(bean.value);
118 else if(bean.inbuilt==
"int")
121 *in = CastUtil::lexical_cast<
int>(bean.value);
124 else if(bean.inbuilt==
"flaot")
126 float *in =
new float;
127 *in = CastUtil::lexical_cast<
float>(bean.value);
130 else if(bean.inbuilt==
"double")
132 double *in =
new double;
133 *in = CastUtil::lexical_cast<
double>(bean.value);
136 else if(bean.inbuilt==
"long")
139 *in = CastUtil::lexical_cast<
long>(bean.value);
142 else if(bean.inbuilt==
"bool")
145 if(bean.value==
"true")
147 else if(bean.value==
"false")
151 else if(bean.inbuilt==
"char")
158 else if(bean.inbuilt!=
"" && bean.value==
"")
160 throw "Invalid value for inbuilt type";
162 else if(bean.injectAs==
"" || bean.injs.size()==0)
166 ClassInfo clas = reflector.getClassInfo(bean.clas);
168 _temp = reflector.newInstanceGVP(ctor);
171 else if(bean.injectAs==
"prop")
177 ClassInfo clas = reflector.getClassInfo(bean.clas);
179 _temp = reflector.newInstanceGVP(ctor);
180 for (
unsigned int var = 0; var < bean.injs.size(); var++)
182 Bean beanc = injbns[bean.injs.at(var)];
184 beanc = beans[bean.injs.at(var)];
185 string methodName(
"set");
186 methodName += AfcUtil::camelCased(bean.names.at(var));
187 if(beanc.inbuilt!=
"")
188 argus.push_back(beanc.inbuilt);
189 else if(beanc.clas!=
"")
190 argus.push_back(beanc.clas);
192 throw "Invalid or no bean type defined";
193 Method meth = clas.getMethod(methodName,argus);
194 void *value = getBean(beanc);
195 valus.push_back(value);
196 reflector.invokeMethod<
void*>(_temp,meth,valus);
201 else if(bean.injectAs==
"cons")
207 ClassInfo clas = reflector.getClassInfo(bean.clas);
208 for (
unsigned int var = 0; var < bean.injs.size(); var++)
210 Bean beanc = injbns[bean.injs.at(var)];
212 beanc = beans[bean.injs.at(var)];
213 if(beanc.inbuilt!=
"")
214 argus.push_back(beanc.inbuilt);
215 else if(beanc.clas!=
"")
216 argus.push_back(beanc.clas);
218 throw "Invalid or no bean type defined";
219 void *value = getBean(beanc);
220 valus.push_back(value);
223 _temp = reflector.newInstanceGVP(ctor,valus);
225 else if(bean.injectAs==
"intf")
231 ClassInfo clas = reflector.getClassInfo(bean.clas);
233 _temp = reflector.newInstanceGVP(ctor);
234 for (
unsigned int var = 0; var < bean.injs.size(); var++)
236 Bean beanc = injbns[bean.injs.at(var)];
238 beanc = beans[bean.injs.at(var)];
239 string methodName(
"set");
240 methodName += AfcUtil::camelCased(bean.names.at(var));
241 if(bean.types.at(var)!=
"")
242 argus.push_back(bean.types.at(var));
244 throw "Invalid or no bean type defined";
245 Method meth = clas.getMethod(methodName,argus);
246 void *value = getBean(beanc);
247 valus.push_back(value);
248 reflector.invokeMethod<
void*>(_temp,meth,valus);
253 objects[type] = _temp;
257 void* FFEADContext::getBean(
string beanName)
259 Bean bean = beans[beanName];
260 return getBean(bean);
264 void FFEADContext::clear()
268 map<string,void*>::iterator objectsIter;
269 for (objectsIter=objects.begin();objectsIter != objects.end();objectsIter++)
271 if(objectsIter->first==
"string" || objectsIter->first==
"int" || objectsIter->first==
"long"
272 || objectsIter->first==
"double" || objectsIter->first==
"float" || objectsIter->first==
"bool"
273 || objectsIter->first==
"char")
274 delete objectsIter->second;
278 reflector.destroy(objectsIter->second,objectsIter->first);