Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 package org.apache.xmlrpc.jaxb;
00020
00021 import javax.xml.bind.JAXBContext;
00022 import javax.xml.bind.JAXBException;
00023
00024 import org.apache.xmlrpc.serializer.ExtSerializer;
00025 import org.xml.sax.Attributes;
00026 import org.xml.sax.ContentHandler;
00027 import org.xml.sax.Locator;
00028 import org.xml.sax.SAXException;
00029
00030
00033 public class JaxbSerializer extends ExtSerializer {
00034 private final JAXBContext context;
00035
00038 public static final String JAXB_TAG = "jaxb";
00039
00043 public JaxbSerializer(JAXBContext pContext) {
00044 context = pContext;
00045 }
00046
00047 protected String getTagName() { return JAXB_TAG; }
00048
00049 protected void serialize(final ContentHandler pHandler, Object pObject) throws SAXException {
00050
00051
00052
00053 ContentHandler h = new ContentHandler() {
00054 public void endDocument() throws SAXException {}
00055 public void startDocument() throws SAXException {}
00056 public void characters(char[] pChars, int pOffset, int pLength) throws SAXException {
00057 pHandler.characters(pChars, pOffset, pLength);
00058 }
00059 public void ignorableWhitespace(char[] pChars, int pOffset, int pLength) throws SAXException {
00060 pHandler.ignorableWhitespace(pChars, pOffset, pLength);
00061 }
00062 public void endPrefixMapping(String pPrefix) throws SAXException {
00063 pHandler.endPrefixMapping(pPrefix);
00064 }
00065 public void skippedEntity(String pName) throws SAXException {
00066 pHandler.endPrefixMapping(pName);
00067 }
00068 public void setDocumentLocator(Locator pLocator) {
00069 pHandler.setDocumentLocator(pLocator);
00070 }
00071 public void processingInstruction(String pTarget, String pData) throws SAXException {
00072 pHandler.processingInstruction(pTarget, pData);
00073 }
00074 public void startPrefixMapping(String pPrefix, String pURI) throws SAXException {
00075 pHandler.startPrefixMapping(pPrefix, pURI);
00076 }
00077 public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
00078 pHandler.endElement(pURI, pLocalName, pQName);
00079 }
00080 public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
00081 pHandler.startElement(pURI, pLocalName, pQName, pAttrs);
00082 }
00083 };
00084 try {
00085 context.createMarshaller().marshal(pObject, h);
00086 } catch (JAXBException e) {
00087 Throwable t = e.getLinkedException();
00088 if (t != null && t instanceof SAXException) {
00089 throw (SAXException) t;
00090 } else {
00091 throw new SAXException(e);
00092 }
00093 }
00094 }
00095 }