org.waveprotocol.box.attachment.proto.AttachmentMetadataProtoImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.waveprotocol.box.attachment.proto.AttachmentMetadataProtoImpl.java

Source

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.attachment.proto;

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */
import org.waveprotocol.box.attachment.AttachmentMetadata;
import org.waveprotocol.box.attachment.AttachmentMetadataUtil;
import org.waveprotocol.box.attachment.ImageMetadata;
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.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

/**
 * Server implementation of AttachmentMetadata.
 *
 * Generated from org/waveprotocol/box/attachment/attachment.proto. Do not edit.
 */

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */
// NOTE(kalman): It would be nicer to add a proto serialisation
// utility rather than having this class at all.
public final class AttachmentMetadataProtoImpl implements AttachmentMetadata,
        // 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.attachment.AttachmentProto.AttachmentMetadata> {
    private org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata proto = null;
    private org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata.Builder protoBuilder = org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata
            .newBuilder();

    public AttachmentMetadataProtoImpl() {
    }

    public AttachmentMetadataProtoImpl(org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata proto) {
        this.proto = proto;
    }

    public AttachmentMetadataProtoImpl(AttachmentMetadata message) {
        copyFrom(message);
    }

    @Override
    public org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata getPB() {
        switchToProto();
        return proto;
    }

    @Override
    public void setPB(org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata proto) {
        this.proto = proto;
        this.protoBuilder = null;
    }

    @Override
    public void copyFrom(AttachmentMetadata message) {

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setAttachmentId(message.getAttachmentId());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setWaveRef(message.getWaveRef());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setFileName(message.getFileName());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setMimeType(message.getMimeType());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setSize(message.getSize());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setCreator(message.getCreator());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setAttachmentUrl(message.getAttachmentUrl());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        setThumbnailUrl(message.getThumbnailUrl());

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (message.hasImageMetadata()) {
            setImageMetadata(new ImageMetadataProtoImpl(message.getImageMetadata()));
        } else {
            clearImageMetadata();
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (message.hasThumbnailMetadata()) {
            setThumbnailMetadata(new ImageMetadataProtoImpl(message.getThumbnailMetadata()));
        } else {
            clearThumbnailMetadata();
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (message.hasMalware()) {
            setMalware(message.getMalware());
        } else {
            clearMalware();
        }
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public String getAttachmentId() {
        switchToProto();
        return proto.getAttachmentId();
    }

    @Override
    public void setAttachmentId(String value) {
        switchToProtoBuilder();
        protoBuilder.setAttachmentId(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public String getWaveRef() {
        switchToProto();
        return proto.getWaveRef();
    }

    @Override
    public void setWaveRef(String value) {
        switchToProtoBuilder();
        protoBuilder.setWaveRef(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public String getFileName() {
        switchToProto();
        return proto.getFileName();
    }

    @Override
    public void setFileName(String value) {
        switchToProtoBuilder();
        protoBuilder.setFileName(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public String getMimeType() {
        switchToProto();
        return proto.getMimeType();
    }

    @Override
    public void setMimeType(String value) {
        switchToProtoBuilder();
        protoBuilder.setMimeType(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public long getSize() {
        switchToProto();
        return proto.getSize();
    }

    @Override
    public void setSize(long value) {
        switchToProtoBuilder();
        protoBuilder.setSize(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public String getCreator() {
        switchToProto();
        return proto.getCreator();
    }

    @Override
    public void setCreator(String value) {
        switchToProtoBuilder();
        protoBuilder.setCreator(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public String getAttachmentUrl() {
        switchToProto();
        return proto.getAttachmentUrl();
    }

    @Override
    public void setAttachmentUrl(String value) {
        switchToProtoBuilder();
        protoBuilder.setAttachmentUrl(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public String getThumbnailUrl() {
        switchToProto();
        return proto.getThumbnailUrl();
    }

    @Override
    public void setThumbnailUrl(String value) {
        switchToProtoBuilder();
        protoBuilder.setThumbnailUrl(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public boolean hasImageMetadata() {
        switchToProto();
        return proto.hasImageMetadata();
    }

    @Override
    public void clearImageMetadata() {
        switchToProtoBuilder();
        protoBuilder.clearImageMetadata();
    }

    @Override
    public ImageMetadataProtoImpl getImageMetadata() {
        switchToProto();
        return new ImageMetadataProtoImpl(proto.getImageMetadata());
    }

    @Override
    public void setImageMetadata(ImageMetadata value) {
        switchToProtoBuilder();
        protoBuilder.clearImageMetadata();
        protoBuilder.setImageMetadata(getOrCreateImageMetadataProtoImpl(value).getPB());
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public boolean hasThumbnailMetadata() {
        switchToProto();
        return proto.hasThumbnailMetadata();
    }

    @Override
    public void clearThumbnailMetadata() {
        switchToProtoBuilder();
        protoBuilder.clearThumbnailMetadata();
    }

    @Override
    public ImageMetadataProtoImpl getThumbnailMetadata() {
        switchToProto();
        return new ImageMetadataProtoImpl(proto.getThumbnailMetadata());
    }

    @Override
    public void setThumbnailMetadata(ImageMetadata value) {
        switchToProtoBuilder();
        protoBuilder.clearThumbnailMetadata();
        protoBuilder.setThumbnailMetadata(getOrCreateImageMetadataProtoImpl(value).getPB());
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    @Override
    public boolean hasMalware() {
        switchToProto();
        return proto.hasMalware();
    }

    @Override
    public void clearMalware() {
        switchToProtoBuilder();
        protoBuilder.clearMalware();
    }

    @Override
    public boolean getMalware() {
        switchToProto();
        return proto.getMalware();
    }

    @Override
    public void setMalware(boolean value) {
        switchToProtoBuilder();
        protoBuilder.setMalware(value);
    }

    /**
     * Licensed to the Apache Software Foundation (ASF) under one
     * or more contributor license agreements. See the NOTICE file
     * distributed with this work for additional information
     * regarding copyright ownership. The ASF licenses this file
     * to you 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.
     */

    /** Get or create a ImageMetadataProtoImpl from a ImageMetadata. */
    private ImageMetadataProtoImpl getOrCreateImageMetadataProtoImpl(ImageMetadata message) {
        if (message instanceof ImageMetadataProtoImpl) {
            return (ImageMetadataProtoImpl) message;
        } else {
            ImageMetadataProtoImpl messageImpl = new ImageMetadataProtoImpl();
            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.attachment.AttachmentProto.AttachmentMetadata.newBuilder()
                    : org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata.newBuilder(proto);
            proto = null;
        }
    }

    private void invalidateAll() {
        proto = null;
        protoBuilder = org.waveprotocol.box.attachment.AttachmentProto.AttachmentMetadata.newBuilder();
    }

    @Override
    public JsonElement toGson(RawStringData raw, Gson gson) {
        JsonObject json = new JsonObject();

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("1", new JsonPrimitive(getAttachmentId()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("2", new JsonPrimitive(getWaveRef()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("3", new JsonPrimitive(getFileName()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("4", new JsonPrimitive(getMimeType()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("5", GsonUtil.toJson(getSize()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("6", new JsonPrimitive(getCreator()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("7", new JsonPrimitive(getAttachmentUrl()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        json.add("8", new JsonPrimitive(getThumbnailUrl()));

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (hasImageMetadata()) {
            {
                JsonElement elem = ((GsonSerializable) getImageMetadata()).toGson(raw, gson);
                json.add("9", elem);
            }
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (hasThumbnailMetadata()) {
            {
                JsonElement elem = ((GsonSerializable) getThumbnailMetadata()).toGson(raw, gson);
                json.add("10", elem);
            }
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (hasMalware()) {
            json.add("11", new JsonPrimitive(getMalware()));
        }
        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();

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("1")) {
            JsonElement elem = jsonObject.get("1");
            setAttachmentId(elem.getAsString());
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("2")) {
            JsonElement elem = jsonObject.get("2");
            setWaveRef(elem.getAsString());
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("3")) {
            JsonElement elem = jsonObject.get("3");
            setFileName(elem.getAsString());
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("4")) {
            JsonElement elem = jsonObject.get("4");
            setMimeType(elem.getAsString());
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("5")) {
            JsonElement elem = jsonObject.get("5");
            setSize(GsonUtil.fromJson(elem));
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("6")) {
            JsonElement elem = jsonObject.get("6");
            setCreator(elem.getAsString());
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("7")) {
            JsonElement elem = jsonObject.get("7");
            setAttachmentUrl(elem.getAsString());
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("8")) {
            JsonElement elem = jsonObject.get("8");
            setThumbnailUrl(elem.getAsString());
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("9")) {
            JsonElement elem = jsonObject.get("9");
            if (!elem.isJsonNull()) {
                {
                    ImageMetadataProtoImpl payload = new ImageMetadataProtoImpl();
                    GsonUtil.extractJsonObject(payload, elem, gson, raw);
                    setImageMetadata(payload);
                }
            }
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("10")) {
            JsonElement elem = jsonObject.get("10");
            if (!elem.isJsonNull()) {
                {
                    ImageMetadataProtoImpl payload = new ImageMetadataProtoImpl();
                    GsonUtil.extractJsonObject(payload, elem, gson, raw);
                    setThumbnailMetadata(payload);
                }
            }
        }

        /**
         * Licensed to the Apache Software Foundation (ASF) under one
         * or more contributor license agreements. See the NOTICE file
         * distributed with this work for additional information
         * regarding copyright ownership. The ASF licenses this file
         * to you 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.
         */
        if (jsonObject.has("11")) {
            JsonElement elem = jsonObject.get("11");
            if (!elem.isJsonNull()) {
                setMalware(elem.getAsBoolean());
            }
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o instanceof AttachmentMetadataProtoImpl) {
            return getPB().equals(((AttachmentMetadataProtoImpl) o).getPB());
        } else {
            return false;
        }
    }

    @Override
    public boolean isEqualTo(Object o) {
        if (equals(o)) {
            return true;
        } else if (o instanceof AttachmentMetadata) {
            return AttachmentMetadataUtil.isEqual(this, (AttachmentMetadata) o);
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return getPB().hashCode();
    }

    @Override
    public String toString() {
        return getPB().toString();
    }

}