KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > util > SoapHelper


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jul 14, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.core.util;
19
20 import java.util.*;
21
22 import org.pentaho.core.connection.IPentahoResultSet;
23 import org.pentaho.core.repository.IContentItem;
24
25 public class SoapHelper {
26
27     public static String JavaDoc toSOAP(String JavaDoc name, Object JavaDoc item) {
28
29         if (item instanceof String JavaDoc) {
30             return toSOAP(name, (String JavaDoc) item);
31         } else if (item instanceof List) {
32             return toSOAP(name, (List) item);
33         } else if (item instanceof IPentahoResultSet) {
34             return toSOAP(name, (IPentahoResultSet) item);
35         } else if (item instanceof IContentItem) {
36             return toSOAP(name, ((IContentItem) item).getId());
37         }
38         return null;
39     }
40
41     private static String JavaDoc toSOAP(String JavaDoc name, IPentahoResultSet resultSet) {
42         StringBuffer JavaDoc messageBuffer = new StringBuffer JavaDoc();
43         messageBuffer.append("<" + name + ">\n"); //$NON-NLS-1$ //$NON-NLS-2$
44
Object JavaDoc[][] columnHeaders = resultSet.getMetaData().getColumnHeaders();
45         Object JavaDoc[][] rowHeaders = resultSet.getMetaData().getRowHeaders();
46         boolean hasColumnHeaders = columnHeaders != null;
47         boolean hasRowHeaders = rowHeaders != null;
48
49         if (hasColumnHeaders) {
50             for (int row = 0; row < columnHeaders.length; row++) {
51                 messageBuffer.append("<COLUMN-HDR-ROW>\n"); //$NON-NLS-1$
52
for (int column = 0; column < columnHeaders[row].length; column++) {
53                     messageBuffer.append("<COLUMN-HDR-ITEM><![CDATA[").append(columnHeaders[row][column]).append("]]></COLUMN-HDR-ITEM>\n"); //$NON-NLS-1$//$NON-NLS-2$
54
}
55                 messageBuffer.append("</COLUMN-HDR-ROW>\n"); //$NON-NLS-1$
56
}
57         }
58
59         if (hasRowHeaders) {
60             for (int row = 0; row < rowHeaders.length; row++) {
61                 messageBuffer.append("<ROW-HDR-ROW>\n"); //$NON-NLS-1$
62
for (int column = 0; column < rowHeaders[row].length; column++) {
63                     messageBuffer.append("<ROW-HDR-ITEM><![CDATA[").append(rowHeaders[row][column]).append("]]></ROW-HDR-ITEM>\n"); //$NON-NLS-1$//$NON-NLS-2$
64
}
65                 messageBuffer.append("</ROW-HDR-ROW>\n"); //$NON-NLS-1$
66
}
67         }
68
69         Object JavaDoc[] dataRow = resultSet.next();
70         while (dataRow != null) {
71             messageBuffer.append("<DATA-ROW>\n"); //$NON-NLS-1$
72
for (int col = 0; col < dataRow.length; col++) {
73                 messageBuffer.append("<DATA-ITEM><![CDATA[").append(dataRow[col]).append("]]></DATA-ITEM>\n"); //$NON-NLS-1$//$NON-NLS-2$
74
}
75             messageBuffer.append("</DATA-ROW>\n"); //$NON-NLS-1$
76
dataRow = resultSet.next();
77         }
78         messageBuffer.append("</" + name + ">\n"); //$NON-NLS-1$ //$NON-NLS-2$
79

80         return messageBuffer.toString();
81     }
82
83     public static String JavaDoc toSOAP(String JavaDoc name, String JavaDoc value) {
84         // example code only, probably bogus
85
return "<" + name + "><![CDATA[" + value + "]]></" + name + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
86
}
87
88     public static String JavaDoc toSOAP(String JavaDoc name, long value) {
89         // example code only, probably bogus
90
return "<" + name + "><![CDATA[" + value + "]]></" + name + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
91
}
92
93     public static String JavaDoc toSOAP(String JavaDoc name, Date value) {
94         // example code only, probably bogus
95
return "<" + name + "><![CDATA[" + value + "]]></" + name + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
96
}
97
98     public static String JavaDoc toSOAP(String JavaDoc name, List list) {
99
100         return "<" + name + "><![CDATA[" + list.toString() + "]]></" + name + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
101
}
102
103 }
104
Popular Tags