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

The following examples show how to use javax.xml.stream.XMLStreamReader#getName() . 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: ResponseBuilder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
final Object readResponse(Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    return setter.put(obj,args);
}
 
Example 2
Source File: ResponseBuilder.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
final Object readResponse(Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    return setter.put(obj,args);
}
 
Example 3
Source File: ResponseBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
final Object readResponse(Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
    Object obj;
    AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
    if (bridge instanceof RepeatedElementBridge) {
        RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
        ArrayList list = new ArrayList();
        QName name = r.getName();
        while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
            list.add(rbridge.unmarshal(r, au));
            XMLStreamReaderUtil.toNextTag(r, name);
        }
        obj = rbridge.collectionHandler().convert(list);
    } else {
        obj = bridge.unmarshal(r, au);
    }
    return setter.put(obj,args);
}
 
Example 4
Source File: EndpointArgumentsBuilder.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected void readWrappedRequest(Message msg, Object[] args) throws JAXBException, XMLStreamException {
    if (!msg.hasPayload()) {
        throw new WebServiceException("No payload. Expecting payload with "+wrapperName+" element");
    }
    XMLStreamReader reader = msg.readPayload();
    XMLStreamReaderUtil.verifyTag(reader,wrapperName);
    reader.nextTag();
    while(reader.getEventType()==XMLStreamReader.START_ELEMENT) {
        // TODO: QName has a performance issue
        QName name = reader.getName();
        WrappedPartBuilder part = wrappedParts.get(name);
        if(part==null) {
            // no corresponding part found. ignore
            XMLStreamReaderUtil.skipElement(reader);
            reader.nextTag();
        } else {
            part.readRequest(args,reader, msg.getAttachments());
        }
        XMLStreamReaderUtil.toNextTag(reader, name);
    }

    // we are done with the body
    reader.close();
    XMLStreamReaderFactory.recycle(reader);
}
 
Example 5
Source File: W3CAddressingWSDLParserExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) {
    QName ua = reader.getName();
    if (ua.equals(AddressingVersion.W3C.wsdlExtensionTag)) {
        String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required");
        binding.addFeature(new AddressingFeature(true, Boolean.parseBoolean(required)));
        XMLStreamReaderUtil.skipElement(reader);
        return true;        // UsingAddressing is consumed
    }

    return false;
}
 
Example 6
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Reads table sub elements (column, foreign key, index) from the XML stream reader and adds
 * them to the given table.
 * 
 * @param xmlReader The reader
 * @param table     The table
 */
private void readTableSubElements(XMLStreamReader xmlReader, Table table) throws XMLStreamException, IOException
{
    int eventType = XMLStreamReader.START_ELEMENT;

    while (eventType != XMLStreamReader.END_ELEMENT)
    {
        eventType = xmlReader.next();
        if (eventType == XMLStreamReader.START_ELEMENT)
        {
            QName elemQName = xmlReader.getName();

            if (isSameAs(elemQName, QNAME_ELEMENT_COLUMN))
            {
                table.addColumn(readColumnElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_FOREIGN_KEY))
            {
                table.addForeignKey(readForeignKeyElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_INDEX))
            {
                table.addIndex(readIndexElement(xmlReader));
            }
            else if (isSameAs(elemQName, QNAME_ELEMENT_UNIQUE))
            {
                table.addIndex(readUniqueElement(xmlReader));
            }
            else {
                readOverElement(xmlReader);
            }
        }
    }
}
 
Example 7
Source File: MemberSubmissionAddressingWSDLParserExtension.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) {
    QName ua = reader.getName();
    if (ua.equals(AddressingVersion.MEMBER.wsdlExtensionTag)) {
        String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required");
        binding.addFeature(new MemberSubmissionAddressingFeature(Boolean.parseBoolean(required)));
        XMLStreamReaderUtil.skipElement(reader);
        return true;        // UsingAddressing is consumed
    }

    return false;
}
 
