|
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 抽象类Node代表一个基本的节点对象,提供了基本的属性和方法用于操作和同步节点数据
|
|
|
|
|
* 主要用于笔记或任务的同步处理
|
|
|
|
|
*/
|
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 默认构造方法,初始化节点的基本属性
|
|
|
|
|
*/
|
|
|
|
|
public Node() {
|
|
|
|
|
mGid = null;
|
|
|
|
|
mName = "";
|
|
|
|
|
mLastModified = 0;
|
|
|
|
|
mDeleted = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据操作ID生成创建操作的JSON对象
|
|
|
|
|
* @param actionId 操作ID,表示需要执行的同步操作类型
|
|
|
|
|
* @return 返回一个包含创建操作信息的JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public abstract JSONObject getCreateAction(int actionId);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据操作ID生成更新操作的JSON对象
|
|
|
|
|
* @param actionId 操作ID,表示需要执行的同步操作类型
|
|
|
|
|
* @return 返回一个包含更新操作信息的JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public abstract JSONObject getUpdateAction(int actionId);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过远程JSON对象设置节点内容
|
|
|
|
|
* @param js 远程JSON对象,包含节点的最新数据
|
|
|
|
|
*/
|
|
|
|
|
public abstract void setContentByRemoteJSON(JSONObject js);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过本地JSON对象设置节点内容
|
|
|
|
|
* @param js 本地JSON对象,包含节点的现有数据
|
|
|
|
|
*/
|
|
|
|
|
public abstract void setContentByLocalJSON(JSONObject js);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从节点内容生成本地JSON对象
|
|
|
|
|
* @return 返回一个包含节点当前状态的JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public abstract JSONObject getLocalJSONFromContent();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据数据库游标确定同步操作类型
|
|
|
|
|
* @param c 数据库游标,指向查询到的节点数据
|
|
|
|
|
* @return 返回一个整数,表示需要执行的同步操作类型
|
|
|
|
|
*/
|
|
|
|
|
public abstract int getSyncAction(Cursor c);
|
|
|
|
|
|
|
|
|
|
// 以下为节点属性的getter和setter方法
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|