KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > web3 > impl > DefaultWeb3StreamerImpl


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
27 import org.xml.sax.helpers.AttributesImpl JavaDoc;
28 import org.xml.sax.ContentHandler JavaDoc;
29
30 /**
31  * TBD
32  *
33  * @author <a HREF="mailto:michael.gerzabek@at.efp.cc">Michael Gerzabek</a>
34  * @since 2.1
35  * @version CVS $Id: DefaultWeb3StreamerImpl.java 164808 2005-04-26 16:07:03Z vgritsenko $
36  */

37 public class DefaultWeb3StreamerImpl implements Web3Streamer, Poolable {
38
39     public void stream(JCO.Function function,
40                        ContentHandler JavaDoc contentHandler)
41     throws SAXException JavaDoc {
42
43         AttributesImpl JavaDoc attributes = new AttributesImpl JavaDoc();
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 JavaDoc 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 JavaDoc contentHandler)
110     throws SAXException JavaDoc {
111
112         AttributesImpl JavaDoc attributes = new AttributesImpl JavaDoc();
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 JavaDoc 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 JavaDoc 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