Example 8
Source File: BaseStreamTest.java    From woodstox with Apache License 2.0 5 votes vote down vote up
/**
 * Method that will iterate through contents of an XML document
 * using specified stream reader; will also access some of data
 * to make sure reader reads most of lazy-loadable data.
 * Method is usually called to try to get an exception for invalid
 * content.
 *
 * @return Dummy value calculated on contents; used to make sure
 *   no dead code is eliminated
 */
protected int streamThrough(XMLStreamReader sr)
    throws XMLStreamException
{
    int result = 0;

    assertNotNull(sr);
    try {
        while (sr.hasNext()) {
            int type = sr.next();
            result += type;
            if (sr.hasText()) {
                /* will also do basic verification for text content, to 
                 * see that all text accessor methods return same content
                 */
                result += getAndVerifyText(sr).hashCode();
            }
            if (sr.hasName()) {
                QName n = sr.getName();
                assertNotNull(n);
                result += n.hashCode();
            }
        }
    } catch (RuntimeException rex) {
        // Let's try to find a nested XMLStreamException, if possible
        Throwable t = rex;
        while (t != null) {
            t = t.getCause();
            if (t instanceof XMLStreamException) {
                throw (XMLStreamException) t;
            }
        }
        // Nope, just a runtime exception
        throw rex;
    }
        
    return result;
}
 
Example 9
Source File: W3CAddressingWSDLParserExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) {
    QName ua = reader.getName();
    if (ua.equals(AddressingVersion.W3C.wsdlExtensionTag)) {
        String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required");
        binding.addFeature(new AddressingFeature(true, Boolean.parseBoolean(required)));
        XMLStreamReaderUtil.skipElement(reader);
        return true;        // UsingAddressing is consumed
    }

    return false;
}
 
Example 10
Source File: W3CAddressingWSDLParserExtension.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private boolean addressibleElement(XMLStreamReader reader, WSDLFeaturedObject binding) {
    QName ua = reader.getName();
    if (ua.equals(AddressingVersion.W3C.wsdlExtensionTag)) {
        String required = reader.getAttributeValue(WSDLConstants.NS_WSDL, "required");
        binding.addFeature(new AddressingFeature(true, Boolean.parseBoolean(required)));
        XMLStreamReaderUtil.skipElement(reader);
        return true;        // UsingAddressing is consumed
    }

    return false;
}
 
Example 11
Source File: StAXMsgBodyReader.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * Reads individual elements inside of a XML Document
 * @param reader xml reader
 * @return a pair representing the Object value of the element (Left) as well as
 *         a boolean value representing either true (part of a list) or false
 *         (single value)
 * @throws XMLStreamException on malformed XML
 */
private static final Pair<Object, Boolean> readElement(final XMLStreamReader reader) throws XMLStreamException {
    final QName elementName = reader.getName();
    final StringBuilder sb = new StringBuilder();
    final Map<String, Object> data = new HashMap<String, Object>();
    final Boolean member = isMember(reader);
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                final QName key = reader.getName();
                final Pair<Object, Boolean> elem = readElement(reader);
                addToElements(key.getLocalPart(), elem, data);
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                if (elementName.equals(reader.getName())) {
                    if (data.size() > 0) {
                        return new ImmutablePair<Object, Boolean>(data, member);
                    } else {
                        return new ImmutablePair<Object, Boolean>(sb.toString(), member);
                    }
                } else {
                    throw new XMLStreamException(reader.getName().getLocalPart());
                }
            }
            case XMLStreamConstants.CHARACTERS: {
                sb.append(reader.getText());
                break;
            }
            default: {
                throw new XMLStreamException();
            }
        }
    }
    throw new XMLStreamException();
}
 
Example 12
Source File: SchemaReaderV3.java    From staedi with Apache License 2.0 5 votes vote down vote up
@Override
protected void readImplementation(XMLStreamReader reader, Map<String, EDIType> types) {
    nextTag(reader, "reading implementation start");
    QName element = reader.getName();

    LoopImplementation impl = readImplementation(reader, element, types);
    if (impl != null) {
        types.put(StaEDISchema.IMPLEMENTATION_ID, impl);
    }
}
 
