/** * Constructor. By default, it creates the necessary services. * * @param enabled * True if the service has been enabled. * */ public StatusService(boolean enabled) { this(enabled, new ConverterService(), new MetadataService(), new ConnegService()); // this.homeRef = new Reference("/"); }
/** * Converts a Representation into a regular Java object. * * @param source * The source representation to convert. * @return The converted Java object. * @throws IOException */ public Object toObject(Representation source) throws IOException { return toObject(source, null, null); }
/** * Converts a regular Java object into a Representation. The converter will * use the preferred variant of the selected converter. * * @param source * The source object to convert. * @return The converted representation. * @throws IOException */ public Representation toRepresentation(Object source) throws IOException { return toRepresentation(source, null, null); }
@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(); }
cs.updatePreferences(clientInfo.getAcceptedMediaTypes(), resultClass); List<? extends Variant> entityVariants; try { entityVariants = cs.getVariants(entity.getClass(), null); request.setEntity(toRepresentation( entity,
} else { result = put(getConverterService().applyPatch(get(), entity), variant);
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { Variant sourceVariant = new Variant(toRestletMediaType(mediaType)); List<Class<?>> classes = getConverterService().getObjectClasses(sourceVariant); for (Class<?> clazz : classes) { if (clazz.isAssignableFrom(type)) { return true; } } return false; }
getConverterService().start();
getConverterService().stop();
/** * 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; }
/** * Apply a patch entity to the current representation of the resource * retrieved by calling {@link #get()}. By default, the * {@link ConverterService#applyPatch(Representation, Representation)} method is used and then the * {@link #put(Representation)} method called. * * @param entity * The patch entity to apply. * @return The optional result entity. * @throws ResourceException * @see <a href="https://tools.ietf.org/html/rfc5789">HTTP PATCH method</a> */ protected Representation patch(Representation entity) throws ResourceException { AnnotationInfo annotationInfo; try { annotationInfo = getAnnotation(Method.PATCH); if (annotationInfo != null) { return doHandle(Method.PATCH, getQuery(), entity); } else { // Default implementation return put(getConverterService().applyPatch(get(), entity)); // doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED); } } catch (IOException e) { throw new ResourceException(e); } }
/** * Converts a regular Java object into a Representation. * * @param source * The source object to convert. * @param target * The target representation variant. * @return The converted representation. * @throws IOException */ public Representation toRepresentation(Object source, Variant target) throws IOException { return toRepresentation(source, target, null); }
/** * Returns the application's converter service or create a new one. * * @return The converter service. */ public org.restlet.service.ConverterService getConverterService() { org.restlet.service.ConverterService result = null; result = getApplication().getConverterService(); if (result == null) { result = new org.restlet.service.ConverterService(); } return result; }
/** * Returns the entity as a higher-level object. This object is created by * the Application's converter service. In order to use this method to * facilitate the parsing of entities, you need to set an instance of a * subclass of ConverterService onto your Restlet Application, overriding * the toObject(Representation) method. <br> * Note that this triggers the parsing of the entity. * * @return The entity as a higher-level object. * @see org.restlet.service.ConverterService * @deprecated Since 1.1, the ConverterService is deprecated, with no * replacement as it doesn't fit well with content negotiation. * Most users prefer to handle those conversion in Resource * subclasses. */ @Deprecated public Object getEntityAsObject() { return getConverterService().toObject(getEntity()); }
/** * 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; }
/** * Converts a regular Java object into a Representation. * * @param source * The source object to convert. * @param target * The target representation media type. * @return The converted representation. * @throws IOException */ public Representation toRepresentation(Object source, MediaType target) throws IOException { return toRepresentation(source, new Variant(target)); }
/** * Constructor. */ public ConverterProvider() { Application application = Application.getCurrent(); if (application != null) { this.converterService = application.getConverterService(); } if (this.converterService == null) { this.converterService = new ConverterService(); } }
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { Representation sourceRepresentation = new InputRepresentation(entityStream, toRestletMediaType(mediaType)); return getConverterService().toObject(sourceRepresentation, type, null); }
/** * Converts an object into a representation based on client preferences. * * @param source * The object to convert. * @param target * The target representation variant. * @return The wrapper representation. * @throws IOException */ public Representation toRepresentation(Object source, Variant target) throws IOException { Representation result = null; if (source != null) { org.restlet.service.ConverterService cs = getConverterService(); result = cs.toRepresentation(source, target, this); } return result; }
/** * Returns the converter service. * * @return The converter service. * @deprecated Since 1.1, the ConverterService is deprecated, with no * replacement as it doesn't fit well with content negotiation. * Most users prefer to handle those conversion in Resource * subclasses. */ @Deprecated private org.restlet.service.ConverterService getConverterService() { org.restlet.service.ConverterService result = null; final Application application = Application.getCurrent(); if (application != null) { result = application.getConverterService(); } else { result = new org.restlet.service.ConverterService(); } return result; }