1 16 17 package org.apache.cocoon.components.web3.impl; 18 19 import com.sap.mw.jco.JCO; 20 21 import org.apache.cocoon.components.web3.Web3Streamer; 22 import org.apache.cocoon.components.web3.Web3; 23 24 import org.apache.avalon.excalibur.pool.Poolable; 25 26 import org.xml.sax.SAXException ; 27 import org.xml.sax.helpers.AttributesImpl ; 28 import org.xml.sax.ContentHandler ; 29 30 37 public class DefaultWeb3StreamerImpl implements Web3Streamer, Poolable { 38 39 public void stream(JCO.Function function, 40 ContentHandler contentHandler) 41 throws SAXException { 42 43 AttributesImpl attributes = new AttributesImpl (); 44 attributes.addAttribute( Web3.URI, Web3.INCLUDE_NAME_ATTR, 45 Web3.INCLUDE_NAME_ATTR, "CDATA", function.getName().toUpperCase() ); 46 contentHandler.startElement( Web3.URI, Web3.INCLUDE_ELEM, 47 Web3.INCLUDE_ELEM, attributes ); 48 attributes.clear(); 49 contentHandler.startElement( Web3.URI, Web3.IMPORT_ELEM, 50 Web3.IMPORT_ELEM, attributes ); 51 streamParameterList( function.getImportParameterList(), contentHandler ); 52 contentHandler.endElement( Web3.URI, Web3.IMPORT_ELEM, Web3.IMPORT_ELEM ); 53 54 attributes.clear(); 55 contentHandler.startElement( Web3.URI, Web3.EXPORT_ELEM, 56 Web3.EXPORT_ELEM, attributes ); 57 streamParameterList( function.getExportParameterList(), contentHandler ); 58 contentHandler.endElement( Web3.URI, Web3.EXPORT_ELEM, Web3.EXPORT_ELEM ); 59 60 JCO.ParameterList tablesParameterList = function.getTableParameterList(); 61 attributes.clear(); 62 contentHandler.startElement( Web3.URI, Web3.TABLES_ELEM, 63 Web3.TABLES_ELEM, attributes ); 64 if (null != tablesParameterList) { 65 for (int i = 0; i < tablesParameterList.getFieldCount(); i++) { 66 attributes.clear(); 67 attributes.addAttribute( Web3.URI, Web3.TABLE_NAME_ATTR, 68 Web3.TABLE_NAME_ATTR, "CDATA", 69 tablesParameterList.getName(i).toUpperCase() ); 70 contentHandler.startElement( Web3.URI, Web3.TABLE_ELEM, 71 Web3.TABLE_ELEM, attributes ); 72 JCO.Table sapTable = tablesParameterList.getTable(i); 73 if (null != sapTable) { 74 for (int j = 0; j < sapTable.getNumRows(); j++) { 75 sapTable.setRow(j); 76 attributes.clear(); 77 attributes.addAttribute(Web3.URI, Web3.ROW_ID_ATTR, 78 Web3.ROW_ID_ATTR, "CDATA", "" + (j + 1)); 79 contentHandler.startElement(Web3.URI, Web3.ROW_ELEM, 80 Web3.ROW_ELEM, attributes); 81 for (int k = 0; k < sapTable.getFieldCount(); k++) { 82 attributes.clear(); 83 attributes.addAttribute(Web3.URI, 84 Web3.FIELD_NAME_ATTR, Web3.FIELD_NAME_ATTR, 85 "CDATA", sapTable.getName(k).toUpperCase()); 86 contentHandler.startElement(Web3.URI, 87 Web3.FIELD_ELEM, Web3.FIELD_ELEM, attributes); 88 String theValue = ( sapTable.getString(k) == null) 89 ? "" : sapTable.getString(k).trim(); 90 contentHandler.characters(theValue.toCharArray(), 0, 91 theValue.length()); 92 contentHandler.endElement(Web3.URI, Web3.FIELD_ELEM, 93 Web3.FIELD_ELEM); 94 } 95 contentHandler.endElement(Web3.URI, Web3.ROW_ELEM, 96 Web3.ROW_ELEM); 97 } 98 contentHandler.endElement(Web3.URI, Web3.TABLE_ELEM, 99 Web3.TABLE_ELEM); 100 } 101 } 102 } 103 contentHandler.endElement(Web3.URI, Web3.TABLES_ELEM, Web3.TABLES_ELEM); 104 contentHandler.endElement( Web3.URI, Web3.INCLUDE_ELEM, 105 Web3.INCLUDE_ELEM ); 106 } 107 108 protected void streamParameterList(JCO.ParameterList pList, 109 ContentHandler contentHandler) 110 throws SAXException { 111 112 AttributesImpl attributes = new AttributesImpl (); 113 if (pList != null) { 114 for (int i = 0; i < pList.getFieldCount(); i++) { 115 attributes.clear(); 116 117 JCO.Field theField = pList.getField(i); 118 if (theField.isStructure()) { 119 JCO.Structure sapStructure = 120 pList.getStructure(pList.getName(i)); 121 attributes.addAttribute(Web3.URI, Web3.STRUCTURE_NAME_ATTR, 122 Web3.STRUCTURE_NAME_ATTR, "CDATA", 123 pList.getName(i).toUpperCase()); 124 contentHandler.startElement(Web3.URI, Web3.STRUCTURE_ELEM, 125 Web3.STRUCTURE_ELEM, attributes); 126 for (int j = 0; j < sapStructure.getFieldCount(); j++) { 127 attributes.clear(); 128 attributes.addAttribute(Web3.URI, Web3.FIELD_NAME_ATTR, 129 Web3.FIELD_NAME_ATTR, "CDATA", 130 sapStructure.getName(j).toUpperCase()); 131 contentHandler.startElement(Web3.URI, Web3.FIELD_ELEM, 132 Web3.FIELD_ELEM, attributes); 133 String theValue = (sapStructure.getString(j) == null) 134 ? "" : sapStructure.getString(j).trim(); 135 contentHandler.characters(theValue.toCharArray(), 0, 136 theValue.length()); 137 contentHandler.endElement(Web3.URI, Web3.FIELD_ELEM, 138 Web3.FIELD_ELEM); 139 } 140 contentHandler.endElement(Web3.URI, Web3.STRUCTURE_ELEM, 141 Web3.STRUCTURE_ELEM); 142 } else { 143 attributes.addAttribute(Web3.URI, Web3.FIELD_NAME_ATTR, 144 Web3.FIELD_NAME_ATTR, "CDATA", 145 pList.getName(i).toUpperCase()); 146 contentHandler.startElement(Web3.URI, Web3.FIELD_ELEM, 147 Web3.FIELD_ELEM, attributes); 148 String theValue = (pList.getString(i) == null) 149 ? "" : pList.getString(i).trim(); 150 contentHandler.characters(theValue.toCharArray(), 0, 151 theValue.length()); 152 contentHandler.endElement(Web3.URI, Web3.FIELD_ELEM, 153 Web3.FIELD_ELEM); 154 } 155 } 156 } 157 } 158 159 } 160 161 | Popular Tags |