/**
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.waveprotocol.box.common.comms.proto;
import org.waveprotocol.wave.federation.ProtocolWaveletDelta;
import org.waveprotocol.wave.federation.ProtocolHashedVersion;
import org.waveprotocol.box.common.comms.WaveletSnapshot;
import org.waveprotocol.wave.federation.proto.ProtocolWaveletDeltaProtoImpl;
import org.waveprotocol.wave.federation.proto.ProtocolHashedVersionProtoImpl;
import org.waveprotocol.box.common.comms.proto.WaveletSnapshotProtoImpl;
import org.waveprotocol.box.common.comms.ProtocolWaveletUpdate;
import org.waveprotocol.box.common.comms.ProtocolWaveletUpdateUtil;
import org.waveprotocol.wave.communication.Blob;
import org.waveprotocol.wave.communication.Codec;
import org.waveprotocol.wave.communication.ProtoEnums;
import org.waveprotocol.wave.communication.proto.Int52;
import org.waveprotocol.wave.communication.proto.ProtoWrapper;
import org.waveprotocol.wave.communication.gson.GsonException;
import org.waveprotocol.wave.communication.gson.GsonSerializable;
import org.waveprotocol.wave.communication.gson.GsonUtil;
import org.waveprotocol.wave.communication.json.RawStringData;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.protobuf.ByteString;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Server implementation of ProtocolWaveletUpdate.
*
* Generated from org/waveprotocol/box/common/comms/waveclient-rpc.proto. Do not edit.
*/
// NOTE(kalman): It would be nicer to add a proto serialisation
// utility rather than having this class at all.
public final class ProtocolWaveletUpdateProtoImpl
implements ProtocolWaveletUpdate,
// Note: fully-qualified path is required for GsonSerializable and ProtoWrapper.
// An import of it is not resolved correctly from inner classes.
// This appears to be a javac bug. The Eclipse compiler handles it fine.
org.waveprotocol.wave.communication.gson.GsonSerializable,
org.waveprotocol.wave.communication.proto.ProtoWrapper<org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate> {
private org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate proto = null;
private org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate.Builder protoBuilder = org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate.newBuilder();
public ProtocolWaveletUpdateProtoImpl() {
}
public ProtocolWaveletUpdateProtoImpl(org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate proto) {
this.proto = proto;
}
public ProtocolWaveletUpdateProtoImpl(ProtocolWaveletUpdate message) {
copyFrom(message);
}
@Override
public org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate getPB() {
switchToProto();
return proto;
}
@Override
public void setPB(org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate proto) {
this.proto = proto;
this.protoBuilder = null;
}
@Override
public void copyFrom(ProtocolWaveletUpdate message) {
setWaveletName(message.getWaveletName());
clearAppliedDelta();
for (ProtocolWaveletDelta field : message.getAppliedDelta()) {
addAppliedDelta(new ProtocolWaveletDeltaProtoImpl(field));
}
if (message.hasCommitNotice()) {
setCommitNotice(new ProtocolHashedVersionProtoImpl(message.getCommitNotice()));
} else {
clearCommitNotice();
}
if (message.hasResultingVersion()) {
setResultingVersion(new ProtocolHashedVersionProtoImpl(message.getResultingVersion()));
} else {
clearResultingVersion();
}
if (message.hasSnapshot()) {
setSnapshot(new WaveletSnapshotProtoImpl(message.getSnapshot()));
} else {
clearSnapshot();
}
if (message.hasMarker()) {
setMarker(message.getMarker());
} else {
clearMarker();
}
if (message.hasChannelId()) {
setChannelId(message.getChannelId());
} else {
clearChannelId();
}
}
@Override
public String getWaveletName() {
switchToProto();
return proto.getWaveletName();
}
@Override
public void setWaveletName(String value) {
switchToProtoBuilder();
protoBuilder.setWaveletName(value);
}
@Override
public List<ProtocolWaveletDeltaProtoImpl> getAppliedDelta() {
switchToProto();
List<ProtocolWaveletDeltaProtoImpl> list = new ArrayList<ProtocolWaveletDeltaProtoImpl>();
for (int i = 0; i < getAppliedDeltaSize(); i++) {
ProtocolWaveletDeltaProtoImpl message = new ProtocolWaveletDeltaProtoImpl(proto.getAppliedDelta(i));
list.add(message);
}
return list;
}
@Override
public void addAllAppliedDelta(List<? extends ProtocolWaveletDelta> values) {
for (ProtocolWaveletDelta message : values) {
addAppliedDelta(message);
}
}
@Override
public ProtocolWaveletDeltaProtoImpl getAppliedDelta(int n) {
switchToProto();
return new ProtocolWaveletDeltaProtoImpl(proto.getAppliedDelta(n));
}
@Override
public void setAppliedDelta(int n, ProtocolWaveletDelta value) {
switchToProtoBuilder();
protoBuilder.setAppliedDelta(n, getOrCreateProtocolWaveletDeltaProtoImpl(value).getPB());
}
@Override
public int getAppliedDeltaSize() {
switchToProto();
return proto.getAppliedDeltaCount();
}
@Override
public void addAppliedDelta(ProtocolWaveletDelta value) {
switchToProtoBuilder();
protoBuilder.addAppliedDelta(getOrCreateProtocolWaveletDeltaProtoImpl(value).getPB());
}
@Override
public void clearAppliedDelta() {
switchToProtoBuilder();
protoBuilder.clearAppliedDelta();
}
@Override
public boolean hasCommitNotice() {
switchToProto();
return proto.hasCommitNotice();
}
@Override
public void clearCommitNotice() {
switchToProtoBuilder();
protoBuilder.clearCommitNotice();
}
@Override
public ProtocolHashedVersionProtoImpl getCommitNotice() {
switchToProto();
return new ProtocolHashedVersionProtoImpl(proto.getCommitNotice());
}
@Override
public void setCommitNotice(ProtocolHashedVersion value) {
switchToProtoBuilder();
protoBuilder.clearCommitNotice();
protoBuilder.setCommitNotice(getOrCreateProtocolHashedVersionProtoImpl(value).getPB());
}
@Override
public boolean hasResultingVersion() {
switchToProto();
return proto.hasResultingVersion();
}
@Override
public void clearResultingVersion() {
switchToProtoBuilder();
protoBuilder.clearResultingVersion();
}
@Override
public ProtocolHashedVersionProtoImpl getResultingVersion() {
switchToProto();
return new ProtocolHashedVersionProtoImpl(proto.getResultingVersion());
}
@Override
public void setResultingVersion(ProtocolHashedVersion value) {
switchToProtoBuilder();
protoBuilder.clearResultingVersion();
protoBuilder.setResultingVersion(getOrCreateProtocolHashedVersionProtoImpl(value).getPB());
}
@Override
public boolean hasSnapshot() {
switchToProto();
return proto.hasSnapshot();
}
@Override
public void clearSnapshot() {
switchToProtoBuilder();
protoBuilder.clearSnapshot();
}
@Override
public WaveletSnapshotProtoImpl getSnapshot() {
switchToProto();
return new WaveletSnapshotProtoImpl(proto.getSnapshot());
}
@Override
public void setSnapshot(WaveletSnapshot value) {
switchToProtoBuilder();
protoBuilder.clearSnapshot();
protoBuilder.setSnapshot(getOrCreateWaveletSnapshotProtoImpl(value).getPB());
}
@Override
public boolean hasMarker() {
switchToProto();
return proto.hasMarker();
}
@Override
public void clearMarker() {
switchToProtoBuilder();
protoBuilder.clearMarker();
}
@Override
public boolean getMarker() {
switchToProto();
return proto.getMarker();
}
@Override
public void setMarker(boolean value) {
switchToProtoBuilder();
protoBuilder.setMarker(value);
}
@Override
public boolean hasChannelId() {
switchToProto();
return proto.hasChannelId();
}
@Override
public void clearChannelId() {
switchToProtoBuilder();
protoBuilder.clearChannelId();
}
@Override
public String getChannelId() {
switchToProto();
return proto.getChannelId();
}
@Override
public void setChannelId(String value) {
switchToProtoBuilder();
protoBuilder.setChannelId(value);
}
/** Get or create a ProtocolWaveletDeltaProtoImpl from a ProtocolWaveletDelta. */
private ProtocolWaveletDeltaProtoImpl getOrCreateProtocolWaveletDeltaProtoImpl(ProtocolWaveletDelta message) {
if (message instanceof ProtocolWaveletDeltaProtoImpl) {
return (ProtocolWaveletDeltaProtoImpl) message;
} else {
ProtocolWaveletDeltaProtoImpl messageImpl = new ProtocolWaveletDeltaProtoImpl();
messageImpl.copyFrom(message);
return messageImpl;
}
}
/** Get or create a ProtocolHashedVersionProtoImpl from a ProtocolHashedVersion. */
private ProtocolHashedVersionProtoImpl getOrCreateProtocolHashedVersionProtoImpl(ProtocolHashedVersion message) {
if (message instanceof ProtocolHashedVersionProtoImpl) {
return (ProtocolHashedVersionProtoImpl) message;
} else {
ProtocolHashedVersionProtoImpl messageImpl = new ProtocolHashedVersionProtoImpl();
messageImpl.copyFrom(message);
return messageImpl;
}
}
/** Get or create a WaveletSnapshotProtoImpl from a WaveletSnapshot. */
private WaveletSnapshotProtoImpl getOrCreateWaveletSnapshotProtoImpl(WaveletSnapshot message) {
if (message instanceof WaveletSnapshotProtoImpl) {
return (WaveletSnapshotProtoImpl) message;
} else {
WaveletSnapshotProtoImpl messageImpl = new WaveletSnapshotProtoImpl();
messageImpl.copyFrom(message);
return messageImpl;
}
}
private void switchToProto() {
if (proto == null) {
proto = protoBuilder.build();
protoBuilder = null;
}
}
private void switchToProtoBuilder() {
if (protoBuilder == null) {
protoBuilder = (proto == null)
? org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate.newBuilder()
: org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate.newBuilder(proto);
proto = null;
}
}
private void invalidateAll() {
proto = null;
protoBuilder = org.waveprotocol.box.common.comms.WaveClientRpc.ProtocolWaveletUpdate.newBuilder();
}
@Override
public JsonElement toGson(RawStringData raw, Gson gson) {
JsonObject json = new JsonObject();
json.add("1", new JsonPrimitive(getWaveletName()));
{
JsonArray array = new JsonArray();
for (int i = 0; i < getAppliedDeltaSize(); i++) {
JsonElement elem = ((GsonSerializable) getAppliedDelta(i)).toGson(raw, gson);
// NOTE(kalman): if multistage parsing worked, split point would go here.
array.add(elem);
}
json.add("2", array);
}
if (hasCommitNotice()) {
{
JsonElement elem = ((GsonSerializable) getCommitNotice()).toGson(raw, gson);
json.add("3", elem);
}
}
if (hasResultingVersion()) {
{
JsonElement elem = ((GsonSerializable) getResultingVersion()).toGson(raw, gson);
json.add("4", elem);
}
}
if (hasSnapshot()) {
{
JsonElement elem = ((GsonSerializable) getSnapshot()).toGson(raw, gson);
json.add("5", elem);
}
}
if (hasMarker()) {
json.add("6", new JsonPrimitive(getMarker()));
}
if (hasChannelId()) {
json.add("7", new JsonPrimitive(getChannelId()));
}
return json;
}
@Override
public void fromGson(JsonElement json, Gson gson, RawStringData raw) throws GsonException {
JsonObject jsonObject = json.getAsJsonObject();
// NOTE: always check with has(...) as the json might not have all required
// fields set; however these (obviously) will need to be set by other means
// before accessing this object.
invalidateAll();
if (jsonObject.has("1")) {
JsonElement elem = jsonObject.get("1");
setWaveletName(elem.getAsString());
}
if (jsonObject.has("2")) {
JsonElement elem = jsonObject.get("2");
{
JsonArray array = elem.getAsJsonArray();
for (int i = 0; i < array.size(); i++) {
ProtocolWaveletDeltaProtoImpl payload = new ProtocolWaveletDeltaProtoImpl();
GsonUtil.extractJsonObject(payload, array.get(i), gson, raw);
addAppliedDelta(payload);
}
}
}
if (jsonObject.has("3")) {
JsonElement elem = jsonObject.get("3");
if (!elem.isJsonNull()) {
{
ProtocolHashedVersionProtoImpl payload = new ProtocolHashedVersionProtoImpl();
GsonUtil.extractJsonObject(payload, elem, gson, raw);
setCommitNotice(payload);
}
}
}
if (jsonObject.has("4")) {
JsonElement elem = jsonObject.get("4");
if (!elem.isJsonNull()) {
{
ProtocolHashedVersionProtoImpl payload = new ProtocolHashedVersionProtoImpl();
GsonUtil.extractJsonObject(payload, elem, gson, raw);
setResultingVersion(payload);
}
}
}
if (jsonObject.has("5")) {
JsonElement elem = jsonObject.get("5");
if (!elem.isJsonNull()) {
{
WaveletSnapshotProtoImpl payload = new WaveletSnapshotProtoImpl();
GsonUtil.extractJsonObject(payload, elem, gson, raw);
setSnapshot(payload);
}
}
}
if (jsonObject.has("6")) {
JsonElement elem = jsonObject.get("6");
if (!elem.isJsonNull()) {
setMarker(elem.getAsBoolean());
}
}
if (jsonObject.has("7")) {
JsonElement elem = jsonObject.get("7");
if (!elem.isJsonNull()) {
setChannelId(elem.getAsString());
}
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o instanceof ProtocolWaveletUpdateProtoImpl) {
return getPB().equals(((ProtocolWaveletUpdateProtoImpl) o).getPB());
} else {
return false;
}
}
@Override
public boolean isEqualTo(Object o) {
if (equals(o)) {
return true;
} else if (o instanceof ProtocolWaveletUpdate) {
return ProtocolWaveletUpdateUtil.isEqual(this, (ProtocolWaveletUpdate) o);
} else {
return false;
}
}
@Override
public int hashCode() {
return getPB().hashCode();
}
@Override
public String toString() {
return getPB().toString();
}
}