Java Code Examples for javax.xml.stream.XMLStreamReader#isEndElement()

The following examples show how to use javax.xml.stream.XMLStreamReader#isEndElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EdmParser.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private EntitySet readEntitySet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_EDM_2008_09, EdmParserConstants.EDM_ENTITY_SET);
  EntitySet entitySet = new EntitySet();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  entitySet.setName(reader.getAttributeValue(null, EdmParserConstants.EDM_NAME));
  String entityType = reader.getAttributeValue(null, EdmParserConstants.EDM_ENTITY_TYPE);
  if (entityType != null) {
    FullQualifiedName fqName = extractFQName(entityType);
    entitySet.setEntityType(fqName);
  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(EdmParserConstants.EDM_ENTITY_TYPE).addContent(EdmParserConstants.EDM_ENTITY_SET));
  }
  entitySet.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI()) && EdmParserConstants.EDM_ENTITY_SET.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  entitySet.setAnnotationElements(annotationElements);
  return entitySet;
}
 
Example 2
Source File: AtomServiceDocumentConsumer.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private WorkspaceImpl parseWorkspace(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_APP_2007, FormatXml.APP_WORKSPACE);

  TitleImpl title = null;
  List<Collection> collections = new ArrayList<Collection>();
  List<ExtensionElement> extElements = new ArrayList<ExtensionElement>();
  CommonAttributesImpl attributes = parseCommonAttribute(reader);
  while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_APP_2007.equals(reader.getNamespaceURI()) && FormatXml.APP_WORKSPACE.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      currentHandledStartTagName = reader.getLocalName();
      if (FormatXml.APP_COLLECTION.equals(currentHandledStartTagName)) {
        collections.add(parseCollection(reader));
      } else if (FormatXml.ATOM_TITLE.equals(currentHandledStartTagName)) {
        title = parseTitle(reader);
      } else {
        extElements.add(parseExtensionSansTitleElement(reader));
      }
    }
  }
  if (title == null) {
    throw new EntityProviderException(EntityProviderException.INVALID_STATE.addContent("Missing element title for workspace"));
  }
  return new WorkspaceImpl().setTitle(title).setCollections(collections).setAttributes(attributes).setExtesionElements(extElements);
}
 
Example 3
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private Key readEntityTypeKey(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_TYPE_KEY);
  List<PropertyRef> keys = new ArrayList<PropertyRef>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  List<AnnotationAttribute> annotationAttributes = readAnnotationAttribute(reader);
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ENTITY_TYPE_KEY.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_PROPERTY_REF.equals(currentHandledStartTagName)) {
        reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY_REF);
        keys.add(readPropertyRef(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  Key key = new Key().setKeys(keys).setAnnotationAttributes(annotationAttributes);
  if (!annotationElements.isEmpty()) {
    key.setAnnotationElements(annotationElements);
  }
  return key;
}
 
Example 4
Source File: EdmParser.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private ReferentialConstraintRole readReferentialConstraintRole(final XMLStreamReader reader) throws EntityProviderException, XMLStreamException {
  ReferentialConstraintRole rcRole = new ReferentialConstraintRole();
  rcRole.setRole(reader.getAttributeValue(null, EdmParserConstants.EDM_ROLE));
  List<PropertyRef> propertyRefs = new ArrayList<PropertyRef>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  rcRole.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_EDM_2008_09.equals(reader.getNamespaceURI())
      && (EdmParserConstants.EDM_ASSOCIATION_PRINCIPAL.equals(reader.getLocalName()) || EdmParserConstants.EDM_ASSOCIATION_DEPENDENT.equals(reader.getLocalName())))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (EdmParserConstants.EDM_PROPERTY_REF.equals(currentHandledStartTagName)) {
        propertyRefs.add(readPropertyRef(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  rcRole.setPropertyRefs(propertyRefs).setAnnotationElements(annotationElements);
  return rcRole;
}
 
Example 5
Source File: XmlLinkConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Reads multiple links with format
 * <pre> {@code
 * <links>
 *  <uri>http://somelink</uri>
 *  <uri>http://anotherLink</uri>
 *  <uri>http://somelink/yetAnotherLink</uri>
 * </links>
 * } </pre>
 * @param reader
 * @param entitySet
 * @return list of string based links
 * @throws EntityProviderException
 */
public List<String> readLinks(final XMLStreamReader reader, final EdmEntitySet entitySet)
    throws EntityProviderException {
  try {
    List<String> links = new ArrayList<String>();
    reader.nextTag();
    reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_D_2007_08, FormatXml.D_LINKS);
    reader.nextTag();
    while (!reader.isEndElement()) {
      if (reader.getLocalName().equals(FormatXml.M_COUNT)) {
        readTag(reader, Edm.NAMESPACE_M_2007_08, FormatXml.M_COUNT);
      } else {
        final String link = readLink(reader);
        links.add(link);
      }
      reader.nextTag();
    }

    reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_D_2007_08, FormatXml.D_LINKS);
    return links;
  } catch (final XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
        .getSimpleName()), e);
  }
}
 
Example 6
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EdmReferentialConstraint readReferentialConstraint(final XMLStreamReader reader) throws XMLStreamException,
    EntityProviderException, EdmException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_CONSTRAINT);
  EdmReferentialConstraintImpl refConstraint = new EdmReferentialConstraintImpl();
  List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>();
  EdmAnnotationsImpl annotations = new EdmAnnotationsImpl();
  annotations.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
          && XmlMetadataConstants.EDM_ASSOCIATION_CONSTRAINT.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_ASSOCIATION_PRINCIPAL.equals(currentHandledStartTagName)) {
        reader
            .require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_PRINCIPAL);
        refConstraint.setPrincipal(readReferentialConstraintRole(reader));
      } else if (XmlMetadataConstants.EDM_ASSOCIATION_DEPENDENT.equals(currentHandledStartTagName)) {
        reader
            .require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ASSOCIATION_DEPENDENT);
        refConstraint.setDependent(readReferentialConstraintRole(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (!annotationElements.isEmpty()) {
    annotations.setAnnotationElements(annotationElements);
  }
  refConstraint.setAnnotations(annotations);
  return refConstraint;
}
 
Example 7
Source File: XmlEntryConsumer.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param reader
 * @param eia
 * @param readProperties
 * @throws EntityProviderException
 * @throws XMLStreamException
 * @throws EdmException
 */
private void readLink(final XMLStreamReader reader, final EntityInfoAggregator eia, final EntityProviderReadProperties readProperties) throws EntityProviderException, XMLStreamException, EdmException {
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_LINK);

  final String rel = reader.getAttributeValue(null, FormatXml.ATOM_REL);
  final String uri = reader.getAttributeValue(null, FormatXml.ATOM_HREF);
  final String type = reader.getAttributeValue(null, FormatXml.ATOM_TYPE);
  final String etag = reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, FormatXml.M_ETAG);

  // read to next tag to check if <link> contains any further tags
  reader.nextTag();

  if (reader.isEndElement()) {
    reader.require(XMLStreamConstants.END_ELEMENT, Edm.NAMESPACE_ATOM_2005, FormatXml.ATOM_LINK);

    if (rel == null || uri == null) {
      throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent(
          FormatXml.ATOM_HREF + "' and/or '" + FormatXml.ATOM_REL).addContent(FormatXml.ATOM_LINK));
    } else if (rel.startsWith(Edm.NAMESPACE_REL_2007_08)) {
      final String navigationPropertyName = rel.substring(Edm.NAMESPACE_REL_2007_08.length());
      entryMetadata.putAssociationUri(navigationPropertyName, uri);
    } else if (rel.equals(Edm.LINK_REL_EDIT_MEDIA)) {
      mediaMetadata.setEditLink(uri);
      mediaMetadata.setEtag(etag);
    }
  } else {
    if (rel != null && rel.startsWith(Edm.NAMESPACE_REL_2007_08)) {
      readInlineContent(reader, eia, readProperties, type, rel);
    }
  }
}
 
Example 8
Source File: AntXmlParser.java    From rich-test-results with Apache License 2.0 5 votes vote down vote up
private void parseProperties(XMLStreamReader xmlStreamReader, TestSuite.Builder suiteBuilder)
    throws XMLStreamException {
  String tagName = null;
  do {
    xmlStreamReader.next();
    if (!xmlStreamReader.hasName()) {
      continue;
    }
    tagName = xmlStreamReader.getName().toString();
    if (xmlStreamReader.isStartElement()) {
      switch (tagName) {
        case "property":
          Builder builder = suiteBuilder.addPropertyBuilder();
          for (int i = 0; i < xmlStreamReader.getAttributeCount(); i++) {
            String attributeValue = xmlStreamReader.getAttributeValue(i);
            switch (xmlStreamReader.getAttributeName(i).toString()) {
              case "name":
                builder.setName(attributeValue);
                break;
              case "value":
                builder.setValue(attributeValue);
                break;
            }
          }
          break;
      }
    } else if (xmlStreamReader.isEndElement() && "properties".equals(tagName)) {
      break;
    }
  } while (!xmlStreamReader.isEndElement() || !"properties".equals(tagName));
}
 
Example 9
Source File: BaseChildElementParser.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void parseChildElements(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model, BaseChildElementParser parser) throws Exception {
  boolean readyWithChildElements = false;
  while (readyWithChildElements == false && xtr.hasNext()) {
    xtr.next();
    if (xtr.isStartElement()) {
      if (parser.getElementName().equals(xtr.getLocalName())) {
        parser.parseChildElement(xtr, parentElement, model);
      }

    } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
      readyWithChildElements = true;
    }
  }
}
 
Example 10
Source File: InputExpressionParser.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void parseChildElement(XMLStreamReader xtr, DmnElement parentElement, Decision decision) throws Exception {
    if (!(parentElement instanceof InputClause))
        return;

    InputClause clause = (InputClause) parentElement;
    LiteralExpression inputExpression = new LiteralExpression();
    inputExpression.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
    inputExpression.setTypeRef(xtr.getAttributeValue(null, ATTRIBUTE_TYPE_REF));

    boolean readyWithInputExpression = false;
    try {
        while (!readyWithInputExpression && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_TEXT.equalsIgnoreCase(xtr.getLocalName())) {
                inputExpression.setText(xtr.getElementText());

            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithInputExpression = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing input expression", e);
    }

    clause.setInputExpression(inputExpression);
}
 
Example 11
Source File: XmlParserStream.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void skipUnknownNode(final XMLStreamReader in) throws XMLStreamException {
    // in case when the unknown node and at least one of its descendant nodes have the same name
    // we cannot properly reach the end just by checking if the current node is an end element and has the same name
    // as the root unknown element. therefore we ignore the names completely and just track the level of nesting
    int levelOfNesting = 0;
    while (in.hasNext()) {
        // in case there are text characters in an element, we cannot skip them by calling nextTag()
        // therefore we skip them by calling next(), and then proceed to next element
        in.next();
        if (!isAtElement(in)) {
            in.nextTag();
        }
        if (in.isStartElement()) {
            levelOfNesting++;
        }

        if (in.isEndElement()) {
            if (levelOfNesting == 0) {
                break;
            }

            levelOfNesting--;
        }
    }

    in.nextTag();
}
 
Example 12
Source File: AtomServiceDocumentConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private WorkspaceImpl parseWorkspace(final XMLStreamReader reader)
    throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_APP_2007, FormatXml.APP_WORKSPACE);

  TitleImpl title = null;
  List<Collection> collections = new ArrayList<Collection>();
  List<ExtensionElement> extElements = new ArrayList<ExtensionElement>();
  CommonAttributesImpl attributes = parseCommonAttribute(reader);
  while (reader.hasNext()
      && !(reader.isEndElement() && Edm.NAMESPACE_APP_2007.equals(reader.getNamespaceURI()) && FormatXml.APP_WORKSPACE
          .equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      currentHandledStartTagName = reader.getLocalName();
      if (FormatXml.APP_COLLECTION.equals(currentHandledStartTagName)) {
        collections.add(parseCollection(reader));
      } else if (FormatXml.ATOM_TITLE.equals(currentHandledStartTagName)) {
        title = parseTitle(reader);
      } else {
        extElements.add(parseExtensionSansTitleElement(reader));
      }
    }
  }
  if (title == null) {
    throw new EntityProviderException(EntityProviderException.INVALID_STATE
        .addContent("Missing element title for workspace"));
  }
  return new WorkspaceImpl().setTitle(title).setCollections(collections).setAttributes(attributes)
      .setExtesionElements(extElements);
}
 
Example 13
Source File: BaseBpmnXMLConverter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
    ExtensionElement extensionElement = new ExtensionElement();
    extensionElement.setName(xtr.getLocalName());
    if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
        extensionElement.setNamespace(xtr.getNamespaceURI());
    }
    if (StringUtils.isNotEmpty(xtr.getPrefix())) {
        extensionElement.setNamespacePrefix(xtr.getPrefix());
    }

    BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes);

    boolean readyWithExtensionElement = false;
    while (!readyWithExtensionElement && xtr.hasNext()) {
        xtr.next();
        if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) {
            if (StringUtils.isNotEmpty(xtr.getText().trim())) {
                extensionElement.setElementText(xtr.getText().trim());
            }
        } else if (xtr.isStartElement()) {
            ExtensionElement childExtensionElement = parseExtensionElement(xtr);
            extensionElement.addChildElement(childExtensionElement);
        } else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
            readyWithExtensionElement = true;
        }
    }
    return extensionElement;
}
 
Example 14
Source File: AtomServiceDocumentConsumer.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
private CollectionImpl parseCollection(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_APP_2007, FormatXml.APP_COLLECTION);
  TitleImpl title = null;
  String resourceIdentifier = reader.getAttributeValue(null, FormatXml.ATOM_HREF);
  CommonAttributesImpl attributes = parseCommonAttribute(reader);
  List<ExtensionElement> extElements = new ArrayList<ExtensionElement>();
  List<Accept> acceptList = new ArrayList<Accept>();
  List<Categories> categories = new ArrayList<Categories>();
  if (resourceIdentifier == null) {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent("href"));
  }
  while (reader.hasNext() && !(reader.isEndElement() && Edm.NAMESPACE_APP_2007.equals(reader.getNamespaceURI()) && FormatXml.APP_COLLECTION.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      currentHandledStartTagName = reader.getLocalName();
      if (FormatXml.ATOM_TITLE.equals(currentHandledStartTagName)) {
        title = parseTitle(reader);
      } else if (FormatXml.APP_ACCEPT.equals(currentHandledStartTagName)) {
        acceptList.add(parseAccept(reader));
      } else if (FormatXml.APP_CATEGORIES.equals(currentHandledStartTagName)) {
        categories.add(parseCategories(reader));
      } else {
        extElements.add(parseExtensionSansTitleElement(reader));
      }
    }
  }
  return new CollectionImpl().setHref(resourceIdentifier).setTitle(title).setCommonAttributes(attributes).setExtesionElements(extElements).setAcceptElements(acceptList).setCategories(categories);
}
 
Example 15
Source File: Base64Type.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Object readObject(MessageReader mreader, Context context) throws DatabindingException {
    XMLStreamReader reader = mreader.getXMLStreamReader();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {
        reader.next();
        while (!reader.isCharacters() && !reader.isEndElement() && !reader.isStartElement()) {
            reader.next();
        }

        if (reader.isStartElement() && reader.getName().equals(AbstractXOPType.XOP_INCLUDE)) {
            return optimizedType.readMtoM(mreader, context);
        }

        if (reader.isEndElement()) {
            reader.next();
            return new byte[0];
        }

        CharArrayWriter writer = new CharArrayWriter(2048);
        while (reader.isCharacters()) {
            writer.write(reader.getTextCharacters(),
                         reader.getTextStart(),
                         reader.getTextLength());
            reader.next();
        }
        Base64Utility.decode(writer.toCharArray(), 0, writer.size(), bos);

        while (reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
            reader.next();
        }

        // Advance just past the end element
        reader.next();

        return bos.toByteArray();
    } catch (Base64Exception | XMLStreamException e) {
        throw new DatabindingException("Could not parse base64Binary data.", e);
    }
}
 
Example 16
Source File: XmlErrorDocumentDeserializer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private boolean notFinished(final XMLStreamReader reader, final String tagName) throws XMLStreamException {
  boolean finished = reader.isEndElement() && tagName.equals(reader.getLocalName());
  return !finished && reader.hasNext();
}
 
Example 17
Source File: FieldExtensionParser.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {

    if (!accepts(parentElement))
      return;

    FieldExtension extension = new FieldExtension();
    BpmnXMLUtil.addXMLLocation(extension, xtr);
    extension.setFieldName(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_NAME));

    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING))) {
      extension.setStringValue(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_STRING));

    } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION))) {
      extension.setExpression(xtr.getAttributeValue(null, ATTRIBUTE_FIELD_EXPRESSION));

    } else {
      boolean readyWithFieldExtension = false;
      try {
        while (readyWithFieldExtension == false && xtr.hasNext()) {
          xtr.next();
          if (xtr.isStartElement() && ELEMENT_FIELD_STRING.equalsIgnoreCase(xtr.getLocalName())) {
            extension.setStringValue(xtr.getElementText().trim());

          } else if (xtr.isStartElement() && ATTRIBUTE_FIELD_EXPRESSION.equalsIgnoreCase(xtr.getLocalName())) {
            extension.setExpression(xtr.getElementText().trim());

          } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
            readyWithFieldExtension = true;
          }
        }
      } catch (Exception e) {
        LOGGER.warn("Error parsing field extension child elements", e);
      }
    }

    if (parentElement instanceof ActivitiListener) {
      ((ActivitiListener) parentElement).getFieldExtensions().add(extension);
    } else if (parentElement instanceof ServiceTask) {
      ((ServiceTask) parentElement).getFieldExtensions().add(extension);
    } else {
      ((SendTask) parentElement).getFieldExtensions().add(extension);
    }
  }
 
Example 18
Source File: XmlEntryConsumer.java    From cloud-odata-java with Apache License 2.0 4 votes vote down vote up
private void readProperties(final XMLStreamReader reader, final EntityInfoAggregator entitySet) throws XMLStreamException, EdmException, EntityProviderException {
  // validate namespace
  checkAllMandatoryNamespacesAvailable();
  reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_M_2007_08, FormatXml.M_PROPERTIES);
  if (entitySet.getEntityType().hasStream()) {
    // external properties
    checkCurrentHandledStartTag(FormatXml.M_PROPERTIES);
  } else {
    // inline properties
    checkCurrentHandledStartTag(FormatXml.ATOM_CONTENT);
  }

  EntityPropertyInfo property;
  XmlPropertyConsumer xpc = new XmlPropertyConsumer();

  String closeTag = null;
  boolean run = true;
  reader.next();

  while (run) {
    if (reader.isStartElement() && closeTag == null) {
      closeTag = reader.getLocalName();
      if (isEdmNamespaceProperty(reader)) {
        if (properties.containsKey(closeTag)) {
          throw new EntityProviderException(EntityProviderException.DOUBLE_PROPERTY.addContent(closeTag));
        }
        property = getValidatedPropertyInfo(entitySet, closeTag);
        final Object value = xpc.readStartedElement(reader, property, typeMappings);
        properties.put(closeTag, value);
        closeTag = null;
      }
    } else if (reader.isEndElement()) {
      if (reader.getLocalName().equals(closeTag)) {
        closeTag = null;
      } else if (Edm.NAMESPACE_M_2007_08.equals(reader.getNamespaceURI()) && FormatXml.M_PROPERTIES.equals(reader.getLocalName())) {
        run = false;
      }
    }
    reader.next();
  }
}
 
Example 19
Source File: XmlErrorDocumentConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private boolean notFinished(final XMLStreamReader reader, final String tagName) throws XMLStreamException {
  boolean finished = reader.isEndElement() && tagName.equals(reader.getLocalName());
  return !finished && reader.hasNext();
}
 
Example 20
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private EdmSchema readSchema(final XMLStreamReader reader, EdmImpl edm) //NOSONAR
    throws XMLStreamException, EntityProviderException, EdmException { 
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_SCHEMA);
  final EdmSchemaImpl schemaImpl = new EdmSchemaImpl();
  final List<EdmUsing> usings = new ArrayList<EdmUsing>();
  final List<EdmComplexType> complexTypes = new ArrayList<EdmComplexType>();
  final List<EdmEntityType> entityTypes = new ArrayList<EdmEntityType>();
  final List<EdmAssociation> associations = new ArrayList<EdmAssociation>();
  final List<EdmEntityContainer> entityContainers = new ArrayList<EdmEntityContainer>();
  final List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>();
  schemaImpl.setNamespace(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_NAMESPACE));
  inscopeMap.put(schemaImpl.getNamespace(), new HashSet<String>());
  schemaImpl.setAlias(reader.getAttributeValue(null, XmlMetadataConstants.EDM_SCHEMA_ALIAS));
  schemaImpl.setAnnotationAttributes(readAnnotationAttribute(reader));
  currentNamespace = schemaImpl.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, schemaImpl.getNamespace()));
      } else if (XmlMetadataConstants.EDM_ENTITY_TYPE.equals(currentHandledStartTagName)) {
        entityTypes.add(readEntityType(reader, edm));
      } else if (XmlMetadataConstants.EDM_COMPLEX_TYPE.equals(currentHandledStartTagName)) {
        complexTypes.add(readComplexType(reader, edm));
      } else if (XmlMetadataConstants.EDM_ASSOCIATION.equals(currentHandledStartTagName)) {
        associations.add(readAssociation(reader, edm));
      } else if (XmlMetadataConstants.EDM_ENTITY_CONTAINER.equals(currentHandledStartTagName)) {
        entityContainers.add(readEntityContainer(reader, (EdmImpl) edm));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (schemaImpl.getAlias() != null) {
    aliasNamespaceMap.put(schemaImpl.getAlias(), schemaImpl.getNamespace());
    edm.setAliasToNamespaceInfo(aliasNamespaceMap);
  }
  if (!annotationElements.isEmpty()) {
    schemaImpl.setAnnotationElements(annotationElements);
  }
  schemaImpl
      .setUsings(usings)
      .setEntityTypes(entityTypes)
      .setComplexTypes(complexTypes)
      .setAssociations(associations)
      .setEntityContainers(entityContainers);

  edm.setAliasToNamespaceInfo(aliasNamespaceMap)
      .setEdmAssociations(associationsMap)
      .setEdmComplexTypes(complexTypesMap)
      .setEdmEntityContainers(containerMap)
      .setDefaultEntityContainer(defaultEdmEntityContainer)
      .setEdmEntitySets(edmEntitySetList)
      .setEdmEntityTypes(entityTypesMap)
      .setEdmFunctionImports(edmFunctionImportList);


  return schemaImpl;
}