diff --git a/Node.java b/Node.java new file mode 100644 index 0000000..746409c --- /dev/null +++ b/Node.java @@ -0,0 +1,110 @@ +/* + * 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; + +// 抽象类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; + + // 存储全局唯一标识符(GID),初始值为null + private String mGid; + // 节点名称,初始为空字符串 + private String mName; + // 最后修改时间戳,初始为0 + private long mLastModified; + // 表示节点是否被删除的标志,初始为false + private boolean mDeleted; + + // 构造函数,初始化各成员变量 + public Node() { + mGid = null; + mName = ""; + mLastModified = 0; + mDeleted = false; + } + + // 抽象方法,获取创建操作对应的JSON对象,具体由子类实现 + public abstract JSONObject getCreateAction(int actionId); + + // 抽象方法,获取更新操作对应的JSON对象,子类按业务逻辑实现 + public abstract JSONObject getUpdateAction(int actionId); + + // 抽象方法,依据远程JSON数据设置节点内容,子类负责解析填充 + public abstract void setContentByRemoteJSON(JSONObject js); + + // 抽象方法,依据本地JSON数据设置节点内容,由子类实现具体逻辑 + public abstract void setContentByLocalJSON(JSONObject js); + + // 抽象方法,从节点内容生成本地JSON对象,子类确定JSON结构 + public abstract JSONObject getLocalJSONFromContent(); + + // 抽象方法,根据游标获取节点的同步操作类型,子类判断逻辑 + public abstract int getSyncAction(Cursor c); + + // 设置GID的方法 + 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; + } + + // 获取GID的方法 + public String getGid() { + return this.mGid; + } + + // 获取名称的方法 + public String getName() { + return this.mName; + } + + // 获取最后修改时间的方法 + public long getLastModified() { + return this.mLastModified; + } + + // 获取是否删除状态的方法 + public boolean getDeleted() { + return this.mDeleted; + } +} \ No newline at end of file