001: /**
002: Transformation - Transformations in Octopus Loader.
003: Copyright (C) 2002-2004 Together
004: This library is free software; you can redistribute it and/or
005: modify it under the terms of the GNU Lesser General Public
006: License as published by the Free Software Foundation; either
007: version 2.1 of the License, or (at your option) any later version.
008: This library is distributed in the hope that it will be useful,
009: but WITHOUT ANY WARRANTY; without even the implied warranty of
010: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: Lesser General Public License for more details.
012: You should have received a copy of the GNU Lesser General Public
013: License along with this library; if not, write to the Free Software
014: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
015: Transformation.java
016: Date: 05.04.2004.
017: @version 1.0
018: @author: Zoran Milakovic zoran@prozone.co.yu
019: @author: Milosevic Sinisa sinisa@prozone.co.yu
020: */package org.webdocwf.util.loader.transformation;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024: import java.util.Vector;
025:
026: import org.w3c.dom.Document;
027: import org.webdocwf.util.loader.LoaderException;
028: import org.webdocwf.util.loader.OctopusXMLUtil;
029: import org.webdocwf.util.loader.logging.Logger;
030:
031: /**
032: *
033: * Transformation - transformations in Octopus Loader.
034: */
035: public class Transformations {
036:
037: public ArrayList transformations = new ArrayList();
038: public ArrayList transformationsTableIDList = new ArrayList();
039: public Logger logger;
040:
041: private int iTransformationSourceColumsCnt = 0;
042:
043: private Vector transformationNames = new Vector();// vector with names of all transformation tags(names from transformation tag)
044: private Vector transformationClassNames = new Vector();//vector with classNames of all transformation tags(className from transformation tag)
045: private Vector transformatorConfigNames = new Vector();//vector with configNames of all transformation tags(configName from transformation tag)
046: private Vector transformationsTargetColumnNames = new Vector();//vector with tableNames of all transformation tags(tableName from transformation tag)
047: private Vector transformationsTableNames = new Vector();//vector with tableNames of all transformation tags(tableName from transformation tag)
048: private Vector transformationsTableIDs = new Vector();//vector with tableIDs of all transformation tags(tableID from transformation tag)
049: private Vector transformationsValueModes = new Vector();//vector with valueMode of all transformation tags(valueMode from transformation tag)
050:
051: /* cached data to avoid loops */
052:
053: //list with all source column names, of all transformations in this transformations tag
054: private List allTransformationsSourceColNames = new ArrayList();
055:
056: /**
057: * Empty constructor of Transformations class
058: */
059: public Transformations(Logger logger) {
060:
061: this .transformationNames = new Vector();
062: this .transformationClassNames = new Vector();
063: this .transformatorConfigNames = new Vector();
064: this .transformationsTableNames = new Vector();
065: this .transformationsTableIDs = new Vector();
066: this .transformationsTableIDList = new ArrayList();
067: this .transformationsValueModes = new Vector();
068: this .logger = logger;
069: }
070:
071: /**
072: * This method creates transformation elements with data from transformation tag (loaderJob.olj)
073: * @param doc represents Object document
074: * @param importJob represents current import job
075: */
076: //Creates Vectors filled with data from transformation tag(name, transformatorClassName, transformatorConfig)
077: //and also from targetColumn tags(tableName, tableID).
078: public void createTransformationElements(Document doc, int importJob)
079: throws LoaderException {
080: //transformation tags
081: this .transformationNames = OctopusXMLUtil.importValue(doc,
082: "transformation", "name", importJob);
083: this .transformationClassNames = OctopusXMLUtil.importValue(doc,
084: "transformation", "transformatorClassName", importJob);
085: this .transformatorConfigNames = OctopusXMLUtil.importValue(doc,
086: "transformation", "transformatorConfig", importJob);
087: //targetColumn tags
088: this .transformationsTargetColumnNames = OctopusXMLUtil
089: .importValue(doc, "targetColumn", "name", importJob);
090: this .transformationsTableNames = OctopusXMLUtil.importValue(
091: doc, "targetColumn", "tableName", importJob);
092: this .transformationsTableIDs = OctopusXMLUtil.importValue(doc,
093: "targetColumn", "tableID", importJob);
094: this .transformationsValueModes = OctopusXMLUtil.importValue(
095: doc, "targetColumn", "valueMode", importJob);
096:
097: createList(this .transformationsTableIDs);
098: try {
099: createTransformations(doc, importJob);
100: } catch (Exception e) {
101: throw new LoaderException("Error in Transformations.", e);
102: }
103: //count all transformations source columns
104: for (int i = 0; i < this .getTransformations().size(); i++) {
105: this .iTransformationSourceColumsCnt += ((Transformation) this
106: .getTransformations().get(i))
107: .getSourceColumnNames().size();
108: }
109: }
110:
111: /** This method will create ArrayList from transTableIDs and transTableNames which are Vectors.
112: * @param transTableIDs represents target table names in importDefinition
113: */
114: private void createList(Vector transTableIDs) {
115: for (int i = 0; i < transTableIDs.size(); i++) {
116: String tableID = transTableIDs.elementAt(i).toString();
117: if (!transformationsTableIDList.contains(tableID)) {
118: transformationsTableIDList.add(tableID);
119: }
120: }
121:
122: }
123:
124: /**
125: * This method will create new ArrayList with objects of Transformation class
126: * @param doc represents Object document
127: * @param importJob represents current import job
128: */
129: private void createTransformations(Document doc, int iJobNumber)
130: throws LoaderException {
131:
132: for (int i = 0; i < this .transformationNames.size(); i++) {
133: try {
134: Transformation newTransformation = new Transformation(
135: this .transformationNames.get(i).toString(),
136: this .transformationClassNames.get(i).toString(),
137: this .transformatorConfigNames.get(i).toString(),
138: OctopusXMLUtil.getDocumentFragment(doc,
139: "transformation", i, iJobNumber));
140: transformations.add(newTransformation);
141: allTransformationsSourceColNames
142: .addAll(newTransformation
143: .getSourceColumnNames());
144: } catch (ClassNotFoundException e) {
145: LoaderException le = new LoaderException(
146: "ClassNotFoundException for class "
147: + this .transformationClassNames.get(i)
148: + " while init transformation named : "
149: + this .transformationNames.get(i)
150: + "\n", e);
151: this .logger
152: .write(
153: "normal",
154: "\nError : ClassNotFoundException for class "
155: + this .transformationClassNames
156: .get(i)
157: + " while init transformation named : "
158: + this .transformationNames
159: .get(i) + "\n");
160: throw le;
161: } catch (Exception e) {
162: LoaderException le = new LoaderException(
163: "Exception while init transformation named : "
164: + this .transformationNames.get(i)
165: + "\n", e);
166: this .logger.write("normal",
167: "\nError : Exception while init transformation named : "
168: + this .transformationNames.get(i)
169: + "\n");
170: throw le;
171: }
172: }
173:
174: }
175:
176: /**
177: * This method returns transform (ArrayList) in which are objects of class Transformation with data for each
178: * transformation tag in this importJob
179: */
180: //returns array list with all Transformation objects
181: public ArrayList getTransformations() {
182: return transformations;
183: }
184:
185: /**
186: * This method returns transformationsTableIDs (ArrayList)
187: */
188: //ZK added this for comparation which table has transformation tags or not
189: public ArrayList getTransformationsTableIDs() {
190: return transformationsTableIDList;
191: }
192:
193: /**
194: * This method reset all variables
195: */
196: //reset transform (array list in which are placed transformation objects)
197: public void reset() {
198:
199: this .transformationNames = new Vector();
200: this .transformationsTargetColumnNames = new Vector();
201: this .transformationClassNames = new Vector();
202: this .transformatorConfigNames = new Vector();
203: this .transformationsValueModes = new Vector();
204: this .transformationsTableIDList = new ArrayList();
205: this .transformations = new ArrayList();
206: }
207:
208: public int getTransformationSourceColumsCnt() {
209: return this .iTransformationSourceColumsCnt;
210: }
211:
212: public List getAllTransformationSourceColNames() {
213: return this.allTransformationsSourceColNames;
214: }
215:
216: }
|