public Key parse(XMLEventReader xmlEventReader, StartElement start)
throws GraphIOException {
try {
// Create the new key. ForType defaults to ALL.
Key key = new Key();
// Parse the attributes.
Iterator iterator = start.getAttributes();
while (iterator.hasNext()) {
Attribute attribute = (Attribute) iterator.next();
String name = attribute.getName().getLocalPart();
String value = attribute.getValue();
if (key.getId() == null && GraphMLConstants.ID_NAME.equals(name)) {
key.setId(value);
} else if (key.getAttributeName() == null
&& GraphMLConstants.ATTRNAME_NAME.equals(name)) {
key.setAttributeName(value);
} else if (key.getAttributeType() == null
&& GraphMLConstants.ATTRTYPE_NAME.equals(name)) {
key.setAttributeType(value);
} else if (GraphMLConstants.FOR_NAME.equals(name)) {
key.setForType(convertFor(value));
}
}
// Make sure the id has been set.
if (key.getId() == null) {
throw new GraphIOException(
"Element 'key' is missing attribute 'id'");
}
while (xmlEventReader.hasNext()) {
XMLEvent event = xmlEventReader.nextEvent();
if (event.isStartElement()) {
StartElement element = (StartElement) event;
String name = element.getName().getLocalPart();
if(GraphMLConstants.DESC_NAME.equals(name)) {
String desc = (String)getParser(name).parse(xmlEventReader, element);
key.setDescription(desc);
} else if(GraphMLConstants.DEFAULT_NAME.equals(name)) {
String defaultValue = (String)getParser(name).parse(xmlEventReader, element);
key.setDefaultValue(defaultValue);
} else {
// Treat anything else as unknown
getUnknownParser().parse(xmlEventReader, element);
}