* @return resulting {@link ODataResponse} with written metadata content
* @throws EntityProviderException
*/
public ODataResponse writeMetadata(final List<Schema> schemas, final Map<String, String> predefinedNamespaces)
throws EntityProviderException {
ODataResponseBuilder builder = ODataResponse.newBuilder();
String dataServiceVersion = ODataServiceVersion.V10;
if (schemas != null) {
dataServiceVersion = calculateDataServiceVersion(schemas);
}
DataServices metadata = new DataServices().setSchemas(schemas).setDataServiceVersion(dataServiceVersion);
OutputStreamWriter writer = null;
CircleStreamBuffer csb = new CircleStreamBuffer();
try {
writer = new OutputStreamWriter(csb.getOutputStream(), DEFAULT_CHARSET);
XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
XmlMetadataProducer.writeMetadata(metadata, xmlStreamWriter, predefinedNamespaces);
} catch (UnsupportedEncodingException e) {
throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
.getSimpleName()), e);
} catch (XMLStreamException e) {
throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
.getSimpleName()), e);
} catch (FactoryConfigurationError e) {
throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
.getSimpleName()), e);
}
builder.entity(csb.getInputStream());
builder.header(ODataHttpHeaders.DATASERVICEVERSION, dataServiceVersion);
return builder.build();
}