Example usage for javax.xml.stream XMLStreamReader nextTag

List of usage examples for javax.xml.stream XMLStreamReader nextTag

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader nextTag.

Prototype

public int nextTag() throws XMLStreamException;

Source Link

Document

Skips any white space (isWhiteSpace() returns true), COMMENT, or PROCESSING_INSTRUCTION, until a START_ELEMENT or END_ELEMENT is reached.

Usage

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readReplace(final XMLStreamReader reader, final DMMeta parentMeta) throws XMLStreamException {
    reader.nextTag();

    // CmdID//  ww w  .j a v  a  2 s.c o m
    final String cmdID = reader.getElementText();
    reader.nextTag();

    // Meta?
    final DMMeta globalMeta = new DMMeta(parentMeta);
    if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$
        globalMeta.putAll(readMeta(reader));
        reader.nextTag();
    }

    // Item+
    boolean continueReplace = true;
    do {
        switch (reader.getEventType()) {
        case XMLEvent.START_ELEMENT:
            final DMItem item = readItem(reader, globalMeta);
            reader.nextTag();
            final Status status = this.commandHandler.replace(item.getTargetURI(), item.getMeta().getFormat(),
                    item.getMeta().getType(), item.getData());
            this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Replace", item.getTargetURI(), null, //$NON-NLS-1$
                    String.valueOf(status.getCode()));

            // Fire replace event
            for (final ProtocolListener messageListener : this.protocolLinsteners) {
                messageListener.replace(item.getTargetURI(), item.getData(), status);
            }
            break;
        case XMLEvent.END_ELEMENT:
            continueReplace = false;
            break;
        default:
            break;
        }
    } while (continueReplace);
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readCopy(final XMLStreamReader reader) throws XMLStreamException {
    reader.nextTag();

    // CmdID//from w  w  w  .j a va2 s.c o  m
    final String cmdID = reader.getElementText();
    reader.nextTag();

    // Meta?
    if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$
        jumpToEndTag(reader, "Meta"); //$NON-NLS-1$
        reader.nextTag();
    }

    // Item+
    boolean continueCopy = true;
    do {
        switch (reader.getEventType()) {
        case XMLEvent.START_ELEMENT:
            final DMItem item = readItem(reader, null);
            reader.nextTag();
            final Status status = this.commandHandler.copy(item.getTargetURI(), item.getSourceURI());
            this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Copy", item.getTargetURI(), //$NON-NLS-1$
                    item.getSourceURI(), String.valueOf(status.getCode()));

            // Fire copy event
            for (final ProtocolListener messageListener : this.protocolLinsteners) {
                messageListener.copy(item.getTargetURI(), item.getSourceURI(), status);
            }
            break;
        case XMLEvent.END_ELEMENT:
            continueCopy = false;
            break;
        default:
            break;
        }
    } while (continueCopy);
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readExec(final XMLStreamReader reader, final DMMeta parentMeta) throws XMLStreamException {
    reader.nextTag();

    // CmdID/*w w w.  j  a va  2  s .co  m*/
    final String cmdID = reader.getElementText();
    reader.nextTag();

    // Meta?
    final DMMeta globalMeta = new DMMeta(parentMeta);
    if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$
        globalMeta.putAll(readMeta(reader));
        reader.nextTag();
    }

    // Correlator?
    final String correlator;
    if (reader.getLocalName().equals("Correlator")) { //$NON-NLS-1$
        correlator = reader.getElementText();
        reader.nextTag();
    } else {
        correlator = null;
    }

    // Item
    final DMItem item = readItem(reader, globalMeta);
    reader.nextTag();

    // Performs the exec command
    final Status status = this.commandHandler.exec(item.getTargetURI(), correlator, item.getMeta().getFormat(),
            item.getMeta().getType(), item.getData());
    this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Exec", item.getTargetURI(), //$NON-NLS-1$
            item.getSourceURI(), String.valueOf(status.getCode()));
    if (status.getDelayedProcessing() != null) {
        this.dmClient.execute(this.client, new Runnable() {

            @Override
            public void run() {
                try {
                    dmClient.initiateManagementSession(server, "", client, devInfoNodes, commandHandler, //$NON-NLS-1$
                            protocolLinsteners, new DMGenericAlert[] { status.getDelayedProcessing().call() });
                } catch (final Exception e) {
                    Activator.logError("Error while initializing management session", e); //$NON-NLS-1$
                }
            }

        });
    }

    // Fire exec event
    for (final ProtocolListener messageListener : this.protocolLinsteners) {
        messageListener.exec(item.getTargetURI(), correlator, item.getData(), status);
    }
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readSequence(final XMLStreamReader reader) throws XMLStreamException {
    reader.nextTag();

    // CmdID//from  w w  w.j  a v  a 2  s  .  c  o m
    final String cmdID = reader.getElementText();
    reader.nextTag();

    // Meta?
    final DMMeta globalMeta;
    if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$
        globalMeta = readMeta(reader);
        reader.nextTag();
    } else {
        globalMeta = new DMMeta();
    }

    // Procces the sequence element
    this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Sequence", null, null, //$NON-NLS-1$
            String.valueOf(StatusCode.OK.getCode()));

    boolean continueSequence = true;
    do {
        switch (reader.getEventType()) {
        case XMLEvent.START_ELEMENT:
            switch (getKey(reader.getLocalName())) {
            case ADD:
                readAdd(reader, globalMeta);
                break;
            case COPY:
                readCopy(reader);
                break;
            case DELETE:
                readDelete(reader);
                break;
            case GET:
                readGet(reader);
                break;
            case REPLACE:
                readReplace(reader, globalMeta);
                break;
            case EXEC:
                readExec(reader, globalMeta);
                break;
            default:
                break;
            }
            reader.nextTag();
            break;
        case XMLEvent.END_ELEMENT:
            continueSequence = false;
            break;
        default:
            break;
        }
    } while (continueSequence);
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readAtomic(final XMLStreamReader reader) throws XMLStreamException {
    reader.nextTag();

    // CmdID/*from  w w  w  .  j a v a2s .  c  om*/
    final String cmdID = reader.getElementText();
    jumpToEndTag(reader, "Atomic"); //$NON-NLS-1$

    // Performs atomic command
    this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Atomic", null, null, //$NON-NLS-1$
            String.valueOf(StatusCode.OPTIONAL_FEATURE_NOT_SUPPORTED.getCode()));
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private DMItem readItem(final XMLStreamReader reader, final DMMeta parentMeta) throws XMLStreamException {
    reader.nextTag();

    // Target?//from   ww w .  j  a va 2s  .c  o  m
    final String targetURI;
    if (reader.getLocalName().equals("Target")) { //$NON-NLS-1$
        reader.nextTag();
        // LocURI
        targetURI = reader.getElementText();
        reader.nextTag();
        // LocName?
        if (reader.getLocalName().equals("LocName")) { //$NON-NLS-1$
            jumpToEndTag(reader, "LocName"); //$NON-NLS-1$
            reader.nextTag();
        }
        reader.nextTag();
    } else {
        targetURI = null;
    }

    // Source?
    final String sourceURI;
    if (reader.getLocalName().equals("Source")) { //$NON-NLS-1$
        reader.nextTag();
        // LocURI
        sourceURI = reader.getElementText();
        reader.nextTag();
        // LocName?
        if (reader.getLocalName().equals("LocName")) { //$NON-NLS-1$
            jumpToEndTag(reader, "LocName"); //$NON-NLS-1$
            reader.nextTag();
        }
        reader.nextTag();
    } else {
        sourceURI = null;
    }

    // Meta?
    final DMMeta meta = new DMMeta(parentMeta);
    if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$
        meta.putAll(readMeta(reader));
        reader.nextTag();
    }

    // Data?
    final String data;
    if (reader.getLocalName().equals("Data")) { //$NON-NLS-1$
        data = reader.getElementText();
        reader.nextTag();
    } else {
        data = null;
    }

    return new DMItem(targetURI, sourceURI, meta, data);
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readFinal(final XMLStreamReader reader) throws XMLStreamException {
    reader.nextTag();

    this.isSessionContinue = !this.statusManager.onlySyncHdrStatus();
}

