/* * 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; /** * 抽象节点基类,定义同步任务数据节点的通用属性和行为 * 作为所有同步实体(如笔记、任务、子任务等)的父类 * 包含同步动作类型定义和基础数据字段管理 */ 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服务器分配的唯一标识符 */ private String mGid; /** 节点显示名称 */ private String mName; /** 最后修改时间戳(毫秒级) */ private long mLastModified; /** 删除标记(逻辑删除) */ private boolean mDeleted; /** * 节点构造函数 * 初始化默认值:gid=null, 名称为空字符串,最后修改时间为0,未删除状态 */ public Node() { mGid = null; mName = ""; mLastModified = 0; mDeleted = false; } // 抽象方法定义(需子类实现) /** * 生成创建动作的JSON数据包 * @param actionId 动作标识符(用于保证操作序列) * @return 包含创建指令的JSON对象 */ public abstract JSONObject getCreateAction(int actionId); /** * 生成更新动作的JSON数据包 * @param actionId 动作标识符 * @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 需要执行的同步动作类型(参考SYNC_ACTION常量) */ public abstract int getSyncAction(Cursor c); // 属性访问方法 /** 设置Google Task服务器ID */ 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; } /** 获取Google Task服务器ID */ public String getGid() { return this.mGid; } /** 获取节点名称 */ public String getName() { return this.mName; } /** 获取最后修改时间戳 */ public long getLastModified() { return this.mLastModified; } /** 获取删除状态 */ public boolean getDeleted() { return this.mDeleted; } }