예제 #1
0
 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;
 }
예제 #2
0
 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;
   }
 }