}
private Association readAssociation(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION);
Association association = new Association();
association.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
List<AssociationEnd> associationEnds = new ArrayList<AssociationEnd>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
association.setAnnotationAttributes(readAnnotationAttribute(reader));
while (reader.hasNext()
&& !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& XmlMetadataConstants.EDM_ASSOCIATION.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (XmlMetadataConstants.EDM_ASSOCIATION_END.equals(currentHandledStartTagName)) {
associationEnds.add(readAssociationEnd(reader));
} else if (XmlMetadataConstants.EDM_ASSOCIATION_CONSTRAINT.equals(currentHandledStartTagName)) {
association.setReferentialConstraint(readReferentialConstraint(reader));
} else {
annotationElements.add(readAnnotationElement(reader));
}
}
}
if (associationEnds.size() < 2 && associationEnds.size() > 2) {
throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
.addContent("Count of association ends should be 2"));
}
if (!annotationElements.isEmpty()) {
association.setAnnotationElements(annotationElements);
}
association.setEnd1(associationEnds.get(0)).setEnd2(associationEnds.get(1));
associationsMap.put(new FullQualifiedName(currentNamespace, association.getName()), association);
return association;
}