Package javax.xml.stream.events

Examples of javax.xml.stream.events.StartElement


        }
        else {
            newNamespace = getEventFactory().createNamespace(namespaceUri);
        }
        newNamespaces.add(newNamespace);
        StartElement oldStartElement = getStartElement();
        this.startElement = getEventFactory()
                .createStartElement(oldStartElement.getName(), oldStartElement.getAttributes(),
                        newNamespaces.iterator());
    }
View Full Code Here


            throws XMLStreamException {
        XMLEvent event = eventReader.nextTag();
        if (!event.isStartElement()) {
            throw new StroapMessageCreationException("Unexpected event: " + event + ", expected StartElement");
        }
        StartElement startElement = event.asStartElement();
        SoapVersion soapVersion = messageFactory.getSoapVersion();
        if (!soapVersion.getEnvelopeName().equals(startElement.getName())) {
            throw new StroapMessageCreationException(
                    "Unexpected name: " + startElement.getName() + ", expected " + soapVersion.getEnvelopeName());
        }
        StroapHeader header = null;
        StroapBody body = null;
        XMLEvent peekedEvent = eventReader.peek();
        while (peekedEvent != null) {
View Full Code Here

            throws XMLStreamException {
        XMLEvent event = eventReader.nextTag();
        if (!event.isStartElement()) {
            throw new StroapMessageCreationException("Unexpected event: " + event + ", expected StartElement");
        }
        StartElement startElement = event.asStartElement();
        SoapVersion soapVersion = messageFactory.getSoapVersion();
        if (!soapVersion.getHeaderName().equals(startElement.getName())) {
            throw new StroapMessageCreationException(
                    "Unexpected name: " + startElement.getName() + ", expected " + soapVersion.getHeaderName());
        }

        if (SoapVersion.SOAP_11.equals(soapVersion)) {
            return new Stroap11Header(startElement, messageFactory);
        }
View Full Code Here

    static StroapBody build(XMLEventReader eventReader, StroapMessageFactory messageFactory) throws XMLStreamException {
        XMLEvent event = eventReader.nextTag();
        if (!event.isStartElement()) {
            throw new StroapMessageCreationException("Unexpected event: " + event + ", expected StartElement");
        }
        StartElement startElement = event.asStartElement();
        SoapVersion soapVersion = messageFactory.getSoapVersion();
        if (!soapVersion.getBodyName().equals(startElement.getName())) {
            throw new StroapMessageCreationException(
                    "Unexpected name: " + startElement.getName() + ", expected " + soapVersion.getBodyName());
        }
        StroapPayload payload;
        if (messageFactory.isPayloadCaching()) {
            payload = new CachingStroapPayload(eventReader);
        }
View Full Code Here

        Assert.isTrue(events.size() >= 2, "not enough events");
        XMLEvent event = events.get(0);
        if (!event.isStartElement()) {
            throw new StroapHeaderException("Unexpected event: " + event + ", expected StartElement");
        }
        StartElement startElement = event.asStartElement();
        event = events.get(events.size() - 1);
        if (!event.isEndElement()) {
            throw new StroapHeaderException("Unexpected event: " + event + ", expected EndElement");
        }
        List<XMLEvent> childEvents = events.subList(1, events.size() - 1);
View Full Code Here

    }
   
   
    private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
        throws XMLStreamException {
        StartElement start = event.asStartElement();
        QName name = start.getName();
        String nsURI = name.getNamespaceURI();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
       
        if (prefix != null) {
            writer.writeStartElement(prefix, localName, nsURI);
        } else if (nsURI != null) {
            writer.writeStartElement(localName, nsURI);
        } else {
            writer.writeStartElement(localName);
        }
        Iterator<XMLEvent> it = CastUtils.cast(start.getNamespaces());
        while (it != null && it.hasNext()) {
            writeEvent(it.next(), writer);
        }
       
        it = CastUtils.cast(start.getAttributes());
        while (it != null && it.hasNext()) {
            writeAttributeEvent(it.next(), writer);           
        }
    }
View Full Code Here

      {
         XMLEvent event = reader.nextEvent();
         switch (event.getEventType())
         {
            case XMLStreamConstants.START_ELEMENT :
               StartElement startElement = event.asStartElement();

               Map<String, String> attr = new HashMap<String, String>();

               Iterator attributes = startElement.getAttributes();
               while (attributes.hasNext())
               {
                  Attribute attribute = (Attribute)attributes.next();
                  attr.put(attribute.getName().getLocalPart(), attribute.getValue());
               }

               String localName = startElement.getName().getLocalPart();
               if (localName.equals(REFERENCE_ELEMENT))
               {
                  String bindName = attr.get(BIND_NAME_ATTR);
                  String className = attr.get(CLASS_NAME_ATTR);
                  String factoryName = attr.get(FACTORY_ATTR);
View Full Code Here

    try {
      EventLoop: while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();

        if (event.isStartElement()) {
          StartElement start = event.asStartElement();
          if (isRemovable(start)) {
            while (reader.hasNext()) {
              XMLEvent next = reader.nextEvent();
              if (next.isEndElement() && next.asEndElement().getName().equals(start.getName()))
                continue EventLoop;
            }
            // If this is reached, we finished the document before the tag ended
            throw new RuntimeException(String.format("End of file was reached before %s closing tag was found.",
                    start.getName()));
          }
          else if (toAdd.containsKey(start.getName().getLocalPart())
                  && !toAdd.get(start.getName().getLocalPart()).isEmpty()) {
            writer.add(event);
            final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
            for (final Tag tag : toAdd.get(start.getName().getLocalPart())) {
              List<Attribute> attrs = new ArrayList<Attribute>();
              for (final AttributeEntry entry : tag) {
                attrs.add(eventFactory.createAttribute(entry.getKey(), entry.getValue()));
              }
              StartElement newStart = eventFactory.createStartElement(QName.valueOf(tag.getName()), attrs.iterator(),
                      null);
              EndElement newEnd = eventFactory.createEndElement(newStart.getName(), null);

              writer.add(newStart);
              writer.add(newEnd);
            }
          }
View Full Code Here

         {
            XMLEvent event = reader.nextEvent();
            switch (event.getEventType())
            {
               case XMLEvent.START_ELEMENT :
                  StartElement element = event.asStartElement();
                  QName name = element.getName();
                  HierarchicalProperty prop = new HierarchicalProperty(name);
                  if (!curProperty.empty())
                     curProperty.peek().addChild(prop);
                  else
                     rootProperty = prop;
View Full Code Here

    }
   
   
    private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
        throws XMLStreamException {
        StartElement start = event.asStartElement();
        QName name = start.getName();
        String nsURI = name.getNamespaceURI();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
       
        if (prefix != null) {
            writer.writeStartElement(prefix, localName, nsURI);
        } else if (nsURI != null) {
            writer.writeStartElement(localName, nsURI);
        } else {
            writer.writeStartElement(localName);
        }
        Iterator it = start.getNamespaces();
        while (it != null && it.hasNext()) {
            writeEvent((XMLEvent)it.next(), writer);
        }
       
        it = start.getAttributes();
        while (it != null && it.hasNext()) {
            writeAttributeEvent((Attribute)it.next(), writer);           
        }
    }
View Full Code Here

TOP

Related Classes of javax.xml.stream.events.StartElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.