KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > transformation > Transformations


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 JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 import org.w3c.dom.Document JavaDoc;
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 JavaDoc transformations = new ArrayList JavaDoc();
41   public ArrayList JavaDoc transformationsTableIDList = new ArrayList JavaDoc();
42   public Logger logger;
43
44   private int iTransformationSourceColumsCnt = 0;
45
46   private Vector JavaDoc transformationNames = new Vector JavaDoc();// vector with names of all transformation tags(names from transformation tag)
47
private Vector JavaDoc transformationClassNames = new Vector JavaDoc();//vector with classNames of all transformation tags(className from transformation tag)
48
private Vector JavaDoc transformatorConfigNames = new Vector JavaDoc();//vector with configNames of all transformation tags(configName from transformation tag)
49
private Vector JavaDoc transformationsTargetColumnNames = new Vector JavaDoc();//vector with tableNames of all transformation tags(tableName from transformation tag)
50
private Vector JavaDoc transformationsTableNames = new Vector JavaDoc();//vector with tableNames of all transformation tags(tableName from transformation tag)
51
private Vector JavaDoc transformationsTableIDs = new Vector JavaDoc();//vector with tableIDs of all transformation tags(tableID from transformation tag)
52
private Vector JavaDoc transformationsValueModes = new Vector JavaDoc();//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 JavaDoc allTransformationsSourceColNames = new ArrayList JavaDoc();
58
59    /**
60    * Empty constructor of Transformations class
61    */

62   public Transformations(Logger logger) {
63
64     this.transformationNames = new Vector JavaDoc();
65     this.transformationClassNames = new Vector JavaDoc();
66     this.transformatorConfigNames = new Vector JavaDoc();
67     this.transformationsTableNames = new Vector JavaDoc();
68      this.transformationsTableIDs = new Vector JavaDoc();
69     this.transformationsTableIDList = new ArrayList JavaDoc();
70     this.transformationsValueModes = new Vector JavaDoc();
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 JavaDoc 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 JavaDoc 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 JavaDoc transTableIDs){
107     for (int i = 0; i < transTableIDs.size(); i++) {
108       String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc();
168    this.transformationsTargetColumnNames = new Vector JavaDoc();
169    this.transformationClassNames = new Vector JavaDoc();
170    this.transformatorConfigNames = new Vector JavaDoc();
171    this.transformationsValueModes = new Vector JavaDoc();
172    this.transformationsTableIDList = new ArrayList JavaDoc();
173    this.transformations = new ArrayList JavaDoc();
174   }
175
176     public int getTransformationSourceColumsCnt() {
177         return this.iTransformationSourceColumsCnt;
178     }
179
180     public List JavaDoc getAllTransformationSourceColNames() {
181             return this.allTransformationsSourceColNames;
182     }
183
184 }
185
Popular Tags