@@ -0,0 +1,2680 @@
+package com.imasson.commandrouter.driver;%0A%0Aimport com.imasson.commandrouter.CommandRouter;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0Aimport java.util.Iterator;%0A%0A/**%0A * The command driver that parse command from Json in String form.%0A *%0A * @author Masson%0A */%0Apublic class JsonDriver extends AbstractDriver %7B%0A%0A    private String mHandlerKey;%0A    private String mCommandKey;%0A    private String mParamKey;%0A%0A    public JsonDriver() %7B%0A        this(%22handler%22, %22command%22, %22param%22);%0A    %7D%0A%0A    public JsonDriver(String handlerKey, String commandKey, String paramKey) %7B%0A        if (handlerKey == null %7C%7C handlerKey.length() == 0) %7B%0A            throw new IllegalArgumentException(%22Argument 'handlerKey' is null or empty!%22);%0A        %7D%0A        if (commandKey == null %7C%7C commandKey.length() == 0) %7B%0A            throw new IllegalArgumentException(%22Argument 'commandKey' is null or empty!%22);%0A        %7D%0A        if (paramKey == null %7C%7C paramKey.length() == 0) %7B%0A            throw new IllegalArgumentException(%22Argument 'paramKey' is null or empty!%22);%0A        %7D%0A%0A        mHandlerKey = handlerKey;%0A        mCommandKey = commandKey;%0A        mParamKey = paramKey;%0A    %7D%0A%0A    @Override%0A    public CommandRouter.Op parseCommand(Object context, Object... rawArgs) %7B%0A        JSONObject jsonObject;%0A%0A        final Object rawArg = rawArgs%5B0%5D;%0A        if (rawArg instanceof String) %7B%0A            try %7B%0A                jsonObject = new JSONObject((String) rawArg);%0A            %7D catch (JSONException ex) %7B%0A                throw new DriverException(%22Error parsing Json%22, ex, rawArgs);%0A            %7D%0A        %7D else if (rawArg instanceof JSONObject) %7B%0A            jsonObject = (JSONObject) rawArg;%0A        %7D else %7B%0A            throw new DriverException(%22Unexpected format of args%22, rawArgs);%0A        %7D%0A%0A        CommandRouter.Op op;%0A        try %7B%0A            String handlerName = jsonObject.getString(mHandlerKey);%0A            String commandName = jsonObject.getString(mCommandKey);%0A            op = new CommandRouter.Op(context, handlerName, commandName);%0A%0A        %7D catch (JSONException ex) %7B%0A            throw new DriverException(%22Error parsing handler or command in Json%22, ex, rawArgs);%0A        %7D%0A%0A        JSONObject paramJsonObject = jsonObject.optJSONObject(mParamKey);%0A        if (paramJsonObject != null) %7B%0A            Iterator keysIterator = paramJsonObject.keys();%0A            while (keysIterator.hasNext()) %7B%0A                String key = (String) keysIterator.next();%0A                String value = paramJsonObject.optString(key);%0A                if (value != null) %7B%0A                    op.addArgument(key, value);%0A                %7D%0A            %7D%0A        %7D%0A%0A        return op;%0A    %7D%0A%7D%0A

add Json (org.json) format driver