}
private Schema readSchema(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_SCHEMA);
Schema schema = new Schema();
List<Using> usings = new ArrayList<Using>();
List<ComplexType> complexTypes = new ArrayList<ComplexType>();
List<EntityType> entityTypes = new ArrayList<EntityType>();
List<Association> associations = new ArrayList<Association>();
List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
schema.setNamespace(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_NAMESPACE));
inscopeMap.put(schema.getNamespace(), new HashSet<String>());
schema.setAlias(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_ALIAS));
schema.setAnnotationAttributes(readAnnotationAttribute(reader));
currentNamespace = schema.getNamespace();
while (reader.hasNext()
&& !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
&& XmlMetadataConstants.EDM_SCHEMA.equals(reader.getLocalName()))) {
reader.next();
if (reader.isStartElement()) {
extractNamespaces(reader);
currentHandledStartTagName = reader.getLocalName();
if (XmlMetadataConstants.EDM_USING.equals(currentHandledStartTagName)) {
usings.add(readUsing(reader, schema.getNamespace()));
} else if (XmlMetadataConstants.EDM_ENTITY_TYPE.equals(currentHandledStartTagName)) {
entityTypes.add(readEntityType(reader));
} else if (XmlMetadataConstants.EDM_COMPLEX_TYPE.equals(currentHandledStartTagName)) {
complexTypes.add(readComplexType(reader));
} else if (XmlMetadataConstants.EDM_ASSOCIATION.equals(currentHandledStartTagName)) {
associations.add(readAssociation(reader));
} else if (XmlMetadataConstants.EDM_ENTITY_CONTAINER.equals(currentHandledStartTagName)) {
entityContainers.add(readEntityContainer(reader));
} else {
annotationElements.add(readAnnotationElement(reader));
}
}
}
if (schema.getAlias() != null) {
aliasNamespaceMap.put(schema.getAlias(), schema.getNamespace());
}
schema.setUsings(usings).setEntityTypes(entityTypes).setComplexTypes(complexTypes).setAssociations(associations)
.setEntityContainers(entityContainers).setAnnotationElements(annotationElements);
return schema;
}