List of usage examples for javax.xml.stream XMLStreamReader getElementText
public String getElementText() throws XMLStreamException;
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readStatus(final XMLStreamReader reader) throws XMLStreamException { jumpToStartTag(reader, "CmdRef"); //$NON-NLS-1$ // CmdRef//from w w w . j a va 2s . c o m final String cmdRef = reader.getElementText(); reader.nextTag(); // Cmd final String cmd = reader.getElementText(); jumpToStartTag(reader, "Data"); //$NON-NLS-1$ // Data final int data = Integer.parseInt(reader.getElementText()); jumpToEndTag(reader, "Status"); //$NON-NLS-1$ // Performs the status if (cmd.equals("SyncHdr")) { //$NON-NLS-1$ switch (data) { case 212: this.isClientAuthenticated = true; break; case 407: this.isClientAuthenticated = false; break; default: break; } } if (this.commandSends.containsKey(cmdRef)) { final Object[] objects = this.commandSends.get(cmdRef); if (cmd.equals("Alert")) { //$NON-NLS-1$ for (final ProtocolListener messageListener : this.protocolLinsteners) { messageListener.clientAlert((String) objects[0], (String) objects[1], (DMItem[]) objects[2], StatusCode.fromInt(data)); } } this.commandSends.remove(cmdRef); } }
From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java
private void readGet(final XMLStreamReader reader) throws XMLStreamException { reader.nextTag();/* w w w .j av a 2s . 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 continueGet = true; do { switch (reader.getEventType()) { case XMLStreamReader.START_ELEMENT: // Performs the get command final DMItem item = readItem(reader, new DMMeta()); reader.nextTag(); final Status status = this.commandHandler.get(item.getTargetURI()); final DMNode results = status.getResult(); if (results != null) { this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Get", item.getTargetURI(), null, //$NON-NLS-1$ String.valueOf(status.getCode()), results.getFormat(), results.getType(), results.getData()); } else { this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Get", item.getTargetURI(), null, //$NON-NLS-1$ String.valueOf(status.getCode())); } // Fire get event for (final ProtocolListener messageListener : this.protocolLinsteners) { messageListener.get(item.getTargetURI(), status); } break; case XMLStreamReader.END_ELEMENT: continueGet = false; break; default: break; } } while (continueGet); }
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 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(); } // 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 ww w. j ava 2 s. com*/ // 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();/* w ww.j a va 2 s. com*/ // 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 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(); } // 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();/* w ww . j a va 2 s . 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 void readAtomic(final XMLStreamReader reader) throws XMLStreamException { reader.nextTag();//from w w w .j a va 2s. co m // CmdID 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 DMMeta readMeta(final XMLStreamReader reader) throws XMLStreamException { final DMMeta meta = new DMMeta(); boolean continueMeta = true; do {//from w w w . j a va 2 s .co m 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; }