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

The following examples show how to use javax.xml.stream.XMLStreamReader#next() . 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: AllowedValuesParser.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void parseChildElement(XMLStreamReader xtr, DmnElement parentElement, Decision decision) throws Exception {
    if (!(parentElement instanceof ItemDefinition))
        return;

    ItemDefinition itemDefinition = (ItemDefinition) parentElement;
    UnaryTests allowedValues = new UnaryTests();

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

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

    itemDefinition.setAllowedValues(allowedValues);
}
 
Example 2
Source File: ExpandDLMethod.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
protected void handleContact(XMLStreamReader reader, EWSMethod.Item responseItem) throws XMLStreamException {
    while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "Contact")) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("EmailAddresses".equals(tagLocalName)) {
                handleEmailAddresses(reader, responseItem);
            } else if ("PhysicalAddresses".equals(tagLocalName)) {
                handlePhysicalAddresses(reader, responseItem);
            } else if ("PhoneNumbers".equals(tagLocalName)) {
                handlePhoneNumbers(reader, responseItem);
            } else {
                responseItem.put(tagLocalName, XMLStreamUtil.getElementText(reader));
            }
        }
    }
}
 
Example 3
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private PropertyRef readPropertyRef(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_PROPERTY_REF);
  PropertyRef propertyRef = new PropertyRef();
  propertyRef.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  propertyRef.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_PROPERTY_REF.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    propertyRef.setAnnotationElements(annotationElements);
  }
  return propertyRef;
}
 
Example 4
Source File: StartBodyInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}*/
public void handleMessage(SoapMessage message) throws Fault {
    if (isGET(message)) {
        LOG.fine("StartBodyInterceptor skipped in HTTP GET method");
        return;
    }
    XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
    //advance to just outside the <soap:body> opening tag, but not
    //to the nextTag as that may skip over white space that is
    //important to keep for ws-security signature digests and stuff
    try {
        int i = xmlReader.next();
        while (i == XMLStreamConstants.NAMESPACE
            || i == XMLStreamConstants.ATTRIBUTE) {
            i = xmlReader.next();
        }
    } catch (XMLStreamException e) {
        throw new SoapFault(new Message("XML_STREAM_EXC", LOG, e.getMessage()), e,
                            message.getVersion().getSender());
    }

}
 
Example 5
Source File: AtomServiceDocumentConsumer.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
private ExtensionElementImpl parseElement(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  List<ExtensionElement> extensionElements = new ArrayList<ExtensionElement>();
  ExtensionElementImpl extElement = new ExtensionElementImpl().setName(reader.getLocalName()).setNamespace(reader.getNamespaceURI()).setPrefix(reader.getPrefix());
  extElement.setAttributes(parseAttribute(reader));
  while (reader.hasNext() && !(reader.isEndElement() && extElement.getName() != null && extElement.getName().equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isCharacters()) {
      extElement.setText(reader.getText());
    } else if (reader.isStartElement()) {
      extensionElements.add(parseExtensionElement(reader));
    }
  }
  extElement.setElements(extensionElements);
  if (extElement.getText() == null && extElement.getAttributes().isEmpty() && extElement.getElements().isEmpty()) {
    throw new EntityProviderException(EntityProviderException.INVALID_STATE.addContent("Invalid extension element"));
  }
  return extElement;
}
 
Example 6
Source File: BaseStAXUT.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected static String getAllCData(XMLStreamReader sr) throws XMLStreamException {
    StringBuffer sb = new StringBuffer();
    while (true) {
        /*
         * Note: CDATA sections CAN be reported as CHARACTERS, but not as
         * SPACE
         */
        int tt = sr.getEventType();
        if (tt != CHARACTERS && tt != CDATA) {
            break;
        }
        sb.append(getAndVerifyText(sr));
        sr.next();
    }
    return sb.toString();
}
 
