}
private AssociationSet readAssociationSet(final XMLStreamReader reader)
throws XMLStreamException, EntityProviderException {
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_SET);
AssociationSet associationSet = new AssociationSet();
List<AssociationSetEnd> ends = new ArrayList<AssociationSetEnd>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
associationSet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
String association = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ASSOCIATION);
if (association != null) {
associationSet.setAssociation(extractFQName(association));
} else {
throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
.addContent(XmlMetadataConstants.EDM_ASSOCIATION).addContent(XmlMetadataConstants.EDM_ASSOCIATION_SET));
}
associationSet.setAnnotationAttributes(readAnnotationAttribute(reader));
while (reader.hasNext()
&& !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& XmlMetadataConstants.EDM_ASSOCIATION_SET.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (XmlMetadataConstants.EDM_ASSOCIATION_END.equals(currentHandledStartTagName)) {
AssociationSetEnd associationSetEnd = new AssociationSetEnd();
associationSetEnd.setEntitySet(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_SET));
associationSetEnd.setRole(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ROLE));
ends.add(associationSetEnd);
} else {
annotationElements.add(readAnnotationElement(reader));
}
}
}
if (ends.size() != 2) {
throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
.addContent("Count of AssociationSet ends should be 2"));
} else {
associationSet.setEnd1(ends.get(0)).setEnd2(ends.get(1));
}
associationSet.setAnnotationElements(annotationElements);
return associationSet;
}