1 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 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 (); private Vector transformationClassNames = new Vector (); private Vector transformatorConfigNames = new Vector (); private Vector transformationsTargetColumnNames = new Vector (); private Vector transformationsTableNames = new Vector (); private Vector transformationsTableIDs = new Vector (); private Vector transformationsValueModes = new Vector (); 54 55 56 private List allTransformationsSourceColNames = new ArrayList (); 58 59 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 79 public void createTransformationElements(Document doc, int importJob) throws LoaderException{ 82 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 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 for(int i = 0; i < this.getTransformations().size(); i++) { 100 this.iTransformationSourceColumsCnt += ((Transformation)this.getTransformations().get(i)).getSourceColumnNames().size(); 101 } 102 } 103 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 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 149 public ArrayList getTransformations() { 151 return transformations; 152 } 153 156 public ArrayList getTransformationsTableIDs() { 158 return transformationsTableIDList; 159 } 160 161 164 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 } 185 | Popular Tags |