}
private FunctionImport readFunctionImport(final XMLStreamReader reader)
throws XMLStreamException, EntityProviderException {
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_FUNCTION_IMPORT);
FunctionImport function = new FunctionImport();
List<FunctionImportParameter> functionParameters = new ArrayList<FunctionImportParameter>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
function.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
function.setHttpMethod(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08,
XmlMetadataConstants.EDM_FUNCTION_IMPORT_HTTP_METHOD));
function.setEntitySet(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_SET));
ReturnType returnType = new ReturnType();
String returnTypeString = reader.getAttributeValue(null, XmlMetadataConstants.EDM_FUNCTION_IMPORT_RETURN);
if (returnTypeString != null) {
if (returnTypeString.startsWith("Collection") || returnTypeString.startsWith("collection")) {
returnType.setMultiplicity(EdmMultiplicity.MANY);
returnTypeString = returnTypeString.substring(returnTypeString.indexOf("(") + 1, returnTypeString.length() - 1);
}
FullQualifiedName fqName = extractFQName(returnTypeString);
returnType.setTypeName(fqName);
function.setReturnType(returnType);
}
function.setAnnotationAttributes(readAnnotationAttribute(reader));
while (reader.hasNext()
&& !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& XmlMetadataConstants.EDM_FUNCTION_IMPORT.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (XmlMetadataConstants.EDM_FUNCTION_PARAMETER.equals(currentHandledStartTagName)) {
functionParameters.add(readFunctionImportParameter(reader));
} else {
annotationElements.add(readAnnotationElement(reader));
}
}
}
if (!annotationElements.isEmpty()) {
function.setAnnotationElements(annotationElements);
}
function.setParameters(functionParameters);
return function;
}