You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
4.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* 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;
/**
* Google任务同步节点的抽象基类
* 定义了同步操作类型常量和节点数据的基本结构
* 提供了创建、更新、删除等同步操作的抽象方法接口
* 子类需实现具体的JSON转换和同步逻辑
*/
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; // Google任务全局唯一标识GID
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任务GID
* @param gid Google任务全局唯一标识
*/
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任务GID
* @return Google任务全局唯一标识
*/
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;
}
}