public EndpointMetadata parse(XMLEventReader xmlEventReader, StartElement start)
throws GraphIOException {
try {
// Create the new endpoint.
EndpointMetadata endpoint = new EndpointMetadata();
// 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 (endpoint.getId() == null && GraphMLConstants.ID_NAME.equals(name)) {
endpoint.setId(value);
} if (endpoint.getPort() == null && GraphMLConstants.PORT_NAME.equals(name)) {
endpoint.setPort(value);
} if (endpoint.getNode() == null && GraphMLConstants.NODE_NAME.equals(name)) {
endpoint.setNode(value);
} if (GraphMLConstants.TYPE_NAME.equals(name)) {
EndpointType t = endpointTypeMap.get(value);
if( t == null ) {
t = EndpointType.UNDIR;
}
endpoint.setEndpointType(t);
} else {
endpoint.setProperty(name, value);
}
}
// Make sure the node has been set.
if (endpoint.getNode() == null) {
throw new GraphIOException(
"Element 'endpoint' is missing attribute 'node'");
}
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);
endpoint.setDescription(desc);
} else {
// Treat anything else as unknown
getUnknownParser().parse(xmlEventReader, element);
}