View Javadoc
1 /*** 2 Transformation - Transformations in Octopus Loader. 3 Copyright (C) 2002-2004 Together 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 This library is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 Lesser General Public License for more details. 12 You should have received a copy of the GNU Lesser General Public 13 License along with this library; if not, write to the Free Software 14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 Transformation.java 16 Date: 05.04.2004. 17 @version 1.0 18 @author: Zoran Milakovic zoran@prozone.co.yu 19 @author: Milosevic Sinisa sinisa@prozone.co.yu 20 */ 21 22 package org.webdocwf.util.loader.transformation; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 import java.util.Vector; 27 28 import org.w3c.dom.Document; 29 import org.webdocwf.util.loader.LoaderException; 30 import org.webdocwf.util.loader.OctopusXMLUtil; 31 import org.webdocwf.util.loader.logging.Logger; 32 33 /*** 34 * 35 * Transformation - transformations in Octopus Loader. 36 */ 37 public class Transformations { 38 39 40 public ArrayList transformations = new ArrayList(); 41 public ArrayList transformationsTableIDList = new ArrayList(); 42 public Logger logger; 43 44 private int iTransformationSourceColumsCnt = 0; 45 46 private Vector transformationNames = new Vector();// vector with names of all transformation tags(names from transformation tag) 47 private Vector transformationClassNames = new Vector();//vector with classNames of all transformation tags(className from transformation tag) 48 private Vector transformatorConfigNames = new Vector();//vector with configNames of all transformation tags(configName from transformation tag) 49 private Vector transformationsTargetColumnNames = new Vector();//vector with tableNames of all transformation tags(tableName from transformation tag) 50 private Vector transformationsTableNames = new Vector();//vector with tableNames of all transformation tags(tableName from transformation tag) 51 private Vector transformationsTableIDs = new Vector();//vector with tableIDs of all transformation tags(tableID from transformation tag) 52 private Vector transformationsValueModes = new Vector();//vector with valueMode of all transformation tags(valueMode from transformation tag) 53 54 /* cached data to avoid loops */ 55 56 //list with all source column names, of all transformations in this transformations tag 57 private List allTransformationsSourceColNames = new ArrayList(); 58 59 /*** 60 * Empty constructor of Transformations class 61 */ 62 public Transformations(Logger logger) { 63 64 this.transformationNames = new Vector(); 65 this.transformationClassNames = new Vector(); 66 this.transformatorConfigNames = new Vector(); 67 this.transformationsTableNames = new Vector(); 68 this.transformationsTableIDs = new Vector(); 69 this.transformationsTableIDList = new ArrayList(); 70 this.transformationsValueModes = new Vector(); 71 this.logger = logger; 72 } 73 74 /*** 75 * This method creates transformation elements with data from transformation tag (loaderJob.olj) 76 * @param doc represents Object document 77 * @param importJob represents current import job 78 */ 79 //Creates Vectors filled with data from transformation tag(name, transformatorClassName, transformatorConfig) 80 //and also from targetColumn tags(tableName, tableID). 81 public void createTransformationElements(Document doc, int importJob) throws LoaderException{ 82 //transformation tags 83 this.transformationNames = OctopusXMLUtil.importValue(doc,"transformation","name", importJob); 84 this.transformationClassNames = OctopusXMLUtil.importValue(doc,"transformation","transformatorClassName", importJob); 85 this.transformatorConfigNames = OctopusXMLUtil.importValue(doc,"transformation","transformatorConfig", importJob); 86 //targetColumn tags 87 this.transformationsTargetColumnNames =OctopusXMLUtil.importValue(doc,"targetColumn","name", importJob); 88 this.transformationsTableNames =OctopusXMLUtil.importValue(doc,"targetColumn","tableName", importJob); 89 this.transformationsTableIDs = OctopusXMLUtil.importValue(doc,"targetColumn","tableID", importJob); 90 this.transformationsValueModes = OctopusXMLUtil.importValue(doc,"targetColumn","valueMode", importJob); 91 92 createList(this.transformationsTableIDs); 93 try { 94 createTransformations(doc,importJob); 95 } catch (Exception e) { 96 throw new LoaderException("Error in Transformations.",e); 97 } 98 //count all transformations source columns 99 for(int i = 0; i < this.getTransformations().size(); i++) { 100 this.iTransformationSourceColumsCnt += ((Transformation)this.getTransformations().get(i)).getSourceColumnNames().size(); 101 } 102 } 103 /*** This method will create ArrayList from transTableIDs and transTableNames which are Vectors. 104 * @param transTableIDs represents target table names in importDefinition 105 */ 106 private void createList(Vector transTableIDs){ 107 for (int i = 0; i < transTableIDs.size(); i++) { 108 String tableID = transTableIDs.elementAt(i).toString(); 109 if (!transformationsTableIDList.contains(tableID)){ 110 transformationsTableIDList.add(tableID); 111 } 112 } 113 114 } 115 /*** 116 * This method will create new ArrayList with objects of Transformation class 117 * @param doc represents Object document 118 * @param importJob represents current import job 119 */ 120 private void createTransformations(Document doc, int iJobNumber) throws LoaderException{ 121 122 for(int i = 0; i < this.transformationNames.size(); i++) { 123 try { 124 Transformation newTransformation = new Transformation( 125 this.transformationNames.get(i).toString(), 126 this.transformationClassNames.get(i).toString(), 127 this.transformatorConfigNames.get(i).toString(), 128 OctopusXMLUtil.getDocumentFragment(doc,"transformation",i, iJobNumber) 129 ); 130 transformations.add(newTransformation); 131 allTransformationsSourceColNames.addAll( newTransformation.getSourceColumnNames() ); 132 }catch(ClassNotFoundException e) { 133 LoaderException le = new LoaderException("ClassNotFoundException for class "+this.transformationClassNames.get(i)+" while init transformation named : "+this.transformationNames.get(i)+"\n",e); 134 this.logger.write("normal", "\nError : ClassNotFoundException for class "+this.transformationClassNames.get(i)+" while init transformation named : "+this.transformationNames.get(i)+"\n"); 135 throw le; 136 }catch(Exception e) { 137 LoaderException le = new LoaderException("Exception while init transformation named : "+this.transformationNames.get(i)+"\n",e); 138 this.logger.write("normal", "\nError : Exception while init transformation named : "+this.transformationNames.get(i)+"\n"); 139 throw le; 140 } 141 } 142 143 } 144 145 /*** 146 * This method returns transform (ArrayList) in which are objects of class Transformation with data for each 147 * transformation tag in this importJob 148 */ 149 //returns array list with all Transformation objects 150 public ArrayList getTransformations() { 151 return transformations; 152 } 153 /*** 154 * This method returns transformationsTableIDs (ArrayList) 155 */ 156 //ZK added this for comparation which table has transformation tags or not 157 public ArrayList getTransformationsTableIDs() { 158 return transformationsTableIDList; 159 } 160 161 /*** 162 * This method reset all variables 163 */ 164 //reset transform (array list in which are placed transformation objects) 165 public void reset() { 166 167 this.transformationNames = new Vector(); 168 this.transformationsTargetColumnNames = new Vector(); 169 this.transformationClassNames = new Vector(); 170 this.transformatorConfigNames = new Vector(); 171 this.transformationsValueModes = new Vector(); 172 this.transformationsTableIDList = new ArrayList(); 173 this.transformations = new ArrayList(); 174 } 175 176 public int getTransformationSourceColumsCnt() { 177 return this.iTransformationSourceColumsCnt; 178 } 179 180 public List getAllTransformationSourceColNames() { 181 return this.allTransformationsSourceColNames; 182 } 183 184 }

This page was automatically generated by Maven