use of javax.xml.bind.MarshalException in project OpenAM by OpenRock.
the class MarshallerImpl method write.
private void write(XMLSerializable obj, ContentHandler writer) throws JAXBException {
try {
if (getSchemaLocation() != null || getNoNSSchemaLocation() != null) {
// if we need to add xsi:schemaLocation or its brother,
// throw in the component to do that.
writer = new SchemaLocationFilter(getSchemaLocation(), getNoNSSchemaLocation(), writer);
}
SAXMarshaller serializer = new SAXMarshaller(writer, prefixMapper, this);
// set a DocumentLocator that doesn't provide any information
writer.setDocumentLocator(new LocatorImpl());
writer.startDocument();
serializer.childAsBody(obj, null);
writer.endDocument();
// extra check
serializer.reconcileID();
} catch (SAXException e) {
throw new MarshalException(e);
}
}
use of javax.xml.bind.MarshalException in project OpenAM by OpenRock.
the class MarshallerImpl method write.
private void write(XMLSerializable obj, ContentHandler writer) throws JAXBException {
try {
if (getSchemaLocation() != null || getNoNSSchemaLocation() != null) {
// if we need to add xsi:schemaLocation or its brother,
// throw in the component to do that.
writer = new SchemaLocationFilter(getSchemaLocation(), getNoNSSchemaLocation(), writer);
}
SAXMarshaller serializer = new SAXMarshaller(writer, prefixMapper, this);
// set a DocumentLocator that doesn't provide any information
writer.setDocumentLocator(new LocatorImpl());
writer.startDocument();
serializer.childAsBody(obj, null);
writer.endDocument();
// extra check
serializer.reconcileID();
} catch (SAXException e) {
throw new MarshalException(e);
}
}
use of javax.xml.bind.MarshalException in project OpenAM by OpenRock.
the class MarshallerImpl method marshal.
public void marshal(Object obj, Result result) throws JAXBException {
//XMLSerializable so = Util.toXMLSerializable(obj);
XMLSerializable so = context.getGrammarInfo().castToXMLSerializable(obj);
if (so == null)
throw new MarshalException(Messages.format(Messages.NOT_MARSHALLABLE));
if (result instanceof SAXResult) {
write(so, ((SAXResult) result).getHandler());
return;
}
if (result instanceof DOMResult) {
Node node = ((DOMResult) result).getNode();
if (node == null) {
try {
DocumentBuilder db = XMLUtils.getSafeDocumentBuilder(false);
Document doc = db.newDocument();
((DOMResult) result).setNode(doc);
write(so, new SAX2DOMEx(doc));
} catch (ParserConfigurationException pce) {
throw new JAXBAssertionError(pce);
}
} else {
write(so, new SAX2DOMEx(node));
}
return;
}
if (result instanceof StreamResult) {
StreamResult sr = (StreamResult) result;
XMLWriter w = null;
if (sr.getWriter() != null)
w = createWriter(sr.getWriter());
else if (sr.getOutputStream() != null)
w = createWriter(sr.getOutputStream());
else if (sr.getSystemId() != null) {
String fileURL = sr.getSystemId();
if (fileURL.startsWith("file:///")) {
if (fileURL.substring(8).indexOf(":") > 0)
fileURL = fileURL.substring(8);
else
fileURL = fileURL.substring(7);
}
try {
w = createWriter(new FileOutputStream(fileURL));
} catch (IOException e) {
throw new MarshalException(e);
}
}
if (w == null)
throw new IllegalArgumentException();
write(so, w);
return;
}
// unsupported parameter type
throw new MarshalException(Messages.format(Messages.UNSUPPORTED_RESULT));
}
use of javax.xml.bind.MarshalException in project OpenAM by OpenRock.
the class MarshallerImpl method marshal.
public void marshal(Object obj, Result result) throws JAXBException {
//XMLSerializable so = Util.toXMLSerializable(obj);
XMLSerializable so = context.getGrammarInfo().castToXMLSerializable(obj);
if (so == null)
throw new MarshalException(Messages.format(Messages.NOT_MARSHALLABLE));
if (result instanceof SAXResult) {
write(so, ((SAXResult) result).getHandler());
return;
}
if (result instanceof DOMResult) {
Node node = ((DOMResult) result).getNode();
if (node == null) {
try {
DocumentBuilder db = XMLUtils.getSafeDocumentBuilder(false);
Document doc = db.newDocument();
((DOMResult) result).setNode(doc);
write(so, new SAX2DOMEx(doc));
} catch (ParserConfigurationException pce) {
throw new JAXBAssertionError(pce);
}
} else {
write(so, new SAX2DOMEx(node));
}
return;
}
if (result instanceof StreamResult) {
StreamResult sr = (StreamResult) result;
XMLWriter w = null;
if (sr.getWriter() != null)
w = createWriter(sr.getWriter());
else if (sr.getOutputStream() != null)
w = createWriter(sr.getOutputStream());
else if (sr.getSystemId() != null) {
String fileURL = sr.getSystemId();
if (fileURL.startsWith("file:///")) {
if (fileURL.substring(8).indexOf(":") > 0)
fileURL = fileURL.substring(8);
else
fileURL = fileURL.substring(7);
}
try {
w = createWriter(new FileOutputStream(fileURL));
} catch (IOException e) {
throw new MarshalException(e);
}
}
if (w == null)
throw new IllegalArgumentException();
write(so, w);
return;
}
// unsupported parameter type
throw new MarshalException(Messages.format(Messages.UNSUPPORTED_RESULT));
}
use of javax.xml.bind.MarshalException in project OpenAM by OpenRock.
the class MarshallerImpl method write.
private void write(XMLSerializable obj, ContentHandler writer) throws JAXBException {
try {
if (getSchemaLocation() != null || getNoNSSchemaLocation() != null) {
// if we need to add xsi:schemaLocation or its brother,
// throw in the component to do that.
writer = new SchemaLocationFilter(getSchemaLocation(), getNoNSSchemaLocation(), writer);
}
SAXMarshaller serializer = new SAXMarshaller(writer, prefixMapper, this);
// set a DocumentLocator that doesn't provide any information
writer.setDocumentLocator(new LocatorImpl());
writer.startDocument();
serializer.childAsBody(obj, null);
writer.endDocument();
// extra check
serializer.reconcileID();
} catch (SAXException e) {
throw new MarshalException(e);
}
}
Aggregations