@Override public T fromString(String value) { if (value == null || value.isEmpty()) { return null; // throw new IllegalStateException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } if (value.length() == 1) { return rawType.cast(value.charAt(0)); } throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(value)); }
@Override public T fromString(String value) { if (value == null || value.isEmpty()) { return null; // throw new IllegalStateException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } if (value.length() == 1) { return rawType.cast(value.charAt(0)); } throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(value)); }
private T convert(String value) { try { return paramConverter.fromString(value); } catch (WebApplicationException wae) { throw wae; } catch (IllegalArgumentException iae) { throw iae; } catch (Exception ex) { throw new ExtractorException(ex); } }
private T convert(String value) { try { return paramConverter.fromString(value); } catch (WebApplicationException wae) { throw wae; } catch (IllegalArgumentException iae) { throw iae; } catch (Exception ex) { throw new ExtractorException(ex); } }
private Object getValue(String v) { try { return valueOf.invoke(null, v); } catch (InvocationTargetException ex) { Throwable target = ex.getTargetException(); if (target instanceof WebApplicationException) { throw (WebApplicationException) target; } else { throw new ExtractorException(target); } } catch (Exception ex) { throw new ProcessingException(ex); } }
private Object getValue(String v) { try { return valueOf.invoke(null, v); } catch (InvocationTargetException ex) { Throwable target = ex.getTargetException(); if (target instanceof WebApplicationException) { throw (WebApplicationException) target; } else { throw new ExtractorException(target); } } catch (Exception ex) { throw new ProcessingException(ex); } }
@Override public Object extract(MultivaluedMap<String, String> parameters) { String v = parameters.getFirst(parameter); if (v != null && !v.trim().isEmpty()) { if (v.length() == 1) { return v.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(v)); } } else if (defaultStringValue != null && !defaultStringValue.trim().isEmpty()) { if (defaultStringValue.length() == 1) { return defaultStringValue.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(defaultStringValue)); } } return defaultPrimitiveTypeValue; } }
@Override public T fromString(final String value) { if (value == null) { throw new IllegalArgumentException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } try { return rawType.cast(HttpDateFormat.readDate(value)); } catch (final ParseException ex) { throw new ExtractorException(ex); } }
@Override public Object extract(MultivaluedMap<String, String> parameters) { String v = parameters.getFirst(parameter); if (v != null && !v.trim().isEmpty()) { if (v.length() == 1) { return v.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(v)); } } else if (defaultStringValue != null && !defaultStringValue.trim().isEmpty()) { if (defaultStringValue.length() == 1) { return defaultStringValue.charAt(0); } else { throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(defaultStringValue)); } } return defaultPrimitiveTypeValue; } }
@Override public T fromString(final String value) { if (value == null) { throw new IllegalArgumentException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } try { return rawType.cast(HttpDateFormat.readDate(value)); } catch (final ParseException ex) { throw new ExtractorException(ex); } }
@Override @Nullable public T fromString(String value) { if (rawType != NonEmptyStringParam.class && Strings.isNullOrEmpty(value)) { return null; } try { return _fromString(value); } catch (InvocationTargetException ex) { final Throwable cause = ex.getCause(); if (cause instanceof WebApplicationException) { throw (WebApplicationException) cause; } else { throw new ExtractorException(cause); } } catch (final Exception ex) { throw new ProcessingException(ex); } }
@Override public T fromString(String value) { try { final SAXSource source = new SAXSource( spfProvider.get().newSAXParser().getXMLReader(), new InputSource(new java.io.StringReader(value))); final Unmarshaller u = getUnmarshaller(rawType); if (rawType.isAnnotationPresent(XmlRootElement.class)) { return rawType.cast(u.unmarshal(source)); } else { return u.unmarshal(source, rawType).getValue(); } } catch (UnmarshalException ex) { throw new ExtractorException(LocalizationMessages.ERROR_UNMARSHALLING_JAXB(rawType), ex); } catch (JAXBException ex) { throw new ProcessingException(LocalizationMessages.ERROR_UNMARSHALLING_JAXB(rawType), ex); } catch (Exception ex) { throw new ProcessingException(LocalizationMessages.ERROR_UNMARSHALLING_JAXB(rawType), ex); } }
@Override public T fromString(final String value) { if (value == null) { throw new IllegalArgumentException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } try { return _fromString(value); } catch (final InvocationTargetException ex) { // if the value is an empty string, return null if (value.isEmpty()) { return null; } final Throwable cause = ex.getCause(); if (cause instanceof WebApplicationException) { throw (WebApplicationException) cause; } else { throw new ExtractorException(cause); } } catch (final Exception ex) { throw new ProcessingException(ex); } }
@Override public T fromString(final String value) { if (value == null) { throw new IllegalArgumentException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } try { return _fromString(value); } catch (final InvocationTargetException ex) { // if the value is an empty string, return null if (value.isEmpty()) { return null; } final Throwable cause = ex.getCause(); if (cause instanceof WebApplicationException) { throw (WebApplicationException) cause; } else { throw new ExtractorException(cause); } } catch (final Exception ex) { throw new ProcessingException(ex); } }
/** * {@inheritDoc} * <p/> * This implementation extracts the value of the parameter applying the underlying * {@link ParamConverter param converter} to the first value found in the list of potential multiple * parameter values. Any other values in the multi-value list will be ignored. * * @param parameters map of parameters. * @return extracted single parameter value. */ @Override public T extract(final MultivaluedMap<String, String> parameters) { final String value = parameters.getFirst(getName()); try { return fromString((value == null && isDefaultValueRegistered()) ? getDefaultValueString() : value); } catch (final WebApplicationException | ProcessingException ex) { throw ex; } catch (final IllegalArgumentException ex) { return defaultValue(); } catch (final Exception ex) { throw new ExtractorException(ex); } } }
/** * {@inheritDoc} * <p/> * This implementation extracts the value of the parameter applying the underlying * {@link ParamConverter param converter} to the first value found in the list of potential multiple * parameter values. Any other values in the multi-value list will be ignored. * * @param parameters map of parameters. * @return extracted single parameter value. */ @Override public T extract(final MultivaluedMap<String, String> parameters) { final String value = parameters.getFirst(getName()); try { return fromString((value == null && isDefaultValueRegistered()) ? getDefaultValueString() : value); } catch (final WebApplicationException | ProcessingException ex) { throw ex; } catch (final IllegalArgumentException ex) { return defaultValue(); } catch (final Exception ex) { throw new ExtractorException(ex); } } }
@Override public T fromString(String value) { if (value == null || value.isEmpty()) { return null; // throw new IllegalStateException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } if (value.length() == 1) { return rawType.cast(value.charAt(0)); } throw new ExtractorException(LocalizationMessages.ERROR_PARAMETER_INVALID_CHAR_VALUE(value)); }
private T convert(String value) { try { return paramConverter.fromString(value); } catch (WebApplicationException wae) { throw wae; } catch (IllegalArgumentException iae) { throw iae; } catch (Exception ex) { throw new ExtractorException(ex); } }
private Object getValue(String v) { try { return valueOf.invoke(null, v); } catch (InvocationTargetException ex) { Throwable target = ex.getTargetException(); if (target instanceof WebApplicationException) { throw (WebApplicationException) target; } else { throw new ExtractorException(target); } } catch (Exception ex) { throw new ProcessingException(ex); } }
@Override public T fromString(final String value) { if (value == null) { throw new IllegalArgumentException(LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value")); } try { return rawType.cast(HttpDateFormat.readDate(value)); } catch (final ParseException ex) { throw new ExtractorException(ex); } }