public static void override(String completeKey, Object value) throws ConfigurationException { Object enumValue = findByKey(completeKey); try { String[] splittedKeys = completeKey.split("\\."); String section = splittedKeys[0]; Class en = PropertiesConfigurationHelper.CONFIGURATION_SECTIONS.get(section); en.getMethod("override", Object.class).invoke(enumValue, value); } catch (Exception e) { throw new ConfigurationException( "Invalid key -" + completeKey + "- or value -" + value + "-", e); } }
public static Object findByKey(String completeKey) throws ConfigurationException { String[] splittedKeys = completeKey.split("\\."); String section = splittedKeys[0]; Class en = PropertiesConfigurationHelper.CONFIGURATION_SECTIONS.get(section); EnumSet values = EnumSet.allOf(en); for (Object v : values) { try { String key = StringUtils.join(Arrays.copyOfRange(splittedKeys, 1, splittedKeys.length), "."); if (((String) en.getMethod("getKey").invoke(v)).equalsIgnoreCase(key)) return v; } catch (Exception e) { throw new ConfigurationException( "Is it " + en.getCanonicalName() + " an Enum that implements the IProperties interface?", e); } } return null; } // findByKey