Example usage for com.google.gwt.user.client.rpc SerializationStreamWriter writeInt

List of usage examples for com.google.gwt.user.client.rpc SerializationStreamWriter writeInt

Introduction

In this page you can find the example usage for com.google.gwt.user.client.rpc SerializationStreamWriter writeInt.

Prototype

void writeInt(int value) throws SerializationException;

Source Link

Usage

From source file:cc.alcina.framework.common.client.util.MultikeyMapBase_CustomFieldSerializer.java

License:Apache License

public static void serialize(SerializationStreamWriter streamWriter, MultikeyMap instance)
        throws SerializationException {
    streamWriter.writeInt(instance.getDepth());
    List<List> tuples = instance.asTuples(instance.getDepth());
    streamWriter.writeInt(tuples.size());
    for (List tuple : tuples) {
        streamWriter.writeInt(tuple.size());
        for (Object object : tuple) {
            streamWriter.writeObject(object);
        }//from   ww  w .j av a2s. c  o m
    }
}

From source file:com.cimpoint.mes.common.entities.EFormField_CustomFieldSerializer.java

License:Open Source License

public static void serialize(SerializationStreamWriter streamWriter, EFormField instance) {
    try {//ww w  . java2 s.c  o m
        Long id = instance.getId();
        if (id == null)
            id = 0L;
        streamWriter.writeLong(id);
        streamWriter.writeString(instance.getName());
        streamWriter.writeString(instance.getLabel());
        streamWriter.writeObject(instance.getForm());
        streamWriter.writeInt(instance.getColumnSpan());
        streamWriter.writeBoolean(instance.getStartNewRow());
        streamWriter.writeBoolean(instance.getEndCurrentRow());
        streamWriter.writeString(instance.getFieldType().toString());

        Set<EFormFieldProperty> formFieldProps = instance.getFormFieldProperties();
        if (formFieldProps == null)
            streamWriter.writeObject(null);
        else
            streamWriter.writeObject(new HashSet<EFormFieldProperty>(formFieldProps));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.colinalworth.gwt.websockets.shared.impl.ClientInvocation_CustomFieldSerializer.java

License:Apache License

public static void serialize(SerializationStreamWriter streamWriter, ClientInvocation instance)
        throws SerializationException {
    streamWriter.writeString(instance.getMethod());
    streamWriter.writeInt(instance.getCallbackId());

    if (instance.getParameters() == null) {
        streamWriter.writeInt(0);/*from ww w  .j a v  a  2 s. c om*/
    } else {
        streamWriter.writeInt(instance.getParameters().length);
        for (Object param : instance.getParameters()) {
            streamWriter.writeObject(param);
        }
    }
}

From source file:com.colinalworth.gwt.websockets.shared.impl.ServerInvocation_CustomFieldSerializer.java

License:Apache License

public static void serialize(SerializationStreamWriter streamWriter, ServerInvocation instance)
        throws SerializationException {
    streamWriter.writeString(instance.getMethod());
    streamWriter.writeInt(instance.getCallbackId());

    streamWriter.writeInt(instance.getParameters().length);
    for (Object param : instance.getParameters()) {
        streamWriter.writeObject(param);
    }/*from  w  w w  .  j av a  2 s.  c om*/
}

From source file:com.extjs.gxt.ui.client.data.RpcMap_CustomFieldSerializer.java

License:sencha.com license

public static void serialize(SerializationStreamWriter streamWriter, RpcMap instance)
        throws SerializationException {
    int size = instance.size();
    streamWriter.writeInt(size);

    for (Entry<String, Object> entry : instance.entrySet()) {
        streamWriter.writeString(entry.getKey());
        streamWriter.writeObject(entry.getValue());
    }//from w  w  w .  j  ava  2s.c om
}

From source file:com.gdevelop.gwt.syncrpc.RemoteServiceInvocationHandler.java

License:Apache License

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    RemoteServiceSyncProxy syncProxy = createSyncProxy();
    Class remoteServiceInft = method.getDeclaringClass();
    for (Class intf : proxy.getClass().getInterfaces()) {
        if (RemoteService.class.isAssignableFrom(intf)) {
            remoteServiceInft = intf;//ww w . j a  v a  2s  .  c  o  m
        }
    }
    SerializationStreamWriter streamWriter = syncProxy.createStreamWriter();
    AsyncCallback callback = null;
    Class[] paramTypes = method.getParameterTypes();
    try {
        // Determine whether sync or async
        boolean isAsync = false;
        // String serviceIntfName =
        // method.getDeclaringClass().getCanonicalName();
        String serviceIntfName = remoteServiceInft.getCanonicalName();
        int paramCount = paramTypes.length;
        Class returnType = method.getReturnType();
        if (method.getDeclaringClass().getCanonicalName().endsWith("Async")) {
            isAsync = true;
            serviceIntfName = serviceIntfName.substring(0, serviceIntfName.length() - 5);
            paramCount--;
            callback = (AsyncCallback) args[paramCount];
            if (asyncCallbackWrapperSupplier != null) {
                callback = asyncCallbackWrapperSupplier.get().wrap(callback);
            }
            // Determine the return type
            Class[] syncParamTypes = new Class[paramCount];
            System.arraycopy(paramTypes, 0, syncParamTypes, 0, paramCount);
            Class clazz;
            try {
                clazz = Class.forName(serviceIntfName);
            } catch (ClassNotFoundException e) {
                throw new InvocationException("There are not sync version of " + serviceIntfName + "Async");
            }
            Method syncMethod = clazz.getMethod(method.getName(), syncParamTypes);
            if (syncMethod != null) {
                returnType = syncMethod.getReturnType();
            } else {
                throw new InvocationException("Sync & Async method does not match.");
            }
        }
        // Interface name
        streamWriter.writeString(serviceIntfName);
        // Method name
        streamWriter.writeString(method.getName());
        // Params count
        streamWriter.writeInt(paramCount);
        // Params type
        for (int i = 0; i < paramCount; i++) {
            streamWriter.writeString(computeBinaryClassName(paramTypes[i]));
        }
        // Params
        for (int i = 0; i < paramCount; i++) {
            writeParam(streamWriter, paramTypes[i], args[i]);
        }
        String payload = streamWriter.toString();
        if (isAsync) {
            final RemoteServiceSyncProxy syncProxy_2 = syncProxy;
            final Class returnType_2 = returnType;
            final String payload_2 = payload;
            final AsyncCallback callback_2 = callback;
            new Thread() {
                public void run() {
                    Object result;
                    try {
                        result = syncProxy_2.doInvoke(getReaderFor(returnType_2), payload_2);
                        if (callback_2 != null) {
                            callback_2.onSuccess(result);
                        }
                    } catch (Throwable e) {
                        if (callback_2 != null) {
                            callback_2.onFailure(e);
                        }
                    }
                }
            }.start();
            return null;
        } else {
            return syncProxy.doInvoke(getReaderFor(returnType), payload);
        }
        /*
         * Object result = syncProxy.doInvoke(getReaderFor(returnType),
         * payload); if (callback != null){ callback.onSuccess(result); }
         * return result;
         */
    } catch (Throwable ex) {
        if (callback != null) {
            callback.onFailure(ex);
            return null;
        }
        Class[] expClasses = method.getExceptionTypes();
        for (Class clazz : expClasses) {
            if (clazz.isAssignableFrom(ex.getClass())) {
                throw ex;
            }
        }
        throw new InvocationException("Exception while invoking the remote service "
                + method.getDeclaringClass().getName() + "." + method.getName(), ex);
    }
}

From source file:com.gdevelop.gwt.syncrpc.RemoteServiceInvocationHandler.java

License:Apache License

private void writeParam(SerializationStreamWriter streamWriter, Class paramType, Object paramValue)
        throws SerializationException {
    if (paramType == boolean.class) {
        streamWriter.writeBoolean((Boolean) paramValue);
        // } else if (paramType == Boolean.class){
        // streamWriter.writeBoolean((Boolean)paramValue);
    } else if (paramType == byte.class) {
        streamWriter.writeByte((Byte) paramValue);
        // } else if (paramType == Byte.class){
        // streamWriter.writeByte((Byte)paramValue);
    } else if (paramType == char.class) {
        streamWriter.writeChar((Character) paramValue);
        // } else if (paramType == Character.class){
        // streamWriter.writeChar((Character)paramValue);
    } else if (paramType == double.class) {
        streamWriter.writeDouble((Double) paramValue);
        // } else if (paramType == Double.class){
        // streamWriter.writeDouble((Double)paramValue);
    } else if (paramType == float.class) {
        streamWriter.writeFloat((Float) paramValue);
        // } else if (paramType == Float.class){
        // streamWriter.writeFloat((Float)paramValue);
    } else if (paramType == int.class) {
        streamWriter.writeInt((Integer) paramValue);
        // }else if (paramType == Integer.class){
        // streamWriter.writeInt((Integer)paramValue);
    } else if (paramType == long.class) {
        streamWriter.writeLong((Long) paramValue);
        // } else if (paramType == Long.class){
        // streamWriter.writeLong((Long)paramValue);
    } else if (paramType == short.class) {
        streamWriter.writeShort((Short) paramValue);
        // } else if (paramType == Short.class){
        // streamWriter.writeShort((Short)paramValue);
    } else if (paramType == String.class) {
        streamWriter.writeString((String) paramValue);
    } else {/*w  ww. ja  v a2s  . c  om*/
        streamWriter.writeObject(paramValue);
    }
}

From source file:com.google.appengine.api.datastore.Entity_CustomFieldSerializer.java

License:Apache License

/**
 * @param streamWriter/*  w w  w.ja  v  a 2s . c  o  m*/
 * @param instance
 * @throws SerializationException
 */
public static void serialize(SerializationStreamWriter streamWriter, Entity instance)
        throws SerializationException {

    // Key
    streamWriter.writeObject(instance.getKey());
    Map<String, Object> properties = instance.getProperties();

    // Number of properties
    streamWriter.writeInt(properties.size());

    for (Entry<String, Object> property : properties.entrySet()) {
        String propertyName = property.getKey();

        // Property name
        streamWriter.writeString(propertyName);

        Object value = property.getValue();
        TYPES type = TYPES.OBJECT;
        if (value instanceof Boolean) {
            type = TYPES.BOOLEAN;
        } else if (value instanceof Byte) {
            type = TYPES.BYTE;
        } else if (value instanceof Character) {
            type = TYPES.CHAR;
        } else if (value instanceof Double) {
            type = TYPES.DOUBLE;
        } else if (value instanceof Float) {
            type = TYPES.FLOAT;
        } else if (value instanceof Integer) {
            type = TYPES.INT;
        } else if (value instanceof Long) {
            type = TYPES.LONG;
        } else if (value instanceof Short) {
            type = TYPES.SHORT;
        } else if (value instanceof String) {
            type = TYPES.STRING;
        } else if (value instanceof Date) {
            type = TYPES.DATE;
        } else if (value instanceof Blob) {
            type = TYPES.BLOB;
        } else if (value instanceof ShortBlob) {
            type = TYPES.SHORTBLOB;
        } else if (value instanceof User) {
            type = TYPES.USER;
        } else if (value instanceof Category) {
            type = TYPES.CATEGORY;
        } else if (value instanceof Email) {
            type = TYPES.EMAIL;
        } else if (value instanceof GeoPt) {
            type = TYPES.GEOPT;
        } else if (value instanceof Link) {
            type = TYPES.LINK;
        } else if (value instanceof PhoneNumber) {
            type = TYPES.PHONENUMBER;
        } else if (value instanceof PostalAddress) {
            type = TYPES.POSTALADDRESS;
        } else if (value instanceof Rating) {
            type = TYPES.RATING;
        }

        // Property kind
        streamWriter.writeInt(type.ordinal());

        // Value
        switch (type) {
        case BOOLEAN:
            streamWriter.writeBoolean((Boolean) value);
            break;
        case BYTE:
            streamWriter.writeByte((Byte) value);
            break;
        case CHAR:
            streamWriter.writeChar((Character) value);
            break;
        case DOUBLE:
            streamWriter.writeDouble((Double) value);
            break;
        case FLOAT:
            streamWriter.writeFloat((Float) value);
            break;
        case INT:
            streamWriter.writeInt((Integer) value);
            break;
        case LONG:
            streamWriter.writeLong((Long) value);
            break;
        case OBJECT:
            streamWriter.writeObject(value);
            break;
        case SHORT:
            streamWriter.writeShort((Short) value);
            break;
        case STRING:
            streamWriter.writeString((String) value);
            break;
        case DATE:
            streamWriter.writeLong(((Date) value).getTime());
            break;
        case BLOB:
            Blob_CustomFieldSerializer.serialize(streamWriter, (Blob) value);
            break;
        case SHORTBLOB:
            ShortBlob_CustomFieldSerializer.serialize(streamWriter, (ShortBlob) value);
            break;
        case USER:
            User_CustomFieldSerializer.serialize(streamWriter, (User) value);
            break;
        case CATEGORY:
            Category_CustomFieldSerializer.serialize(streamWriter, (Category) value);
            break;
        case EMAIL:
            Email_CustomFieldSerializer.serialize(streamWriter, (Email) value);
            break;
        case GEOPT:
            GeoPt_CustomFieldSerializer.serialize(streamWriter, (GeoPt) value);
            break;
        case LINK:
            Link_CustomFieldSerializer.serialize(streamWriter, (Link) value);
            break;
        case PHONENUMBER:
            PhoneNumber_CustomFieldSerializer.serialize(streamWriter, (PhoneNumber) value);
            break;
        case POSTALADDRESS:
            PostalAddress_CustomFieldSerializer.serialize(streamWriter, (PostalAddress) value);
            break;
        case RATING:
            Rating_CustomFieldSerializer.serialize(streamWriter, (Rating) value);
            break;
        }

        // Unindexed
        streamWriter.writeBoolean(instance.isUnindexedProperty(propertyName));
    }
}

From source file:com.google.common.collect.ImmutableTable_CustomFieldSerializerBase.java

License:Apache License

public static void serialize(SerializationStreamWriter writer, ImmutableTable<Object, Object, Object> table)
        throws SerializationException {
    writer.writeInt(table.rowKeySet().size());
    for (Object rowKey : table.rowKeySet()) {
        writer.writeObject(rowKey);/*w w  w . jav  a2s .c o m*/
        Map_CustomFieldSerializerBase.serialize(writer, table.row(rowKey));
    }
}

From source file:com.google.common.collect.LinkedHashMultimap_CustomFieldSerializer.java

License:Apache License

public static void serialize(SerializationStreamWriter stream, LinkedHashMultimap<?, ?> multimap)
        throws SerializationException {
    stream.writeInt(multimap.keySet().size());
    for (Object key : multimap.keySet()) {
        stream.writeObject(key);/*  w  w  w .j a  v a 2s.  co m*/
    }
    stream.writeInt(multimap.size());
    for (Map.Entry<?, ?> entry : multimap.entries()) {
        stream.writeObject(entry.getKey());
        stream.writeObject(entry.getValue());
    }
}