Example 13
Source File: ToolsStaxUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static List<Tag> getTags(final File source) throws Exception {
    List<Tag> tags = new ArrayList<>();
    Collection<String> ignoreEmptyTags = Collections.singleton("sequence");

    try (InputStream is = new BufferedInputStream(Files.newInputStream(source.toPath()))) {
        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
        Tag newTag = null;
        int count = 0;
        QName checkingPoint = null;

        final Deque<Tag> stack = new ArrayDeque<>();

        while (reader.hasNext()) {
            int event = reader.next();

            if (checkingPoint != null) {
                count++;
            }

            if (event == XMLStreamConstants.START_ELEMENT) {
                newTag = new Tag();
                newTag.setName(reader.getName());

                if (ignoreEmptyTags.contains(reader.getLocalName())) {
                    checkingPoint = reader.getName();
                }

                for (int i = 0; i < reader.getAttributeCount(); i++) {
                    newTag.getAttributes().put(reader.getAttributeName(i),
                            reader.getAttributeValue(i));
                }
                stack.push(newTag);
            } else if (event == XMLStreamConstants.CHARACTERS) {
                newTag.setText(reader.getText());
            } else if (event == XMLStreamConstants.END_ELEMENT) {
                Tag startTag = stack.pop();

                if (checkingPoint != null && checkingPoint.equals(reader.getName())) {
                    if (count == 1) {
                        //Tag is empty, and it's in the ignore collection, so we just skip this tag
                    } else {
                        tags.add(startTag);
                    }
                    count = 0;
                    checkingPoint = null;
                } else {
                    tags.add(startTag);
                }
            }
        }
        reader.close();
    }
    return tags;
}
 
Example 14
Source File: DeploymentDescriptorParser.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected static void failWithFullName(String key, XMLStreamReader reader) {
    throw new ServerRtException(
            key,
            reader.getLocation().getLineNumber(),
            reader.getName());
}
 
Example 15
Source File: FoolProofParserExtension.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private QName pre(XMLStreamReader xsr) {
    return xsr.getName();
}
 
Example 16
Source File: FoolProofParserExtension.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private QName pre(XMLStreamReader xsr) {
    return xsr.getName();
}
 
Example 17
Source File: FoolProofParserExtension.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private QName pre(XMLStreamReader xsr) {
    return xsr.getName();
}
 
Example 18
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 19
Source File: DataReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a bean from the given xml stream reader.
 * 
 * @param xmlReader The reader
 */
private void readBean(XMLStreamReader xmlReader) throws XMLStreamException, DdlUtilsXMLException
{
    QName    elemQName  = xmlReader.getName();
    Location location   = xmlReader.getLocation();
    Map      attributes = new HashMap();
    String   tableName  = null;

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        attributes.put(isCaseSensitive() ? attrQName.getLocalPart() : attrQName.getLocalPart().toLowerCase(),
                       xmlReader.getAttributeValue(idx));
    }
    readColumnSubElements(xmlReader, attributes);

    if ("table".equals(elemQName.getLocalPart()))
    {
        tableName = (String)attributes.get("table-name");
    }
    else
    {
        tableName  = elemQName.getLocalPart();
    }

    Table table = _model.findTable(tableName, isCaseSensitive());

    if (table == null)
    {
        _log.warn("Data XML contains an element " + elemQName + " at location " + location +
                  " but there is no table defined with this name. This element will be ignored.");
    }
    else
    {
        DynaBean bean = _model.createDynaBeanFor(table);

        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);
            String value  = (String)attributes.get(isCaseSensitive() ? column.getName() : column.getName().toLowerCase());

            if (value != null)
            {
                setColumnValue(bean, table, column, value);
            }
        }
        getSink().addBean(bean);
        consumeRestOfElement(xmlReader);
    }
}
 
Example 20
Source File: FoolProofParserExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private QName pre(XMLStreamReader xsr) {
    return xsr.getName();
}