@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { List<? extends Variant> variants; try { Variant targetVariant = new Variant(toRestletMediaType(mediaType)); variants = getConverterService().getVariants(type, targetVariant); } catch (IOException e) { throw new ResourceException(e); } return (variants != null) && !variants.isEmpty(); }
/** * Returns a list of request variants based on the annotation value. * * @param metadataService * The metadata service to use. * @return A list of request variants. * @throws IOException */ @SuppressWarnings("unchecked") public List<Variant> getRequestVariants(MetadataService metadataService, org.restlet.service.ConverterService converterService) throws IOException { List<Variant> result = null; Class<?>[] classes = getJavaInputTypes(); if (classes != null && classes.length >= 1) { result = getVariants(metadataService, getInput()); if (result == null) { Class<?> inputClass = classes[0]; if (inputClass != null) { result = (List<Variant>) converterService.getVariants( inputClass, null); } } } return result; }
/** * Returns a list of response variants based on the annotation value. * * @param metadataService * The metadata service to use. * @param converterService * The converter service to use. * @return A list of response variants. * @throws IOException */ @SuppressWarnings("unchecked") public List<Variant> getResponseVariants(MetadataService metadataService, org.restlet.service.ConverterService converterService) throws IOException { List<Variant> result = null; if ((getJavaOutputType() != null) && (getJavaOutputType() != void.class) && (getJavaOutputType() != Void.class)) { result = getVariants(metadataService, getOutput()); if (result == null) { result = (List<Variant>) converterService.getVariants( getJavaOutputType(), null); } } return result; }
List<? extends Variant> entityVariants; try { entityVariants = cs.getVariants(entity.getClass(), null); request.setEntity(toRepresentation( entity,