private void checkIfMandatory(Map<ConfigurationProperty, List<String>> results, ConfigurationProperty p) throws InterpreterPropertyException { if ( p.isMandatory() && ! results.containsKey(p)) { throw new InterpreterPropertyException( "Mandatory property " + p + " was not set. " + "You can set this property with the -" + p.getSwitchName() + " switch, " + "the -" + p.getSwitchShortName() + " switch or the " + p.getSystemProperty() + " system property" ); } } }
/** * This is a property with a boolean value which defaults to false * * The user can 'turn this option on' by passing a command line switch without a value (e.g. -d ) in which case we need to * set the value to true * * @param property * @return true if this is a boolean switch property */ private boolean isBooleanSwitchProperty(ConfigurationProperty property) { return property.hasDefaults() && property.getDefaults().length == 1 && property.getDefaults()[0].equals("false"); }
private void checkValues(ConfigurationProperty p, List<String> values) throws InterpreterPropertyException { Pattern pattern = Pattern.compile(p.getValidatingExpression()); for (String value : values) { Matcher m = pattern.matcher(value); if ( ! m.matches()) { throw new InterpreterPropertyException( "Could not parse the value for interpreter property " + p + " expected to be in the form " + p.getExample() ); } } }
private void checkValueCount(ConfigurationProperty p, List<String> values) throws InterpreterPropertyException { if ( values.size() < p.getMinValueCount()) { throw new InterpreterPropertyException("At least " + p.getMinValueCount() + " value(s) must be supplied for the property " + p); } else if ( values.size() > p.getMaxValueCount()) { throw new InterpreterPropertyException("At most " + p.getMaxValueCount() + " value(s) must be supplied for the property " + p); } }
public static ConfigurationProperty getConfigPropertyForSysProp(String systemProperty) { ConfigurationProperty result = null; for ( ConfigurationProperty p : values()) { if ( p.getSystemProperty().equals(systemProperty)) { result = p; break; } } return result; }
private void addPropertyValues(Map<ConfigurationProperty, List<String>> propertyMap, StringTokenizer st, ConfigurationProperty property) throws InterpreterPropertyException { List<String> l = getOrCreatePropertyList(propertyMap, property); if ( ! st.hasMoreTokens() ) { if (isBooleanSwitchProperty(property)) { l.add("true"); } else { throw new InterpreterPropertyException( String.format("No value was given for switch -%s (-%s), and Chorus cannot provide a default", property.getSwitchShortName(), property.getSwitchName() ) ); } } else { while(st.hasMoreTokens()) { l.add(st.nextToken()); } } }
public String getHyphenatedSwitch() { return delegate.getHyphenatedSwitch(); }
private void mergeValues(List<String> valuesFromSource, ConfigurationProperty p, List<String> vals) { switch(p.getPropertySourceMode()) { case APPEND: vals.addAll(valuesFromSource); break; case OVERRIDE: vals.clear(); vals.addAll(valuesFromSource); break; default: throw new UnsupportedOperationException("Unknown source mode " + p.getPropertySourceMode()); } }
public int getMinValueCount() { return delegate.getMinValueCount(); }
public String getSwitchName() { return delegate.getSwitchName(); }
public String getSwitchShortName() { return delegate.getSwitchShortName(); }
public String getValidatingExpression() { return delegate.getValidatingExpression(); }
public String getExample() { return delegate.getExample(); }
public int getMaxValueCount() { return delegate.getMaxValueCount(); }
public String[] getDefaults() { return delegate.getDefaults(); }
public String getSystemProperty() { return delegate.getSystemProperty(); }
private String getSwitches(Properties sysPropsForTest) { StringBuilder sb = new StringBuilder(); for ( Map.Entry<Object,Object> property : sysPropsForTest.entrySet()) { String propertyName = property.getKey().toString(); if ( isAChorusSwitchProperty(propertyName)) { ConfigurationProperty c = ChorusConfigProperty.getConfigPropertyForSysProp(propertyName); sb.append(" ").append(c.getHyphenatedSwitch()); sb.append(" ").append(property.getValue().toString()); } } return sb.toString(); }
public PropertySourceMode getPropertySourceMode() { return delegate.getPropertySourceMode(); } }
/** * Add to the provided propertyMap any properties available from this source * * Where the map already contains property values under a given key, extra property values should be * appended to the List * @return propertyMap, with parsed properties added */ public Map<ConfigurationProperty, List<String>> parseProperties(Map<ConfigurationProperty, List<String>> propertyMap, String... args) { for ( ConfigurationProperty p : getProperties()) { String value = System.getProperty(p.getSystemProperty()); if ( value != null ) { addValues(propertyMap, p, value); } } return propertyMap; }
public Map<ConfigurationProperty, List<String>> parseProperties(Map<ConfigurationProperty, List<String>> propertyMap, String... args) throws InterpreterPropertyException { for ( ConfigurationProperty p : getProperties()) { if ( p.hasDefaults()) { List<String> properties = getOrCreatePropertyList(propertyMap, p); Collections.addAll(properties, p.getDefaults()); } } return propertyMap; } }