protected Object convertScheduled(String name, Object value) throws MessageFormatException { Object result = value; if (AMQ_SCHEDULED_DELAY.equals(name)){ result = TypeConversionSupport.convert(value, Long.class); } else if (AMQ_SCHEDULED_PERIOD.equals(name)){ result = TypeConversionSupport.convert(value, Long.class); } else if (AMQ_SCHEDULED_REPEAT.equals(name)){ result = TypeConversionSupport.convert(value, Integer.class); } return result; }
public static Converter lookupConverter(Class<?> from, Class<?> to) { // use wrapped type for primitives if (from.isPrimitive()) { from = convertPrimitiveTypeToWrapperType(from); } if (to.isPrimitive()) { to = convertPrimitiveTypeToWrapperType(to); } if (from.equals(to)) { return IDENTITY_CONVERTER; } return CONVERSION_MAP.get(new ConversionKey(from, to)); }
public static Object convert(Object value, Class<?> to) { if (value == null) { // lets avoid NullPointerException when converting to boolean for null values if (boolean.class.isAssignableFrom(to)) { return Boolean.FALSE; } return null; } // eager same instance type test to avoid the overhead of invoking the type converter // if already same type if (to.isInstance(value)) { return to.cast(value); } // lookup converter Converter c = lookupConverter(value.getClass(), to); if (c != null) { return c.convert(value); } else { return null; } }
public static boolean isDestForcedDurable(final ActiveMQDestination destination) { boolean isForceDurable = false; if (destination != null) { final Map<String, String> options = destination.getOptions(); if (options != null) { isForceDurable = (boolean) TypeConversionSupport.convert(options.get("forceDurable"), boolean.class); } } return isForceDurable; } }
TypeConversionSupport.Converter converter = TypeConversionSupport.lookupConverter(value.getClass(), to); if (converter != null) { return converter.convert(value);
public static Converter lookupConverter(Class<?> from, Class<?> to) { // use wrapped type for primitives if (from.isPrimitive()) { from = convertPrimitiveTypeToWrapperType(from); } if (to.isPrimitive()) { to = convertPrimitiveTypeToWrapperType(to); } if (from.equals(to)) { return IDENTITY_CONVERTER; } return CONVERSION_MAP.get(new ConversionKey(from, to)); }
@Override public long getLongProperty(String name) throws JMSException { Object value = getObjectProperty(name); if (value == null) { throw new NumberFormatException("property " + name + " was null"); } Long rc = (Long) TypeConversionSupport.convert(value, Long.class); if (rc == null) { throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a long"); } return rc.longValue(); }
public static String convertToString(Object value, Class to) { if (value == null) { return null; } // already a String if (value instanceof String) { return (String) value; } // special for String[] as we do not want to use a PropertyEditor for that if (String[].class.isInstance(value)) { String[] array = (String[]) value; return StringArrayConverter.convertToString(array); } // special for String to List<ActiveMQDestination> as we do not want to use a PropertyEditor for that if (List.class.isInstance(value)) { // if the list is a ActiveMQDestination, then return a comma list String answer = StringToListOfActiveMQDestinationConverter.convertFromActiveMQDestination(value); if (answer != null) { return answer; } } TypeConversionSupport.Converter converter = TypeConversionSupport.lookupConverter(value.getClass(), String.class); if (converter != null) { return (String) converter.convert(value); } else { throw new IllegalArgumentException("Cannot convert from " + value.getClass() + " to " + to + " with value " + value); } }
public static Converter lookupConverter(Class<?> from, Class<?> to) { // use wrapped type for primitives if (from.isPrimitive()) { from = convertPrimitiveTypeToWrapperType(from); } if (to.isPrimitive()) { to = convertPrimitiveTypeToWrapperType(to); } if (from.equals(to)) { return IDENTITY_CONVERTER; } return CONVERSION_MAP.get(new ConversionKey(from, to)); }
@Override public short getShortProperty(String name) throws JMSException { Object value = getObjectProperty(name); if (value == null) { throw new NumberFormatException("property " + name + " was null"); } Short rc = (Short) TypeConversionSupport.convert(value, Short.class); if (rc == null) { throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a short"); } return rc.shortValue(); }
public static Object convert(Object value, Class<?> to) { if (value == null) { // lets avoid NullPointerException when converting to boolean for null values if (boolean.class.isAssignableFrom(to)) { return Boolean.FALSE; } return null; } // eager same instance type test to avoid the overhead of invoking the type converter // if already same type if (to.isInstance(value)) { return to.cast(value); } // lookup converter Converter c = lookupConverter(value.getClass(), to); if (c != null) { return c.convert(value); } else { return null; } }
public static Converter lookupConverter(Class<?> from, Class<?> to) { // use wrapped type for primitives if (from.isPrimitive()) { from = convertPrimitiveTypeToWrapperType(from); } if (to.isPrimitive()) { to = convertPrimitiveTypeToWrapperType(to); } if (from.equals(to)) { return IDENTITY_CONVERTER; } return CONVERSION_MAP.get(new ConversionKey(from, to)); }
@Override public int getIntProperty(String name) throws JMSException { Object value = getObjectProperty(name); if (value == null) { throw new NumberFormatException("property " + name + " was null"); } Integer rc = (Integer) TypeConversionSupport.convert(value, Integer.class); if (rc == null) { throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as an integer"); } return rc.intValue(); }
public static Object convert(Object value, Class<?> to) { if (value == null) { // lets avoid NullPointerException when converting to boolean for null values if (boolean.class.isAssignableFrom(to)) { return Boolean.FALSE; } return null; } // eager same instance type test to avoid the overhead of invoking the type converter // if already same type if (to.isInstance(value)) { return to.cast(value); } // lookup converter Converter c = lookupConverter(value.getClass(), to); if (c != null) { return c.convert(value); } else { return null; } }
@Override public byte getByteProperty(String name) throws JMSException { Object value = getObjectProperty(name); if (value == null) { throw new NumberFormatException("property " + name + " was null"); } Byte rc = (Byte) TypeConversionSupport.convert(value, Byte.class); if (rc == null) { throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a byte"); } return rc.byteValue(); }
public static Object convert(Object value, Class<?> to) { if (value == null) { // lets avoid NullPointerException when converting to boolean for null values if (boolean.class.isAssignableFrom(to)) { return Boolean.FALSE; } return null; } // eager same instance type test to avoid the overhead of invoking the type converter // if already same type if (to.isInstance(value)) { return to.cast(value); } // lookup converter Converter c = lookupConverter(value.getClass(), to); if (c != null) { return c.convert(value); } else { return null; } }
@Override public double getDoubleProperty(String name) throws JMSException { Object value = getObjectProperty(name); if (value == null) { throw new NullPointerException("property " + name + " was null"); } Double rc = (Double) TypeConversionSupport.convert(value, Double.class); if (rc == null) { throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a double"); } return rc.doubleValue(); }
public static String convertToString(Object value, Class to) { if (value == null) { return null; } // already a String if (value instanceof String) { return (String) value; } // special for String[] as we do not want to use a PropertyEditor for that if (String[].class.isInstance(value)) { String[] array = (String[]) value; return StringArrayConverter.convertToString(array); } // special for String to List<ActiveMQDestination> as we do not want to use a PropertyEditor for that if (List.class.isInstance(value)) { // if the list is a ActiveMQDestination, then return a comma list String answer = StringToListOfActiveMQDestinationConverter.convertFromActiveMQDestination(value); if (answer != null) { return answer; } } TypeConversionSupport.Converter converter = TypeConversionSupport.lookupConverter(value.getClass(), String.class); if (converter != null) { return (String) converter.convert(value); } else { throw new IllegalArgumentException("Cannot convert from " + value.getClass() + " to " + to + " with value " + value); } }
@Override public boolean getBooleanProperty(String name) throws JMSException { Object value = getObjectProperty(name); if (value == null) { return false; } Boolean rc = (Boolean) TypeConversionSupport.convert(value, Boolean.class); if (rc == null) { throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a boolean"); } return rc.booleanValue(); }
@Override public float getFloatProperty(String name) throws JMSException { Object value = getObjectProperty(name); if (value == null) { throw new NullPointerException("property " + name + " was null"); } Float rc = (Float) TypeConversionSupport.convert(value, Float.class); if (rc == null) { throw new MessageFormatException("Property " + name + " was a " + value.getClass().getName() + " and cannot be read as a float"); } return rc.floatValue(); }