From source file:org.eclipse.smila.connectivity.framework.agent.jobfile.JobFileReader.java

/**
 * Parse JobFile, read Records from the XML stream. The stream must be currently at the RecordList start tag.
 * /*  w w w.  j av a 2s.  c  om*/
 * @param staxReader
 *          source XML stream
 * @param url
 *          the url of the job file
 * @throws XMLStreamException
 *           StAX error.
 */
private void parse(final XMLStreamReader staxReader, final URL url) throws XMLStreamException {
    staxReader.nextTag();
    if (isStartTag(staxReader, TAG_JOB_FILE)) {
        while (staxReader.hasNext()) {
            staxReader.nextTag();
            if (isStartTag(staxReader, TAG_ADD)) {
                staxReader.nextTag();
                do {
                    final Record record = _recordReader.readRecord(staxReader);
                    if (record != null) {
                        try {
                            loadAttachments(record);
                            _jobFileHandler.add(record);
                        } catch (IOException e) {
                            final String msg = "Error loading attachments for record " + record.getId()
                                    + ". Record is skipped.";
                            if (_log.isErrorEnabled()) {
                                _log.error(msg, e);
                            }
                        }
                    } // if
                    staxReader.nextTag();
                } while (staxReader.hasNext() && !isEndTag(staxReader, TAG_ADD));
            } else if (isStartTag(staxReader, TAG_DELETE)) {
                staxReader.nextTag();
                do {
                    final Record record = _recordReader.readRecord(staxReader);
                    _jobFileHandler.delete(record);
                    staxReader.nextTag();
                } while (staxReader.hasNext() && !isEndTag(staxReader, TAG_DELETE));
            } else if (isEndTag(staxReader, TAG_JOB_FILE)) {
                break;
            }
        } // while
    } else {
        throw new XMLStreamException(
                "Invalid document " + url + ". Must begin with tag <" + TAG_JOB_FILE + ">");
    }
}

