If you think the Android project Locast-Core-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package edu.mit.mobile.android.locast.data;
//fromwww.java2s.com/*
* Copyright (C) 2011 MIT Mobile Experience Lab
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.json.JSONObject;
import android.accounts.Account;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import edu.mit.mobile.android.locast.data.JsonSyncableItem.SyncItem;
import edu.mit.mobile.android.locast.sync.SyncEngine;
/**
* <p>
* This class maps local database content to/from JSON so it can be sent to /retrieved from the
* server.
* </p>
*
* <p>
* To use, {@link #put(String, SyncItem)} items, placing the local DB column in key. Keys that start
* with {@link JsonSyncableItem#PREFIX_IGNORE_KEY} will not be stored in/retrieved from the
* database, but will still be processed by the {@link SyncEngine}.
* </p>
*
* @author <a href="mailto:spomeroy@mit.edu">Steve Pomeroy</a>
*
*/publicclass SyncMap extends HashMap<String, SyncItem> {
/**
*
*/privatestaticfinallong serialVersionUID = 4817034517893809747L;
/**
* If set, this item is treated as a child of another item and a parent must sync before this
* can be sync'd. This ensures that even if a sync event is triggered for the child, it will
* never attempt to synch before its parent.
*
* This really only looks to see that the parent has gotten a public URI first, so as soon as
* that happens, the child will be able to sync.
*/publicstaticfinal String FLAG_PARENT_MUST_SYNC_FIRST = "parent_must_sync_first";
privatestaticfinal HashSet<String> mFlags = new HashSet<String>();
public SyncMap() {
}
public SyncMap(SyncMap syncMap) {
super(syncMap);
}
publicvoid addFlag(String flag) {
mFlags.add(flag);
}
publicvoid removeFlag(String flag) {
mFlags.remove(flag);
}
publicboolean isFlagSet(String flag) {
return mFlags.contains(flag);
}
public Set<String> getFlags() {
returnnew HashSet<String>(mFlags);
}
/**
* Called just before an item is sync'd.
*
* @param c
* Cursor pointing to the given item.
*
* @throws SyncException
*/publicvoid onPreSyncItem(ContentResolver cr, Uri uri, Cursor c) throws SyncException {
}
/**
* Hook called after an item has been synchronized on the server. Called each time the sync
* request is made. Make sure to call through when subclassing.
* @param account TODO
* @param uri
* Local URI pointing to the item.
* @param updated
* true if the item was updated during the sync.
*
* @throws SyncException
* @throws IOException
*/publicvoid onPostSyncItem(Context context, Account account, Uri uri, JSONObject item, boolean updated)
throws SyncException, IOException {
for (final SyncItem childItem : this.values()) {
childItem.onPostSyncItem(context, account, uri, item, updated);
}
}
}