1 12 package org.openbravo.xmlEngine; 13 14 import java.util.Vector ; 15 import java.util.Enumeration ; 16 17 import org.apache.log4j.Logger ; 18 19 22 class SectionValue { 23 SectionTemplate sectionTemplate; 24 DataValue dataValue; 25 StringBuffer strSection; 26 XmlVectorValue vecHeadValue; 27 XmlVectorValue vecFootValue; 28 Vector <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 vecFunctionValue = new Vector <FunctionValue>(); 47 for (Enumeration 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 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 (); 67 } else { 68 dataValue.strDetailValue = new StringBuffer (); 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 strSection.append(vecHeadValue.printPreviousStringBuffer()); 80 81 if (sectionTemplate.intLevel != sectionTemplate.dataTemplate.intTotalLevels) { 83 SectionValue section = (SectionValue)dataValue.vecSectionValue.elementAt(sectionTemplate.intLevel + 1); 84 strSection.append(section.strSection); 85 } else { 86 strSection.append(dataValue.strDetailValue); 89 } 91 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 e = vecFunctionValue.elements() ; e.hasMoreElements() ;) { 109 FunctionValue functionInstance = (FunctionValue)e.nextElement(); 110 functionInstance.acumulate(); 111 } 112 } 113 } 114 | Popular Tags |