Class Variant

java.lang.Object
org.restlet.representation.Variant
Direct Known Subclasses:
RepresentationInfo, VariantInfo

public class Variant extends Object
Descriptor for available representations of a resource. It contains all the important metadata about a representation but is not able to actually serve the representation's content itself.

For this, you need to use on of the Representation subclasses.
Author:
Jerome Louvel
  • Constructor Details

    • Variant

      public Variant()
      Default constructor.
    • Variant

      public Variant(MediaType mediaType)
      Constructor.
      Parameters:
      mediaType - The media type.
    • Variant

      public Variant(MediaType mediaType, Language language)
      Constructor.
      Parameters:
      mediaType - The media type.
      language - The language.
  • Method Details

    • createClientInfo

      public ClientInfo createClientInfo()
      Creates a ClientInfo instance with preferences matching exactly the current variant.
      Returns:
      The new ClientInfo instance.
    • equals

      public boolean equals(Object other)
      Indicates if the current variant is equal to the given variant.
      Overrides:
      equals in class Object
      Parameters:
      other - The other variant.
      Returns:
      True if the current variant includes the other.
    • getCharacterSet

      public CharacterSet getCharacterSet()
      Returns the character set or null if not applicable. Note that when used with HTTP connectors, this property maps to the "Content-Type" header.
      Returns:
      The character set or null if not applicable.
    • getEncodings

      public List<Encoding> getEncodings()
      Returns the modifiable list of encodings applied to the entity-body. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null encoding to this list.

      Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.
      Returns:
      The list of encodings applied to the entity-body.
    • getLanguages

      public List<Language> getLanguages()
      Returns the modifiable list of languages. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null language to this list.

      Note that when used with HTTP connectors, this property maps to the "Content-Language" header.
      Returns:
      The list of languages.
    • getLocationRef

      public Reference getLocationRef()
      Returns an optional location reference. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.

      Note that when used with HTTP connectors, this property maps to the "Content-Location" header.
      Returns:
      The identifier.
    • getMediaType

      public MediaType getMediaType()
      Returns the media type.

      Note that when used with HTTP connectors, this property maps to the "Content-Type" header.
      Returns:
      The media type.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • includes

      public boolean includes(Variant other)
      Indicates if the current variant includes the given variant.
      Parameters:
      other - The other variant.
      Returns:
      True if the current variant includes the other.
    • isCompatible

      public boolean isCompatible(Variant other)
      Indicates if the current variant is compatible with the given variant.
      Parameters:
      other - The other variant.
      Returns:
      True if the current variant is compatible with the other.
    • setCharacterSet

      public void setCharacterSet(CharacterSet characterSet)
      Sets the character set or null if not applicable.

      Note that when used with HTTP connectors, this property maps to the "Content-Type" header.
      Parameters:
      characterSet - The character set or null if not applicable.
    • setEncodings

      public void setEncodings(List<Encoding> encodings)
      Sets the list of encodings applied to the entity-body.

      Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.
      Parameters:
      encodings - The list of encodings applied to the entity-body.
    • setLanguages

      public void setLanguages(List<Language> languages)
      Sets the list of languages.

      Note that when used with HTTP connectors, this property maps to the "Content-Language" header.
      Parameters:
      languages - The list of languages.
    • setLocationRef

      public void setLocationRef(Reference location)
      Sets the optional identifier. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.

      Note that when used with HTTP connectors, this property maps to the "Content-Location" header.
      Parameters:
      location - The location reference.
    • setLocationRef

      public void setLocationRef(String locationUri)
      Sets the identifier from a URI string.

      Note that when used with HTTP connectors, this property maps to the "Content-Location" header.
      Parameters:
      locationUri - The location URI to parse.
    • setMediaType

      public void setMediaType(MediaType mediaType)
      Sets the media type.

      Note that when used with HTTP connectors, this property maps to the "Content-Type" header.
      Parameters:
      mediaType - The media type.
    • toString

      public String toString()
      Overrides:
      toString in class Object