KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > xmlEngine > FunctionTemplate


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.xmlEngine;
13
14 import java.text.DecimalFormat JavaDoc;
15
16 import org.apache.log4j.Logger ;
17
18 class FunctionTemplate implements XmlComponentTemplate, IDComponent {
19   protected String JavaDoc fieldName;
20   protected FieldTemplate fieldTemplate;
21   DecimalFormat JavaDoc formatOutput;
22   DecimalFormat JavaDoc formatSimple;
23   public DataTemplate dataTemplate;
24   protected XmlComponentTemplate arg1Template;
25   protected XmlComponentTemplate arg2Template;
26
27   static Logger log4jFunctionTemplate = Logger.getLogger(FunctionTemplate.class);
28
29   public FunctionTemplate() {}
30
31   public FunctionTemplate(String JavaDoc fieldName, FieldTemplate field,
32       DecimalFormat JavaDoc formatOutput, DecimalFormat JavaDoc formatSimple, DataTemplate dataTemplate) {
33     this.fieldName = fieldName;
34     this.fieldTemplate = field;
35     this.formatOutput = formatOutput;
36     this.formatSimple = formatSimple;
37     this.dataTemplate = dataTemplate;
38   }
39
40   public FunctionTemplate(String JavaDoc fieldName, DecimalFormat JavaDoc formatOutput, DecimalFormat JavaDoc formatSimple,
41       DataTemplate dataTemplate, XmlComponentTemplate arg1, XmlComponentTemplate arg2) {
42     this.fieldName = fieldName; // XmlEngineNP: in fact its a function name
43
this.formatOutput = formatOutput;
44     this.formatSimple = formatSimple;
45     this.dataTemplate = dataTemplate;
46     this.arg1Template = arg1;
47     this.arg2Template = arg2;
48   }
49
50   public int type() {
51     return FUNCTION;
52   }
53
54   public String JavaDoc printFormatOutput(double value) {
55     if (formatOutput != null) {
56       return formatOutput.format(value);
57     } else {
58       return Double.toString(value);
59     }
60   }
61
62   public String JavaDoc printFormatSimple(double value) {
63     if (formatSimple != null) {
64       return formatSimple.format(value);
65     } else {
66       return Double.toString(value);
67     }
68   }
69
70   public FunctionValue createFunctionValue(XmlDocument xmlDocument) {return null;}
71
72   /* CHX
73      public FunctionValue searchFunction(XmlDocument xmlDocument) {
74      log4jFunctionTemplate.debug("Searching : " + fieldName);
75      for (Enumeration e1 = xmlDocument.hasDataValue.elements() ; e1.hasMoreElements();) {
76      DataValue dataValue = (DataValue)e1.nextElement();
77      for (Enumeration e2 = dataValue.vecFunctionValueData.elements() ; e2.hasMoreElements();) {
78      FunctionValue functionValue = (FunctionValue)e2.nextElement();
79      log4jFunctionTemplate.debug("Comparing in vecFunctionValueData: " + fieldName + " & " + functionValue.functionTemplate.fieldName);
80      if (functionValue.functionTemplate.fieldName.equals(fieldName)) {
81      log4jFunctionTemplate.debug("Found in vecFunctionValueData: " + fieldName);
82      return functionValue;
83      }
84      }
85      for (Enumeration e3 = dataValue.vecFunctionValueOutSection.elements() ; e3.hasMoreElements();) {
86      FunctionValue functionValue = (FunctionValue)e3.nextElement();
87      log4jFunctionTemplate.debug("Comparing in vecFunctionOutSection: " + fieldName + " & " + functionValue.functionTemplate.fieldName);
88      if (functionValue.functionTemplate.fieldName.equals(fieldName)) {
89      log4jFunctionTemplate.debug("Found in vecFunctionOutSection: " + fieldName);
90      return functionValue;
91      }
92      }
93      }
94      log4jFunctionTemplate.debug("Function: " + fieldName + " not found");
95      return null;
96      }
97      */

98   //CHX
99
public FunctionValue searchFunction(XmlDocument xmlDocument) {
100     FunctionValue functionValue = (FunctionValue)xmlDocument.hasXmlComponentValue.get(this);
101     return functionValue;
102   }
103
104   public XmlComponentValue createXmlComponentValue(XmlDocument xmlDocument) {
105     return createFunctionValue(xmlDocument);
106   }
107
108 }
109
Popular Tags