/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at .
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox ,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.dynamo.xmlrpc;
import java.io.*;
import com.silverwrist.dynamo.HttpStatusCode;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;
public class XmlRpcResult implements SelfRenderable, XmlRpcSelfSerializing
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private Object m_obj;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public XmlRpcResult(Object obj)
{
m_obj = obj;
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface SelfRenderable
*--------------------------------------------------------------------------------
*/
public void render(SelfRenderControl control) throws IOException, RenderingException
{
// Serialize the output value to a StringWriter.
StringWriter wr = new StringWriter();
wr.write("\r\n");
XmlRpcSerializer.get().serialize(wr,m_obj);
wr.write("\r\n\r\n");
// Now render the binary equivalent of this structure.
byte[] data = null;
try
{ // get a complete rendering of this data
data = wr.toString().getBytes("UTF-8");
} // end try
catch (UnsupportedEncodingException e)
{ // WTF? shouldn't happen
data = wr.toString().getBytes();
} // end catch
// send out the bytes as an XML message body
control.status(HttpStatusCode.S_OK);
BinaryRenderControl bctrl = control.getBinaryRender();
bctrl.setContentType("text/xml; charset=UTF-8");
bctrl.setContentLength(data.length);
OutputStream stm = bctrl.getStream();
stm.write(data);
stm.flush();
} // end render
/*--------------------------------------------------------------------------------
* Implementations from interface XmlRpcSelfSerializing
*--------------------------------------------------------------------------------
*/
public void serializeXmlRpc(Writer wr) throws IOException
{
XmlRpcSerializer.get().serialize(wr,m_obj);
} // end serializeXmlRpc
} // end class XmlRpcResult