/** * 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 void testDisplayValue() { PropertyManager mgr = new PropertyManager(); mgr.setProperty(PropertyDescriptor.VFS_REFRESH_PERIOD, 4); Property<Integer> property = mgr.getProperty(PropertyDescriptor.VFS_REFRESH_PERIOD); assertEquals("4", property.getDisplayValue()); mgr.setProperty(SimpleAuthenticationPlugin.SIMPLE_PASSWORD, "the_password"); Property<String> secretProperty = mgr.getProperty(SimpleAuthenticationPlugin.SIMPLE_PASSWORD); assertEquals(PropertyDescriptor.SECRET_DISPLAY_VALUE, secretProperty.getDisplayValue()); assertEquals("the_password", secretProperty.getValue()); } }
/** * 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); } } }
/** * Returns a context 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 value * @throws NullPointerException if the descriptor argument is null */ <T> 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 (descriptor.getType().isAssignableFrom(type)) { return type.cast(property.getValue()); } } return null; }
/** * 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); }
/** * 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; }
/** * 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. 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); } }
public void testGetProperty() { PropertyManager mgr = new PropertyManager(); mgr.setProperty(FOO, foo); Property<Foo> property = mgr.getProperty(FOO); assertEquals(foo, property.getValue()); }
/** * 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); }
/** * 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; }
/** * 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); } }
/** * 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); } } }
/** * 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); }
/** * 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; }
/** * 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(); } 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); } }
/** * 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 * @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); } } }
/** * 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; }