001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: OperArithmetic.java 9331 2007-09-28 08:53:09Z lzheng $
023: */
024: package com.bostechcorp.cbesb.common.trn.compiler;
025:
026: import com.bostechcorp.cbesb.common.util.PropertyList;
027: import com.bostechcorp.cbesb.common.util.TabbingPrintWriter;
028:
029: public class OperArithmetic extends OperBuiltin {
030:
031: protected PropertyList miscPropertyList = new PropertyList();
032:
033: protected Filter filter = new Filter();
034:
035: public OperArithmetic(String name) {
036: super (name);
037: this .builtinType = OpType.BUILTIN_OP_ARITHMETIC;
038: }
039:
040: public void handleProperty(String propertyName, String propertyValue) {
041: super .handleProperty(propertyName, propertyValue);
042: if (propertyName.equalsIgnoreCase("arithmeticType")) {
043: if (propertyValue.equalsIgnoreCase("integer"))
044: this .arithmeticType = ArithmeticType.ARTYPE_INTEGER;
045: else if (propertyValue.equalsIgnoreCase("float"))
046: this .arithmeticType = ArithmeticType.ARTYPE_FLOAT;
047: else
048: this .arithmeticType = ArithmeticType.ARTYPE_STRING;
049: } else if (propertyName.equalsIgnoreCase("expression")) {
050: this .setStrExp(propertyValue);
051: Expression exp = new Expression(this .strExp);
052: exp.build();
053: this .setExp(exp);
054: }
055:
056: }
057:
058: public void handlePropertyList(String propertyListName,
059: String propertyName, String propertyValue) {
060:
061: miscPropertyList.putProperty(propertyListName, propertyName,
062: propertyValue);
063: if (propertyListName.equalsIgnoreCase("filter")) {
064: if (propertyName.equalsIgnoreCase("class"))
065: filter.setClassName(propertyValue);
066: else if (propertyName.endsWith("method"))
067: filter.setMethodName(propertyValue);
068:
069: }
070: }
071:
072: // parameters for while,if,elseif,else,arithmetic operation
073: protected short arithmeticType = ArithmeticType.ARTYPE_STRING;
074: protected String strExp;
075: protected Expression exp;
076:
077: public short getArithmeticType() {
078: return arithmeticType;
079: }
080:
081: public void setArithmeticType(short arithmeticType) {
082: this .arithmeticType = arithmeticType;
083: }
084:
085: public Expression getExp() {
086: return exp;
087: }
088:
089: public void setExp(Expression exp) {
090: this .exp = exp;
091: }
092:
093: public String getStrExp() {
094: return strExp;
095: }
096:
097: public void setStrExp(String strExp) {
098: this .strExp = strExp;
099: }
100:
101: public void startCode(TransformerCompiler compiler) {
102: TabbingPrintWriter javaWriter = compiler.javaWriter;
103:
104: javaWriter.println("// START ARITHMETIC ");
105: // javaWriter.println("inStrings = new String["+this.sources.length+"];");
106: //for (int i=0; i<this.sources.length; i++) javaWriter.println("inStrings["+i+"] = dataAddresses["+this.sources[i].getAddressIndex()+"].getValue(sourceTree, userVars);");
107: javaWriter.println("outStrings = new String["
108: + this .targets.length + "];");
109:
110: String[] varArray = DataAddress.createVarArray(this .sources,
111: this .arithmeticType);
112:
113: javaWriter.println("outStrings[0]=String.valueOf("
114: + this .getExp().getJavaExp(varArray) + ");");
115:
116: this .filter.generateCode(javaWriter, compiler.getProjName());
117:
118: for (int i = 0; i < this .targets.length; i++) {
119: javaWriter.println("dataAddresses["
120: + this .targets[i].getAddressIndex()
121: + "].setValue(targetDoc, outTree, outStrings[" + i
122: + "],metadataMap);");
123: }
124:
125: }
126:
127: @Override
128: public void endCode(TabbingPrintWriter javaWriter) {
129:
130: javaWriter.println("// END ARITHMETIC ");
131: }
132:
133: }
|