Example 7
Source File: CfgGui.java    From aion with MIT License 6 votes vote down vote up
/** Populate this object from XML data */
public void fromXML(final XMLStreamReader sr) throws XMLStreamException {
    loop:
    while (sr.hasNext()) {
        int eventType = sr.next();
        switch (eventType) {
            case XMLStreamReader.START_ELEMENT:
                String elelmentName = sr.getLocalName().toLowerCase();
                switch (elelmentName) {
                    case "launcher":
                        this.cfgGuiLauncher.fromXML(sr);
                        break;
                    default:
                        break;
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                break loop;
        }
    }
}
 
Example 8
Source File: GetUserConfigurationMethod.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
private Item handleUserConfiguration(XMLStreamReader reader) throws XMLStreamException {
    Item responseItem = new Item();
    while (reader.hasNext() && !(XMLStreamUtil.isEndTag(reader, "UserConfiguration"))) {
        reader.next();
        if (XMLStreamUtil.isStartTag(reader)) {
            String tagLocalName = reader.getLocalName();
            if ("DictionaryEntry".equals(tagLocalName)) {
                handleDictionaryEntry(reader, responseItem);
            }
        }
    }
    return responseItem;
}
 
Example 9
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 10
Source File: CDataChunkSizeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "xml-data")
public void testStAX(String xml, int chunkSize, int expectedNumOfChunks, boolean withinLimit) throws Exception {
    XMLInputFactory xifactory = XMLInputFactory.newInstance();
    xifactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", true);
    if (chunkSize > 0) {
        xifactory.setProperty(CDATA_CHUNK_SIZE, chunkSize);
    }
    XMLStreamReader streamReader = xifactory.createXMLStreamReader(new StringReader(xml));

    StringBuilder cdata = new StringBuilder();
    int numOfChunks = 0;
    boolean isWithinLimit = true;
    while (streamReader.hasNext()) {
        int eventType = streamReader.next();
        switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                debugPrint("\nElement: " + streamReader.getLocalName());
                break;
            case XMLStreamConstants.CDATA:
                String text = streamReader.getText();
                numOfChunks++;
                if (text.length() > chunkSize) {
                    isWithinLimit = false;
                }
                debugPrint("\nCDATA: " + text.length());
                cdata.append(text);
                break;
            case XMLStreamConstants.CHARACTERS:
                debugPrint("\nCharacters: " + streamReader.getText().length());
                break;
        }
    }
    debugPrint("CData in single chunk:" + cdata.toString().length());
    Assert.assertEquals(numOfChunks, expectedNumOfChunks);
    Assert.assertEquals(isWithinLimit, withinLimit);
}
 
Example 11
Source File: ExcelUtil.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to read the "workbook.xml" in the document and find out the sheet id for
 * given sheet name, or the first sheet if sheetName is null or empty.
 * @param workbook InputStream of the workbook. Caller is responsible for closing it.
 * @param sheetName Sheet name to lookup.
 * @return Non-null value if found a sheet with given name. Otherwise null
 * @throws XMLStreamException
 */
public static String getSheetId(final InputStream workbook, final String sheetName) throws XMLStreamException {
  checkNotNull(workbook);

  final XMLStreamReader wbReader  = XML_INPUT_FACTORY.createXMLStreamReader(workbook);
  final boolean retrieveFirstSheet = sheetName == null || sheetName.isEmpty();

  while (wbReader.hasNext()) {
    wbReader.next();
    final int event = wbReader.getEventType();
    switch (event) {
      case START_ELEMENT: {
        final String name = wbReader.getLocalName();
        if (SHEET.equals(name)) {
          String sheet = wbReader.getAttributeValue(/*namespaceURI=*/null, SHEET_NAME);
          // Sheet names are case insensitive
          if (retrieveFirstSheet || sheetName.equalsIgnoreCase(sheet)) {
            return wbReader.getAttributeValue(SHEET_ID_NS, SHEET_ID);
          }
        }
        break;
      }
    }
  }

  return null;
}
 
Example 12
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
protected static final List<TaggedValue> readTaggedValueGroup(final XMLStreamReader reader) {
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    try {
        if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
            while (reader.hasNext()) {
                reader.next();
                switch (reader.getEventType()) {
                    case XMLStreamConstants.START_ELEMENT: {
                        if ("TaggedValue".equals(reader.getLocalName())) {
                            taggedValues.add(assertNotNull(readTaggedValue(reader)));
                            break;
                        } else {
                            throw new AssertionError(reader.getLocalName());
                        }
                    }
                    case XMLStreamConstants.END_ELEMENT: {
                        if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                            return taggedValues;
                        } else {
                            throw new AssertionError(reader.getLocalName());
                        }
                    }
                    case XMLStreamConstants.CHARACTERS: {
                        // Ignore.
                        break;
                    }
                    default: {
                        throw new AssertionError(reader.getEventType());
                    }
                }
            }
        } else {
            throw new AssertionError(reader.getLocalName());
        }
    } catch (final XMLStreamException e) {
        LOG.warn(e.getMessage());
    }
    throw new AssertionError();
}
 
