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

xyz.thepathfinder.android.SubscribableCrudModel Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package xyz.thepathfinder.android;

import com.google.gson.JsonObject;

/**
 * @param  Listener type
 * @author David Robinson
 */
public abstract class SubscribableCrudModel> extends SubscribableModel {

    public SubscribableCrudModel(String path, PathfinderServices services) {
        super(path, services);
    }

    public void connect() {
        JsonObject json = this.getMessageHeader("read");
        this.getServices().getConnection().sendMessage(json.toString());
    }

    protected void create() {
        if (this.isConnected()) {
            throw new IllegalStateException("Already created");
        }

        JsonObject json = this.getMessageHeader("create");
        json.add("value", this.createValueJson());

        this.getServices().getConnection().sendMessage(json.toString());
    }

    public void delete() {
        if (!this.isConnected()) {
            throw new IllegalStateException("Not connected to object on Pathfinder server");
        }

        JsonObject json = this.getMessageHeader("delete");
        this.getServices().getConnection().sendMessage(json.toString());
    }

    protected void update(JsonObject value) {
        if (!this.isConnected()) {
            throw new IllegalStateException("Not connected to object on Pathfinder server");
        }

        JsonObject json = this.getMessageHeader("update");
        json.add("value", value);

        this.getServices().getConnection().sendMessage(json.toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy