package org.n0m.pawsqlite; import android.util.Log; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CallbackContext; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class PawSQLite extends CordovaPlugin { private static final String TAG = "PawSQLite"; DBManager dbManager; @Override protected void pluginInitialize() { Log.d(TAG, "Initialized Plugin"); this.dbManager = new DBManager(this.cordova); } @Override public boolean execute(String actionStr, JSONArray args, CallbackContext callbackContext) throws JSONException { CallbackWrapper callback = new CallbackWrapper(callbackContext); // Get Action DBAction action; try { action = DBAction.valueOf(actionStr.toUpperCase()); } catch (IllegalArgumentException e) { return false; } // Get DB Name String dbName = args.optString(0).trim(); if (dbName.isEmpty()) { callback.error( "Unknown Database", "Database name not included in request" ); return true; } // Remove dbName so that remaining args can be handled appropriately args.remove(0); // Queue request DBRequest request = new DBRequest(action, args, callback); dbManager.queueRequest(dbName, request); return true; } private JSONObject jsonError(String name, String message) throws JSONException { JSONObject response = new JSONObject(); JSONObject error = new JSONObject(); error.put("name", name); error.put("message", message); response.put("error", error); return response; } }