diff --git a/Node.java b/Node.java new file mode 100644 index 0000000..3de06bf --- /dev/null +++ b/Node.java @@ -0,0 +1,126 @@ +/* + * 版权声明:2010-2011年,MiCode开源社区(www.micode.net) + * + * 根据Apache License 2.0(以下简称“许可证”)授权; + * 除非遵守许可证,否则不得使用此文件。 + * 你可以在以下网址获得许可证的副本: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 除非适用法律要求或书面同意,否则根据许可证分发的软件 + * 按“原样”分发,不附带任何明示或暗示的保证或条件。 + * 请参阅许可证,了解许可证下的权利和限制的具体语言。 + */ + +package net.micode.notes.gtask.data; + +import android.database.Cursor; + +import org.json.JSONObject; + +/** + * 定义一个抽象类Node,代表GTask数据模型中的一个节点。 + */ +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; + + // GTask的ID + private String mGid; + // 节点名称 + private String mName; + // 最后修改时间 + private long mLastModified; + // 是否被删除 + private boolean mDeleted; + + /** + * Node类的构造函数。 + */ + 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); + + // Setter和Getter方法 + 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; + } +} \ No newline at end of file