Package it.freedomotic.gwtclient.client.api

Source Code of it.freedomotic.gwtclient.client.api.FreedomoticStompHelper

package it.freedomotic.gwtclient.client.api;



import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;


//helper class with methods to parse messages from the stomp queue
public class FreedomoticStompHelper {


  public static Payload parseMessage(String message)
  {
    final Payload payload = new Payload();
   
    Document messageDom = XMLParser.parse(message);   
    NodeList statements = messageDom.getElementsByTagName("it.freedomotic.reactions.Statement");           
    for (int i = 0; i < statements.getLength(); i++) {
      Element statement = (Element)statements.item(i);
       payload.enqueueStatement(parseStatement(statement));    
     }       
        return payload;                          
  }
  private static Statement parseStatement(Element statementNode)
  {
    Statement statement = new Statement();   
    statement.setLogical(getElementTextValue(statementNode,"logical"));
    statement.setAttribute(getElementTextValue(statementNode,"attribute"));
    statement.setOperand(getElementTextValue(statementNode,"operand"));
    statement.setValue(getElementTextValue(statementNode,"value"));
    return statement;
   
  }
  /**
     * Utility method to return the values of elements of the form <myTag>tag
     * value</myTag>
     */
    private static String getElementTextValue(Element parent, String elementTag) {
      // If the xml is not coming from a known good source, this method would
      // have to include safety checks.
      return parent.getElementsByTagName(elementTag).item(0).getFirstChild()
        .getNodeValue();
    }
 
}
TOP

Related Classes of it.freedomotic.gwtclient.client.api.FreedomoticStompHelper

TOP
Copyright © 2018 www.massapi.com. 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.