Example usage for com.google.gwt.user.server.rpc.impl TypeNameObfuscator getClassNameForTypeId

List of usage examples for com.google.gwt.user.server.rpc.impl TypeNameObfuscator getClassNameForTypeId

Introduction

In this page you can find the example usage for com.google.gwt.user.server.rpc.impl TypeNameObfuscator getClassNameForTypeId.

Prototype

String getClassNameForTypeId(String id) throws SerializationException;

Source Link

Document

Returns the name of the class that should be instantiated based on an obfuscated identifier.

Usage

From source file:org.gwtrpc4j.stream.JClientSerializationStreamReader.java

License:Apache License

@Override
protected Object deserialize(String typeSignature) throws SerializationException {
    Object instance = null;//from   ww w . ja v a 2s . c  o  m
    try {
        Class<?> instanceClass;
        if (hasFlags(FLAG_ELIDE_TYPE_NAMES)) {
            if (getSerializationPolicy() instanceof TypeNameObfuscator) {
                TypeNameObfuscator obfuscator = (TypeNameObfuscator) getSerializationPolicy();
                String instanceClassName = obfuscator.getClassNameForTypeId(typeSignature);
                instanceClass = Class.forName(instanceClassName, false, classLoader);
            } else {
                throw new SerializationException(
                        "The GWT module was compiled with RPC type name elision enabled, but "
                                + getSerializationPolicy().getClass().getName() + " does not implement "
                                + TypeNameObfuscator.class.getName());
            }
        } else {
            SerializedInstanceReference serializedInstRef = SerializabilityUtil
                    .decodeSerializedInstanceReference(typeSignature);
            instanceClass = Class.forName(serializedInstRef.getName(), false, classLoader);
            validateTypeVersions(instanceClass, serializedInstRef);
        }

        assert serializationPolicy != null;

        // TODO active the validateDeserialize Policy : read file from the
        // server
        // serializationPolicy.validateDeserialize(instanceClass);

        Class<?> customSerializer = SerializabilityUtil.hasCustomFieldSerializer(instanceClass);

        int index = reserveDecodedObjectIndex();

        instance = instantiate(customSerializer, instanceClass);

        rememberDecodedObject(index, instance);

        Object replacement = deserializeImpl(customSerializer, instanceClass, instance);

        // It's possible that deserializing an object requires the original
        // proxy
        // object to be replaced.
        if (instance != replacement) {
            rememberDecodedObject(index, replacement);
            instance = replacement;
        }

        return instance;

    } catch (ClassNotFoundException e) {
        throw new SerializationException(e);
    } catch (InstantiationException e) {
        throw new SerializationException(e);
    } catch (IllegalAccessException e) {
        throw new SerializationException(e);
    } catch (IllegalArgumentException e) {
        throw new SerializationException(e);
    } catch (InvocationTargetException e) {
        throw new SerializationException(e.getTargetException());
    } catch (NoSuchMethodException e) {
        throw new SerializationException(e);
    }
}