private AssociationEnd readAssociationEnd(final XMLStreamReader reader) throws EntityProviderException,
XMLStreamException {
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_END);
AssociationEnd associationEnd = new AssociationEnd();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
associationEnd.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE));
associationEnd.setMultiplicity(EdmMultiplicity.fromLiteral(reader.getAttributeValue(null,
XmlMetadataConstants.EDM_ASSOCIATION_MULTIPLICITY)));
String type = reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE);
if (type == null) {
throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
.addContent(XmlMetadataConstants.EDM_TYPE).addContent(XmlMetadataConstants.EDM_ASSOCIATION_END));
}
associationEnd.setType(extractFQName(type));
associationEnd.setAnnotationAttributes(readAnnotationAttribute(reader));
while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& XmlMetadataConstants.EDM_ASSOCIATION_END.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (XmlMetadataConstants.EDM_ASSOCIATION_ONDELETE.equals(currentHandledStartTagName)) {
OnDelete onDelete = new OnDelete();
for (int i = 0; i < EdmAction.values().length; i++) {
if (EdmAction.values()[i].name().equalsIgnoreCase(
reader.getAttributeValue(null, XmlMetadataConstants.EDM_ONDELETE_ACTION))) {
onDelete.setAction(EdmAction.values()[i]);
}
}
associationEnd.setOnDelete(onDelete);
} else {
annotationElements.add(readAnnotationElement(reader));
}
}
}
if (!annotationElements.isEmpty()) {
associationEnd.setAnnotationElements(annotationElements);
}
return associationEnd;
}