01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the
09: * Free Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: *
21: *
22: * $Id: OperUser.java 9331 2007-09-28 08:53:09Z lzheng $
23: */
24: package com.bostechcorp.cbesb.common.trn.compiler;
25:
26: import java.util.Enumeration;
27:
28: import com.bostechcorp.cbesb.common.util.TabbingPrintWriter;
29:
30: public class OperUser extends OperClass {
31:
32: public OperUser(String name) {
33: super (name);
34: this .type = OpType.OPTYPE_USER;
35:
36: }
37:
38: @Override
39: public void startCode(TransformerCompiler compiler) {
40: TabbingPrintWriter javaWriter = compiler.javaWriter;
41:
42: javaWriter.println("// START " + this .className + " ");
43: javaWriter.println("inStrings = new String["
44: + this .sources.length + "];");
45: for (int i = 0; i < this .sources.length; i++)
46: javaWriter.println("inStrings[" + i + "] = dataAddresses["
47: + this .sources[i].getAddressIndex()
48: + "].getValue(sourceTree,metadataMap);");
49:
50: javaWriter.println("outStrings = new String["
51: + this .targets.length + "];");
52:
53: javaWriter.println("if(true){");
54: javaWriter.addTab();
55: // javaWriter.println("Class userClass=Class.forName(\""+this.getClassName()+"\", true, RuntimeClassLoader.getClassLoader(getServiceAssemblyName(), this));");
56: // javaWriter.println(" ITransformationOperation opUser=(ITransformationOperation)userClass.newInstance();");
57: // javaWriter.println("opResult=opUser.process(inStrings, outStrings);");
58: javaWriter.println("opResult = opClasses[" + this .classIndex
59: + "].process(inStrings, outStrings);");
60: javaWriter.println("if (opResult) {");
61: javaWriter.addTab();
62:
63: this .filter.generateCode(javaWriter, compiler.getProjName());
64: for (int i = 0; i < this .targets.length; i++) {
65: javaWriter.println("dataAddresses["
66: + this .targets[i].getAddressIndex()
67: + "].setValue(targetDoc, outTree, outStrings[" + i
68: + "],metadataMap);");
69: }
70: javaWriter.delTab();
71: javaWriter.println("}");
72: javaWriter.delTab();
73: javaWriter.println("}");
74:
75: }
76:
77: public void makeClassInstances(TabbingPrintWriter javaWriter) {
78: javaWriter
79: .println("userClass=Class.forName(\""
80: + this .getClassName()
81: + "\", true, RuntimeClassLoader.getClassLoader(getServiceAssemblyName(), this));");
82: javaWriter
83: .println("opClasses["
84: + this .getClassIndex()
85: + "] = (ITransformationOperation)userClass.newInstance();");
86: if (this .miscProperties != null) {
87: for (Enumeration e = this .miscProperties.propertyNames(); e
88: .hasMoreElements();) {
89: String name = (String) e.nextElement();
90: String value = this .miscProperties.getProperty(name);
91: javaWriter.println("opClasses[" + this .classIndex
92: + "].addProperty(\"" + name + "\", \"" + value
93: + "\");");
94: }
95: }
96:
97: }
98: }
|