KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > xmla > impl > DefaultXmlaResponse


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/xmla/impl/DefaultXmlaResponse.java#2 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2005 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.xmla.impl;
11
12 import java.io.OutputStream JavaDoc;
13 import java.io.UnsupportedEncodingException JavaDoc;
14
15 import mondrian.olap.Util;
16 import mondrian.xmla.*;
17
18 /**
19  * Default implementation of {@link mondrian.xmla.XmlaResponse}.
20  *
21  * @author Gang Chen
22  */

23 public class DefaultXmlaResponse implements XmlaResponse {
24
25     // TODO: add a msg to MondrianResource for this.
26
private static final String JavaDoc MSG_ENCODING_ERROR = "Encoding unsupported: ";
27
28     private SaxWriter writer;
29     private final String JavaDoc encoding;
30
31     public DefaultXmlaResponse(OutputStream JavaDoc outputStream, String JavaDoc encoding) {
32         this.encoding = encoding;
33         try {
34             writer = new DefaultSaxWriter(outputStream, this.encoding);
35         } catch (UnsupportedEncodingException JavaDoc uee) {
36             throw Util.newError(uee, MSG_ENCODING_ERROR + encoding);
37         }
38     }
39
40     public SaxWriter getWriter() {
41         return writer;
42     }
43
44     public void error(Throwable JavaDoc t) {
45         writer.completeBeforeElement("root");
46         Throwable JavaDoc throwable = XmlaUtil.rootThrowable(t);
47         writer.startElement("Messages");
48         writer.startElement("Error", new String JavaDoc[] {
49                 "ErrorCode", throwable.getClass().getName(),
50                 "Description", throwable.getMessage(),
51                 "Source", "Mondrian",
52                 "Help", "",
53         });
54         writer.endElement(); // </Messages>
55
writer.endElement(); // </Error>
56
}
57
58 }
59
60 // End DefaultXmlaResponse.java
61
Popular Tags