KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > generator > WriteImportDefinition


1
2 /*
3 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
4
5
6     Copyright (C) 2003 Together
7
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     Lesser General Public License for more details.
17
18     You should have received a copy of the GNU Lesser General Public
19     License along with this library; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */

22
23 package org.webdocwf.util.loader.generator;
24
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27 import org.webdocwf.util.loader.LoaderException;
28 import org.webdocwf.util.loader.logging.Logger;
29 import org.webdocwf.util.loader.logging.StandardLogger;
30
31 /**
32  *
33  * WriteImportDefinition class creates ImportDefinition.xml file.
34  * @author Radoslav Dutina
35  * @version 1.0
36  */

37 public class WriteImportDefinition {
38     private Logger logger;
39
40     /**
41      * Construct object WriteImportDefinition with associated parameters.
42      * @param document is the org.w3c.dom.Document object, which is created in CreateIncludeFile class.
43      * @param root is the root element from document object.
44      * @param importDefinitionAttributes is references to ImportDefinitionAttributes object.
45      * @param generatorParameters represents the references to InputParameter object.
46      * @throws LoaderException
47      */

48
49     public WriteImportDefinition(Document JavaDoc document, Element JavaDoc root, ImportDefinitionAttributes importDefinitionAttributes, InputParameters generatorParameters) throws LoaderException {
50                 setLogger();
51                 this.logger.write("full", "WriteImportDefinition is started.");
52         if (!generatorParameters.getFullMode()) {
53
54             Element JavaDoc childRoot1 = (Element JavaDoc) document.createElement("copyTable");
55             root.appendChild(childRoot1);
56             childRoot1.setAttribute("name", importDefinitionAttributes.getName());
57             childRoot1.setAttribute("sourceTableName", importDefinitionAttributes.getName());
58             childRoot1.setAttribute("targetTableName", importDefinitionAttributes.getName());
59             // childRoot1.setAttribute("logMode", importDefinitionAttributes.getLogMode());
60
childRoot1.setAttribute("objectIDIncrement", importDefinitionAttributes.getObjectIDIncrementid());
61             childRoot1.setAttribute("oidLogic", "false");
62             childRoot1.setAttribute("onErrorContinue", "false");
63
64         } else {
65             Element JavaDoc childRoot1 = (Element JavaDoc) document.createElement("importDefinition");
66             root.appendChild(childRoot1);
67             childRoot1.setAttribute("name", importDefinitionAttributes.getName());
68             childRoot1.setAttribute("tableName", importDefinitionAttributes.getTableName());
69             //childRoot1.setAttribute("objectIDIncrement", importDefinitionAttributes.getObjectIDIncrementid());
70
// childRoot1.setAttribute("logMode", importDefinitionAttributes.getLogMode());
71

72             Element JavaDoc childRoot2 = (Element JavaDoc) document.createElement("valueColumns");
73             childRoot1.appendChild(childRoot2);
74
75             for (int i = 0; i < importDefinitionAttributes.getTagSourceColumnName().length; i++) {
76                 if (generatorParameters.getSourceType().equalsIgnoreCase("csv")) {
77                     Element JavaDoc childRoot3 = (Element JavaDoc) document.createElement("valueColumn");
78                     childRoot2.appendChild(childRoot3);
79                     childRoot3.setAttribute("sourceColumnName", importDefinitionAttributes.getTagSourceColumnName()[i]);
80                     childRoot3.setAttribute("targetTableName", importDefinitionAttributes.getTagTargetTableName()[i]);
81                     childRoot3.setAttribute("targetColumnName", importDefinitionAttributes.getTagTargetColumnName()[i]);
82                     childRoot3.setAttribute("targetTableID", importDefinitionAttributes.getTagTargetTableID()[i]);
83                     childRoot3.setAttribute("valueMode", generatorParameters.getValueMode());
84                 } else {
85                     if (!generatorParameters.getValueMode().equalsIgnoreCase("Overwrite")) {
86                         if (!importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("oid") && !importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("version")) {
87                             boolean fk = true;
88                             for (int j = 0; j < RelationshipsAttributes.getForeignVariables().length; j = j + 5) {
89                                 if (RelationshipsAttributes.getForeignVariables()[j + 2].equalsIgnoreCase(importDefinitionAttributes.getTagSourceColumnName()[i])) {
90                                     fk = false;
91                                     break;
92                                 }
93                             }
94                             if (fk) {
95                                 Element JavaDoc childRoot3 = (Element JavaDoc) document.createElement("valueColumn");
96                                 childRoot2.appendChild(childRoot3);
97                                 childRoot3.setAttribute("sourceColumnName", importDefinitionAttributes.getTagSourceColumnName()[i]);
98                                 childRoot3.setAttribute("targetTableName", importDefinitionAttributes.getTagTargetTableName()[i]);
99                                 childRoot3.setAttribute("targetColumnName", importDefinitionAttributes.getTagTargetColumnName()[i]);
100                                 childRoot3.setAttribute("targetTableID", importDefinitionAttributes.getTagTargetTableID()[i]);
101                                 childRoot3.setAttribute("valueMode", generatorParameters.getValueMode());
102
103                             }
104                         }
105                     } else {
106 // if (!importDefinitionAttributes.getTagSourceColumnName()[i].equalsIgnoreCase("version")) {
107
if (!importDefinitionAttributes.getTagColumnType()[i].toLowerCase().endsWith("identity")) {
108                                 Element JavaDoc childRoot3 = (Element JavaDoc) document.createElement("valueColumn");
109                                 childRoot2.appendChild(childRoot3);
110                                 childRoot3.setAttribute("sourceColumnName", importDefinitionAttributes.getTagSourceColumnName()[i]);
111                                 childRoot3.setAttribute("targetTableName", importDefinitionAttributes.getTagTargetTableName()[i]);
112                                 childRoot3.setAttribute("targetColumnName", importDefinitionAttributes.getTagTargetColumnName()[i]);
113                                 childRoot3.setAttribute("targetTableID", importDefinitionAttributes.getTagTargetTableID()[i]);
114                                 childRoot3.setAttribute("valueMode", generatorParameters.getValueMode());
115                             }
116 // } else {
117
// Element childRoot5 = (Element) document.createElement("constantColumns");
118
// childRoot1.appendChild(childRoot5);
119
// Element childRoot3 = (Element) document.createElement("constantColumn");
120
// childRoot5.appendChild(childRoot3);
121
// childRoot3.setAttribute("constantValue", "0");
122
// childRoot3.setAttribute("targetTableName", importDefinitionAttributes.getTagTargetTableName()[i]);
123
// childRoot3.setAttribute("targetColumnName", "version");
124
// childRoot3.setAttribute("targetTableID", "0");
125
// childRoot3.setAttribute("valueMode", generatorParameters.getValueMode());
126
// }
127
}
128                 }
129             }
130
131             if (!generatorParameters.getSourceType().equalsIgnoreCase("csv")) {
132                 int j = 0;
133                 if (generatorParameters.getValueMode().equalsIgnoreCase("Overwrite")) {
134                     //
135
} else {
136                     //valueMode=Overwrite
137
if (RelationshipsAttributes.getForeignVariables().length != 0) {
138                         Element JavaDoc childRoot100 = (Element JavaDoc) document.createElement("relationColumns");
139                         childRoot1.appendChild(childRoot100);
140                         for (int i = 0; i < RelationshipsAttributes.getForeignVariables().length; i = i + 5) {
141                             Element JavaDoc childRoot101 = (Element JavaDoc) document.createElement("relationColumn");
142                             childRoot100.appendChild(childRoot101);
143                             childRoot101.setAttribute("relationSourceTableName", RelationshipsAttributes.getForeignVariables()[i + 3]);
144                             childRoot101.setAttribute("relationTargetTableName", importDefinitionAttributes.getTableName());
145                             childRoot101.setAttribute("relationTargetColumnName", RelationshipsAttributes.getForeignVariables()[i + 2]);
146
147                             if (i > 5 && RelationshipsAttributes.getForeignVariables()[i + 3].equalsIgnoreCase(RelationshipsAttributes.getForeignVariables()[(i + 3) - 5])) {
148                                 j = j + 1;
149                             } else {
150                                 j = 0;
151                             }
152                             childRoot101.setAttribute("relationSourceTableID", "" + j);
153                             childRoot101.setAttribute("relationTargetTableID", "0");
154                             childRoot101.setAttribute("relationMode", generatorParameters.getValueMode());
155                         }
156                     }
157                 }
158
159                 int k = 0;
160                 int l = 0;
161                 if (RelationshipsAttributes.getForeignVariables().length != 0) {
162                     Element JavaDoc childRoot200 = (Element JavaDoc) document.createElement("tables");
163                     childRoot1.appendChild(childRoot200);
164                     for (int i = 0; i < RelationshipsAttributes.getForeignVariables().length; i = i + 5) {
165                         TableAttributes tableAttributes = new TableAttributes(importDefinitionAttributes.getTableName(), generatorParameters.getValueMode());
166                         if (l == 0) {
167                             //in the first loop
168
Element JavaDoc childRoot201 = (Element JavaDoc) document.createElement("table");
169                             childRoot200.appendChild(childRoot201);
170                             childRoot201.setAttribute("tableName", tableAttributes.getTableName());
171                             childRoot201.setAttribute("tableID", "" + k);
172                             childRoot201.setAttribute("insert", tableAttributes.getInsert());
173                             childRoot201.setAttribute("tableMode", tableAttributes.getTableMode());
174                             childRoot201.setAttribute("oidLogic", tableAttributes.getOidLogic());
175                             l++;
176                             k++;
177                         }
178                         if (generatorParameters.getValueMode().equalsIgnoreCase("Overwrite")) {
179                             //
180
} else {
181                             //valueMode=Overwrite
182
if (RelationshipsAttributes.getForeignVariables()[i + 3].equalsIgnoreCase(importDefinitionAttributes.getTableName())) {
183                                 //k=k+1
184
Element JavaDoc childRoot202 = (Element JavaDoc) document.createElement("table");
185                                 childRoot200.appendChild(childRoot202);
186                                 childRoot202.setAttribute("tableName", tableAttributes.getTableName());
187                                 childRoot202.setAttribute("tableID", "" + k);
188                                 childRoot202.setAttribute("insert", "false");
189                                 childRoot202.setAttribute("tableMode", tableAttributes.getTableMode());
190                                 childRoot202.setAttribute("oidLogic", tableAttributes.getOidLogic());
191                                 k++; //
192
} else {
193                                 k = 0;
194                                 if (i > 5 && RelationshipsAttributes.getForeignVariables()[i + 3].equalsIgnoreCase(RelationshipsAttributes.getForeignVariables()[(i + 3) - 5])) {
195                                     k = k + 1;
196                                 } else {
197                                     k = 0;
198                                 }
199                                 Element JavaDoc childRoot205 = (Element JavaDoc) document.createElement("table");
200                                 childRoot200.appendChild(childRoot205);
201                                 childRoot205.setAttribute("tableName", RelationshipsAttributes.getForeignVariables()[i + 3]);
202                                 childRoot205.setAttribute("tableID", "" + k);
203                                 childRoot205.setAttribute("insert", "false");
204                                 childRoot205.setAttribute("tableMode", tableAttributes.getTableMode());
205                                 childRoot205.setAttribute("oidLogic", tableAttributes.getOidLogic());
206                             }
207                         }
208                     }
209                 } else {
210                     //RelationshipsAttributes.getForeignVariables().length==0
211
Element JavaDoc childRoot200 = (Element JavaDoc) document.createElement("tables");
212                     childRoot1.appendChild(childRoot200);
213                     Element JavaDoc childRoot203 = (Element JavaDoc) document.createElement("table");
214                     childRoot200.appendChild(childRoot203);
215                     TableAttributes tableAttributes = new TableAttributes(importDefinitionAttributes.getTableName(), generatorParameters.getValueMode());
216                     childRoot203.setAttribute("tableName", tableAttributes.getTableName());
217                     childRoot203.setAttribute("tableID", "" + k);
218                     childRoot203.setAttribute("insert", tableAttributes.getInsert());
219                     childRoot203.setAttribute("tableMode", tableAttributes.getTableMode());
220                     childRoot203.setAttribute("oidLogic", tableAttributes.getOidLogic());
221                 }
222             } else {
223                 //for csv tables
224
Element JavaDoc childRoot200 = (Element JavaDoc) document.createElement("tables");
225                 childRoot1.appendChild(childRoot200);
226                 Element JavaDoc childRoot201 = (Element JavaDoc) document.createElement("table");
227                 childRoot200.appendChild(childRoot201);
228                 TableAttributes tableAttributes = new TableAttributes(importDefinitionAttributes.getTableName(), generatorParameters.getValueMode());
229                 childRoot201.setAttribute("tableName", tableAttributes.getTableName());
230                 childRoot201.setAttribute("tableID", tableAttributes.getTableID());
231                 childRoot201.setAttribute("insert", tableAttributes.getInsert());
232                 childRoot201.setAttribute("tableMode", tableAttributes.getTableMode());
233                 childRoot201.setAttribute("oidLogic", tableAttributes.getOidLogic());
234
235             }
236         }
237         this.logger.write("full", "WriteImportDefinition is finished.");
238     }
239     /**
240                     * This method will set logger object
241                     * @param logger
242                       */

243     private void setLogger() {
244         this.logger = StandardLogger.getCentralLogger();
245     }
246 }
247
Popular Tags