📄 transformation.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.lang.reflect.Constructor;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.webdocwf.util.loader.ConfigReader;
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 Transformation {
private String transformationName;
private String transformationClassName;
private String transformatorConfigName;
private Vector sourceColumnNames = new Vector();
private List transformationTargetColumns = new ArrayList();
private Transformer transformer;
private Logger logger;
private JavaScriptEvaluator jsEvaluator;
private Element transformationDocFragment;
public Transformation(String name, String className, String configString, Element doc) throws Exception {
this.transformationName = name;
this.transformationClassName = className;
this.transformatorConfigName = configString;
this.transformationDocFragment = doc;
String javaScriptExpression = "";
NodeList childNodes = this.transformationDocFragment.getElementsByTagName("javaScript");
if ( childNodes.item(0) != null ){
javaScriptExpression = childNodes.item(0).getFirstChild().getNodeValue();
}
try {
init();
if (javaScriptExpression != ""){
//instantiate JavaScriptEvaluator for transformation with javaScript
jsEvaluator = new JavaScriptEvaluator();
jsEvaluator.setExpression(javaScriptExpression);
jsEvaluator.setVariableNames(this.sourceColumnNames);
this.transformer = (Transformer) jsEvaluator;
}else{
//instantiate transformer
Class transformatorClass = Class.forName(this.transformationClassName);
Class[] ArgClassArray = new Class[] { };
Object[] ArgObject = new Object[] { };
Constructor transConstructor = transformatorClass.getDeclaredConstructor(ArgClassArray);
this.transformer = (Transformer)(transConstructor.newInstance(ArgObject));
}
if(transformatorConfigName != null && this.transformer != null) {
this.transformer.configure(transformatorConfigName);
}
}catch(Exception e) {
throw new LoaderException("Error during transformation!",e);
}
}
public Transformation(String name, String className, Element doc) throws Exception {
new Transformation(name,className,null,doc);
}
/**
* This method set logger object
*/
public void setLogger(Logger logger) {
if (this.transformer instanceof JavaScriptEvaluator){
jsEvaluator.setLogger(logger);
}else{
this.logger = logger;
}
}
private void init() {
initSourceColumns();
initTargetColumns();
}
/**
* @param doc represents Object document
* @param importJob represents current import job
*/
private void initSourceColumns() {
//ZK change this because of problem with reading xml file, because of method importValue which reads all data from <importDefinition>tag
if (this.transformationDocFragment!=null){
this.sourceColumnNames = OctopusXMLUtil.importValueForTransform(this.transformationDocFragment, "sourceColumn","name");
}
}
private void initTargetColumns() {
Vector targetColumnNames = OctopusXMLUtil.importValueForTransform(this.transformationDocFragment, "targetColumn","name");
Vector targetTableNames = OctopusXMLUtil.importValueForTransform(this.transformationDocFragment, "targetColumn","tableName");
Vector targetTableIDs = OctopusXMLUtil.importValueForTransform(this.transformationDocFragment, "targetColumn","tableID");
Vector targetValueModes = OctopusXMLUtil.importValueForTransform(this.transformationDocFragment, "targetColumn","valueMode");
for(int i = 0; i < targetColumnNames.size(); i++) {
this.transformationTargetColumns.add(new TransformationTargetColumn(
(String)targetColumnNames.get(i),
(String)targetTableNames.get(i),
(String)targetTableIDs.get(i),
(String)targetValueModes.get(i)
));
}
}
/**
* Returns Vector with source column names
* @return vector
*/
public Vector getSourceColumnNames() {
return this.sourceColumnNames;
}
/**
* Returns Vector with target column names
* @return vector
*/
public Vector getTargetColumnNames() {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getName() );
}
return retVal;
}
/**
* Returns Vector with target column names
* @param index logical table index
* @return vector
*/
public Vector getTargetColumnNames(int index) {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getTableID().equals( String.valueOf(index) ) )
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getName() );
}
return retVal;
}
/**
* Returns Vector with target column types
* @param index logical table index
* @return vector
*/
public Vector getTargetColumnTypes(int index) {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getTableID().equals( String.valueOf(index) ) )
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getType() );
// else
// retVal.add(null);
}
return retVal;
}
/**
* Returns Vector with target column types on ordered places, and
* add null if in this place logic table is different than specified
* @param index logical table index
* @return vector
*/
public Vector getOrderedTargetColumnTypes(int index) {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getTableID().equals( String.valueOf(index) ) )
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getType() );
else
retVal.add(null);
}
return retVal;
}
/**
* Returns Vector with target value modes
* @param index logical table index
* @return vector
*/
public Vector getTargetValueModes(int index) {
Vector retVal = new Vector();
for(int i = 0; i < this.transformationTargetColumns.size(); i++) {
if( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getTableID().equals( String.valueOf(index) ) )
retVal.add( ((TransformationTargetColumn)this.transformationTargetColumns.get(i)).getValueMode() );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -