protected EdmAnnotation<?> getAnnotationElements(XMLEvent2 event, XMLEventReader2 reader) { StartElement2 annotationStartElement = event.asStartElement(); QName2 q = annotationStartElement.getName(); String value = null; EdmAnnotationElement<?> element = null; List<EdmAnnotation<?>> list = new ArrayList<EdmAnnotation<?>>(); if (!NON_USER_NAMESPACES.contains(q.getNamespaceUri())) { // a user extension while (reader.hasNext()) { event = reader.nextEvent(); if (event.isStartElement()) { EdmAnnotation<?> childElement = getAnnotationElements(event, reader); if (childElement != null) { list.add(childElement); } } else if (event.isCharacters()) { value = event.asCharacters().getData().trim(); } else if (event.isEndElement()) { if (value != null) { element = EdmAnnotation.element( q.getNamespaceUri(), q.getPrefix(), q.getLocalPart(), String.class, value); } else { element = EdmAnnotation.element( q.getNamespaceUri(), q.getPrefix(), q.getLocalPart(), String.class, ""); } element.setAnnotationElements(list); element.setAnnotations(getAnnotations(annotationStartElement)); return element; } } } return null; }
protected List<EdmAnnotation<?>> getAnnotations(StartElement2 element) { // extract Annotation attributes try { Enumerable<Attribute2> atts = element.getAttributes(); List<EdmAnnotation<?>> annots = new ArrayList<EdmAnnotation<?>>(); for (Attribute2 att : atts) { QName2 q = att.getName(); if (isExtensionNamespace(q.getNamespaceUri())) { // a user extension annots.add( EdmAnnotation.attribute( q.getNamespaceUri(), q.getPrefix(), q.getLocalPart(), att.getValue())); } } return annots; } catch (Exception ex) { // not all of the xml parsing implementations implement getAttributes() yet. return null; } }
private static void writeDocumentation(EdmItem item, XMLWriter2 writer) { EdmDocumentation doc = item.getDocumentation(); if (null != doc && (null != doc.getSummary() || null != doc.getLongDescription())) { QName2 d = new QName2(edm, "Documentation"); writer.startElement(d); { if (null != doc.getSummary()) { QName2 s = new QName2(edm, "Summary"); writer.startElement(s); writer.writeText(doc.getSummary()); writer.endElement(s.getLocalPart()); } if (null != doc.getLongDescription()) { QName2 s = new QName2(edm, "LongDescription"); writer.startElement(s); writer.writeText(doc.getLongDescription()); writer.endElement(s.getLocalPart()); } } writer.endElement(d.getLocalPart()); } }