From source file:org.eclipse.smila.datamodel.record.stax.RecordReader.java

/**
 * read Record list from the XML stream. The stream must be currently at the RecordList start tag.
 * /*from   w  w  w . j  a v a  2  s .c  o m*/
 * @param staxReader
 *          source XML stream
 * @return Record list read from stream or an empty list, if stream is not currently at a RecordList start tag.
 * @throws XMLStreamException
 *           StAX error.
 */
public List<Record> readRecords(final XMLStreamReader staxReader) throws XMLStreamException {
    final List<Record> records = new ArrayList<Record>();
    if (isStartTag(staxReader, RecordParser.TAG_RECORDLIST)) {
        staxReader.nextTag();
        while (isStartTag(staxReader, RecordParser.TAG_RECORD)) {
            records.add(readRecord(staxReader));
            staxReader.nextTag();
        }
    }
    return records;
}

From source file:org.eclipse.smila.datamodel.record.stax.RecordReader.java

/**
 * read Record from the XML stream. The stream must be currently at the Record start tag.
 * /*from www .jav  a  2  s.  com*/
 * @param staxReader
 *          source XML stream
 * @return Record read from stream or null, if stream is not currently at a Record start tag.
 * @throws XMLStreamException
 *           StAX error.
 */
public Record readRecord(final XMLStreamReader staxReader) throws XMLStreamException {
    Record record = null;
    if (isStartTag(staxReader, RecordParser.TAG_RECORD)) {
        record = _recordFactory.createRecord();
        staxReader.nextTag(); // go to next element (eventually Id)
        if (isStartTag(staxReader, IdParser.TAG_ID)) {
            record.setId(_idReader.readId(staxReader));
            staxReader.nextTag(); // move beyond </Id>
        }
        record.setMetadata(readMetadata(staxReader));
        readAttachments(staxReader, record);
    }
    return record;
}