public static void enableCcp(String componentName, String componentVersion, String installPath, String compoentHostName, String ccpServerHostName) { enableCcp(componentName, componentVersion, installPath, compoentHostName, ccpServerHostName, 5670); }
public static String getResourcePath(String fileName) { URL url = getResource(fileName); if (url == null) { return null; } try { return url.toURI().getPath(); } catch (URISyntaxException e) { return null; } }
public static boolean isEmpty (Object value) { if (value == null) { return true; } if (value.getClass() == String.class) { return isEmpty(value.toString()); } if (value.getClass().isArray()) { return Array.getLength(value) == 0; } if (value instanceof Collection) { return ((Collection)value).size() == 0; } return false; }
private void populateBoyersList() { Map<String, String> parseSimpleArrayAsMap = ConfigUtil.parseSimpleArrayAsMap(serviceName + ".http.monitoringFilter.baseUri"); List<String> keys = new ArrayList<String>(parseSimpleArrayAsMap.keySet()); // Collections.sort(keys); Collections.sort(keys, new Comparator<String>() { // Overriding the compare method to sort the age public int compare(String str1, String str2) { return Integer.parseInt(str1) - Integer.parseInt(str2); } }); for (String key : keys) { String baseUri = parseSimpleArrayAsMap.get(key); boyers.add(new BoyerMoore(baseUri)); } }
@Override public int compare(String o1, String o2) { if (o1==o2 || o1.equals(o2)) { return 0; } // get if keys represent arrays. If so, compare the keys by their array index int indexOf1 = o1.lastIndexOf("."); if (indexOf1 < 0) { return o1.compareTo(o2); } int indexOf2 = o2.lastIndexOf("."); if (indexOf2 < 0) { return o1.compareTo(o2); } indexOf1++; indexOf2++; if (ConfigUtil.isNumeric(o1, indexOf1, -1) && ConfigUtil.isNumeric(o2, indexOf2, -1)) { Comparable n1 = ConfigUtil.toNumber(o1, indexOf1, -1); Comparable n2 = ConfigUtil.toNumber(o2, indexOf2, -1); if (n1 == null || n2 == null) { return o1.compareTo(o2); } return n1.compareTo(n2); } return o1.compareTo(o2); } }
final String mapKey = stripKey(key); final String innerMapKey = getInnerMapKey(key);
/** * notified on reload configuration event */ @Override public void configurationChanged() { HashSet<Param> changedParams = new HashSet(); // read dynamic parameters for (Param param : parameters) { if (! param.isStatic()) { // preserve current value Object oldValue = param.getValue(); // read new value readAndValidateParameter(param); // get if parameter value had changed if (! ConfigUtil.equalValues(oldValue, param.getValue())) { changedParams.add(param); } } } // invoke listeners for all changed parameters if (! changedParams.isEmpty()) { for (ConfigChangeListener listener : configChangeListeners) { listener.configurationChanged(changedParams); } } } //==================================================================================================================
public static boolean isNumeric(String value) { return isNumeric(value, 0, -1); }
if (! ConfigUtil.isHexadecimal(hexValue)) { return "'" + hexValue + "' is not a valid hexadecimal value.";
private List<BoyerMoore> populateBoyersList() { List<BoyerMoore> boyers = new ArrayList<BoyerMoore>(); Map<String, String> parseSimpleArrayAsMap = ConfigUtil.parseSimpleArrayAsMap(configuration, apiName + ".http.monitoringBaseUri"); List<String> keys = new ArrayList<String>(parseSimpleArrayAsMap.keySet()); // Collections.sort(keys); Collections.sort(keys, new Comparator<String>() { // Overriding the compare method to sort the age public int compare(String str1, String str2) { return Integer.parseInt(str1) - Integer.parseInt(str2); } }); for (String key : keys) { String baseUri = parseSimpleArrayAsMap.get(key); boyers.add(new BoyerMoore(baseUri)); } return boyers; }
@Override public void validate(String name, T value) { ParamValidator validator = null; // get a validator instance according to if the given Boolean parameter value is enabled/disabled if (byBooleanParam) { validator = getValidator(validatorType, (Boolean)ifParam.getValue()); // validate given <param> only if <ifParam> value equals the given <ifValue> } else if (ConfigUtil.equalValues(ifParam.getValue(), ifValue)) { validator = getValidator(validatorType, required); } // validate value if (validator != null) { validator.validate(name, value); } } //------------------------------------------------------------------------------------------
/** * parse an simple array and return it as a Map. Can be used in conjunction with {@code ConfigUtil#parseComplexArrayStructure(String)} * @param configPrefix the prefix that is the basis of the array. E.g. * * given: * * smartcardAdaptor.cardFeatures.23.sbmMSB.0=0x00 * smartcardAdaptor.cardFeatures.23.sbmMSB.1=0x01 * * the config prefix will be: * smartcardAdaptor.cardFeatures.23.sbmMSB * * @return the Map where the index is the key and the value is the value. */ public static Map<String, String> parseSimpleArrayAsMap(String configPrefix) { Configuration configuration = ConfigurationFactory.getConfiguration(); return parseSimpleArrayAsMap(configuration, configPrefix); }
@Override public void validate(String name, String value) { if (validateAndReturnIfEmpty(name, value)) { return; } URL url = ConfigUtil.getResource(value); if (url == null) { throw new ValidationConfigException("File '" + value + "' cannot be found (Parameter: " + name + ")"); } } //------------------------------------------------------------------------------------------
protected boolean validateAndReturnIfEmpty(String name, T value) { if (ConfigUtil.isEmpty(value)) { if (required) { throw new ValidationConfigException("Required parameter value is empty: " + name); } return true; } return false; } //------------------------------------------------------------------------------------------