ADD file via upload

shenyifei
p3o5nagmu 8 months ago
parent b04237380e
commit 685ab78271

@ -0,0 +1,97 @@
/*
* 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 android.util.Log;
import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
// MetaData类继承自Task类从命名来看可能是用于处理与任务相关的元数据信息比如关联的特定标识等
public class MetaData extends Task {
// 定义一个用于日志记录的标签,使用类的简单名称(即不包含包名的类名),方便在查看日志时识别该类相关的输出信息
private final static String TAG = MetaData.class.getSimpleName();
// 用于存储相关的GID可能是某种全局唯一标识符具体取决于业务逻辑初始化为null
private String mRelatedGid = null;
// 设置元数据的方法接收一个GID可能用于关联其他对象或任务和一个JSON对象包含具体的元数据信息作为参数
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 尝试将给定的GID放入JSON对象中对应的键由GTaskStringUtils.META_HEAD_GTASK_ID指定可能用于标记该元数据关联的具体任务ID
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
// 如果在向JSON对象中放入数据时出现异常记录错误日志提示设置相关GID失败
Log.e(TAG, "failed to put related gid");
}
// 将处理后的JSON对象转换为字符串并设置为该对象的笔记内容这里假设Task类中有对应的setNotes方法用于设置笔记相关内容
setNotes(metaInfo.toString());
// 设置该对象的名称名称由GTaskStringUtils.META_NOTE_NAME指定可能是一个固定的用于标识元数据类型的名称
setName(GTaskStringUtils.META_NOTE_NAME);
}
// 获取关联的GID的方法外部可以通过调用此方法获取之前设置的相关标识符
public String getRelatedGid() {
return mRelatedGid;
}
// 重写自Task类的方法用于判断该元数据对象是否值得保存这里的判断依据是看其笔记内容是否为null若不为null则认为值得保存
@Override
public boolean isWorthSaving() {
return getNotes()!= null;
}
// 重写自Task类的方法用于根据远程的JSON数据设置该对象的内容并在这个过程中提取相关的GID信息
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes()!= null) {
try {
// 将获取到的笔记内容字符串转换为JSON对象以便从中提取相关信息
JSONObject metaInfo = new JSONObject(getNotes().trim());
// 从JSON对象中获取关联的GID字符串并赋值给成员变量mRelatedGid
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
// 如果在解析JSON获取GID时出现异常记录警告日志并将mRelatedGid设置为null
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
}
}
// 重写自Task类的方法这里明确抛出异常表示该方法不应该被调用可能在业务逻辑中该类对于通过本地JSON设置内容的操作是不支持的
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
// 重写自Task类的方法同样抛出异常表示该方法不应该被调用可能该类不需要从内容生成本地JSON这种操作或者这种操作不符合其业务逻辑
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
// 重写自Task类的方法再次抛出异常表示该方法不应该被调用可能在数据同步相关的操作中该类不需要执行获取同步动作的这个逻辑具体取决于整体的业务设计
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}
Loading…
Cancel
Save