java类javax.xml.stream.XMLStreamReader的实例源码

PolicyWSDLParserExtension.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
private void processReferenceUri(
        final String policyUri,
        final WSDLObject element,
        final XMLStreamReader reader,
        final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {

    if (null == policyUri || policyUri.length() == 0) {
        return;
    }
    if ('#' != policyUri.charAt(0)) { // external uri (already)
        getUnresolvedUris(false).add(policyUri);
    }

    addHandlerToMap(map, element,
            new PolicyRecordHandler(
            HandlerType.PolicyUri,
            SafePolicyReader.relativeToAbsoluteUrl(policyUri, reader.getLocation().getSystemId())));
}
Bug6481678.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testNamespaceContext() {
    is = new java.io.ByteArrayInputStream(getXML().getBytes());
    try {
        XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    NamespaceContext context = sr.getNamespaceContext();
                    Assert.assertTrue(context.getPrefix(namespaceURIApple).equals(prefixApple));
                }
            }
        }
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
FastInfosetUtil.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Returns the FI parser allocated for this thread.
 */
public static XMLStreamReader createFIStreamReader(InputStream in) {
    // Check if compatible implementation of FI was found
    if (FastInfosetReflection.fiStAXDocumentParser_new == null) {
        throw new XMLReaderException("fastinfoset.noImplementation");
    }

    try {
        // Do not use StAX pluggable layer for FI
        Object sdp = FastInfosetReflection.fiStAXDocumentParser_new.newInstance();
        FastInfosetReflection.fiStAXDocumentParser_setStringInterning.invoke(sdp, Boolean.TRUE);
        FastInfosetReflection.fiStAXDocumentParser_setInputStream.invoke(sdp, in);
        return (XMLStreamReader) sdp;
    } catch (Exception e) {
        throw new XMLStreamReaderException(e);
    }
}
SDDocumentSource.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Creates a {@link SDDocumentSource} from {@link XMLStreamBuffer}.
 */
public static SDDocumentSource create(final URL systemId, final XMLStreamBuffer xsb) {
    return new SDDocumentSource() {
        public XMLStreamReader read(XMLInputFactory xif) throws XMLStreamException {
            return xsb.readAsXMLStreamReader();
        }

        public XMLStreamReader read() throws XMLStreamException {
            return xsb.readAsXMLStreamReader();
        }

        public URL getSystemId() {
            return systemId;
        }
    };
}
Bug6481678.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testChildElementNamespace() {
    is = new java.io.ByteArrayInputStream(getXML().getBytes());
    try {
        XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    QName qname = sr.getName();
                    Assert.assertTrue(qname.getPrefix().equals(prefixApple) && qname.getNamespaceURI().equals(namespaceURIApple)
                            && qname.getLocalPart().equals(childElement));
                }
            }
        }
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
StAXSourceTest.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
/**
 * @bug 8152530
 * Verifies that StAXSource handles empty namespace properly. NPE was thrown
 * before the fix.
 * @throws Exception if the test fails
 */
@Test
public final void testStAXSourceWEmptyNS() throws Exception {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
        + "<EntityList>\n"
        + "  <Entity xmlns=\"\">\n"
        + "  </Entity>\n"
        + "  <Entity xmlns=\"\">\n"
        + "  </Entity>\n"
        + "</EntityList> ";

    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));
    xsr.nextTag();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Entity")) {
        StringWriter stringResult = new StringWriter();
        t.transform(new StAXSource(xsr), new StreamResult(stringResult));
        System.out.println("result: \n" + stringResult.toString());
    }
}
ResponseBuilder.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
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);
}
DocumentStaxUtils.java 文件源码 项目:gate-core 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Processes a GateDocumentFeatures or Annotation element to build a
 * feature map. The element is expected to contain Feature children,
 * each with a Name and Value. The reader will be returned positioned
 * on the closing GateDocumentFeatures or Annotation tag.
 * 
 * @throws XMLStreamException
 */
