001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt;
029
030import com.google.gwt.user.client.rpc.CustomFieldSerializer;
031import com.google.gwt.user.client.rpc.SerializationException;
032import com.google.gwt.user.client.rpc.SerializationStreamReader;
033import com.google.gwt.user.client.rpc.SerializationStreamWriter;
034
035/**
036 * GWT serializer for {@link CmsRpcException}.<p>
037 *
038 * This deliberately serializes only the exception data maintained by
039 * {@link CmsRpcException}. In particular, it prevents GWT from reflectively
040 * accessing fields declared by {@link Throwable}, which is not permitted by
041 * the Java module system.<p>
042 */
043public final class CmsRpcException_CustomFieldSerializer extends CustomFieldSerializer<CmsRpcException> {
044
045    /**
046     * Deserializes the exception data.<p>
047     *
048     * @param streamReader the reader
049     * @param instance the instance
050     *
051     * @throws SerializationException if something goes wrong
052     */
053    public static void deserialize(SerializationStreamReader streamReader, CmsRpcException instance)
054    throws SerializationException {
055
056        instance.setOriginalCauseMessage(streamReader.readString());
057        instance.setOriginalClassName(streamReader.readString());
058        instance.setOriginalMessage(streamReader.readString());
059        instance.setOriginalStackTrace((StackTraceElement[])streamReader.readObject());
060    }
061
062    /**
063     * Serializes the exception data.<p>
064     *
065     * @param streamWriter the writer
066     * @param instance the instance
067     *
068     * @throws SerializationException if something goes wrong
069     */
070    public static void serialize(SerializationStreamWriter streamWriter, CmsRpcException instance)
071    throws SerializationException {
072
073        streamWriter.writeString(instance.getOriginalCauseMessage());
074        streamWriter.writeString(instance.getOriginalClassName());
075        streamWriter.writeString(instance.getOriginalMessage());
076        streamWriter.writeObject(instance.getOriginalStackTrace());
077    }
078
079    /**
080     * @see com.google.gwt.user.client.rpc.CustomFieldSerializer#deserializeInstance(com.google.gwt.user.client.rpc.SerializationStreamReader, java.lang.Object)
081     */
082    @Override
083    public void deserializeInstance(SerializationStreamReader streamReader, CmsRpcException instance)
084    throws SerializationException {
085
086        deserialize(streamReader, instance);
087    }
088
089    /**
090     * @see com.google.gwt.user.client.rpc.CustomFieldSerializer#serializeInstance(com.google.gwt.user.client.rpc.SerializationStreamWriter, java.lang.Object)
091     */
092    @Override
093    public void serializeInstance(SerializationStreamWriter streamWriter, CmsRpcException instance)
094    throws SerializationException {
095
096        serialize(streamWriter, instance);
097    }
098}