Example 13
Source File: TestCharacterLimits.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public void testLongWhitespaceCoalescing() throws Exception {
    try {
        Reader reader = createLongReader("", "", true);
        XMLInputFactory factory = getNewInputFactory();
        factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        factory.setProperty(WstxInputProperties.P_MAX_TEXT_LENGTH, Integer.valueOf(1000));
        XMLStreamReader xmlreader = factory.createXMLStreamReader(reader);
        while (xmlreader.next() != XMLStreamReader.START_ELEMENT) {
        }
        xmlreader.nextTag();
        fail("Should have failed");
    } catch (XMLStreamException ex) {
        _verifyTextLimitException(ex);
    }
}
 
Example 14
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
/**
 * The UML:Namespace.ownedElement is simply a list of model elements that can belong in a
 * name-space.
 *
 * It has no identity of its own and is only present in the serialization format.
 */
protected static final List<NamespaceOwnedElement> readNamespaceOwnedElement(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.NAMESPACE_DOT_OWNED_ELEMENT, reader);
    final List<NamespaceOwnedElement> ownedElements = new LinkedList<NamespaceOwnedElement>();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                if (match(XmiElementName.CLASS, reader)) {
                    ownedElements.add(assertNotNull(readClassType(reader.getName(), reader)));
                } else if (match(XmiElementName.ASSOCIATION_CLASS, reader)) {
                    ownedElements.add(assertNotNull(readClassType(reader.getName(), reader)));
                } else if (match(XmiElementName.ASSOCIATION, reader)) {
                    ownedElements.add(assertNotNull(readClassType(reader.getName(), reader)));
                } else if (match(XmiElementName.DATA_TYPE, reader)) {
                    ownedElements.add(assertNotNull(readDataType(reader)));
                } else if (match(XmiElementName.ENUMERATION, reader)) {
                    ownedElements.add(assertNotNull(readEnumeration(reader)));
                } else if (match(XmiElementName.TAG_DEFINITION, reader)) {
                    ownedElements.add(assertNotNull(readTagDefinition(reader)));
                } else if (match(XmiElementName.GENERALIZATION, reader)) {
                    ownedElements.add(assertNotNull(readGeneralization(reader)));
                } else if (match(XmiElementName.COMMENT, reader)) {
                    skipElement(reader, false);
                } else if (match(XmiElementName.PACKAGE, reader)) {
                    ownedElements.add(assertNotNull(readPackage(reader)));
                } else {
                    throw new AssertionError(reader.getName());
                    // skipElement(reader);
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(XmiElementName.NAMESPACE_DOT_OWNED_ELEMENT, reader);
                return Collections.unmodifiableList(ownedElements);
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
        }
    }
    throw new AssertionError();
}
 
Example 15
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private EntityType readEntityType(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_TYPE);
  EntityType entityType = new EntityType();
  List<Property> properties = new ArrayList<Property>();
  List<NavigationProperty> navPropertiesList = new ArrayList<NavigationProperty>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  Key key = null;

  entityType.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String hasStream = reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, XmlMetadataConstants.M_ENTITY_TYPE_HAS_STREAM);
  if (hasStream != null) {
    entityType.setHasStream("true".equalsIgnoreCase(hasStream));
  }

  if (reader.getAttributeValue(null, XmlMetadataConstants.EDM_TYPE_ABSTRACT) != null) {
    entityType.setAbstract("true".equalsIgnoreCase(reader.getAttributeValue(null,
        XmlMetadataConstants.EDM_TYPE_ABSTRACT)));
  }
  String baseType = reader.getAttributeValue(null, XmlMetadataConstants.EDM_BASE_TYPE);
  if (baseType != null) {
    entityType.setBaseType(extractFQName(baseType));
  }
  entityType.setCustomizableFeedMappings(readCustomizableFeedMappings(reader));
  entityType.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ENTITY_TYPE.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_ENTITY_TYPE_KEY.equals(currentHandledStartTagName)) {
        key = readEntityTypeKey(reader);
      } else if (XmlMetadataConstants.EDM_PROPERTY.equals(currentHandledStartTagName)) {
        properties.add(readProperty(reader));
      } else if (XmlMetadataConstants.EDM_NAVIGATION_PROPERTY.equals(currentHandledStartTagName)) {
        navPropertiesList.add(readNavigationProperty(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
      extractNamespaces(reader);
    }
  }
  if (!annotationElements.isEmpty()) {
    entityType.setAnnotationElements(annotationElements);
  }
  entityType.setKey(key).setProperties(properties).setNavigationProperties(navPropertiesList);
  if (entityType.getName() != null) {
    FullQualifiedName fqName = new FullQualifiedName(currentNamespace, entityType.getName());
    entityTypesMap.put(fqName, entityType);
  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent("Name"));
  }
  return entityType;
}
 