public static FeatureMap readFeatureMap(XMLStreamReader xsr)
        throws XMLStreamException {
  FeatureMap fm = Factory.newFeatureMap();
  while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
    xsr.require(XMLStreamConstants.START_ELEMENT, null, "Feature");
    Object featureName = null;
    Object featureValue = null;
    while(xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
      if("Name".equals(xsr.getLocalName())) {
        featureName = readFeatureNameOrValue(xsr);
      }
      else if("Value".equals(xsr.getLocalName())) {
        featureValue = readFeatureNameOrValue(xsr);
      }
      else {
        throw new XMLStreamException("Feature element should contain "
                + "only Name and Value children", xsr.getLocation());
      }
    }
    fm.put(featureName, featureValue);
  }
  return fm;
}
Jsr173MR1Req8Test.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
@Test
public void testDefaultAttrNS() {
    XMLInputFactory ifac = XMLInputFactory.newInstance();

    try {
        XMLStreamReader re = ifac.createXMLStreamReader(getClass().getResource(INPUT_FILE1).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE1));
        while (re.hasNext()) {
            int event = re.next();
            if (event == XMLStreamConstants.START_ELEMENT) {
                // System.out.println("#attrs = " + re.getAttributeCount());
                Assert.assertTrue(re.getAttributeCount() == 2);
                // This works if "" is replaced by null too
                // System.out.println("attr1 = " + re.getAttributeValue("",
                // "attr1"));
                Assert.assertTrue(re.getAttributeValue("", "attr1").equals("pass"));
            }
        }
        re.close();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
NamespaceTest.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void testNamespaceContext() {
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
        XMLStreamReader sr = xif.createXMLStreamReader(is);
        while (sr.hasNext()) {
            int eventType = sr.next();
            if (eventType == XMLStreamConstants.START_ELEMENT) {
                if (sr.getLocalName().equals(childElement)) {
                    NamespaceContext context = sr.getNamespaceContext();
                    Assert.assertTrue(context.getPrefix(namespaceURI).equals(prefix));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
FastInfosetStreamSOAPCodec.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
private XMLStreamReader getXMLStreamReader(InputStream in) {
    // If the _retainState is true (FI stateful) then pick up Codec assiciated XMLStreamReader
    if (_retainState) {
        if (_statefulParser != null) {
            _statefulParser.setInputStream(in);
            return _statefulParser;
        } else {
            return _statefulParser = FastInfosetCodec.createNewStreamReader(in, _retainState);
        }
    }

    // Otherwise thread assiciated XMLStreamReader
    return READER_FACTORY.doCreate(null, in, false);
}
CIMProgressiveParser.java 文件源码 项目:powsybl-core 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Utility to use when we meet a startElement in the CIM XML Document.
 * Only the startElement that contains the CIMURI is used.
 *
 * @param xmlsr
 *            The XMLStreamReader used to read the CIM XML Document
 */
public void startElement(final XMLStreamReader xmlsr) {

    // if null, the element is not interpreted

    // We search for a <cim:...> element or for the <md:Model.profile> element
    if(xmlsr.getPrefix().equals("cim")) {
        hasGoodVersion = (xmlsr.getNamespaceURI().equals(CIMURI.CIMURI));
        done = true;
    }
    else if(xmlsr.getPrefix().equals("md") && xmlsr.getName().equals("Model.profile")){
        profileElement = true;
    }

}
WSDLParserExtensionFacade.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.messageElements(msg, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
WSDLParserExtensionFacade.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
public boolean messageElements(EditableWSDLMessage msg, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.messageElements(msg, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
UnmarshallerImpl.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
@Override
public <T> JAXBElement<T> unmarshal(XMLStreamReader reader, Class<T> expectedType) throws JAXBException {
    if (expectedType==null) {
        throw new IllegalArgumentException();
    }
    return (JAXBElement)unmarshal0(reader,getBeanInfo(expectedType));
}
StAXEventAllocatorBase.java 文件源码 项目:OpenJSharp 阅读 22 收藏 0 点赞 0 评论 0
protected void addAttributes(StartElementEvent event,XMLStreamReader streamReader){
    AttributeBase attr = null;
    for(int i=0; i<streamReader.getAttributeCount() ;i++){
        attr = (AttributeBase)factory.createAttribute(streamReader.getAttributeName(i),
                                streamReader.getAttributeValue(i));
        attr.setAttributeType(streamReader.getAttributeType(i));
        attr.setSpecified(streamReader.isAttributeSpecified(i));
        event.addAttribute(attr);
    }
}
GraphMLImporter.java 文件源码 项目:cuttlefish 阅读 20 收藏 0 点赞 0 评论 0
private void readGraph(XMLStreamReader xmlReader) {
    String edgeDefault = "";

    for (int i = 0; i < xmlReader.getAttributeCount(); ++i) {
        String attr = xmlReader.getAttributeLocalName(i);

        if (attr.equalsIgnoreCase(GRAPH_EDGEDEFAULT)) {
            edgeDefault = xmlReader.getAttributeValue(i);
        }
    }

    network.setDirected(edgeDefault.equalsIgnoreCase(EDGE_DIRECTED));
}
StreamReaderBufferCreator.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
private void storeElementWithInScopeNamespaces(XMLStreamReader reader) {
    storeQualifiedName(T_ELEMENT_LN,
            reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());

    if (reader.getNamespaceCount() > 0) {
        storeNamespaceAttributes(reader);
    }

    if (reader.getAttributeCount() > 0) {
        storeAttributes(reader);
    }
}
PolicyWSDLParserExtension.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
@Override
public boolean bindingOperationFaultElements(final EditableWSDLBoundFault fault, final XMLStreamReader reader) {
    LOGGER.entering();
    final boolean result = processSubelement(fault, reader, getHandlers4BindingFaultOpMap());
    LOGGER.exiting(result);
    return result;
}
WSDLParserExtensionFacade.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
public boolean definitionsElements(XMLStreamReader reader){
    for (WSDLParserExtension e : extensions) {
        if (e.definitionsElements(reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
PolicyWSDLParserExtension.java 文件源码 项目:OpenJSharp 阅读 25 收藏 0 点赞 0 评论 0
@Override
public boolean serviceElements(final EditableWSDLService service, final XMLStreamReader reader) {
    LOGGER.entering();
    final boolean result = processSubelement(service, reader, getHandlers4ServiceMap());
    LOGGER.exiting();
    return result;
}
XMLStreamReaderUtil.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
public static int nextElementContent(XMLStreamReader reader) {
    int state = nextContent(reader);
    if (state == CHARACTERS) {
        throw new XMLStreamReaderException(
            "xmlreader.unexpectedCharacterContent", reader.getText());
    }
    return state;
}
Sources.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Returns an instance of XMLStreamReader.
 *
 * @return an instance of XMLStreamReader.
 */
private XMLStreamReader getXMLStreamReader() {
    XMLStreamReader r = null;
    try {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        r = xif.createXMLStreamReader(new ByteArrayInputStream("".getBytes()));
    } catch (XMLStreamException ex) {}

    return r;
}
DeploymentDescriptorParser.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
protected String getMandatoryAttribute(XMLStreamReader reader, Attributes attrs, String name) {
    String value = getAttribute(attrs, name);
    if (value == null) {
        failWithLocalName("runtime.parser.missing.attribute", reader, name);
    }
    return value;
}
WSDLParserExtensionFacade.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
public boolean portTypeOperationFaultElements(EditableWSDLFault fault, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.portTypeOperationFaultElements(fault, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
UnmarshallerImpl.java 文件源码 项目:OpenJSharp 阅读 25 收藏 0 点赞 0 评论 0
public Object unmarshal0(XMLStreamReader reader, JaxBeanInfo expectedType) throws JAXBException {
    if (reader == null) {
        throw new IllegalArgumentException(
            Messages.format(Messages.NULL_READER));
    }

    int eventType = reader.getEventType();
    if (eventType != XMLStreamConstants.START_ELEMENT
        && eventType != XMLStreamConstants.START_DOCUMENT) {
        // TODO: convert eventType into event name
        throw new IllegalStateException(
            Messages.format(Messages.ILLEGAL_READER_STATE,eventType));
    }

    XmlVisitor h = createUnmarshallerHandler(null,false,expectedType);
    StAXConnector connector=StAXStreamConnector.create(reader,h);

    try {
        connector.bridge();
    } catch (XMLStreamException e) {
        throw handleStreamException(e);
    }

    Object retVal = h.getContext().getResult();
    h.getContext().clearResult();
    return retVal;
}
WSDLParserExtensionFacade.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
public boolean portTypeElements(EditableWSDLPortType portType, XMLStreamReader reader) {
    for (WSDLParserExtension e : extensions) {
        if (e.portTypeElements(portType, reader)) {
            return true;
        }
    }
    XMLStreamReaderUtil.skipElement(reader);
    return true;
}
JAXBHeader.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
public XMLStreamReader readHeader() throws XMLStreamException {
    if(infoset==null) {
        MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
        writeTo(buffer.createFromXMLStreamWriter());
        infoset = buffer;
    }
    return infoset.readAsXMLStreamReader();
}
XMLStreamReaderUtil.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
public static int nextElementContent(XMLStreamReader reader) {
    int state = nextContent(reader);
    if (state == CHARACTERS) {
        throw new XMLStreamReaderException(
            "xmlreader.unexpectedCharacterContent", reader.getText());
    }
    return state;
}
PolicyUtils.java 文件源码 项目:OpenJSharp 阅读 18 收藏 0 点赞 0 评论 0
/**
 * If the {@code reader} is not {@code null}, this method will try to close the
 * {@code reader} instance and log warning about any unexpected
 * {@link IOException} that may occur.
 *
 * @param reader resource to be closed
 */
public static void closeResource(XMLStreamReader reader) {
    if (reader != null) {
        try {
            reader.close();
        } catch (XMLStreamException e) {
            LOGGER.warning(LocalizationMessages.WSP_0023_UNEXPECTED_ERROR_WHILE_CLOSING_RESOURCE(reader.toString()), e);
        }
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号