Class CustomAttributes


  • public class CustomAttributes
    extends Object
    A class used to store the values of custom attributes associated to a resource extension. This class is mainly targeted at users of Java client in order to specify/retrieve custom attributes.

    Use the setAttribute methods to associate one (or several) values to an attribute, and use the getValue/getValues methods to retrive those values when coming directly from service invocations.

    For both kind of operations (set/get) the data types used should ideally be consistent with the previously configured custom attributes at the Server. This allows your custom data to be successfully validated when sent to server, or to be correctly retrieved when reading a response.

    For photo or text, you may use String, for numeric sensible choices are Integer or Double, for boolean use Boolean, and for date you may use Date.

    See also: BaseScimResource.addCustomAttributes(CustomAttributes) and BaseScimResource.getCustomAttributes(String).

    • Constructor Detail

      • CustomAttributes

        public CustomAttributes​(String uri)
        Constructs an instance of this class to store the attribute values associated to an extension whose URI is supplied.
        Parameters:
        uri - A string denoting the URI of an existing extension
    • Method Detail

      • getUri

        public String getUri()
        Retrieves the URI to which this CustomAttributes instance is tied.
        Returns:
        The URI as a String
      • getAttributeNames

        public Set<String> getAttributeNames()
        Returns the names of all attributes currently part of this instance object.
        Returns:
        A Set of Strings
      • remove

        public void remove​(String name)
        Removes an attribute (and associated value) from this object
        Parameters:
        name - The name of the attribute to remove. Use the exactly the same String as when the attribute was set
      • setAttribute

        public void setAttribute​(String name,
                                 String value)
        Sets the value of an attribute using a String.
        Parameters:
        name - Name of attribute
        value - A String object. Must be non-null, or else it won't be stored
      • setAttribute

        public void setAttribute​(String name,
                                 Boolean value)
        Sets the value of an attribute using a Boolean.
        Parameters:
        name - Name of attribute
        value - A Boolean object. Must be non-null, or else it won't be stored
      • setAttribute

        public void setAttribute​(String name,
                                 Double value)
        Sets the value of an attribute using a Double.
        Parameters:
        name - Name of attribute
        value - A Double object. Must be non-null, or else it won't be stored
      • setAttribute

        public void setAttribute​(String name,
                                 Integer value)
        Sets the value of an attribute using an Integer.
        Parameters:
        name - Name of attribute
        value - An Integer object. Must be non-null, or else it won't be stored
      • setAttribute

        public void setAttribute​(String name,
                                 Date value)
        Sets the value of an attribute using a java.util.Date.
        Parameters:
        name - Name of attribute
        value - A Date object. Must be non-null, or else it won't be stored
      • setAttribute

        public void setAttribute​(String name,
                                 List<?> values)
        Sets the value of an attribute using a List of objects.
        Parameters:
        name - Name of attribute
        values - A non-empty, non-null list of values.
      • getValues

        public <T> List<T> getValues​(String name,
                                     Class<T> cls)
        Returns the values of a multi-valued custom attribute as a List of objects of the specified type. If you are not sure about the data type of the attribute, use String for type parameter T: in this case toString is used to generate a representation.
        Type Parameters:
        T - Type parameter for cls
        Parameters:
        name - The name of the custom attribute
        cls - Specifies the type utilized to read the attribute values
        Returns:
        null if the attribute is not known to this object, or if it was not possible to read any of its values using the type provided. Otherwise, a list of values associated to the attribute is returned (when the attribute is not multivalued, a singleton list is returned: use getValue to get atomic values instead).
      • getValue

        public <T> T getValue​(String name,
                              Class<T> cls)
        Returns the value of a custom attribute as an instance of the specified type. If you are not sure about the data type of the attribute, use String for type parameter T: in this case toString is used to generate a representation.
        Type Parameters:
        T - Type parameter for cls
        Parameters:
        name - The name of the custom attribute
        cls - Specifies the type utilized to read the attribute value
        Returns:
        null if the attribute is not known to this object, or if it was not possible to read its value using the type provided. Otherwise, the value associated to the attribute is returned (when the attribute is multivalued, only the first value found is taken into account: use getValues to get all values).