Example 16
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
protected static final ClassType readClassType(final QName elementName, final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(elementName, reader);
    boolean isAbstract = false;
    final List<Attribute> attributes = new LinkedList<Attribute>();
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    final Identifier id = getId(reader);
    final String name = getName(reader, null, XmiAttributeName.NAME);
    XmiAssociationConnection connection = null;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                    taggedValues.addAll(readTaggedValueGroup(reader));
                } else if (match(XmiElementName.CLASSIFIER_DOT_FEATURE, reader)) {
                    try {
                        attributes.addAll(readClassifierDotFeature(reader));
                    } catch (final AssertionError e) {
                        throw new XmiBadModelElementException(name.toString(), e);
                    }
                } else if ("GeneralizableElement.generalization".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if ("ModelElement.comment".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if ("ModelElement.clientDependency".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if ("Namespace.ownedElement".equals(reader.getLocalName())) {
                    skipElement(reader, false);
                } else if (match(XmiElementName.ASSOCIATION_DOT_CONNECTION, reader)) {
                    connection = assertNotNull(readAssociationConnection(reader));
                } else {
                    skipElement(reader, true);
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(elementName, reader);
                if (match(XmiElementName.CLASS, elementName)) {
                    return new ClassType(id, name, isAbstract, attributes, taggedValues);
                } else if (match(XmiElementName.ASSOCIATION_CLASS, elementName)) {
                    return new ClassType(id, name, isAbstract, attributes, connection.getLHS(),
                            connection.getRHS(), taggedValues);
                } else if (match(XmiElementName.ASSOCIATION, elementName)) {
                    return new ClassType(id, name, connection.getLHS(), connection.getRHS(), taggedValues);
                } else {
                    throw new AssertionError(elementName);
                }
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
        }
    }
    throw new AssertionError();
}
 
Example 17
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private FunctionImport readFunctionImport(final XMLStreamReader reader)
    throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_FUNCTION_IMPORT);
  FunctionImport function = new FunctionImport();
  List<FunctionImportParameter> functionParameters = new ArrayList<FunctionImportParameter>();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  FullQualifiedName fqName;
  function.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  function.setHttpMethod(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08,
      XmlMetadataConstants.EDM_FUNCTION_IMPORT_HTTP_METHOD));
  function.setEntitySet(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_SET));

  String returnTypeString = reader.getAttributeValue(null, XmlMetadataConstants.EDM_FUNCTION_IMPORT_RETURN);
  if (returnTypeString != null) {
    ReturnType returnType = new ReturnType();
    if (returnTypeString.startsWith("Collection") || returnTypeString.startsWith("collection")) {
      returnTypeString = returnTypeString.substring(returnTypeString.indexOf("(") + 1, returnTypeString.length() - 1);
      returnType.setMultiplicity(EdmMultiplicity.MANY);
    } else {
      returnType.setMultiplicity(EdmMultiplicity.ONE);
    }
    fqName = extractFQName(returnTypeString);
    returnType.setTypeName(fqName);
    function.setReturnType(returnType);
  }
  function.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_FUNCTION_IMPORT.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      currentHandledStartTagName = reader.getLocalName();
      if (XmlMetadataConstants.EDM_FUNCTION_PARAMETER.equals(currentHandledStartTagName)) {
        functionParameters.add(readFunctionImportParameter(reader));
      } else {
        annotationElements.add(readAnnotationElement(reader));
      }
    }
  }
  if (!annotationElements.isEmpty()) {
    function.setAnnotationElements(annotationElements);
  }
  function.setParameters(functionParameters);
  return function;
}
 
