All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.github.dockerjava.api.model.VolumeRW Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package org.testifyproject.testifyproject.github.dockerjava.api.model;

import java.org.testifyproject.testifyproject.IOException;
import java.util.Map.Entry;

import org.testifyproject.apache.org.testifyproject.testifyprojectmons.lang.builder.EqualsBuilder;
import org.testifyproject.apache.org.testifyproject.testifyprojectmons.lang.builder.HashCodeBuilder;

import org.testifyproject.testifyproject.fasterxml.jackson.core.JsonGenerator;
import org.testifyproject.testifyproject.fasterxml.jackson.core.JsonParser;
import org.testifyproject.testifyproject.fasterxml.jackson.core.JsonProcessingException;
import org.testifyproject.testifyproject.fasterxml.jackson.core.ObjectCodec;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.DeserializationContext;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.JsonDeserializer;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.JsonNode;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.JsonSerializer;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.SerializerProvider;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.node.NullNode;
import org.testifyproject.testifyproject.github.dockerjava.core.RemoteApiVersion;

/**
 * Represents a bind mounted volume in a Docker container.
 *
 * @see Bind
 * @org.testifyproject.testifyprojectprecated since {@link RemoteApiVersion#VERSION_1_20}
 */
@JsonDeserialize(using = VolumeRW.Deserializer.class)
@JsonSerialize(using = VolumeRW.Serializer.class)
@Deprecated
public class VolumeRW {

    private Volume volume;

    private AccessMode accessMode = AccessMode.rw;

    public VolumeRW(Volume volume) {
        this.volume = volume;
    }

    public VolumeRW(Volume volume, AccessMode accessMode) {
        this.volume = volume;
        this.accessMode = accessMode;
    }

    public Volume getVolume() {
        return volume;
    }

    public AccessMode getAccessMode() {
        return accessMode;
    }

    /**
     * Returns a string representation of this {@link VolumeRW} suitable for inclusion in a JSON message. The returned String is simply the
     * container path, {@link #getPath()}.
     *
     * @return a string representation of this {@link VolumeRW}
     */
    @Override
    public String toString() {
        return getVolume() + ":" + getAccessMode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof VolumeRW) {
            VolumeRW other = (VolumeRW) obj;
            return new EqualsBuilder().append(getVolume(), other.getVolume()).append(accessMode, other.getAccessMode())
                    .isEquals();
        } else {
            return super.equals(obj);
        }
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(getVolume()).append(getAccessMode()).toHashCode();
    }

    public static class Serializer extends JsonSerializer {

        @Override
        public void serialize(VolumeRW volumeRW, JsonGenerator jsonGen, SerializerProvider serProvider)
                throws IOException, JsonProcessingException {

            jsonGen.writeStartObject();
            jsonGen.writeFieldName(volumeRW.getVolume().getPath());
            jsonGen.writeString(Boolean.toString(volumeRW.getAccessMode().toBoolean()));
            jsonGen.writeEndObject();
        }

    }

    public static class Deserializer extends JsonDeserializer {
        @Override
        public VolumeRW org.testifyproject.testifyprojectserialize(JsonParser jsonParser, DeserializationContext org.testifyproject.testifyprojectserializationContext)
                throws IOException, JsonProcessingException {
            ObjectCodec oc = jsonParser.getCodec();
            JsonNode node = oc.readTree(jsonParser);
            if (!node.equals(NullNode.getInstance())) {
                Entry field = node.fields().next();
                String volume = field.getKey();
                AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean());
                return new VolumeRW(new Volume(volume), accessMode);
            } else {
                return null;
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy