public String getETag() { if (eTag == null) { eTag = computeETag(this); } return eTag; }
pmd.prompt = pPrompt; pmd.promptAgain = pPromptAgain; result.add(pmd); } else if (NAME_ELEMENT.equals(key)) { result = new CachedCommandModel(name, eTag); result.dashOk = unknownAreOperands; result.setUsage(usage); result.setAddedUploadOption(addedUploadOption); pmd.prompt = pPrompt; pmd.promptAgain = pPromptAgain; result.add(pmd); } else if (result == null && name != null && !name.isEmpty()) { result = new CachedCommandModel(name, eTag); result.dashOk = unknownAreOperands; result.setUsage(usage); result.setAddedUploadOption(addedUploadOption);
bw.write(CachedCommandModel.computeETag(cm)); bw.newLine(); CachedCommandModel ccm = (CachedCommandModel) cm; if (ccm.isAddedUploadOption()) { bw.write(ADDEDUPLOADOPTIONS_ELEMENT); bw.write(": true"); str = ccm.getUsage(); if (str != null && !str.isEmpty()) { bw.write(USAGE_ELEMENT);
if (commandModel instanceof CachedCommandModel) { CachedCommandModel ccm = (CachedCommandModel) commandModel; this.usage = ccm.getUsage(); addedUploadOption = ccm.isAddedUploadOption();
/** * Interface to enable factoring out common HTTP connection management code. * <p> * The implementation of this interface must implement * <ul> * <li>{@link #prepareConnection} - to perform all pre-connection configuration - set headers, chunking, etc. * as well as writing any payload to the outbound connection. In short * anything needed prior to the URLConnection#connect invocation. * <p> * The caller will invoke this method after it has invoked {@link URL#openConnection} * but before it invokes {@link URL#connect}. * <li>{@link #useConnection} - to read from the * input stream, etc. The caller will invoke this method after it has * successfully invoked {@link URL#connect}. * </ul> * Because the caller might have to work with multiple URLConnection objects * (as it follows redirection, for example) this contract allows the caller * to delegate to the HttpCommand implementation multiple times to configure * each of the URLConnections objects, then to invoke useConnection only * once after it has the "final" URLConnection object. For this reason * be sure to implement prepareConnection so that it can be invoked * multiple times. * */ interface HttpCommand { /** * Configures the HttpURLConnection (headers, chuncking, etc.) according * to the needs of this use of the connection and then writes any * required outbound payload to the connection.
CachedCommandModel cm = new CachedCommandModel(name); boolean sawFile = false; try { cm.setUsage(usage); String dashOk = getAttr(cmdattrs, "unknown-options-are-operands"); if (dashOk != null) opt.promptAgain = getAttr(attributes, "promptAgain"); cm.add(opt); if (opt.getType() == File.class) sawFile = true; pm.param._primary = true; pm.param._multiple = multiple; cm.add(pm); cm.add(new ParamModelData("upload", Boolean.class, true, null)); addedUploadOption = true; cm.setAddedUploadOption(true);
/** * Interface to enable factoring out common HTTP connection management code. * <p> * The implementation of this interface must implement * <ul> * <li>{@link #prepareConnection} - to perform all pre-connection configuration - set headers, chunking, etc. * as well as writing any payload to the outbound connection. In short * anything needed prior to the URLConnection#connect invocation. * <p> * The caller will invoke this method after it has invoked {@link URL#openConnection} * but before it invokes {@link URL#connect}. * <li>{@link #useConnection} - to read from the * input stream, etc. The caller will invoke this method after it has * successfully invoked {@link URL#connect}. * </ul> * Because the caller might have to work with multiple URLConnection objects * (as it follows redirection, for example) this contract allows the caller * to delegate to the HttpCommand implementation multiple times to configure * each of the URLConnections objects, then to invoke useConnection only * once after it has the "final" URLConnection object. For this reason * be sure to implement prepareConnection so that it can be invoked * multiple times. * */ interface HttpCommand { /** * Configures the HttpURLConnection (headers, chuncking, etc.) according * to the needs of this use of the connection and then writes any * required outbound payload to the connection.
@Override public boolean validateCommandModelETag(CommandModel model, String eTag) { if (model == null) { return true; //Unexisting model => it is ok (but weard in fact) } if (eTag == null || eTag.isEmpty()) { return false; } String actualETag = CachedCommandModel.computeETag(model); return eTag.equals(actualETag); }
JSONObject obj = new JSONObject(str); obj = obj.getJSONObject("command"); CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag); cm.dashOk = obj.optBoolean("@unknown-options-are-operands", false); cm.managedJob = obj.optBoolean("@managed-job", false); cm.setUsage(obj.optString("usage", null)); Object optns = obj.opt("option"); if (!JSONObject.NULL.equals(optns)) { cm.add(opt); cm.add(new ParamModelData("upload", Boolean.class, true, null)); addedUploadOption = true; cm.setAddedUploadOption(true); cm.add(new ParamModelData("notify",Boolean.class,false, "false")); this.usage = cm.getUsage(); return cm; } catch (JSONException ex) {
@Override public boolean validateCommandModelETag(CommandModel model, String eTag) { if (model == null) { return true; //Unexisting model => it is ok (but weard in fact) } if (eTag == null || eTag.isEmpty()) { return false; } String actualETag = CachedCommandModel.computeETag(model); return eTag.equals(actualETag); }
String eTag = CachedCommandModel.computeETag(rac.getCommandModel()); rac = null; initializeRemoteAdminCommand(); rac.fetchCommandModel(); String newETag = CachedCommandModel.computeETag(rac.getCommandModel()); if (eTag != null && eTag.equals(newETag)) { return; //Nothing change in command model
String eTag = CachedCommandModel.computeETag(rac.getCommandModel()); rac = null; initializeRemoteAdminCommand(); rac.fetchCommandModel(); String newETag = CachedCommandModel.computeETag(rac.getCommandModel()); if (eTag != null && eTag.equals(newETag)) { return; //Nothing change in command model