/** * Resets the configuration to the default (as parsed in the constructor) */ public void setDefault() { try { parseConfiguration(defaultConfig); } catch (ConfigurationException e) { // can not happen else the default config is already validated // within the constructor } } /**
/** * Resets the configuration to the default (as parsed in the constructor) */ public void setDefault() { try { parseConfiguration(defaultConfig); } catch (ConfigurationException e) { // can not happen else the default config is already validated // within the constructor } } /**
@SuppressWarnings("unchecked") public LanguageConfiguration(String property, String[] defaultConfig){ if(property == null || property.isEmpty()){ throw new IllegalArgumentException("The parsed property MUST NOT be NULL nor empty!"); } this.property = property; this.defaultConfig = defaultConfig != null ? Arrays.asList(defaultConfig) : Collections.EMPTY_LIST; try { parseConfiguration(this.defaultConfig); } catch (ConfigurationException e) { throw new IllegalArgumentException("Inalied default configuration " + e.getMessage()); } }
@SuppressWarnings("unchecked") public LanguageConfiguration(String property, String[] defaultConfig){ if(property == null || property.isEmpty()){ throw new IllegalArgumentException("The parsed property MUST NOT be NULL nor empty!"); } this.property = property; this.defaultConfig = defaultConfig != null ? Arrays.asList(defaultConfig) : Collections.EMPTY_LIST; try { parseConfiguration(this.defaultConfig); } catch (ConfigurationException e) { throw new IllegalArgumentException("Inalied default configuration " + e.getMessage()); } }
/** * Reads the configuration for the parsed value. <p> * This implementation supports * <code>null</code> (sets the default), <code>String[]</code>, * <code>Collections<?></code> (Object{@link #toString() toString()} is called * on members) and comma separated {@link String}. * @param value the value * @throws ConfigurationException if the configuration of is invalid */ protected void processConfiguration(Object value) throws ConfigurationException { Collection<?> config; if(value == null){ config = defaultConfig; } else if (value instanceof String[]){ config = Arrays.asList((String[]) value); } else if (value instanceof Collection<?>){ config = (Collection<?>)value; } else if (value instanceof String){ config = Arrays.asList(value.toString().split(",")); } else { throw new ConfigurationException(property, "Values of type '" + value.getClass() +"' are not supported (supported are " + "String[], Collection<?>, comma separated String and " + "NULL to reset to the default configuration)!"); } parseConfiguration(config); }
/** * Reads the configuration for the parsed value. <p> * This implementation supports * <code>null</code> (sets the default), <code>String[]</code>, * <code>Collections<?></code> (Object{@link #toString() toString()} is called * on members) and comma separated {@link String}. * @param value the value * @throws ConfigurationException if the configuration of is invalid */ protected void processConfiguration(Object value) throws ConfigurationException { Collection<?> config; if(value == null){ config = defaultConfig; } else if (value instanceof String[]){ config = Arrays.asList((String[]) value); } else if (value instanceof Collection<?>){ config = (Collection<?>)value; } else if (value instanceof String){ config = Arrays.asList(value.toString().split(",")); } else { throw new ConfigurationException(property, "Values of type '" + value.getClass() +"' are not supported (supported are " + "String[], Collection<?>, comma separated String and " + "NULL to reset to the default configuration)!"); } parseConfiguration(config); }