Example 18
Source File: XmiReader.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
protected static final AssociationEnd readAssociationEnd(final XMLStreamReader reader) {
    try {
        assertName(XmiElementName.ASSOCIATION_END, reader);
        final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
        final Identifier id = getId(reader);
        final String name = getName(reader, DEFAULT_EMPTY_NAME, XmiAttributeName.NAME);
        final String associatedAttribName = getName(reader, DEFAULT_EMPTY_NAME, XmiAttributeName.ASSOCIATED_ATTRIBUTE_NAME);
        final boolean isNavigable = getBoolean(XmiAttributeName.IS_NAVIGABLE, true, reader);
        Identifier participant = null;
        final Range range = new Range(Identifier.random(), Occurs.ONE, Occurs.ONE, EMPTY_TAGGED_VALUE_LIST);
        Multiplicity multiplicity = new Multiplicity(Identifier.random(), EMPTY_TAGGED_VALUE_LIST, range);
        while (reader.hasNext()) {
            reader.next();
            switch (reader.getEventType()) {
                case XMLStreamConstants.START_ELEMENT: {
                    if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                        taggedValues.addAll(readTaggedValueGroup(reader));
                    } else if (match(XmiElementName.ASSOCIATION_END_DOT_MULTIPLICITY, reader)) {
                        multiplicity = assertNotNull(readAssociationEndMultiplicity(reader));
                    } else if (match(XmiElementName.ASSOCIATION_END_DOT_PARTICIPANT, reader)) {
                        participant = readAssociationEndParticipant(reader);
                    } else {
                        throw new UnsupportedOperationException(reader.getName().toString());
                        // skipElement(reader);
                    }
                    break;
                }
                case XMLStreamConstants.END_ELEMENT: {
                    assertName(XmiElementName.ASSOCIATION_END, reader);
                    if (participant == null) {
                        throw new AssertionError(XmiElementName.ASSOCIATION_END_DOT_PARTICIPANT);
                    }
                    return new AssociationEnd(multiplicity, name, isNavigable, id, taggedValues, participant, associatedAttribName);
                }
                case XMLStreamConstants.CHARACTERS: {
                    // Ignore.
                    break;
                }
                default: {
                    throw new AssertionError(reader.getEventType());
                }
            }
        }
    } catch (final XMLStreamException e) {
        throw new XmiRuntimeException(e);
    }
    throw new AssertionError();
}
 
Example 19
Source File: StreamReaderBufferCreator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private void storeElementAndChildrenNoEx(XMLStreamReader reader) throws XMLStreamException {
    int depth = 1;
    if (_storeInScopeNamespacesOnElementFragment) {
        storeElementWithInScopeNamespaces(reader);
    } else {
        storeElement(reader);
    }

    while(depth > 0) {
        _eventType = reader.next();
        switch (_eventType) {
            case XMLStreamReader.START_ELEMENT:
                depth++;
                storeElement(reader);
                break;
            case XMLStreamReader.END_ELEMENT:
                depth--;
                storeStructure(T_END);
                break;
            case XMLStreamReader.NAMESPACE:
                storeNamespaceAttributes(reader);
                break;
            case XMLStreamReader.ATTRIBUTE:
                storeAttributes(reader);
                break;
            case XMLStreamReader.SPACE:
            case XMLStreamReader.CHARACTERS:
            case XMLStreamReader.CDATA: {
                storeContentCharacters(T_TEXT_AS_CHAR_ARRAY,
                        reader.getTextCharacters(), reader.getTextStart(),
                        reader.getTextLength());
                break;
            }
            case XMLStreamReader.COMMENT:
                storeComment(reader);
                break;
            case XMLStreamReader.PROCESSING_INSTRUCTION:
                storeProcessingInstruction(reader);
                break;
        }
    }

    /*
     * Move to next item after the end of the element
     * that has been stored
     */
    _eventType = reader.next();
}
 
Example 20
Source File: TsoGeneratorSpeedAutomaton.java    From powsybl-core with Mozilla Public License 2.0 4 votes vote down vote up
public static TsoGeneratorSpeedAutomaton fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
    LimitsXmlParsingState state = null;
    String text = null;
    List<String> onUnderSpeedDiconnectedGenerators = new ArrayList<>();
    List<String> onOverSpeedDiconnectedGenerators = new ArrayList<>();
    while (xmlsr.hasNext()) {
        int eventType = xmlsr.next();
        switch (eventType) {
            case XMLEvent.CHARACTERS:
                text = xmlsr.getText();
                break;

            case XMLEvent.START_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case ON_UNDER_SPEED_DISCONNECTED_GENERATORS:
                        state = LimitsXmlParsingState.UNDER;
                        break;

                    case ON_OVER_SPEED_DISCONNECTED_GENERATORS:
                        state = LimitsXmlParsingState.OVER;
                        break;

                    case GEN:
                    case INDEX:
                        // nothing to do
                        break;

                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;
            case XMLEvent.END_ELEMENT:
                switch (xmlsr.getLocalName()) {
                    case ON_UNDER_SPEED_DISCONNECTED_GENERATORS:
                    case ON_OVER_SPEED_DISCONNECTED_GENERATORS:
                        state = null;
                        break;

                    case GEN:
                        LimitsXmlParsingState.addGenerator(state, text, onUnderSpeedDiconnectedGenerators, onOverSpeedDiconnectedGenerators);
                        break;

                    case INDEX:
                        return new TsoGeneratorSpeedAutomaton(contingencyId, onUnderSpeedDiconnectedGenerators, onOverSpeedDiconnectedGenerators);

                    default:
                        throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
                }
                break;

            default:
                break;
        }
    }
    throw new AssertionError("Should not happen");
}