KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Vector JavaDoc;
15 import java.util.Enumeration JavaDoc;
16
17 import org.apache.log4j.Logger ;
18
19 /**
20   Each of the breaks in a DataValue
21  **/

22 class SectionValue {
23   SectionTemplate sectionTemplate;
24   DataValue dataValue;
25   StringBuffer JavaDoc strSection;
26   XmlVectorValue vecHeadValue;
27   XmlVectorValue vecFootValue;
28   Vector JavaDoc<FunctionValue> vecFunctionValue;
29   FieldValue breakFieldValue;
30   static Logger log4jSectionValue = Logger.getLogger(SectionValue.class);
31
32   public SectionValue(SectionTemplate sectionTemplate, XmlDocument xmlDocument, DataValue dataValue) {
33     this.sectionTemplate = sectionTemplate;
34     this.dataValue = dataValue;
35
36     vecHeadValue = new XmlVectorValue(sectionTemplate.vecHeadTemplate, xmlDocument);
37     vecFootValue = new XmlVectorValue(sectionTemplate.vecFootTemplate, xmlDocument);
38
39     if (sectionTemplate.breakFieldTemplate == null) {
40       breakFieldValue = null;
41     } else {
42       breakFieldValue = sectionTemplate.breakFieldTemplate.createFieldValue(xmlDocument);
43     }
44
45     //vector of Functions
46
vecFunctionValue = new Vector JavaDoc<FunctionValue>();
47     for (Enumeration JavaDoc e1 = sectionTemplate.vecFunctionTemplate.elements() ; e1.hasMoreElements();) {
48       FunctionTemplate functionTemplate = (FunctionTemplate)e1.nextElement();
49       FunctionValue functionValue = functionTemplate.createFunctionValue(xmlDocument);
50       vecFunctionValue.addElement(functionValue);
51       log4jSectionValue.debug("Function: " + functionValue.functionTemplate.fieldName);
52     }
53   }
54
55   public void init() {
56     log4jSectionValue.debug("(Init) Levels: " + sectionTemplate.dataTemplate.intTotalLevels + " actual level: " + sectionTemplate.intLevel);
57     if (breakFieldValue != null) {
58       breakFieldValue.savePrevious();
59     }
60     for (Enumeration JavaDoc e = vecFunctionValue.elements() ; e.hasMoreElements() ;) {
61       FunctionValue functionInstance = (FunctionValue)e.nextElement();
62       functionInstance.init();
63     }
64     if (sectionTemplate.intLevel != sectionTemplate.dataTemplate.intTotalLevels) {
65       SectionValue section = (SectionValue)dataValue.vecSectionValue.elementAt(sectionTemplate.intLevel + 1);
66       section.strSection = new StringBuffer JavaDoc();
67     } else {
68       dataValue.strDetailValue = new StringBuffer JavaDoc();
69     }
70   }
71
72   public void close() {
73     log4jSectionValue.debug("(Close) Levels:" + sectionTemplate.dataTemplate.intTotalLevels + " actual level: " + sectionTemplate.intLevel);
74     if (sectionTemplate.intLevel != sectionTemplate.dataTemplate.intTotalLevels) {
75       SectionValue section = (SectionValue)dataValue.vecSectionValue.elementAt(sectionTemplate.intLevel + 1);
76       section.close();
77     }
78     // Head of the section
79
strSection.append(vecHeadValue.printPreviousStringBuffer());
80
81     // add next section
82
if (sectionTemplate.intLevel != sectionTemplate.dataTemplate.intTotalLevels) {
83       SectionValue section = (SectionValue)dataValue.vecSectionValue.elementAt(sectionTemplate.intLevel + 1);
84       strSection.append(section.strSection);
85     } else {
86       // log4jSectionValue.debug("Adding strDetail length detail: " + dataValue.strDetailValue.length() + " section length: " + strSection.length());
87
// System.gc();
88
strSection.append(dataValue.strDetailValue);
89       // log4jSectionValue.debug("AƱadido strDetail"+ " section length: " + strSection.length());
90
}
91     // Foot of the section
92
strSection.append(vecFootValue.printPreviousStringBuffer());
93
94     init();
95     log4jSectionValue.debug("End of close");
96
97   }
98
99   public boolean check() {
100     if (breakFieldValue != null) {
101       return breakFieldValue.check();
102     } else {
103       return true;
104     }
105   }
106
107   public void acumulate() {
108     for (Enumeration JavaDoc e = vecFunctionValue.elements() ; e.hasMoreElements() ;) {
109       FunctionValue functionInstance = (FunctionValue)e.nextElement();
110       functionInstance.acumulate();
111     }
112   }
113 }
114
Popular Tags