|
|
/*
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
*
|
|
|
* 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 net.micode.notes.gtask.data;
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
/**
|
|
|
* Node类是抽象类,
|
|
|
* 声明了九种数据同步场景变量,
|
|
|
* 还声明了一些同步操作方法
|
|
|
*/
|
|
|
public abstract class Node {
|
|
|
public static final int SYNC_ACTION_NONE = 0; //无同步操作
|
|
|
|
|
|
public static final int SYNC_ACTION_ADD_REMOTE = 1; //远程添加操作
|
|
|
|
|
|
public static final int SYNC_ACTION_ADD_LOCAL = 2; //本地添加操作
|
|
|
|
|
|
public static final int SYNC_ACTION_DEL_REMOTE = 3; //远程删除操作
|
|
|
|
|
|
public static final int SYNC_ACTION_DEL_LOCAL = 4; //本地删除操作
|
|
|
|
|
|
public static final int SYNC_ACTION_UPDATE_REMOTE = 5; //远程更新操作
|
|
|
|
|
|
public static final int SYNC_ACTION_UPDATE_LOCAL = 6; //本地更新操作
|
|
|
|
|
|
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; //更新冲突
|
|
|
|
|
|
public static final int SYNC_ACTION_ERROR = 8; //同步出错
|
|
|
|
|
|
private String mGid;
|
|
|
|
|
|
private String mName;
|
|
|
|
|
|
private long mLastModified;
|
|
|
|
|
|
private boolean mDeleted;
|
|
|
|
|
|
//无参构造法,创建Node对象时无需传入任何参数
|
|
|
public Node() {
|
|
|
mGid = null; //常由云端生成
|
|
|
mName = ""; //不初始化为null:避免后续调用mName.length等方法时触发空指针异常
|
|
|
mLastModified = 0;
|
|
|
mDeleted = false;
|
|
|
}
|
|
|
|
|
|
//JSONObject是JSON实例的抽象类,生成同步创建操作JSON数据,返回操作ID
|
|
|
public abstract JSONObject getCreateAction(int actionId);
|
|
|
|
|
|
//生成同步更新操作的JSON数据,返回操作ID
|
|
|
public abstract JSONObject getUpdateAction(int actionId);
|
|
|
|
|
|
//这是一个方法,根据远程JSON数据设置内容(远程数据同步到本地)(具体操作)
|
|
|
public abstract void setContentByRemoteJSON(JSONObject js);
|
|
|
|
|
|
//这是一个方法,根据本地JSON数据设置内容(本地数据处理)(具体操作)
|
|
|
public abstract void setContentByLocalJSON(JSONObject js);
|
|
|
|
|
|
//将本地内容转换成JSON数据,同步到远程
|
|
|
public abstract JSONObject getLocalJSONFromContent();
|
|
|
|
|
|
//通过游标获取同步操作类型,在前面声明为类型变量0-8
|
|
|
public abstract int getSyncAction(Cursor c);
|
|
|
|
|
|
public void setGid(String gid) {
|
|
|
this.mGid = gid;
|
|
|
}
|
|
|
|
|
|
public void setName(String name) {
|
|
|
this.mName = name;
|
|
|
}
|
|
|
|
|
|
public void setLastModified(long lastModified) {
|
|
|
this.mLastModified = lastModified;
|
|
|
}
|
|
|
|
|
|
public void setDeleted(boolean deleted) {
|
|
|
this.mDeleted = deleted;
|
|
|
}
|
|
|
|
|
|
public String getGid() {
|
|
|
return this.mGid;
|
|
|
}
|
|
|
|
|
|
public String getName() {
|
|
|
return this.mName;
|
|
|
}
|
|
|
|
|
|
public long getLastModified() {
|
|
|
return this.mLastModified;
|
|
|
}
|
|
|
|
|
|
public boolean getDeleted() {
|
|
|
return this.mDeleted;
|
|
|
}
|
|
|
|
|
|
}
|