/** * Parse a string representation of a value and returns the corresponding typed value. * * @param s the string to parse * @return the corresponding value * @throws NullPointerException if the argument is null * @throws IllegalArgumentException if the string value cannot be parsed for some reason */ public final T parse(String s) throws NullPointerException, IllegalArgumentException { if (s == null) { throw new NullPointerException("Cannot parse null property values"); } try { return doParse(s); } catch (Exception e) { throw new IllegalArgumentException("Illegal property value " + s, e); } }
/** * Returns a property or null if it cannot be found. * * @param desc the property descriptor * @param <T> the property parameter type * @return the property object * @throws NullPointerException if the descriptor argument is null */ public <T> Property<T> getProperty(PropertyDescriptor<T> desc) throws NullPointerException { if (desc == null) { throw new NullPointerException(); } return getProperty(desc.getName(), desc.getType()); }
/** * Parse a string representation of a value and returns the correspondig property value. * * @param s the string to parse * @return the corresponding property * @throws NullPointerException if the argument is null * @throws IllegalArgumentException if the string value cannot be parsed for some reason */ public final Property<T> toProperty(String s) throws NullPointerException, IllegalArgumentException { T value = parse(s); return new Property<T>(this, value); }
/** * Set a context property to a new value. * * @param desc the property descriptor * @param value the property value * @param <T> the property parameter type * @throws NullPointerException if the descriptor argument or the value is null * @throws IllegalArgumentException if the string value cannot be converted to the property type */ <T> void parseProperty(PropertyDescriptor<T> desc, String value) throws NullPointerException, IllegalArgumentException { if (desc == null) { throw new NullPointerException("No null descriptor allowed"); } if (value == null) { throw new NullPointerException("No null value accepted"); } else { Property<T> property = desc.toProperty(value); log.log(Level.FINE, "Setting property " + desc.name + " to value " + property.getValue()); properties.put(desc.getName(), property); } } }
/** * Set a context property to a new value. If the provided value is null, then the property is removed. * * @param desc the property descriptor * @param value the property value * @param <T> the property parameter type * @throws NullPointerException if the descriptor argument is null */ <T> void setProperty(PropertyDescriptor<T> desc, T value) throws NullPointerException { if (desc == null) { throw new NullPointerException("No null descriptor allowed"); } if (value == null) { log.log(Level.FINE, "Removing property " + desc.name); properties.remove(desc.getName()); } else { Property<T> property = new Property<T>(desc, value); log.log(Level.FINE, "Setting property " + desc.name + " to value " + property.getValue()); properties.put(desc.getName(), property); } }
/** * Returns a property or null if it cannot be found. * * @param propertyName the name of the property * @param type the property type * @param <T> the property parameter type * @return the property object * @throws NullPointerException if any argument is null */ private <T> Property<T> getProperty(String propertyName, Class<T> type) throws NullPointerException { if (propertyName == null) { throw new NullPointerException("No null property name accepted"); } if (type == null) { throw new NullPointerException("No null property type accepted"); } Property<?> property = properties.get(propertyName); if (property != null) { PropertyDescriptor<?> descriptor = property.getDescriptor(); if (type.equals(descriptor.getType())) { return (Property<T>)property; } } return null; }
public static PropertyDescriptor<String> create(String name, String defaultValue, String description, boolean secret) { return new PropertyDescriptor<String>(String.class, name, defaultValue, description, secret) { @Override protected String doParse(String s) throws Exception { return s; } }; }
public static PropertyDescriptor<Integer> create(String name, Integer defaultValue, String description) { return create(name, defaultValue, description, false); }
/** * Set a context property to a new value. If the provided value is null, then the property is removed. * * @param desc the property descriptor * @param value the property value * @param <T> the property parameter type * @throws NullPointerException if the descriptor argument is null * @throws IllegalArgumentException if the string value cannot be converted to the property type */ <T> void setProperty(PropertyDescriptor<T> desc, String value) throws NullPointerException, IllegalArgumentException { if (desc == null) { throw new NullPointerException(); } if (value == null) { log.log(Level.FINE, "Removing property " + desc.name); properties.remove(desc.getName()); } else { Property<T> property = desc.toProperty(value); log.log(Level.FINE, "Setting property " + desc.name + " to value " + property.getValue()); properties.put(desc.getName(), property); } } }
while (i.hasNext()) { PropertyDescriptor<?> descriptor = i.next(); log.fine("Adding plugin " + plugin + " property " + descriptor.getName()); configureProperty(context, config, descriptor);
/** * Returns a property or null if it cannot be found. * * @param propertyName the name of the property * @param type the property type * @param <T> the property parameter type * @return the property object * @throws NullPointerException if any argument is null */ private <T> Property<T> getProperty(String propertyName, Class<T> type) throws NullPointerException { if (propertyName == null) { throw new NullPointerException("No null property name accepted"); } if (type == null) { throw new NullPointerException("No null property type accepted"); } Property<?> property = properties.get(propertyName); if (property != null) { PropertyDescriptor<?> descriptor = property.getDescriptor(); if (type.equals(descriptor.getType())) { return (Property<T>)property; } } return null; }
public static PropertyDescriptor<Integer> create(String name, Integer defaultValue, String description, boolean secret) { return new PropertyDescriptor<Integer>(Integer.class, name, defaultValue, description, secret) { @Override protected Integer doParse(String s) throws Exception { return Integer.parseInt(s); } }; }
public static PropertyDescriptor<String> create(String name, String defaultValue, String description) { return create(name, defaultValue, description, false); }
/** * Returns a property value or null if it cannot be found. * * @param desc the property descriptor * @param <T> the property parameter type * @return the property value * @throws NullPointerException if the descriptor argument is null */ public <T> T getPropertyValue(PropertyDescriptor<T> desc) throws NullPointerException { if (desc == null) { throw new NullPointerException(); } Property<T> property = getProperty(desc.getName(), desc.getType()); return property != null ? property.getValue() : null; }
/** * Set a context property to a new value. * * @param desc the property descriptor * @param value the property value * @param <T> the property parameter type * @throws NullPointerException if the descriptor argument or the value is null * @throws IllegalArgumentException if the string value cannot be converted to the property type */ <T> void parseProperty(PropertyDescriptor<T> desc, String value) throws NullPointerException, IllegalArgumentException { if (desc == null) { throw new NullPointerException("No null descriptor allowed"); } if (value == null) { throw new NullPointerException("No null value accepted"); } else { Property<T> property = desc.toProperty(value); log.log(Level.FINE, "Setting property " + desc.name + " to value " + property.getValue()); properties.put(desc.getName(), property); } } }
/** * Set a context property to a new value. If the provided value is null, then the property is removed. * * @param desc the property descriptor * @param value the property value * @param <T> the property parameter type * @throws NullPointerException if the descriptor argument is null */ <T> void setProperty(PropertyDescriptor<T> desc, T value) throws NullPointerException { if (desc == null) { throw new NullPointerException("No null descriptor allowed"); } if (value == null) { log.log(Level.FINE, "Removing property " + desc.name); properties.remove(desc.getName()); } else { Property<T> property = new Property<T>(desc, value); log.log(Level.FINE, "Setting property " + desc.name + " to value " + property.getValue()); properties.put(desc.getName(), property); } }
/** * Parse a string representation of a value and returns the correspondig property value. * * @param s the string to parse * @return the corresponding property * @throws NullPointerException if the argument is null * @throws IllegalArgumentException if the string value cannot be parsed for some reason */ public final Property<T> toProperty(String s) throws NullPointerException, IllegalArgumentException { T value = parse(s); return new Property<T>(this, value); }
/** * Parse a string representation of a value and returns the corresponding typed value. * * @param s the string to parse * @return the corresponding value * @throws NullPointerException if the argument is null * @throws IllegalArgumentException if the string value cannot be parsed for some reason */ public final T parse(String s) throws NullPointerException, IllegalArgumentException { if (s == null) { throw new NullPointerException("Cannot parse null property values"); } try { return doParse(s); } catch (Exception e) { throw new IllegalArgumentException("Illegal property value " + s, e); } }
/** * Returns a property or null if it cannot be found. * * @param propertyName the name of the property * @param type the property type * @param <T> the property parameter type * @return the property object * @throws NullPointerException if any argument is null */ private <T> Property<T> getProperty(String propertyName, Class<T> type) throws NullPointerException { if (propertyName == null) { throw new NullPointerException("No null property name accepted"); } if (type == null) { throw new NullPointerException("No null property type accepted"); } Property<?> property = properties.get(propertyName); if (property != null) { PropertyDescriptor<?> descriptor = property.getDescriptor(); if (type.equals(descriptor.getType())) { return (Property<T>)property; } } return null; }
public static PropertyDescriptor<List> create(String name, List defaultValue, String description, boolean secret) { return new PropertyDescriptor<List>(List.class, name, defaultValue, description, secret) { @Override protected List doParse(String s) throws Exception { String[] split = Utils.split(s, ','); List<String> list = Arrays.asList(split); for (int i = 0;i < list.size();i++) { list.set(i, list.get(i).trim()); } return list; } }; }