FileDocCategorySizeDatePackage
Data.javaAPI DocGlassfish v2 API5770Tue Jun 19 17:49:08 BST 2007com.sun.grizzly.cometd.bayeux

Data

public class Data extends VerbBase
Data representation of client/server interaction. window.parent.cometd.deliver([ { // user-sent data "data": { "someField": ["some", "random", "values"], }, // the usual message meta-data "channel": "/originating/channel", // event ID "id": "slkjdlkj32", "timestamp": "TimeAtServer", // optional meta-data "authToken": "SOME_NONCE_THAT_NEEDS_TO_BE_PROVIDED_SUBSEQUENTLY" }, { "data": { "blah blah": ["more", "random", "values"], }, // the usual message meta-data "channel": "/originating/channel", // event ID "id": "slkjdlkj31", "timestamp": "TimeAtServer", "authToken": "SOME_NONCE_THAT_NEEDS_TO_BE_PROVIDED_SUBSEQUENTLY" } // , ... ]);
author
Jeanfrancois Arcand

Fields Summary
private Random
random
private HashMap
data
private String
connectionId
private String
clientId
private String
id
private String
timestamp
Constructors Summary
public Data()

    
      
        type = Verb.DATA;
    
Methods Summary
public java.lang.StringgetClientId()

        return clientId;
    
public java.lang.StringgetConnectionId()

        return connectionId;
    
public java.util.HashMapgetData()

        return data;
    
public java.lang.StringgetJSONData()

        StringBuffer response = new StringBuffer();
        
        response.append("\n{");
        response.append("\"id\":\"");
        response.append(Long.toHexString(random.nextLong()));
        response.append("\",");
        response.append("\"timestamp\":\"");
        response.append(FastHttpDateFormat.getCurrentDate());
        response.append("\",");
        response.append("\"data\":{");        
        
        Iterator<String> iterator = data.keySet().iterator();
        String key = "";
        Object value;
        int size = data.size() -1;
        int i = 0;
        while(iterator.hasNext()){
            key = iterator.next();
            value = data.get(key);
            response.append("\"");
            response.append(key);
            response.append("\":");
            if (value instanceof String){
                response.append("\"" + value + "\"");   
            } else {
                response.append(value);  
            }
            
            if (i++ < size){
                response.append(",");
            }
        }
        response.append("},");  
        response.append("\"channel\":\"");
        response.append(channel);
        response.append("\"");
        response.append("}]");
        return response.toString();
    
public voidsetClientId(java.lang.String clientId)

        this.clientId = clientId;
    
public voidsetConnectionId(java.lang.String connectionId)

        this.connectionId = connectionId;
    
public voidsetData(java.util.HashMap data)

        this.data = data;
    
public java.lang.StringtoJSON()

        
        return "[{" 
                + "\"error\":\"" + error + "\","
                + "\"successful\":" + successful + ","                
                + "\"channel\":\"" + channel + "\"},"            
                + getJSONData();