Example usage for javax.xml.stream XMLStreamReader getLocalName

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

Introduction

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

Prototype

public String getLocalName();

Source Link

Document

Returns the (local) name of the current event.

Usage

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

private void readAdd(final XMLStreamReader reader, final DMMeta parentMeta) throws XMLStreamException {
    reader.nextTag();//from www  .  j  av a 2 s.  co m

    // CmdID
    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 continueAdd = true;
    do {
        switch (reader.getEventType()) {
        case XMLEvent.START_ELEMENT:
            // Performs the add command
            final DMItem item = readItem(reader, globalMeta);
            reader.nextTag();
            final Status status = this.commandHandler.add(item.getTargetURI(), item.getMeta().getFormat(),
                    item.getMeta().getType(), item.getData());
            this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Add", item.getTargetURI(), null, //$NON-NLS-1$
                    String.valueOf(status.getCode()));

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

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

private void readDelete(final XMLStreamReader reader) throws XMLStreamException {
    reader.nextTag();//from   w ww  . j a  v  a 2s .c om

    // CmdID
    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 continueDelete = true;
    do {
        switch (reader.getEventType()) {
        case XMLEvent.START_ELEMENT:
            final DMItem item = readItem(reader, new DMMeta());
            reader.nextTag();
            final Status status = this.commandHandler.delete(item.getTargetURI());
            this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Delete", item.getTargetURI(), null, //$NON-NLS-1$
                    String.valueOf(status.getCode()));

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

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();/*from  ww w  .  j  a v  a 2  s.  c  o m*/

    // CmdID
    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();//from  w  ww  .  jav  a2s.  c o  m

    // CmdID
    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();/*from w  w  w  . j  a  v a  2s  . c o  m*/

    // CmdID
    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();//from  w w  w  . j av a  2s.  c o  m

    // CmdID
    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 DMMeta readMeta(final XMLStreamReader reader) throws XMLStreamException {
    final DMMeta meta = new DMMeta();
    boolean continueMeta = true;
    do {//from   ww w  .ja  v  a 2 s . c om
        switch (reader.next()) {
        case XMLEvent.START_ELEMENT:
            switch (DMMeta.getKey(reader.getLocalName())) {
            case DMMeta.FORMAT:
                meta.put(DMMeta.FORMAT, reader.getElementText());
                break;
            case DMMeta.TYPE:
                meta.put(DMMeta.TYPE, reader.getElementText());
                break;
            default:
                break;
            }
            break;
        case XMLEvent.END_ELEMENT:
            continueMeta = false;
            break;
        default:
            break;
        }
    } while (continueMeta);

    return meta;
}

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();// www  .j a v  a 2  s  .c o  m

    // Target?
    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 static void jumpToStartTag(final XMLStreamReader reader, final String tag) throws XMLStreamException {
    while (reader.next() != XMLStreamReader.START_ELEMENT || !reader.getLocalName().equals(tag)) {
        continue;
    }/*from   w  ww  .  j ava 2  s.c o  m*/
}

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

private static void jumpToEndTag(final XMLStreamReader reader, final String tag) throws XMLStreamException {
    while (reader.next() != XMLStreamReader.END_ELEMENT || !reader.getLocalName().equals(tag)) {
        continue;
    }//from www.j  a va  2s  . co  m
}