// Path: camelwatch-api/src/main/java/org/camelwatch/api/MessageFactory.java
// public class MessageFactory {
// 
// 	public Message build(Element e) {
// 		Message m = new Message();
// 		m.setExchangeId(e.getAttributeValue("exchangeId"));
// 		Element headers = e.getChild("headers");
// 		if (headers != null) {
// 			for (Element header : headers.getChildren("header")) {
// 				m.getHeaders().put(header.getAttributeValue("key"), header.getTextTrim());
// 			}
// 		}
// 		Element body = e.getChild("body");
// 		if (body != null) {
// 			m.setBody(body.getTextTrim());
// 			m.setBodyType(body.getAttributeValue("type"));
// 		}
// 		return m;
// 	}
// 
// 	public List<Message> buildList(Document doc) {
// 		List<Message> results = Lists.newArrayList();
// 		for (Element messageElement : doc.getRootElement().getChildren("message")) {
// 			results.add(build(messageElement));
// 		}
// 		return results;
// 	}
// 
// }
// 
// Path: camelwatch-api/src/main/java/org/camelwatch/api/Message.java
// public class Message {
// 
// 	private String				exchangeId;
// 
// 	private final Map<String, String>	headers	= Maps.newHashMap();
// 
// 	private String				body;
// 
// 	private String				bodyType;
// 
// 	public String getBody() {
// 		return body;
// 	}
// 
// 	public String getBodyType() {
// 		return bodyType;
// 	}
// 
// 	public String getExchangeId() {
// 		return exchangeId;
// 	}
// 
// 	public Map<String, String> getHeaders() {
// 		return headers;
// 	}
// 
// 	public void setBody(String body) {
// 		this.body = body;
// 	}
// 
// 	public void setBodyType(String bodyType) {
// 		this.bodyType = bodyType;
// 	}
// 
// 	public void setExchangeId(String exchangeId) {
// 		this.exchangeId = exchangeId;
// 	}
// }


import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import org.camelwatch.api.MessageFactory;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
import org.camelwatch.api.Message;

	public Message browseMessageAsXml(int offset, boolean includeBody) throws Exception {
		String result = (String) conn.invoke(instance.getObjectName(),
				"browseMessageAsXml",
				new Object[] { offset },
				new String[] { "java.lang.Integer" });
		if (result == null)
			return null;
		Document doc = new SAXBuilder().build(new StringReader(result));
		Element root = doc.getRootElement();
		return new MessageFactory().build(root);
	}

	@Override
	public String browseMessageBody(int offset) throws Exception {
		Object result = conn.invoke(instance.getObjectName(),
				"browseMessageBody",
				new Object[] { offset },
				new String[] { "java.lang.Integer" });
		return (String) result;
	}

	@Override
	public List<Message> browseRangeMessagesAsXml(int offset, int end, boolean includeBody) throws Exception {

		String result = (String) conn.invoke(instance.getObjectName(), "browseRangeMessagesAsXml", new Object[] {
				offset, end, includeBody }, new String[] { "java.lang.Integer", "java.lang.Integer",
				"java.lang.Boolean" });
		if (result == null)
			return Collections.EMPTY_LIST;
		Document doc = new SAXBuilder().build(new StringReader(result));

// Path: camelwatch-api/src/main/java/org/camelwatch/api/MessageFactory.java
// public class MessageFactory {
// 
// 	public Message build(Element e) {
// 		Message m = new Message();
// 		m.setExchangeId(e.getAttributeValue("exchangeId"));
// 		Element headers = e.getChild("headers");
// 		if (headers != null) {
// 			for (Element header : headers.getChildren("header")) {
// 				m.getHeaders().put(header.getAttributeValue("key"), header.getTextTrim());
// 			}
// 		}
// 		Element body = e.getChild("body");
// 		if (body != null) {
// 			m.setBody(body.getTextTrim());
// 			m.setBodyType(body.getAttributeValue("type"));
// 		}
// 		return m;
// 	}
// 
// 	public List<Message> buildList(Document doc) {
// 		List<Message> results = Lists.newArrayList();
// 		for (Element messageElement : doc.getRootElement().getChildren("message")) {
// 			results.add(build(messageElement));
// 		}
// 		return results;
// 	}
// 
// }
// 
// Path: camelwatch-api/src/main/java/org/camelwatch/api/Message.java
// public class Message {
// 
// 	private String				exchangeId;
// 
// 	private final Map<String, String>	headers	= Maps.newHashMap();
// 
// 	private String				body;
// 
// 	private String				bodyType;
// 
// 	public String getBody() {
// 		return body;
// 	}
// 
// 	public String getBodyType() {
// 		return bodyType;
// 	}
// 
// 	public String getExchangeId() {
// 		return exchangeId;
// 	}
// 
// 	public Map<String, String> getHeaders() {
// 		return headers;
// 	}
// 
// 	public void setBody(String body) {
// 		this.body = body;
// 	}
// 
// 	public void setBodyType(String bodyType) {
// 		this.bodyType = bodyType;
// 	}
// 
// 	public void setExchangeId(String exchangeId) {
// 		this.exchangeId = exchangeId;
// 	}
// }


// Path: camelwatch-api/src/main/java/org/camelwatch/api/endpoint/EndpointOperationsJmxImpl.java
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import org.camelwatch.api.MessageFactory;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
import org.camelwatch.api.Message;

	public Message browseMessageAsXml(int offset, boolean includeBody) throws Exception {
		String result = (String) conn.invoke(instance.getObjectName(),
				"browseMessageAsXml",
				new Object[] { offset },
				new String[] { "java.lang.Integer" });
		if (result == null)
			return null;
		Document doc = new SAXBuilder().build(new StringReader(result));
		Element root = doc.getRootElement();
		return new MessageFactory().build(root);
	}

	@Override
	public String browseMessageBody(int offset) throws Exception {
		Object result = conn.invoke(instance.getObjectName(),
				"browseMessageBody",
				new Object[] { offset },
				new String[] { "java.lang.Integer" });
		return (String) result;
	}

	@Override
	public List<Message> browseRangeMessagesAsXml(int offset, int end, boolean includeBody) throws Exception {

		String result = (String) conn.invoke(instance.getObjectName(), "browseRangeMessagesAsXml", new Object[] {
				offset, end, includeBody }, new String[] { "java.lang.Integer", "java.lang.Integer",
				"java.lang.Boolean" });
		if (result == null)
			return Collections.EMPTY_LIST;
		Document doc = new SAXBuilder().build(new StringReader(result));

		List<Message> results = new MessageFactory().buildList(doc);
