/*
 * 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;
// 导入Cursor和Log类
import android.database.Cursor;
import android.util.Log;
// 导入GTaskStringUtils类
import net.micode.notes.tool.GTaskStringUtils;
// 导入JSONException和JSONObject类
import org.json.JSONException;
import org.json.JSONObject;
public class MetaData extends Task {
// 定义一个常量，用于标识MetaData类的名称
    private final static String TAG = MetaData.class.getSimpleName();

// 声明一个名为mRelatedGid的字符串变量，初始值为null
    private String mRelatedGid = null;

 // 设置元数据
    public void setMeta(String gid, JSONObject metaInfo) {
        try {
            // 将gid放入metaInfo中
            metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
        } catch (JSONException e) {
            // 如果出现JSONException异常，则打印错误日志
            Log.e(TAG, "failed to put related gid");
        }
// 设置笔记
        setNotes(metaInfo.toString());
// 设置名称
        setName(GTaskStringUtils.META_NOTE_NAME);
    }

 // 获取相关GID
    public String getRelatedGid() {
        return mRelatedGid;
    }

    @Override
    // 重写isWorthSaving()方法
    public boolean isWorthSaving() {
        // 如果getNotes()方法返回的值不为null，则返回true，否则返回false
        return getNotes() != null;
    }

    @Override
    // 重写setContentByRemoteJSON方法
    public void setContentByRemoteJSON(JSONObject js) {
        // 调用父类的setContentByRemoteJSON方法
        super.setContentByRemoteJSON(js);
        // 如果getNotes()不为空
        if (getNotes() != null) {
            try {
                // 将getNotes()的值转换为JSONObject
                JSONObject metaInfo = new JSONObject(getNotes().trim());
                // 获取metaInfo中的GTaskStringUtils.META_HEAD_GTASK_ID的值
                mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
            } catch (JSONException e) {
                // 打印日志
                Log.w(TAG, "failed to get related gid");
                // 将mRelatedGid设置为null
                mRelatedGid = null;
            }
        }
    }

    @Override
    public void setContentByLocalJSON(JSONObject js) {
       
        // 根据本地JSON设置内容
        throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
    }

    @Override
    // 重写父类方法，获取本地JSON数据
    public JSONObject getLocalJSONFromContent() {
        // 抛出非法访问错误，提示MetaData:getLocalJSONFromContent方法不应该被调用
        throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
    }

    @Override
    // 重写getSyncAction方法
    public int getSyncAction(Cursor c) {
        // 获取Cursor对象
        throw new IllegalAccessError("MetaData:getSyncAction should not be called");
    }

}
