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

VerbUtils

public class VerbUtils extends Object
This class unmarshal a JSON message into a Java Object.
author
Jeanfrancois Arcand

Fields Summary
private static final String
META
private static final String
HANDSHAKE
private static final String
CONNECT
private static final String
DISCONNECT
private static final String
RECONNECT
private static final String
SUBSCRIBE
private static final String
UNSUBSCRIBE
private static final String
STATUS
private static final String
PING
private static final String
DATA
Constructors Summary
public VerbUtils()

    
    
    
      
    
Methods Summary
private static voidconfigureExt(VerbBase vb, java.util.Map map)

        Map extMap = (Map)map.get("ext");
        if (extMap == null) return;
        
        Ext ext = new Ext();
        ext.setExtensionMap(extMap);
        vb.setExt(ext);
    
private static final ConnectnewConnect(java.util.Map map)

        Connect connect = new Connect();
        
        connect.setAuthToken((String)map.get("authToken"));
        connect.setChannel((String)map.get("channel"));
        connect.setClientId((String)map.get("clientId"));
        connect.setConnectionType((String)map.get("connectionType"));
        
        return connect;
    
private static final DatanewData(java.util.Map map)

        Data data = new Data();
        
        data.setChannel((String)map.get("channel"));
        data.setClientId((String)map.get("clientId"));
        data.setData((HashMap)map.get("data"));
        
        return data;
    
private static final DisconnectnewDisconnect(java.util.Map map)

        Disconnect disconnect = new Disconnect();
        
        disconnect.setAuthToken((String)map.get("authToken"));
        disconnect.setChannel((String)map.get("channel"));
        disconnect.setClientId((String)map.get("clientId"));
        disconnect.setConnectionType((String)map.get("connectionType"));
        
        return disconnect;
    
private static final HandshakenewHandshake(java.util.Map map)

        Handshake handshake = new Handshake();
        
        handshake.setAuthScheme((String)map.get("authScheme"));
        handshake.setAuthUser((String)map.get("authUser"));
        handshake.setAuthToken((String)map.get("authToken"));
        handshake.setChannel((String)map.get("channel"));
        handshake.setVersion(String.valueOf((Double)map.get("version")));
        handshake.setMinimumVersion(String.valueOf((Double)map.get("minimumVersion")));
        handshake.setAdvice(new Advice());

        return handshake; 
    
private static final PingnewPing(java.util.Map map)

        Ping ping = new Ping();
        
        ping.setChannel((String)map.get("channel"));
        return ping;
    
private static final ReconnectnewReconnect(java.util.Map map)

        Reconnect reconnect = new Reconnect();
        
        reconnect.setAuthToken((String)map.get("authToken"));
        reconnect.setChannel((String)map.get("channel"));
        reconnect.setClientId((String)map.get("clientId"));
        reconnect.setConnectionType((String)map.get("connectionType"));
        
        return reconnect;
    
private static final StatusnewStatus(java.util.Map map)

        Status status = new Status();
        
        status.setChannel((String)map.get("channel"));
        return status;        
    
private static final SubscribenewSubscribe(java.util.Map map)

        Subscribe subscribe = new Subscribe();
        
        subscribe.setChannel((String)map.get("channel"));
        subscribe.setAuthToken((String)map.get("authToken"));
        subscribe.setSubscription((String)map.get("subscription"));
        subscribe.setClientId((String)map.get("clientId"));
        return subscribe;
    
private static final UnsubscribenewUnsubscribe(java.util.Map map)

        Unsubscribe unsubscribe = new Unsubscribe();
        
        unsubscribe.setChannel((String)map.get("channel"));
        unsubscribe.setAuthToken((String)map.get("authToken"));
        unsubscribe.setSubscription((String)map.get("subscription"));
        unsubscribe.setClientId((String)map.get("clientId"));
        return unsubscribe;
    
public static Verbparse(java.lang.Object verb)

   
        
        if (verb.getClass().isArray()){
            int length = Array.getLength(verb);
            for (int i=0; i < length; i++){
                return parseMap((Map)Array.get(verb,i));
            }
        }
        throw new RuntimeException("Wrong type");  
    
protected static VerbparseMap(java.util.Map map)

        
        String channel = (String)map.get("channel");
        
        if (!channel.startsWith(META)){
            return newData(map);
        }
        
        VerbBase vb = null;
        if (channel.indexOf(HANDSHAKE) != -1){
            vb = newHandshake(map);
        } else if (channel.indexOf(CONNECT) != -1){
            vb = newConnect(map);
        } else if (channel.indexOf(DISCONNECT) != -1){
            vb = newDisconnect(map);            
        } else if (channel.indexOf(RECONNECT) != -1){
            vb = newReconnect(map);
        } else if (channel.indexOf(SUBSCRIBE) != -1){
            vb = newSubscribe(map);
        } else if (channel.indexOf(UNSUBSCRIBE) != -1){
            vb = newUnsubscribe(map);
        } else if (channel.indexOf(PING) != -1){
            vb = newPing(map);
        } else if (channel.indexOf(STATUS) != -1){
            vb = newStatus(map);
        }
        configureExt(vb,map);        
        return vb;