📄 stafutil.java
字号:
return resolvedResult; } return new STAFResult(STAFResult.Ok, value); } /***********************************************************************/ /* Description: */ /* This method resolves any STAF variables that are contained within */ /* the string passed in by submitting a */ /* RESOLVE STRING <value> */ /* request to the VAR service on the local system. */ /* Then it checks if the resolved value is an integer and returns an */ /* error if it's not an integer. */ /* */ /* Input: Option name whose value is being resolved */ /* Value for the option that may contain STAF variables */ /* STAF handle */ /* */ /* Returns: */ /* STAFResult.rc = the return code (STAFResult.Ok if successful) */ /* STAFResult.result = the resolved option value if successful */ /* an error message if not successful */ /***********************************************************************/ public static STAFResult resolveInitVarAndCheckInt( String option, String value, STAFHandle handle) { STAFResult resolvedValue = resolveInitVar(value, handle); if (resolvedValue.rc != STAFResult.Ok) return resolvedValue; try { Integer.parseInt(resolvedValue.result); } catch (NumberFormatException e) { return new STAFResult( STAFResult.InvalidValue, option + " value must be numeric. " + option + "=" + resolvedValue.result); } return resolvedValue; } /***********************************************************************/ /* Description: */ /* This method gets the version of STAF (or of a STAF service) */ /* running on a specified machine by submitting a VERSION request to */ /* either the MISC service (to get the version of STAF) or to another*/ /* STAF service on the specified machine. Then it checks if the */ /* version meets the minimum required version specified by the */ /* minRequiredVersion argument. If the version is at or above the */ /* required version, STAFResult.Ok is returned in the rc and the */ /* version running on the specified machine is returned in the */ /* result. If the version is lower than the mininum required */ /* version, STAFResult.InvalidSTAFVersion is returned in the rc with */ /* an error message returned in the result. If another error occurs */ /* (e.g. RC 16 if the machine is not currently running STAF, etc.), */ /* that error will be returned. */ /* */ /* Input: 1) machine: endpoint of the machine whose STAF or STAF */ /* service version is to be compared */ /* 2) handle: STAF handle to use to submit the request */ /* 3) minRequiredVersion: The minimum required version. */ /* The version must have the following format unless it's */ /* blank or "<N/A>", which equates to "no version" and is */ /* internally represented as 0.0.0.0 */ /* */ /* a[.b[.c[.d]]] [text] */ /* */ /* where: */ /* - a, b, c, and d (if specified) are numeric */ /* - text is separated by one or more spaces from the */ /* version numbers */ /* */ /* Versions are compared as follows: */ /* a) The numeric versions (a[.b[.c[.d]]]) are numerically */ /* compared. */ /* b) If the numeric versions are "equal", then the [text] */ /* values are compared using a case-insensitive string */ /* compare. Except, note that no text is considered */ /* GREATER than any text (e.g."3.1.0" > "3.1.0 Beta 1"). */ /* */ /* Examples: */ /* "3" = "3.0" = "3.0.0" = "3.0.0.0" */ /* "3.0.0" < "3.1.0" */ /* "3.0.2" < "3.0.3" */ /* "3.0.0" < "3.1" */ /* "3.0.9" < "3.0.10" */ /* "3.1.0 Beta 1" < "3.1.0" */ /* "3.1.0 Alpha 1" < "3.1.0 Beta 1" */ /* */ /* 4) service: Name of the service for which you want the */ /* version of. Optional. Defaults to "MISC" which means */ /* that you want to compare the version of STAF running on */ /* the machine. Or, you can specify the name of a STAF */ /* service (such as STAX, Event, Cron, etc.) that implements*/ /* a VERSION request and follows the STAF version format */ /* requirements. */ /* */ /* Returns: */ /* STAFResult.rc = the return code (STAFResult.Ok if successful) */ /* STAFResult.result = the resolved option value if successful */ /* an error message if not successful */ /***********************************************************************/ public static STAFResult compareSTAFVersion( String machine, STAFHandle handle, String minRequiredVersion) { // The default is to check the version of STAF running (which is // done by submitting a VERSION request to the MISC service) return compareSTAFVersion( machine, handle, minRequiredVersion, "MISC"); } public static STAFResult compareSTAFVersion( String machine, STAFHandle handle, String minRequiredVersion, String service) { STAFResult res = handle.submit2( machine, service, "VERSION"); if (res.rc != STAFResult.Ok) { return new STAFResult( res.rc, "Request VERSION submitted to the " + service + " service on machine " + machine + " failed." + " Additional info: " + res.result); } else { STAFVersion version; STAFVersion minReqVersion; try { version = new STAFVersion(res.result); } catch (NumberFormatException e) { // Should never happen return new STAFResult( STAFResult.InvalidValue, "Invalid value specified for the version: " + res.result + ", Exception info: " + e.toString()); } try { minReqVersion = new STAFVersion(minRequiredVersion); } catch (NumberFormatException e) { return new STAFResult( STAFResult.InvalidValue, "Invalid value specified for the minimum required " + "version: " + minRequiredVersion + ", Exception info: " + e.toString()); } if (version.compareTo(minReqVersion) < 0) { String servMsg = service + " service"; if (service.equalsIgnoreCase("MISC")) servMsg = "STAF"; return new STAFResult( STAFResult.InvalidSTAFVersion, "Machine " + machine + " is running " + servMsg + " Version " + version + ". Version " + minRequiredVersion + " or later is required."); } else { return new STAFResult(STAFResult.Ok, version.toString()); } } } /***********************************************************************/ /* Description: */ /* This method returns the data with a privacy delimiters */ /* */ /* Input: A string. For example: "secret" */ /* */ /* Returns: */ /* String with privacy delimiters added. */ /* For example: "!!@secret@!!" */ /***********************************************************************/ public static String addPrivacyDelimiters(String data) { return STAFUtilAddPrivacyDelimiters(data); } /***********************************************************************/ /* Description: */ /* This method removes any privacy delimiters from the data */ /* */ /* Input: A string. For example: "!!@secret@!!" */ /* */ /* An integer containing the number of levels of privacy data */ /* to remove (optional). The default is 0 which indicates to */ /* remove all levels of privacy data. */ /* Returns: */ /* String with privacy delimiters removed. */ /* For example: "secret" */ /***********************************************************************/ public static String removePrivacyDelimiters(String data) { return STAFUtil.removePrivacyDelimiters(data, 0); } public static String removePrivacyDelimiters(String data, int numLevels) { return STAFUtilRemovePrivacyDelimiters(data, numLevels); } /***********************************************************************/ /* Description: */ /* This method masks any private data indicated by the privacy */ /* delimiters by replacing the private data with asterisks. */ /* */ /* Input: A string. For example: "!!@secret@!!" */ /* */ /* Returns: */ /* String with privacy prefixes removed. */ /* For example: "************" */ /***********************************************************************/ public static String maskPrivateData(String data) { return STAFUtilMaskPrivateData(data); } /***********************************************************************/ /* Description: */ /* This method escapes all privacy delimiters found in the data and */ /* returns the updated data. */ /* */ /* Input: A string. For example: "!!@secret@!!" */ /* */ /* Returns: */ /* A string with all privacy delimiters escaped. */ /* For example: "^!!@secret^@!!" */ /***********************************************************************/ public static String escapePrivacyDelimiters(String data) { return STAFUtilEscapePrivacyDelimiters(data); } /************************/ /* All the native stuff */ /************************/ private static native void initialize(); private static native String STAFUtilAddPrivacyDelimiters(String data); private static native String STAFUtilRemovePrivacyDelimiters( String data, int numLevels); private static native String STAFUtilMaskPrivateData(String data); private static native String STAFUtilEscapePrivacyDelimiters(String data); // Static initializer - called first time class is loaded. static { System.loadLibrary("STAF"); System.loadLibrary("JSTAF"); initialize(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -