Package io.jans.scim.model.scim2
Class CustomAttributes
- java.lang.Object
-
- io.jans.scim.model.scim2.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 thegetValue
/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
ortext
, you may useString
, fornumeric
sensible choices areInteger
orDouble
, forboolean
useBoolean
, and fordate
you may useDate
.See also:
BaseScimResource.addCustomAttributes(CustomAttributes)
andBaseScimResource.getCustomAttributes(String)
.
-
-
Constructor Summary
Constructors Constructor Description CustomAttributes(String uri)
Constructs an instance of this class to store the attribute values associated to an extension whose URI is supplied.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>
getAttributeNames()
Returns the names of all attributes currently part of this instance object.String
getUri()
Retrieves the URI to which thisCustomAttributes
instance is tied.<T> T
getValue(String name, Class<T> cls)
Returns the value of a custom attribute as an instance of the specified type.<T> List<T>
getValues(String name, Class<T> cls)
Returns the values of a multi-valued custom attribute as aList
of objects of the specified type.void
remove(String name)
Removes an attribute (and associated value) from this objectvoid
setAttribute(String name, Boolean value)
Sets the value of an attribute using aBoolean
.void
setAttribute(String name, Double value)
Sets the value of an attribute using aDouble
.void
setAttribute(String name, Integer value)
Sets the value of an attribute using anInteger
.void
setAttribute(String name, String value)
Sets the value of an attribute using aString
.void
setAttribute(String name, Date value)
Sets the value of an attribute using ajava.util.Date
.void
setAttribute(String name, List<?> values)
Sets the value of an attribute using aList
of objects.
-
-
-
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 thisCustomAttributes
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 aString
.- Parameters:
name
- Name of attributevalue
- 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 aBoolean
.- Parameters:
name
- Name of attributevalue
- 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 aDouble
.- Parameters:
name
- Name of attributevalue
- 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 anInteger
.- Parameters:
name
- Name of attributevalue
- 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 ajava.util.Date
.- Parameters:
name
- Name of attributevalue
- 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 aList
of objects.- Parameters:
name
- Name of attributevalues
- 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 aList
of objects of the specified type. If you are not sure about the data type of the attribute, useString
for type parameter T: in this casetoString
is used to generate a representation.- Type Parameters:
T
- Type parameter for cls- Parameters:
name
- The name of the custom attributecls
- 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, useString
for type parameter T: in this casetoString
is used to generate a representation.- Type Parameters:
T
- Type parameter for cls- Parameters:
name
- The name of the custom attributecls
- 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).
-
-