@Test public void testWriteMetadataDocument() throws Exception { MetadataDocumentWriter writer = new MetadataDocumentWriter(entityDataModel); writer.startDocument(); writer.writeMetadataDocument(); writer.endDocument(); assertEquals(prettyPrintXml(readContent(EXPECTED_METADATA_DOC_PATH)), prettyPrintXml(writer.getXml())); }
public void writeMetadataDocument() throws ODataRenderException { try { xmlWriter.writeStartElement(EDMX_NS, EDMX); xmlWriter.writeNamespace(EDMX_PREFIX, EDMX_NS); xmlWriter.writeAttribute(VERSION, ODATA_VERSION); xmlWriter.writeStartElement(EDMX_NS, EDMX_DATA_SERVICES); boolean entityContinerWritten = false; for (Schema schema : entityDataModel.getSchemas()) { xmlWriter.writeStartElement(SCHEMA); xmlWriter.writeDefaultNamespace(EDM_NS); xmlWriter.writeAttribute(NAMESPACE, schema.getNamespace()); for (Type type : schema.getTypes()) { switch (type.getMetaType()) { case ENTITY: entityTypeWriter.write((EntityType) type); break; case COMPLEX: complexTypeWriter.write((ComplexType) type); break; case ENUM: enumTypeWriter.write((EnumType) type); break; default: LOG.error("Unexpected type: {}", type.getFullyQualifiedName()); throw new ODataRenderException("Unexpected type: " + type.getFullyQualifiedName()); } } if (!entityContinerWritten) { writeEntityContainer(entityDataModel.getEntityContainer()); entityContinerWritten = true; } xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } catch (XMLStreamException e) { LOG.error("Not possible to start stream XML"); throw new ODataRenderException("Not possible to start stream XML: ", e); } }
MetadataDocumentWriter { public void writeMetadataDocument() throws ODataRenderException { try { xmlWriter.writeStartElement(EDMX_NS, EDMX); xmlWriter.writeNamespace(EDMX_PREFIX, EDMX_NS); xmlWriter.writeAttribute(VERSION, ODATA_VERSION); xmlWriter.writeStartElement(EDMX_NS, EDMX_DATA_SERVICES); boolean entityContinerWritten = false; for (Schema schema : entityDataModel.getSchemas()) { xmlWriter.writeStartElement(SCHEMA); xmlWriter.writeDefaultNamespace(EDM_NS); xmlWriter.writeAttribute(NAMESPACE, schema.getNamespace()); for (Type type : schema.getTypes()) { switch (type.getMetaType()) { case ENTITY: entityTypeWriter.write((EntityType) type); break; case COMPLEX: complexTypeWriter.write((ComplexType) type); break; case ENUM: enumTypeWriter.write((EnumType) type); break; default: LOG.error("Unexpected type: {}", type.getFullyQualifiedName()); throw new ODataRenderException("Unexpected type: " + type.getFullyQualifiedName()); } } if (!entityContinerWritten) { writeEntityContainer(entityDataModel.getEntityContainer()); entityContinerWritten = true; } xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } catch (XMLStreamException e) { LOG.error("Not possible to start stream XML"); throw new ODataRenderException("Not possible to start stream XML: ", e); } } }
MetadataDocumentWriter { public void writeMetadataDocument() throws ODataRenderException { try { xmlWriter.writeStartElement(EDMX_NS, EDMX); xmlWriter.writeNamespace(EDMX_PREFIX, EDMX_NS); xmlWriter.writeAttribute(VERSION, ODATA_VERSION); xmlWriter.writeStartElement(EDMX_NS, EDMX_DATA_SERVICES); boolean entityContinerWritten = false; for (Schema schema : entityDataModel.getSchemas()) { xmlWriter.writeStartElement(SCHEMA); xmlWriter.writeDefaultNamespace(EDM_NS); xmlWriter.writeAttribute(NAMESPACE, schema.getNamespace()); for (Type type : schema.getTypes()) { switch (type.getMetaType()) { case ENTITY: entityTypeWriter.write((EntityType) type); break; case COMPLEX: complexTypeWriter.write((ComplexType) type); break; case ENUM: enumTypeWriter.write((EnumType) type); break; default: LOG.error("Unexpected type: {}", type.getFullyQualifiedName()); throw new ODataRenderException("Unexpected type: " + type.getFullyQualifiedName()); } } if (!entityContinerWritten) { writeEntityContainer(entityDataModel.getEntityContainer()); entityContinerWritten = true; } xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } catch (XMLStreamException e) { LOG.error("Not possible to start stream XML"); throw new ODataRenderException("Not possible to start stream XML: ", e); } } MetadataDocumentWriter(EntityDataModel entityDataModel); }
MetadataDocumentWriter { public void writeMetadataDocument() throws ODataRenderException { try { xmlWriter.writeStartElement(EDMX_NS, EDMX); xmlWriter.writeNamespace(EDMX_PREFIX, EDMX_NS); xmlWriter.writeAttribute(VERSION, ODATA_VERSION); xmlWriter.writeStartElement(EDMX_NS, EDMX_DATA_SERVICES); boolean entityContinerWritten = false; for (Schema schema : entityDataModel.getSchemas()) { xmlWriter.writeStartElement(SCHEMA); xmlWriter.writeDefaultNamespace(EDM_NS); xmlWriter.writeAttribute(NAMESPACE, schema.getNamespace()); for (Type type : schema.getTypes()) { switch (type.getMetaType()) { case ENTITY: entityTypeWriter.write((EntityType) type); break; case COMPLEX: complexTypeWriter.write((ComplexType) type); break; case ENUM: enumTypeWriter.write((EnumType) type); break; default: LOG.error("Unexpected type: {}", type.getFullyQualifiedName()); throw new ODataRenderException("Unexpected type: " + type.getFullyQualifiedName()); } } if (!entityContinerWritten) { writeEntityContainer(entityDataModel.getEntityContainer()); entityContinerWritten = true; } xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } catch (XMLStreamException e) { LOG.error("Not possible to start stream XML"); throw new ODataRenderException("Not possible to start stream XML: ", e); } } MetadataDocumentWriter(EntityDataModel entityDataModel); void startDocument(); void endDocument(); void writeMetadataDocument(); String getXml(); }
MetadataDocumentWriter { public void writeMetadataDocument() throws ODataRenderException { try { xmlWriter.writeStartElement(EDMX_NS, EDMX); xmlWriter.writeNamespace(EDMX_PREFIX, EDMX_NS); xmlWriter.writeAttribute(VERSION, ODATA_VERSION); xmlWriter.writeStartElement(EDMX_NS, EDMX_DATA_SERVICES); boolean entityContinerWritten = false; for (Schema schema : entityDataModel.getSchemas()) { xmlWriter.writeStartElement(SCHEMA); xmlWriter.writeDefaultNamespace(EDM_NS); xmlWriter.writeAttribute(NAMESPACE, schema.getNamespace()); for (Type type : schema.getTypes()) { switch (type.getMetaType()) { case ENTITY: entityTypeWriter.write((EntityType) type); break; case COMPLEX: complexTypeWriter.write((ComplexType) type); break; case ENUM: enumTypeWriter.write((EnumType) type); break; default: LOG.error("Unexpected type: {}", type.getFullyQualifiedName()); throw new ODataRenderException("Unexpected type: " + type.getFullyQualifiedName()); } } if (!entityContinerWritten) { writeEntityContainer(entityDataModel.getEntityContainer()); entityContinerWritten = true; } xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); } catch (XMLStreamException e) { LOG.error("Not possible to start stream XML"); throw new ODataRenderException("Not possible to start stream XML: ", e); } } MetadataDocumentWriter(EntityDataModel entityDataModel); void startDocument(); void endDocument(); void writeMetadataDocument(); String getXml();  }