|
|
/*
|
|
|
* 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; // 导入Cursor类,用于数据库操作时获取数据
|
|
|
|
|
|
import org.json.JSONObject; // 导入JSONObject类,用于处理JSON数据
|
|
|
|
|
|
// 定义一个抽象类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 = ""; // 初始化名称为空字符串
|
|
|
mLastModified = 0; // 初始化修改时间为0
|
|
|
mDeleted = false; // 初始化删除状态为false
|
|
|
}
|
|
|
|
|
|
// 抽象方法:获取创建操作的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();
|
|
|
|
|
|
// 抽象方法:从Cursor中获取同步动作
|
|
|
public abstract int getSyncAction(Cursor c);
|
|
|
|
|
|
// 设置唯一标识符
|
|
|
public void setGid(String gid) {
|
|
|
this.mGid = gid; // 设置mGid的值
|
|
|
}
|
|
|
|
|
|
// 设置节点名称
|
|
|
public void setName(String name) {
|
|
|
this.mName = name; // 设置mName的值
|
|
|
}
|
|
|
|
|
|
// 设置上次修改时间
|
|
|
public void setLastModified(long lastModified) {
|
|
|
this.mLastModified = lastModified; // 设置mLastModified的值
|
|
|
}
|
|
|
|
|
|
// 设置删除状态
|
|
|
public void setDeleted(boolean deleted) {
|
|
|
this.mDeleted = deleted; // 设置mDeleted的值
|
|
|
}
|
|
|
|
|
|
// 获取唯一标识符
|
|
|
public String getGid() {
|
|
|
return this.mGid; // 返回mGid的值
|
|
|
}
|
|
|
|
|
|
// 获取节点名称
|
|
|
public String getName() {
|
|
|
return this.mName; // 返回mName的值
|
|
|
}
|
|
|
|
|
|
// 获取上次修改时间
|
|
|
public long getLastModified() {
|
|
|
return this.mLastModified; // 返回mLastModified的值
|
|
|
}
|
|
|
|
|
|
// 获取删除状态
|
|
|
public boolean getDeleted() {
|
|
|
return this.mDeleted; // 返回mDeleted的值
|
|
|
}
|
|
|
|
|
|
}
|