📄 transformations.java
字号:
/**
Transformation - Transformations in Octopus Loader.
Copyright (C) 2002-2004 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Transformation.java
Date: 05.04.2004.
@version 1.0
@author: Milosevic Sinisa sinisa@prozone.co.yu
*/
package org.webdocwf.util.loader.transformation;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.w3c.dom.Document;
import org.webdocwf.util.loader.LoaderException;
import org.webdocwf.util.loader.OctopusXMLUtil;
import org.webdocwf.util.loader.logging.Logger;
/**
*
* Transformation - transformations in Octopus Loader.
*/
public class Transformations {
public ArrayList transformations = new ArrayList();
public ArrayList transformationsTableIDList = new ArrayList();
public Logger logger;
private int iTransformationSourceColumsCnt = 0;
private Vector transformationNames = new Vector();// vector with names of all transformation tags(names from transformation tag)
private Vector transformationClassNames = new Vector();//vector with classNames of all transformation tags(className from transformation tag)
private Vector transformatorConfigNames = new Vector();//vector with configNames of all transformation tags(configName from transformation tag)
private Vector transformationsTargetColumnNames = new Vector();//vector with tableNames of all transformation tags(tableName from transformation tag)
private Vector transformationsTableNames = new Vector();//vector with tableNames of all transformation tags(tableName from transformation tag)
private Vector transformationsTableIDs = new Vector();//vector with tableIDs of all transformation tags(tableID from transformation tag)
private Vector transformationsValueModes = new Vector();//vector with valueMode of all transformation tags(valueMode from transformation tag)
/* cached data to avoid loops */
//list with all source column names, of all transformations in this transformations tag
private List allTransformationsSourceColNames = new ArrayList();
/**
* Empty constructor of Transformations class
*/
public Transformations(Logger logger) {
this.transformationNames = new Vector();
this.transformationClassNames = new Vector();
this.transformatorConfigNames = new Vector();
this.transformationsTableNames = new Vector();
this.transformationsTableIDs = new Vector();
this.transformationsTableIDList = new ArrayList();
this.transformationsValueModes = new Vector();
this.logger = logger;
}
/**
* This method creates transformation elements with data from transformation tag (loaderJob.olj)
* @param doc represents Object document
* @param importJob represents current import job
*/
//Creates Vectors filled with data from transformation tag(name, transformatorClassName, transformatorConfig)
//and also from targetColumn tags(tableName, tableID).
public void createTransformationElements(Document doc, int importJob) throws LoaderException{
//transformation tags
this.transformationNames = OctopusXMLUtil.importValue(doc,"transformation","name", importJob);
this.transformationClassNames = OctopusXMLUtil.importValue(doc,"transformation","transformatorClassName", importJob);
this.transformatorConfigNames = OctopusXMLUtil.importValue(doc,"transformation","transformatorConfig", importJob);
//targetColumn tags
this.transformationsTargetColumnNames =OctopusXMLUtil.importValue(doc,"targetColumn","name", importJob);
this.transformationsTableNames =OctopusXMLUtil.importValue(doc,"targetColumn","tableName", importJob);
this.transformationsTableIDs = OctopusXMLUtil.importValue(doc,"targetColumn","tableID", importJob);
this.transformationsValueModes = OctopusXMLUtil.importValue(doc,"targetColumn","valueMode", importJob);
createList(this.transformationsTableIDs);
try {
createTransformations(doc,importJob);
} catch (Exception e) {
throw new LoaderException("Error in Transformations.",e);
}
//count all transformations source columns
for(int i = 0; i < this.getTransformations().size(); i++) {
this.iTransformationSourceColumsCnt += ((Transformation)this.getTransformations().get(i)).getSourceColumnNames().size();
}
}
/** This method will create ArrayList from transTableIDs and transTableNames which are Vectors.
* @param transTableIDs represents target table names in importDefinition
*/
private void createList(Vector transTableIDs){
for (int i = 0; i < transTableIDs.size(); i++) {
String tableID = transTableIDs.elementAt(i).toString();
if (!transformationsTableIDList.contains(tableID)){
transformationsTableIDList.add(tableID);
}
}
}
/**
* This method will create new ArrayList with objects of Transformation class
* @param doc represents Object document
* @param importJob represents current import job
*/
private void createTransformations(Document doc, int iJobNumber) throws LoaderException{
for(int i = 0; i < this.transformationNames.size(); i++) {
try {
Transformation newTransformation = new Transformation(
this.transformationNames.get(i).toString(),
this.transformationClassNames.get(i).toString(),
this.transformatorConfigNames.get(i).toString(),
OctopusXMLUtil.getDocumentFragment(doc,"transformation",i, iJobNumber)
);
transformations.add(newTransformation);
allTransformationsSourceColNames.addAll( newTransformation.getSourceColumnNames() );
}catch(ClassNotFoundException e) {
LoaderException le = new LoaderException("ClassNotFoundException for class "+this.transformationClassNames.get(i)+" while init transformation named : "+this.transformationNames.get(i)+"\n",e);
this.logger.write("normal", "\nError : ClassNotFoundException for class "+this.transformationClassNames.get(i)+" while init transformation named : "+this.transformationNames.get(i)+"\n");
throw le;
}catch(Exception e) {
LoaderException le = new LoaderException("Exception while init transformation named : "+this.transformationNames.get(i)+"\n",e);
this.logger.write("normal", "\nError : Exception while init transformation named : "+this.transformationNames.get(i)+"\n");
throw le;
}
}
}
/**
* This method returns transform (ArrayList) in which are objects of class Transformation with data for each
* transformation tag in this importJob
*/
//returns array list with all Transformation objects
public ArrayList getTransformations() {
return transformations;
}
/**
* This method returns transformationsTableIDs (ArrayList)
*/
//ZK added this for comparation which table has transformation tags or not
public ArrayList getTransformationsTableIDs() {
return transformationsTableIDList;
}
/**
* This method reset all variables
*/
//reset transform (array list in which are placed transformation objects)
public void reset() {
this.transformationNames = new Vector();
this.transformationsTargetColumnNames = new Vector();
this.transformationClassNames = new Vector();
this.transformatorConfigNames = new Vector();
this.transformationsValueModes = new Vector();
this.transformationsTableIDList = new ArrayList();
this.transformations = new ArrayList();
}
public int getTransformationSourceColumsCnt() {
return this.iTransformationSourceColumsCnt;
}
public List getAllTransformationSourceColNames() {
return this.allTransformationsSourceColNames;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -