@Test public void testFunctionImport() throws XMLStreamException, EntityProviderException { 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\"/>" + "<Property Name=\"" + propertyNames[1] + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>" + "</EntityType>" + "<EntityType Name= \"Room\" >" + "<Key><PropertyRef Name=\"RoomId\"/></Key>" + "<Property Name=\"" + "RoomId" + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "<Property Name=\"" + propertyNames[2] + "\" Type=\"Edm.String\" />" + "</EntityType>" + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">" + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>" + "<FunctionImport Name=\"EmployeeSearch\" ReturnType=\"Collection(RefScenario.Employee)\" " + "EntitySet=\"Employees\" m:HttpMethod=\"GET\">" + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" />" + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />" + "</FunctionImport>" + "<FunctionImport Name=\"RoomSearch\" ReturnType=\"Collection(RefScenario.Room)\" " + "EntitySet=\"Rooms\" m:HttpMethod=\"GET\">" + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" Mode=\"In\"/>" + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />" + "</FunctionImport>" + "<FunctionImport Name=\"NoParamters\" ReturnType=\"Collection(RefScenario.Room)\" " + "EntitySet=\"Rooms\" m:HttpMethod=\"GET\">" + "</FunctionImport>" + "<FunctionImport Name=\"NoReturn\" " + "EntitySet=\"Rooms\" m:HttpMethod=\"GET\"/>" + "<FunctionImport Name=\"SingleRoomReturnType\" ReturnType=\"RefScenario.Room\" " + "EntitySet=\"Rooms\" m:HttpMethod=\"GET\">" + "</FunctionImport>" + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>"; XmlMetadataConsumer parser = new XmlMetadataConsumer(); XMLStreamReader reader = createStreamReader(xmWithEntityContainer); DataServices result = parser.readMetadata(reader, true); for (Schema schema : result.getSchemas()) { for (EntityContainer container : schema.getEntityContainers()) { assertEquals("Container1", container.getName()); assertEquals(Boolean.TRUE, container.isDefaultEntityContainer()); assertEquals(5, container.getFunctionImports().size()); FunctionImport functionImport1 = container.getFunctionImports().get(0); assertEquals("EmployeeSearch", functionImport1.getName()); assertEquals("Employees", functionImport1.getEntitySet()); assertEquals(NAMESPACE, functionImport1.getReturnType().getTypeName().getNamespace()); assertEquals("Employee", functionImport1.getReturnType().getTypeName().getName()); assertEquals(EdmMultiplicity.MANY, functionImport1.getReturnType().getMultiplicity()); assertEquals("GET", functionImport1.getHttpMethod()); assertEquals(2, functionImport1.getParameters().size()); assertEquals("q1", functionImport1.getParameters().get(0).getName()); assertEquals(EdmSimpleTypeKind.String, functionImport1.getParameters().get(0).getType()); assertEquals(Boolean.TRUE, functionImport1.getParameters().get(0).getFacets().isNullable()); assertEquals("q2", functionImport1.getParameters().get(1).getName()); assertEquals(EdmSimpleTypeKind.Int32, functionImport1.getParameters().get(1).getType()); assertEquals(Boolean.FALSE, functionImport1.getParameters().get(1).getFacets().isNullable()); FunctionImport functionImport2 = container.getFunctionImports().get(1); assertEquals("RoomSearch", functionImport2.getName()); assertEquals("Rooms", functionImport2.getEntitySet()); assertEquals(NAMESPACE, functionImport2.getReturnType().getTypeName().getNamespace()); assertEquals("Room", functionImport2.getReturnType().getTypeName().getName()); assertEquals(EdmMultiplicity.MANY, functionImport2.getReturnType().getMultiplicity()); assertEquals("GET", functionImport2.getHttpMethod()); assertEquals(2, functionImport2.getParameters().size()); assertEquals(new FullQualifiedName("RefScenario", "Room"), functionImport2.getReturnType().getTypeName()); assertEquals(EdmMultiplicity.MANY, functionImport2.getReturnType().getMultiplicity()); FunctionImportParameter functionImportParameter = functionImport2.getParameters().get(0); assertEquals("q1", functionImportParameter.getName()); assertEquals(EdmSimpleTypeKind.String, functionImport2.getParameters().get(0).getType()); assertEquals(Boolean.TRUE, functionImport2.getParameters().get(0).getFacets().isNullable()); assertEquals("In", functionImportParameter.getMode()); assertEquals("q2", functionImport2.getParameters().get(1).getName()); assertEquals(EdmSimpleTypeKind.Int32, functionImport2.getParameters().get(1).getType()); assertEquals(Boolean.FALSE, functionImport2.getParameters().get(1).getFacets().isNullable()); assertEquals(null, functionImport2.getParameters().get(1).getMode()); FunctionImport functionImport3 = container.getFunctionImports().get(2); assertEquals("NoParamters", functionImport3.getName()); List<FunctionImportParameter> parameters3 = functionImport3.getParameters(); assertNotNull(parameters3); assertEquals(0, parameters3.size()); FunctionImport functionImport4 = container.getFunctionImports().get(3); assertEquals("NoReturn", functionImport4.getName()); List<FunctionImportParameter> parameters4 = functionImport4.getParameters(); assertNotNull(parameters4); assertEquals(0, parameters4.size()); assertNull(functionImport4.getReturnType()); FunctionImport functionImport5 = container.getFunctionImports().get(4); assertEquals("SingleRoomReturnType", functionImport5.getName()); List<FunctionImportParameter> parameters5 = functionImport5.getParameters(); assertNotNull(parameters5); assertEquals(0, parameters5.size()); assertEquals(new FullQualifiedName("RefScenario", "Room"), functionImport5.getReturnType().getTypeName()); assertEquals(EdmMultiplicity.ONE, functionImport5.getReturnType().getMultiplicity()); } } }
public DataServices readMetadata(final XMLStreamReader reader, final boolean validate) throws EntityProviderException { try { initialize(); DataServices dataServices = new DataServices(); List<Schema> schemas = new ArrayList<Schema>(); 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)); } 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)); } if (validate) { validate(); } dataServices.setSchemas(schemas); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
XmlMetadataConsumer { public DataServices readMetadata(final XMLStreamReader reader, final boolean validate) throws EntityProviderException { try { initialize(); DataServices dataServices = new DataServices(); List<Schema> schemas = new ArrayList<Schema>(); 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)); } 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)); } if (validate) { validate(); } dataServices.setSchemas(schemas); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } } }
XmlMetadataConsumer { public DataServices readMetadata(final XMLStreamReader reader, final boolean validate) throws EntityProviderException { try { initialize(); DataServices dataServices = new DataServices(); List<Schema> schemas = new ArrayList<Schema>(); 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)); } 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)); } if (validate) { validate(); } dataServices.setSchemas(schemas); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  }
XmlMetadataConsumer { public DataServices readMetadata(final XMLStreamReader reader, final boolean validate) throws EntityProviderException { try { initialize(); DataServices dataServices = new DataServices(); List<Schema> schemas = new ArrayList<Schema>(); 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)); } 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)); } if (validate) { validate(); } dataServices.setSchemas(schemas); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  DataServices readMetadata(final XMLStreamReader reader, final boolean validate); }
XmlMetadataConsumer { public DataServices readMetadata(final XMLStreamReader reader, final boolean validate) throws EntityProviderException { try { initialize(); DataServices dataServices = new DataServices(); List<Schema> schemas = new ArrayList<Schema>(); 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)); } 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)); } if (validate) { validate(); } dataServices.setSchemas(schemas); reader.close(); return dataServices; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }  DataServices readMetadata(final XMLStreamReader reader, final boolean validate);  }