@Override public void setProperty(String name, Object value) { if (!(value instanceof String)) { value = ConverterRegistry.getConverter().asString(value); } contextParameters.put(name, value); }
/** * Put meta data to this archive manifest. If <code>key</code> already exists is overridden. Meta <code>value</code> is * converted to string and can be any type for which there is a {@link Converter} registered. * * @param key meta data key, * @param value meta data value. */ public void putMeta(String key, Object value) { manifest.getMainAttributes().putValue(key, ConverterRegistry.getConverter().asString(value)); }
/** * Set configuration object property. Convert <code>value</code> to string and set property. If property already * exists overwrite old value. If <code>value</code> argument is null this setter does nothing. * * @param name property name, * @param value property value, null ignored. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. * @throws ConverterException if there is no converter registered for value type. */ public void setProperty(String name, Object value) { Params.notNullOrEmpty(name, "Property name"); if(value != null) { properties.setProperty(name, converter.asString(value)); } }
/** * Set this configuration object value. Value is converter to string before store it. If <code>value</code> argument * is null this setter will reset this configuration object value. * * @param value value to set, null accepted. * @throws IllegalArgumentException if <code>value</code> argument is an empty string. * @throws ConverterException if there is no converter registered for value type. */ public void setValue(Object value) { if(value instanceof String) { Params.notEmpty((String)value, "Value"); this.value = (String)value; } else { this.value = value != null ? converter.asString(value) : null; } }
/** * Implements equality test logic. This method converts value to string using {@link Converter} then compare it with * operand. As a consequence operand format must be compatible with value type. For example if value type is a * {@link Date} operand syntax should be ISO8601; please see {@link Converter} documentation for supported formats. */ @Override public boolean evaluate(Object value, String operand) { if (value == null) { return operand.equals("null"); } if (value instanceof Date) { return evaluateDates((Date) value, operand); } return ConverterRegistry.getConverter().asString(value).equals(operand); }
/** * Convert value object to string and delegates {@link #add(String, String)}. String conversion is performed by * {@link Converter} and may throw {@link ConverterException}. * * @param name cookie name, not null or empty, * @param value cookie value, not null or empty. * @throws IllegalArgumentException if <code>name</code> argument is null or empty. * @throws IllegalArgumentException if <code>value</code> argument is null or empty. * @throws ConverterException if value object has no converter registered or object value serialization fails. */ public void add(String name, Object value) { add(name, ConverterRegistry.getConverter().asString(value)); }
/** * Set variables value. If variable name already exists its value is overridden. Convert variable value to string before * storing to variables map. Null is not accepted for either variable name or its value. * <p> * This method uses {@link Converter} to convert variable value to string. If there is no converter able to handle given * variable value type this method rise exception. * * @param name variable name, * @param value variable value. * @throws IllegalArgumentException if variable name is null or empty or value is null. * @throws ConverterException if there is no converter able to handle given value type. */ public void put(String name, Object value) { Params.notNullOrEmpty(name, "Variable name"); Params.notNull(value, "Variable %s value", name); variables.put(name, ConverterRegistry.getConverter().asString(value)); }
@Override public String asString(Object object) { if(object == null) { return null; } if(object instanceof String) { return (String)object; } Converter converter = getConverter(object.getClass()); if(converter == null) { throw new ConverterException("No registered converter for |%s|.", object.getClass()); } try { return converter.asString(object); } catch(ConverterException e) { throw e; } catch(Throwable t) { throw new ConverterException(t); } }
return ConverterRegistry.getConverter().asString(value);
throw new TemplateException("Invalid element |%s|. Operand for VALUE operator without formatter should be convertible to string.", element); value = ConverterRegistry.getConverter().asString(object);