protected Collection<Object> convertCollection(List<String> values, Collection<Object> out) { for (String string : values) { out.add(converter.convert(string)); } return out; } }
@Override public Object convert(String value) throws WebApplicationException { Object[] array = (Object[])Array.newInstance(type, 1); array[0] = concrete.convert(value); return null; }
@Override public Object convert(List<String> value) throws WebApplicationException { if (value == null || value.size() == 0) { return Array.newInstance(type, 0); } Object array = Array.newInstance(type, value.size()); for (int i = 0; i < value.size(); ++i) { Array.set(array, i, concrete.convert(value.get(i))); } return array; } }
@Override public Object getValue(RuntimeContext runtimeContext) throws IOException { if (runtimeContext == null) { return null; } UriInfo uriInfo = runtimeContext.getUriInfo(); MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(false); List<String> values = queryParameters.get(getName()); if (values == null) { values = new LinkedList<String>(); } if (values.size() == 0 && hasDefaultValue()) { values.add(getDefaultValue()); } decodeValues(values); // we found query parameter values with the specified name try { return getConvertor().convert(values); } catch (ConversionException e) { throw new WebApplicationException(e.getCause(), Response.Status.NOT_FOUND); } }
@Override public Object getValue(RuntimeContext runtimeContext) throws IOException { if (runtimeContext == null) { return null; } List<String> allValues = new ArrayList<String>(); List<PathSegment> segments = runtimeContext.getAttribute(SearchResult.class).getData().getMatchedURIs().get(0); // get the matrix parameter only from the last segment PathSegment segment = segments.get(segments.size() - 1); MultivaluedMap<String, String> matrixParameters = segment.getMatrixParameters(); List<String> values = matrixParameters.get(getName()); if (values != null) { allValues.addAll(values); } if (allValues.size() == 0 && hasDefaultValue()) { allValues.add(getDefaultValue()); } decodeValues(allValues); // we found matrix parameters with the specified name try { return getConvertor().convert(allValues); } catch (ConversionException e) { throw new WebApplicationException(e.getCause(), Response.Status.NOT_FOUND); } } }
@Override public Object getValue(RuntimeContext runtimeContext) throws IOException { if (runtimeContext == null) { return null; } // for all headers HttpHeaders httpHeaders = runtimeContext.getHttpHeaders(); List<String> values = httpHeaders.getRequestHeader(getName()); if (values == null) { values = new LinkedList<String>(); } if (values.size() == 0 && hasDefaultValue()) { values.add(getDefaultValue()); } try { return getConvertor().convert(values); } catch (ConversionException e) { logger.error(Messages.getMessage("conversionError", this, values), e); throw new WebApplicationException(e.getCause(), Response.Status.BAD_REQUEST); } } }
return getConvertor().convert(values); } catch (ConversionException e) {
return getConvertor().convert(value); } catch (ConversionException e) { logger.error(Messages.getMessage("conversionError", this, value), e);