|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.ericmignot.modeler.helpers.data; |
|
19 |
| |
|
20 |
| import java.io.UnsupportedEncodingException; |
|
21 |
| import java.net.URLDecoder; |
|
22 |
| |
|
23 |
| import org.ericmignot.modeler.data.BusinessObject; |
|
24 |
| import org.ericmignot.modeler.data.Model; |
|
25 |
| import org.ericmignot.modeler.util.xml.XMLHelper; |
|
26 |
| import org.w3c.dom.Element; |
|
27 |
| import org.w3c.dom.NodeList; |
|
28 |
| |
|
29 |
| public class BusinessObjectFactory { |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| private static BusinessObjectFactory uniqueInstance; |
|
35 |
105
| public static BusinessObjectFactory getInstance()
|
|
36 |
| { |
|
37 |
105
| if (BusinessObjectFactory.uniqueInstance == null)
|
|
38 |
| { |
|
39 |
1
| BusinessObjectFactory.uniqueInstance = new BusinessObjectFactory();
|
|
40 |
| } |
|
41 |
105
| return BusinessObjectFactory.uniqueInstance;
|
|
42 |
| } |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
17
| public BusinessObject createBusinessObject(String xml, Model model)
|
|
50 |
| { |
|
51 |
17
| Element bo = XMLHelper.getFirstElementByName(xml, "BusinessObject");
|
|
52 |
17
| return this.createBusinessObject(bo, model);
|
|
53 |
| } |
|
54 |
| |
|
55 |
106
| public BusinessObject createBusinessObject(Element bo, Model model)
|
|
56 |
| { |
|
57 |
106
| BusinessObject toReturn =null;
|
|
58 |
| |
|
59 |
106
| String className = bo.getAttributes().getNamedItem("class").getNodeValue();
|
|
60 |
106
| try {
|
|
61 |
106
| toReturn = (BusinessObject) Class.forName(className).newInstance();
|
|
62 |
| } catch (InstantiationException e) { |
|
63 |
0
| e.printStackTrace();
|
|
64 |
0
| return null;
|
|
65 |
| } catch (IllegalAccessException e) { |
|
66 |
0
| e.printStackTrace();
|
|
67 |
0
| return null;
|
|
68 |
| } catch (ClassNotFoundException e) { |
|
69 |
0
| e.printStackTrace();
|
|
70 |
0
| return null;
|
|
71 |
| } |
|
72 |
| |
|
73 |
106
| NodeList paramList = bo.getElementsByTagName("Param");
|
|
74 |
106
| for (int j = 0; j < paramList.getLength(); j++)
|
|
75 |
| { |
|
76 |
381
| Element param = (Element) paramList.item(j);
|
|
77 |
381
| String paramName = param.getAttributes().getNamedItem("Name").getNodeValue();
|
|
78 |
381
| String paramValue = param.getAttributes().getNamedItem("Value").getNodeValue();
|
|
79 |
381
| try {
|
|
80 |
381
| paramValue = URLDecoder.decode(paramValue, "utf-8");
|
|
81 |
| } catch (UnsupportedEncodingException e) { |
|
82 |
0
| e.printStackTrace();
|
|
83 |
| } |
|
84 |
381
| toReturn.setFieldValue(paramName, paramValue);
|
|
85 |
| } |
|
86 |
| |
|
87 |
106
| NodeList referenceList = bo.getElementsByTagName("Reference");
|
|
88 |
106
| for (int j = 0; j < referenceList.getLength(); j++)
|
|
89 |
| { |
|
90 |
70
| Element reference = (Element) referenceList.item(j);
|
|
91 |
70
| String type = reference.getAttributes().getNamedItem("Type").getNodeValue();
|
|
92 |
70
| String Id = reference.getAttributes().getNamedItem("Id").getNodeValue();
|
|
93 |
70
| BusinessObject referenceValue = model.getBusinessObjectById(type, Long.parseLong(Id));
|
|
94 |
70
| if (referenceValue != null)
|
|
95 |
| { |
|
96 |
70
| String referenceName = reference.getAttributes().getNamedItem("Name").getNodeValue();
|
|
97 |
70
| toReturn.setReference(referenceName, referenceValue);
|
|
98 |
| } |
|
99 |
| } |
|
100 |
| |
|
101 |
106
| return toReturn;
|
|
102 |
| } |
|
103 |
| } |