Java Code Examples for javax.xml.stream.XMLStreamConstants#END_ELEMENT

The following examples show how to use javax.xml.stream.XMLStreamConstants#END_ELEMENT . 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: ProvisionedStateXmlParser30.java    From galleon with Apache License 2.0 6 votes vote down vote up
private ProvisionedFeaturePack readFeaturePack(XMLExtendedStreamReader reader) throws XMLStreamException {
    final ProvisionedFeaturePack.Builder fpBuilder = ProvisionedFeaturePack.builder(parseSource(reader).getFPID());
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return fpBuilder.build();
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());
                switch (element) {
                    case PACKAGES:
                        readPackageList(reader, fpBuilder);
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 2
Source File: ProvisioningXmlParser30.java    From galleon with Apache License 2.0 6 votes vote down vote up
private static void readTransitive(XMLExtendedStreamReader reader, FeaturePackDepsConfigBuilder<?> builder) throws XMLStreamException {
    ParsingUtils.parseNoAttributes(reader);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getLocalName());
                switch (element) {
                    case FEATURE_PACK:
                        readTransitiveFeaturePackDep(reader, builder);
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 3
Source File: DocumentStaxUtils.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * A copy of the nextTag algorithm from the XMLStreamReader javadocs,
 * but which also skips over DTD events as well as whitespace,
 * comments and PIs.
 * 
 * @param xsr the reader to advance
 * @return {@link XMLStreamConstants#START_ELEMENT} or
 *         {@link XMLStreamConstants#END_ELEMENT} for the next tag.
 * @throws XMLStreamException
 */
private static int nextTagSkipDTD(XMLStreamReader xsr)
        throws XMLStreamException {
  int eventType = xsr.next();
  while((eventType == XMLStreamConstants.CHARACTERS && xsr.isWhiteSpace())
          || (eventType == XMLStreamConstants.CDATA && xsr.isWhiteSpace())
          || eventType == XMLStreamConstants.SPACE
          || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
          || eventType == XMLStreamConstants.COMMENT
          || eventType == XMLStreamConstants.DTD) {
    eventType = xsr.next();
  }
  if(eventType != XMLStreamConstants.START_ELEMENT
          && eventType != XMLStreamConstants.END_ELEMENT) {
    throw new XMLStreamException("expected start or end tag", xsr
            .getLocation());
  }
  return eventType;
}
 
Example 4
Source File: ProvisioningXmlParser30.java    From galleon with Apache License 2.0 6 votes vote down vote up
static void readUniverses(XMLExtendedStreamReader reader, FeaturePackDepsConfigBuilder<?> fpBuilder) throws XMLStreamException {
    ParsingUtils.parseNoAttributes(reader);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName().getLocalPart());
                switch (element) {
                    case UNIVERSE:
                        readUniverse(reader, fpBuilder);
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
}
 
Example 5
Source File: Bug6613059Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void addMenu(XMLEventReader xer, XMLEvent event) throws XMLStreamException {
    // user did not submit this part of code, just jump to the end of menu
    // element
    int eventType = 0;
    while (true) {
        event = xer.nextEvent();
        // System.out.println("event: " + event);
        eventType = event.getEventType();
        if (eventType == XMLStreamConstants.END_ELEMENT && event.asEndElement().getName().equals(new QName("menu"))) {
            break;
        }
    }
}
 
Example 6
Source File: XmlUtil.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
public static String readUntilEndElementWithDepth(String endElementName, XMLStreamReader reader, XmlEventHandlerWithDepth eventHandler) throws XMLStreamException {
    Objects.requireNonNull(endElementName);
    Objects.requireNonNull(reader);

    String text = null;
    int event;
    int depth = 0;
    while (!((event = reader.next()) == XMLStreamConstants.END_ELEMENT
            && reader.getLocalName().equals(endElementName))) {
        text = null;
        switch (event) {
            case XMLStreamConstants.START_ELEMENT:
                if (eventHandler != null) {
                    String startLocalName = reader.getLocalName();
                    eventHandler.onStartElement(depth);
                    // if handler has already consumed end element we must decrease the depth
                    if (reader.getEventType() == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals(startLocalName)) {
                        depth--;
                    }
                }
                depth++;
                break;

            case XMLStreamConstants.END_ELEMENT:
                depth--;
                break;

            case XMLStreamConstants.CHARACTERS:
                text = reader.getText();
                break;

            default:
                break;
        }
    }
    return text;
}
 
Example 7
Source File: FeatureSpecXmlParser10.java    From galleon with Apache License 2.0 5 votes vote down vote up
private void parseCapabilities(XMLExtendedStreamReader reader, FeatureSpec.Builder spec, boolean provides) throws XMLStreamException {
    ParsingUtils.parseNoAttributes(reader);
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName());
                switch (element) {
                    case CAPABILITY:
                        final CapabilitySpec cap = parseCapabilityName(reader);
                            if (provides) {
                                spec.providesCapability(cap);
                            } else {
                                spec.requiresCapability(cap);
                            }
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 8
Source File: Util.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final static String getEventTypeString(int eventType) {
    switch (eventType){
        case XMLStreamConstants.START_ELEMENT:
            return "START_ELEMENT";
        case XMLStreamConstants.END_ELEMENT:
            return "END_ELEMENT";
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
            return "PROCESSING_INSTRUCTION";
        case XMLStreamConstants.CHARACTERS:
            return "CHARACTERS";
        case XMLStreamConstants.COMMENT:
            return "COMMENT";
        case XMLStreamConstants.START_DOCUMENT:
            return "START_DOCUMENT";
        case XMLStreamConstants.END_DOCUMENT:
            return "END_DOCUMENT";
        case XMLStreamConstants.ENTITY_REFERENCE:
            return "ENTITY_REFERENCE";
        case XMLStreamConstants.ATTRIBUTE:
            return "ATTRIBUTE";
        case XMLStreamConstants.DTD:
            return "DTD";
        case XMLStreamConstants.CDATA:
            return "CDATA";
    }
    return "UNKNOWN_EVENT_TYPE";
}
 
Example 9
Source File: FastInfosetConnector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void handleFragmentedCharacters() throws XMLStreamException, SAXException {
    buffer.setLength(0);

    // Append characters of first character event
    buffer.append(fastInfosetStreamReader.getTextCharacters(),
            fastInfosetStreamReader.getTextStart(),
            fastInfosetStreamReader.getTextLength());

    // Consume all character
    while(true) {
        switch(fastInfosetStreamReader.peekNext()) {
            case XMLStreamConstants.START_ELEMENT :
                processBufferedText(true);
                return;
            case XMLStreamConstants.END_ELEMENT :
                processBufferedText(false);
                return;
            case XMLStreamConstants.CHARACTERS :
            case XMLStreamConstants.CDATA :
            case XMLStreamConstants.SPACE :
                // Append characters of second and subsequent character events
                fastInfosetStreamReader.next();
                buffer.append(fastInfosetStreamReader.getTextCharacters(),
                        fastInfosetStreamReader.getTextStart(),
                        fastInfosetStreamReader.getTextLength());
                break;
            default:
                fastInfosetStreamReader.next();
        }
    }
}
 
Example 10
Source File: ConfigLayerXml.java    From galleon with Apache License 2.0 5 votes vote down vote up
public static void readConfigLayer(XMLExtendedStreamReader reader, ConfigLayerSpec.Builder builder) throws XMLStreamException {
    String name = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final Attribute attribute = Attribute.of(reader.getAttributeName(i));
        switch (attribute) {
            case NAME:
                name = reader.getAttributeValue(i);
                builder.setName(name);
                break;
            default:
                throw ParsingUtils.unexpectedAttribute(reader, i);
        }
    }
    if (name == null) {
        throw ParsingUtils.missingAttributes(reader.getLocation(), Collections.singleton(Attribute.NAME));
    }
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT:
                return;
            case XMLStreamConstants.START_ELEMENT:
                Element e = Element.elementsByLocal.get(reader.getName().getLocalPart());
                if(e != null) {
                    switch(e) {
                        case DEPENDENCIES:
                            readDeps(reader, builder);
                            break;
                        default:
                            throw ParsingUtils.unexpectedContent(reader);
                    }
                } else if (!FeatureGroupXml.handleFeatureGroupBodyElement(reader, builder)) {
                    throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            default:
                throw ParsingUtils.unexpectedContent(reader);
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 11
Source File: Util.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public final static String getEventTypeString(int eventType) {
    switch (eventType){
        case XMLStreamConstants.START_ELEMENT:
            return "START_ELEMENT";
        case XMLStreamConstants.END_ELEMENT:
            return "END_ELEMENT";
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
            return "PROCESSING_INSTRUCTION";
        case XMLStreamConstants.CHARACTERS:
            return "CHARACTERS";
        case XMLStreamConstants.COMMENT:
            return "COMMENT";
        case XMLStreamConstants.START_DOCUMENT:
            return "START_DOCUMENT";
        case XMLStreamConstants.END_DOCUMENT:
            return "END_DOCUMENT";
        case XMLStreamConstants.ENTITY_REFERENCE:
            return "ENTITY_REFERENCE";
        case XMLStreamConstants.ATTRIBUTE:
            return "ATTRIBUTE";
        case XMLStreamConstants.DTD:
            return "DTD";
        case XMLStreamConstants.CDATA:
            return "CDATA";
    }
    return "UNKNOWN_EVENT_TYPE";
}
 
Example 12
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
protected void advanceBody(
    SoapMessage msg, Node body
) throws SOAPException, XMLStreamException, WSSecurityException {
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(new DOMSource(body));
    // advance just past body
    int evt = reader.next();
    int i = 0;
    while (reader.hasNext() && i < 1
           && (evt != XMLStreamConstants.END_ELEMENT || evt != XMLStreamConstants.START_ELEMENT)) {
        reader.next();
        i++;
    }
    msg.setContent(XMLStreamReader.class, reader);
}
 
Example 13
Source File: Util.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final static String getEventTypeString(int eventType) {
    switch (eventType){
        case XMLStreamConstants.START_ELEMENT:
            return "START_ELEMENT";
        case XMLStreamConstants.END_ELEMENT:
            return "END_ELEMENT";
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
            return "PROCESSING_INSTRUCTION";
        case XMLStreamConstants.CHARACTERS:
            return "CHARACTERS";
        case XMLStreamConstants.COMMENT:
            return "COMMENT";
        case XMLStreamConstants.START_DOCUMENT:
            return "START_DOCUMENT";
        case XMLStreamConstants.END_DOCUMENT:
            return "END_DOCUMENT";
        case XMLStreamConstants.ENTITY_REFERENCE:
            return "ENTITY_REFERENCE";
        case XMLStreamConstants.ATTRIBUTE:
            return "ATTRIBUTE";
        case XMLStreamConstants.DTD:
            return "DTD";
        case XMLStreamConstants.CDATA:
            return "CDATA";
    }
    return "UNKNOWN_EVENT_TYPE";
}
 
Example 14
Source File: FeaturePackXmlParser20.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public void readElement(XMLExtendedStreamReader reader, Builder fpBuilder) throws XMLStreamException {
    fpBuilder.setFPID(readFpl(reader).getFPID());
    while (reader.hasNext()) {
        switch (reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT: {
                return;
            }
            case XMLStreamConstants.START_ELEMENT: {
                final Element element = Element.of(reader.getName().getLocalPart());
                switch (element) {
                    case UNIVERSES:
                        ProvisioningXmlParser30.readUniverses(reader, fpBuilder);
                        break;
                    case DEPENDENCIES:
                        readFeaturePackDeps(reader, fpBuilder);
                        break;
                    case DEFAULT_CONFIGS:
                        ProvisioningXmlParser30.parseDefaultConfigs(reader, fpBuilder);
                        break;
                    case CONFIG:
                        final ConfigModel.Builder config = ConfigModel.builder();
                        ConfigXml.readConfig(reader, config);
                        try {
                            fpBuilder.addConfig(config.build());
                        } catch (ProvisioningDescriptionException e) {
                            throw new XMLStreamException("Failed to parse config element", reader.getLocation(), e);
                        }
                        break;
                    case DEFAULT_PACKAGES:
                        readDefaultPackages(reader, fpBuilder);
                        break;
                    case TRANSITIVE:
                        readTransitive(reader, fpBuilder);
                        break;
                    case PLUGINS:
                        parsePlugins(reader, fpBuilder);
                        break;
                    case PATCH:
                        parsePatchFor(reader, fpBuilder);
                        break;
                    default:
                        throw ParsingUtils.unexpectedContent(reader);
                }
                break;
            }
            default: {
                throw ParsingUtils.unexpectedContent(reader);
            }
        }
    }
    throw ParsingUtils.endOfDocument(reader.getLocation());
}
 
Example 15
Source File: StAXSchemaParser.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
    XMLEvent currentEvent = input.peek();
    if (currentEvent != null) {
        int eventType = currentEvent.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(currentEvent.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        loop: while (input.hasNext()) {
            currentEvent = input.nextEvent();
            eventType = currentEvent.getEventType();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                StartElement start = currentEvent.asStartElement();
                fillQName(fElementQName, start.getName());
                fLocationWrapper.setLocation(start.getLocation());
                fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
                fillXMLAttributes(start);
                fillDeclaredPrefixes(start);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                EndElement end = currentEvent.asEndElement();
                fillQName(fElementQName, end.getName());
                fillDeclaredPrefixes(end);
                fLocationWrapper.setLocation(end.getLocation());
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                break;
            case XMLStreamConstants.SPACE:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
                fillProcessingInstruction(pi.getData());
                fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                fDepth++;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}
 
Example 16
Source File: StAXStream2SAX.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void bridge() throws XMLStreamException {

        try {
            // remembers the nest level of elements to know when we are done.
            int depth=0;

            // skip over START_DOCUMENT
            int event = staxStreamReader.getEventType();
            if (event == XMLStreamConstants.START_DOCUMENT) {
                event = staxStreamReader.next();
            }

            // If not a START_ELEMENT (e.g., a DTD), skip to next tag
            if (event != XMLStreamConstants.START_ELEMENT) {
                event = staxStreamReader.nextTag();
                // An error if a START_ELEMENT isn't found now
                if (event != XMLStreamConstants.START_ELEMENT) {
                    throw new IllegalStateException("The current event is " +
                            "not START_ELEMENT\n but" + event);
                }
            }

            handleStartDocument();

            do {
                // These are all of the events listed in the javadoc for
                // XMLEvent.
                // The spec only really describes 11 of them.
                switch (event) {
                    case XMLStreamConstants.START_ELEMENT :
                        depth++;
                        handleStartElement();
                        break;
                    case XMLStreamConstants.END_ELEMENT :
                        handleEndElement();
                        depth--;
                        break;
                    case XMLStreamConstants.CHARACTERS :
                        handleCharacters();
                        break;
                    case XMLStreamConstants.ENTITY_REFERENCE :
                        handleEntityReference();
                        break;
                    case XMLStreamConstants.PROCESSING_INSTRUCTION :
                        handlePI();
                        break;
                    case XMLStreamConstants.COMMENT :
                        handleComment();
                        break;
                    case XMLStreamConstants.DTD :
                        handleDTD();
                        break;
                    case XMLStreamConstants.ATTRIBUTE :
                        handleAttribute();
                        break;
                    case XMLStreamConstants.NAMESPACE :
                        handleNamespace();
                        break;
                    case XMLStreamConstants.CDATA :
                        handleCDATA();
                        break;
                    case XMLStreamConstants.ENTITY_DECLARATION :
                        handleEntityDecl();
                        break;
                    case XMLStreamConstants.NOTATION_DECLARATION :
                        handleNotationDecl();
                        break;
                    case XMLStreamConstants.SPACE :
                        handleSpace();
                        break;
                    default :
                        throw new InternalError("processing event: " + event);
                }

                event=staxStreamReader.next();
            } while (depth!=0);

            handleEndDocument();
        } catch (SAXException e) {
            throw new XMLStreamException(e);
        }
    }
 
Example 17
Source File: ParsingUtils.java    From galleon with Apache License 2.0 4 votes vote down vote up
public static XMLStreamException unexpectedContent(final XMLStreamReader reader) {
    final String kind;
    switch (reader.getEventType()) {
        case XMLStreamConstants.ATTRIBUTE:
            kind = "attribute";
            break;
        case XMLStreamConstants.CDATA:
            kind = "cdata";
            break;
        case XMLStreamConstants.CHARACTERS:
            kind = "characters";
            break;
        case XMLStreamConstants.COMMENT:
            kind = "comment";
            break;
        case XMLStreamConstants.DTD:
            kind = "dtd";
            break;
        case XMLStreamConstants.END_DOCUMENT:
            kind = "document end";
            break;
        case XMLStreamConstants.END_ELEMENT:
            kind = "element end";
            break;
        case XMLStreamConstants.ENTITY_DECLARATION:
            kind = "entity declaration";
            break;
        case XMLStreamConstants.ENTITY_REFERENCE:
            kind = "entity ref";
            break;
        case XMLStreamConstants.NAMESPACE:
            kind = "namespace";
            break;
        case XMLStreamConstants.NOTATION_DECLARATION:
            kind = "notation declaration";
            break;
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
            kind = "processing instruction";
            break;
        case XMLStreamConstants.SPACE:
            kind = "whitespace";
            break;
        case XMLStreamConstants.START_DOCUMENT:
            kind = "document start";
            break;
        case XMLStreamConstants.START_ELEMENT:
            kind = "element start";
            break;
        default:
            kind = "unknown";
            break;
    }

    return new XMLStreamException("unexpected content: " + kind + (reader.hasName() ? reader.getName() : null) +
            (reader.hasText() ? reader.getText() : null), reader.getLocation());
}
 
Example 18
Source File: DeploymentDescriptorParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private List<A> parseAdapters(XMLStreamReader reader) {
    if (!reader.getName().equals(QNAME_ENDPOINTS)) {
        failWithFullName("runtime.parser.invalidElement", reader);
    }

    List<A> adapters = new ArrayList<A>();

    Attributes attrs = XMLStreamReaderUtil.getAttributes(reader);
    String version = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_VERSION);
    if (!ATTRVALUE_SUPPORTED_VERSIONS.contains(version)) {
        failWithLocalName("runtime.parser.invalidVersionNumber", reader, version);
    }

    while (XMLStreamReaderUtil.nextElementContent(reader) != XMLStreamConstants.END_ELEMENT) {

        if (reader.getName().equals(QNAME_ENDPOINT)) {
            attrs = XMLStreamReaderUtil.getAttributes(reader);

            String name = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_NAME);
            if (!names.add(name)) {
                logger.warning(
                        WsservletMessages.SERVLET_WARNING_DUPLICATE_ENDPOINT_NAME(/*name*/));
            }

            String implementationName =
                    getMandatoryNonEmptyAttribute(reader, attrs, ATTR_IMPLEMENTATION);
            Class<?> implementorClass = getImplementorClass(implementationName, reader);

            MetadataReader metadataReader = null;
            ExternalMetadataFeature externalMetadataFeature = null;

            // parse subelements to instantiate externalMetadataReader, if necessary ...
            XMLStreamReaderUtil.nextElementContent(reader);
            if (reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
                externalMetadataFeature = configureExternalMetadataReader(reader);
                if (externalMetadataFeature != null) {
                    metadataReader = externalMetadataFeature.getMetadataReader(implementorClass.getClassLoader(), false);
                }
            }

            QName serviceName = getQNameAttribute(attrs, ATTR_SERVICE);
            if (serviceName == null) {
                serviceName = EndpointFactory.getDefaultServiceName(implementorClass, metadataReader);
            }

            QName portName = getQNameAttribute(attrs, ATTR_PORT);
            if (portName == null) {
                portName = EndpointFactory.getDefaultPortName(serviceName, implementorClass, metadataReader);
            }

            //get enable-mtom attribute value
            String enable_mtom = getAttribute(attrs, ATTR_ENABLE_MTOM);
            String mtomThreshold = getAttribute(attrs, ATTR_MTOM_THRESHOLD_VALUE);
            String dbMode = getAttribute(attrs, ATTR_DATABINDING);
            String bindingId = getAttribute(attrs, ATTR_BINDING);
            if (bindingId != null) {
                // Convert short-form tokens to API's binding ids
                bindingId = getBindingIdForToken(bindingId);
            }
            WSBinding binding = createBinding(bindingId, implementorClass, enable_mtom, mtomThreshold, dbMode);
            if (externalMetadataFeature != null) {
                    binding.getFeatures().mergeFeatures(new WebServiceFeature[]{externalMetadataFeature},
                    true);
            }

            String urlPattern = getMandatoryNonEmptyAttribute(reader, attrs, ATTR_URL_PATTERN);

            // TODO use 'docs' as the metadata. If wsdl is non-null it's the primary.
            boolean handlersSetInDD = setHandlersAndRoles(binding, reader, serviceName, portName);

            EndpointFactory.verifyImplementorClass(implementorClass, metadataReader);
            SDDocumentSource primaryWSDL = getPrimaryWSDL(reader, attrs, implementorClass, metadataReader);

            WSEndpoint<?> endpoint = WSEndpoint.create(
                    implementorClass, !handlersSetInDD,
                    null,
                    serviceName, portName, container, binding,
                    primaryWSDL, docs.values(), createEntityResolver(), false
            );
            adapters.add(adapterFactory.createAdapter(name, urlPattern, endpoint));
        } else {
            failWithLocalName("runtime.parser.invalidElement", reader);
        }
    }
    return adapters;
}
 
Example 19
Source File: StAX2SAXReader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void adapt() throws XMLStreamException, SAXException {
    QName qname;
    String prefix, localPart;
    AttributesImpl attrs = new AttributesImpl();
    char[] buffer;
    int nsc;
    int nat;

    _handler.startDocument();

    try {

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


            switch(event) {
            case  XMLStreamConstants.START_ELEMENT: {
                // Report namespace events first
                nsc = _reader.getNamespaceCount();
                for (int i = 0; i < nsc; i++) {
                    _handler.startPrefixMapping(_reader.getNamespacePrefix(i),
                        _reader.getNamespaceURI(i));
                }

                // Collect list of attributes
                attrs.clear();
                nat = _reader.getAttributeCount();
                for (int i = 0; i < nat; i++) {
                    QName q = _reader.getAttributeName(i);
                    String qName = _reader.getAttributePrefix(i);
                    if (qName == null || qName == "") {
                        qName = q.getLocalPart();
                    } else {
                        qName = qName + ":" +  q.getLocalPart();
                    }
                    attrs.addAttribute(_reader.getAttributeNamespace(i),
                                       q.getLocalPart(),
                                       qName,
                                       _reader.getAttributeType(i),
                                       _reader.getAttributeValue(i));
                }

                // Report start element
                qname = _reader.getName();
                prefix = qname.getPrefix();
                localPart = qname.getLocalPart();

                _handler.startElement(_reader.getNamespaceURI(),
                                      localPart,
                                      (prefix.length() > 0) ?
                                          (prefix + ":" + localPart) : localPart,
                                      attrs);
                break;
            }
            case  XMLStreamConstants.END_ELEMENT: {
                // Report end element
                qname = _reader.getName();
                prefix = qname.getPrefix();
                localPart = qname.getLocalPart();

                _handler.endElement(_reader.getNamespaceURI(),
                                    localPart,
                                    (prefix.length() > 0) ?
                                        (prefix + ":" + localPart) : localPart);

                // Report end namespace events
                nsc = _reader.getNamespaceCount();
                for (int i = 0; i < nsc; i++) {
                    _handler.endPrefixMapping(_reader.getNamespacePrefix(i));
                }
                break;
            }
            case XMLStreamConstants.CHARACTERS:
                _handler.characters(_reader.getTextCharacters(), _reader.getTextStart(), _reader.getTextLength());
                break;
            case XMLStreamConstants.COMMENT:
                _lexicalHandler.comment(_reader.getTextCharacters(), _reader.getTextStart(), _reader.getTextLength());
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                _handler.processingInstruction(_reader.getPITarget(), _reader.getPIData());
                break;
            case XMLStreamConstants.END_DOCUMENT:
                break;
            default:
                throw new RuntimeException(CommonResourceBundle.getInstance().getString("message.StAX2SAXReader", new Object[]{Integer.valueOf(event)}));
            } // switch
        }
    }
    catch (XMLStreamException e) {
        _handler.endDocument();     // flush whatever we have
        throw e;
    }

    _handler.endDocument();
}
 
Example 20
Source File: StAXSchemaParser.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void parse(XMLStreamReader input) throws XMLStreamException, XNIException {
    if (input.hasNext()) {
        int eventType = input.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(input.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        boolean first = true;
        loop: while (input.hasNext()) {
            if (!first) {
                eventType = input.next();
            }
            else {
                first = false;
            }
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                fLocationWrapper.setLocation(input.getLocation());
                fNamespaceContext.setNamespaceContext(input.getNamespaceContext());
                fillQName(fElementQName, input.getNamespaceURI(),
                    input.getLocalName(), input.getPrefix());
                fillXMLAttributes(input);
                fillDeclaredPrefixes(input);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                fLocationWrapper.setLocation(input.getLocation());
                fNamespaceContext.setNamespaceContext(input.getNamespaceContext());
                fillQName(fElementQName, input.getNamespaceURI(),
                    input.getLocalName(), input.getPrefix());
                fillDeclaredPrefixes(input);
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                fTempString.setValues(input.getTextCharacters(),
                    input.getTextStart(), input.getTextLength());
                fSchemaDOMParser.characters(fTempString, null);
                break;
            case XMLStreamConstants.SPACE:
                fTempString.setValues(input.getTextCharacters(),
                    input.getTextStart(), input.getTextLength());
                fSchemaDOMParser.ignorableWhitespace(fTempString, null);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                fTempString.setValues(input.getTextCharacters(),
                    input.getTextStart(), input.getTextLength());
                fSchemaDOMParser.characters(fTempString, null);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                fillProcessingInstruction(input.getPIData());
                fSchemaDOMParser.processingInstruction(input.getPITarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                ++fDepth;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}