@Test public void testEntityType() throws XMLStreamException, EntityProviderException, EdmException, UnsupportedEncodingException { final String xmWithEntityContainer = "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\"" + Edm.NAMESPACE_EDMX_2007_06 + "\">" + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "<Schema Namespace=\"" + NAMESPACE + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Employee\" m:HasStream=\"true\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\"" + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "</EntityType>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">" + "<EntitySet Name=\"Photos\" EntityType=\"" + NAMESPACE2 + ".Photo\"/>" + "</EntityContainer>" + "<EntityContainer Name=\"Container2\" m:IsDefaultEntityContainer=\"true\">" + "<EntitySet Name=\"Sign\" EntityType=\"" + NAMESPACE3 + ".Sign\"/>" + "</EntityContainer>" + "</Schema>" + "<Schema Namespace=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Photo\">" + "<Key><PropertyRef Name=\"Id\"/></Key>" + "<Property Name=\"Id\" Type=\"Edm.Int32\" Nullable=\"false\"/>" + "</EntityType>" + "<EntityType Name= \"Name\">" + "<Key><PropertyRef Name=\"NameId\"/></Key>" + "<Property Name=\"NameId\" Type=\"Edm.Int32\" Nullable=\"false\"/>" + "</EntityType>" + "<EntityContainer Name=\"Container2\" m:IsDefaultEntityContainer=\"true\">" + "<EntitySet Name=\"Name\" EntityType=\"" + NAMESPACE2 + ".Name\"/>" + "<EntitySet Name=\"Photo\" EntityType=\"" + NAMESPACE2 + ".Photo\"/>" + "</EntityContainer>" + "</Schema>" + "<Schema Namespace=\"" + NAMESPACE3 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">" + "<EntityType Name= \"Sign\">" + "<Key><PropertyRef Name=\"Id\"/></Key>" + "<Property Name=\"Id\" Type=\"Edm.Int32\" Nullable=\"false\"/>" + "</EntityType>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataDeserializer parser = new XmlMetadataDeserializer(); InputStream reader = createStreamReader(xmWithEntityContainer); EdmDataServices result = parser.readMetadata(reader, true); assertEquals("2.0", result.getDataServiceVersion()); assertEquals(NAMESPACE, result.getEdm().getSchemas().get(0).getNamespace()); assertEquals(NAMESPACE2, result.getEdm().getSchemas().get(1).getNamespace()); assertEquals(NAMESPACE3, result.getEdm().getSchemas().get(2).getNamespace()); assertEquals("Employee", result.getEdm().getSchemas().get(0).getEntityTypes().get(0).getName()); assertNotNull(result.getEdm().getSchemas().get(0).getEntityTypes().get(0).getProperty("EmployeeId")); assertEquals("Photo", result.getEdm().getSchemas().get(1).getEntityTypes().get(0).getName()); assertNotNull(result.getEdm().getSchemas().get(1).getEntityTypes().get(0).getProperty("Id")); assertEquals("Name", result.getEdm().getSchemas().get(1).getEntityTypes().get(1).getName()); assertEquals("NameId", result.getEdm().getSchemas().get(1).getEntityTypes() .get(1).getKeyProperties().get(0).getName()); assertEquals("Sign", result.getEdm().getSchemas().get(2).getEntityTypes().get(0).getName()); assertNotNull(result.getEdm().getSchemas().get(2).getEntityTypes().get(0).getProperty("Id")); }
public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } } }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  EdmDataServices readMetadata(final InputStream content, final boolean validate); }
XmlMetadataDeserializer { public EdmDataServices readMetadata(final InputStream content, final boolean validate) throws EntityProviderException, EdmException { try { initialize(); EdmDataServices dataServices = new EdmDataServices(); List<EdmSchema> schemas = new ArrayList<EdmSchema>(); EdmImpl edm = new EdmImpl(); XMLStreamReader reader = XmlHelper.createStreamReader(content); while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDMX_2007_06.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); if (XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName())) { edmNamespace = reader.getNamespaceURI(); checkEdmNamespace(); schemas.add(readSchema(reader, edm)); } else if (XmlMetadataConstants.EDM_DATA_SERVICES.equals(reader .getLocalName())) { dataServices.setDataServiceVersion(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, "DataServiceVersion")); } } } if (!reader.isEndElement() || !XmlMetadataConstants.EDMX_TAG.equals(reader.getLocalName())) { throw new EntityProviderException(EntityProviderException.MISSING_TAG .addContent(XmlMetadataConstants.EDMX_TAG)); } setBaseTypeForEntityType(); setBaseTypeForComplexType(); setDetailsForEntitySet(); setAssociationSetForNavigations(); if (validate) { validate(); } edm.setEdmSchemas(schemas); dataServices.setClientEdm(edm); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  EdmDataServices readMetadata(final InputStream content, final boolean validate);  }