Example usage for com.vaadin.server JsonCodec decodeInternalOrCustomType

List of usage examples for com.vaadin.server JsonCodec decodeInternalOrCustomType

Introduction

In this page you can find the example usage for com.vaadin.server JsonCodec decodeInternalOrCustomType.

Prototype

public static Object decodeInternalOrCustomType(Type targetType, JsonValue value,
            ConnectorTracker connectorTracker) 

Source Link

Usage

From source file:org.semanticsoft.vaaclipse.app.servlet.VaaclipseServerRpcHandler.java

License:Open Source License

private ServerRpcMethodInvocation parseServerRpcInvocation(String connectorId, String interfaceName,
        String methodName, JSONArray parametersJson, ConnectorTracker connectorTracker) throws JSONException {
    ClientConnector connector = connectorTracker.getConnector(connectorId);

    ServerRpcManager<?> rpcManager = connector.getRpcManager(interfaceName);
    if (rpcManager == null) {
        /*/*from w  ww  .j av  a  2  s  .  c  o  m*/
         * Security: Don't even decode the json parameters if no RpcManager
         * corresponding to the received method invocation has been
         * registered.
         */
        getLogger().warning("Ignoring RPC call to " + interfaceName + "." + methodName + " in connector "
                + connector.getClass().getName() + "(" + connectorId
                + ") as no RPC implementation is registered");
        return null;
    }

    // Use interface from RpcManager instead of loading the class based on
    // the string name to avoid problems with OSGi
    Class<? extends ServerRpc> rpcInterface = rpcManager.getRpcInterface();

    ServerRpcMethodInvocation invocation = new ServerRpcMethodInvocation(connectorId, rpcInterface, methodName,
            parametersJson.length());

    Object[] parameters = new Object[parametersJson.length()];
    Type[] declaredRpcMethodParameterTypes = invocation.getMethod().getGenericParameterTypes();

    for (int j = 0; j < parametersJson.length(); ++j) {
        Object parameterValue = parametersJson.get(j);
        Type parameterType = declaredRpcMethodParameterTypes[j];
        parameters[j] = JsonCodec.decodeInternalOrCustomType(parameterType, parameterValue, connectorTracker);
    }
    invocation.setParameters(parameters);
    return invocation;
}