|
|
/*
|
|
|
* 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.java
|
|
|
* 描述: 数据节点抽象基类,定义了同步操作的基本接口和属性
|
|
|
* 作用: 为TaskList、Task和MetaData等具体类提供统一的接口和基本功能
|
|
|
*/
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
/**
|
|
|
* Node抽象类
|
|
|
* 定义了同步操作的基本接口和属性,是TaskList、Task和MetaData等类的基类
|
|
|
* 提供了数据同步过程中需要的基本操作和状态定义
|
|
|
*/
|
|
|
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;
|
|
|
|
|
|
/** Google Task ID */
|
|
|
private String mGid;
|
|
|
|
|
|
/** 节点名称 */
|
|
|
private String mName;
|
|
|
|
|
|
/** 最后修改时间 */
|
|
|
private long mLastModified;
|
|
|
|
|
|
/** 是否已删除 */
|
|
|
private boolean mDeleted;
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
|
* 初始化节点的基本属性
|
|
|
*/
|
|
|
public Node() {
|
|
|
mGid = null;
|
|
|
mName = "";
|
|
|
mLastModified = 0;
|
|
|
mDeleted = false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取创建操作的JSON对象
|
|
|
*
|
|
|
* @param actionId 操作ID
|
|
|
* @return 创建操作的JSON对象
|
|
|
*/
|
|
|
public abstract JSONObject getCreateAction(int actionId);
|
|
|
|
|
|
/**
|
|
|
* 获取更新操作的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);
|
|
|
|
|
|
/**
|
|
|
* 设置Google Task ID
|
|
|
*
|
|
|
* @param gid Google Task ID
|
|
|
*/
|
|
|
public void setGid(String gid) {
|
|
|
this.mGid = gid;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置节点名称
|
|
|
*
|
|
|
* @param name 节点名称
|
|
|
*/
|
|
|
public void setName(String name) {
|
|
|
this.mName = name;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置最后修改时间
|
|
|
*
|
|
|
* @param lastModified 最后修改时间
|
|
|
*/
|
|
|
public void setLastModified(long lastModified) {
|
|
|
this.mLastModified = lastModified;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置删除状态
|
|
|
*
|
|
|
* @param deleted 是否已删除
|
|
|
*/
|
|
|
public void setDeleted(boolean deleted) {
|
|
|
this.mDeleted = deleted;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取Google Task ID
|
|
|
*
|
|
|
* @return Google Task ID
|
|
|
*/
|
|
|
public String getGid() {
|
|
|
return this.mGid;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取节点名称
|
|
|
*
|
|
|
* @return 节点名称
|
|
|
*/
|
|
|
public String getName() {
|
|
|
return this.mName;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取最后修改时间
|
|
|
*
|
|
|
* @return 最后修改时间
|
|
|
*/
|
|
|
public long getLastModified() {
|
|
|
return this.mLastModified;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取删除状态
|
|
|
*
|
|
|
* @return 是否已删除
|
|
|
*/
|
|
|
public boolean getDeleted() {
|
|
|
return this.mDeleted;
|
|
|
}
|
|
|
|
|
|
}
|