Class ConverterHelper

    • Constructor Summary

      Constructors 
      Constructor Description
      ConverterHelper()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.List<java.lang.Class<?>> addObjectClass​(java.util.List<java.lang.Class<?>> objectClasses, java.lang.Class<?> objectClass)
      Adds an object class to the given list.
      protected java.util.List<VariantInfo> addVariant​(java.util.List<VariantInfo> variants, VariantInfo userVariant)
      Adds a variant to the given list.
      java.util.List<VariantInfo> addVariants​(java.lang.Class<?> sourceClass, org.restlet.representation.Variant targetVariant, java.util.List<VariantInfo> variants)
      Returns the list of variants that can be converted from a given object class.
      abstract java.util.List<java.lang.Class<?>> getObjectClasses​(org.restlet.representation.Variant source)
      Returns the list of object classes that can be converted from a given variant.
      abstract java.util.List<VariantInfo> getVariants​(java.lang.Class<?> source)
      Returns the list of variants that can be converted from a given object class.
      java.util.List<VariantInfo> getVariants​(java.lang.Class<?> sourceClass, org.restlet.representation.Variant targetVariant)
      Returns the list of variants that can be converted from a given object class by a specific converter helper.
      abstract float score​(java.lang.Object source, org.restlet.representation.Variant target, org.restlet.resource.Resource resource)
      Scores the affinity of this helper with the source class.
      abstract <T> float score​(org.restlet.representation.Representation source, java.lang.Class<T> target, org.restlet.resource.Resource resource)
      Scores the affinity of this helper with the source class.
      abstract <T> T toObject​(org.restlet.representation.Representation source, java.lang.Class<T> target, org.restlet.resource.Resource resource)
      Converts a Representation into a regular Java object.
      abstract org.restlet.representation.Representation toRepresentation​(java.lang.Object source, org.restlet.representation.Variant target, org.restlet.resource.Resource resource)
      Converts a regular Java object into a Representation.
      <T> void updatePreferences​(java.util.List<org.restlet.data.Preference<org.restlet.data.MediaType>> preferences, java.lang.Class<T> entity)
      Updates the preferences of the given ClientInfo object with conversion capabilities for the given entity class.
      void updatePreferences​(java.util.List<org.restlet.data.Preference<org.restlet.data.MediaType>> preferences, org.restlet.data.MediaType mediaType, float score)
      Updates the preferences of the given ClientInfo object with conversion capabilities for the given entity class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConverterHelper

        public ConverterHelper()
    • Method Detail

      • addObjectClass

        protected java.util.List<java.lang.Class<?>> addObjectClass​(java.util.List<java.lang.Class<?>> objectClasses,
                                                                    java.lang.Class<?> objectClass)
        Adds an object class to the given list. Creates a new list if necessary.
        Parameters:
        objectClasses - The object classes list to update or null.
        objectClass - The object class to add.
        Returns:
        The input object classes list or a new one.
      • addVariant

        protected java.util.List<VariantInfo> addVariant​(java.util.List<VariantInfo> variants,
                                                         VariantInfo userVariant)
        Adds a variant to the given list. Creates a new list if necessary.
        Parameters:
        variants - The variants list to update or null.
        userVariant - The variant to add if not null.
        Returns:
        The input variants list or a new one.
      • addVariants

        public java.util.List<VariantInfo> addVariants​(java.lang.Class<?> sourceClass,
                                                       org.restlet.representation.Variant targetVariant,
                                                       java.util.List<VariantInfo> variants)
                                                throws java.io.IOException
        Returns the list of variants that can be converted from a given object class.
        Parameters:
        sourceClass - The source class.
        targetVariant - The expected representation metadata.
        variants - The variants list to update.
        Returns:
        The list of variants that can be converted from a given object class.
        Throws:
        java.io.IOException
      • getObjectClasses

        public abstract java.util.List<java.lang.Class<?>> getObjectClasses​(org.restlet.representation.Variant source)
        Returns the list of object classes that can be converted from a given variant.
        Parameters:
        source - The source variant.
        Returns:
        The list of object class that can be converted.
      • getVariants

        public abstract java.util.List<VariantInfo> getVariants​(java.lang.Class<?> source)
                                                         throws java.io.IOException
        Returns the list of variants that can be converted from a given object class. The preferred variant should be set in first position.
        Parameters:
        source - The source object class.
        Returns:
        The list of variants that can be converted.
        Throws:
        java.io.IOException
      • getVariants

        public java.util.List<VariantInfo> getVariants​(java.lang.Class<?> sourceClass,
                                                       org.restlet.representation.Variant targetVariant)
                                                throws java.io.IOException
        Returns the list of variants that can be converted from a given object class by a specific converter helper.
        Parameters:
        sourceClass - The source class.
        targetVariant - The expected representation metadata.
        Returns:
        The list of variants that can be converted.
        Throws:
        java.io.IOException
      • score

        public abstract float score​(java.lang.Object source,
                                    org.restlet.representation.Variant target,
                                    org.restlet.resource.Resource resource)
        Scores the affinity of this helper with the source class.
        Parameters:
        source - The source object to convert.
        target - The expected representation metadata.
        resource - The calling resource.
        Returns:
        The affinity score of this helper.
      • score

        public abstract <T> float score​(org.restlet.representation.Representation source,
                                        java.lang.Class<T> target,
                                        org.restlet.resource.Resource resource)
        Scores the affinity of this helper with the source class.
        Type Parameters:
        T - The expected class of the Java object.
        Parameters:
        source - The source representation to convert.
        target - The expected class of the Java object.
        resource - The calling resource.
        Returns:
        The affinity score of this helper.
      • toObject

        public abstract <T> T toObject​(org.restlet.representation.Representation source,
                                       java.lang.Class<T> target,
                                       org.restlet.resource.Resource resource)
                                throws java.io.IOException
        Converts a Representation into a regular Java object.
        Type Parameters:
        T - The expected class of the Java object.
        Parameters:
        source - The source representation to convert.
        target - The expected class of the Java object.
        resource - The calling resource.
        Returns:
        The converted Java object.
        Throws:
        java.io.IOException
      • toRepresentation

        public abstract org.restlet.representation.Representation toRepresentation​(java.lang.Object source,
                                                                                   org.restlet.representation.Variant target,
                                                                                   org.restlet.resource.Resource resource)
                                                                            throws java.io.IOException
        Converts a regular Java object into a Representation.
        Parameters:
        source - The source object to convert.
        target - The expected representation metadata.
        resource - The calling resource.
        Returns:
        The converted representation.
        Throws:
        java.io.IOException
      • updatePreferences

        public <T> void updatePreferences​(java.util.List<org.restlet.data.Preference<org.restlet.data.MediaType>> preferences,
                                          java.lang.Class<T> entity)
        Updates the preferences of the given ClientInfo object with conversion capabilities for the given entity class.
        Parameters:
        preferences - The media type preferences.
        entity - The entity class to convert.
      • updatePreferences

        public void updatePreferences​(java.util.List<org.restlet.data.Preference<org.restlet.data.MediaType>> preferences,
                                      org.restlet.data.MediaType mediaType,
                                      float score)
        Updates the preferences of the given ClientInfo object with conversion capabilities for the given entity class.
        Parameters:
        preferences - The media type preferences.
        mediaType - The media type to update to add to the preferences.
        score - The media type score to use as a quality score.