Class AttributeUtils


  • public class AttributeUtils
    extends Object
    Utility methods for handling attributes and attribute values.
    Author:
    Martin Lindström (martin.lindstrom@litsec.se)
    • Method Detail

      • createAttribute

        public static Attribute createAttribute​(String name,
                                                String friendlyName,
                                                String nameFormat)
        Utility method that creates an Attribute given its name, friendly name and name format.
        Parameters:
        name - the attribute name
        friendlyName - the attribute friendly name (may be null)
        nameFormat - the name format
        Returns:
        an Attribute object
      • createAttributeValueObject

        public static <T extends XMLObject> T createAttributeValueObject​(Class<T> clazz)
        Creates an AttributeValue object of the given class. The type of the attribute value will be the field that is declared as TYPE_NAME of the given class.

        After the object has been constructed, its setter methods should be called to setup the value object before adding it to the attribute itself.

        Type Parameters:
        T - the type
        Parameters:
        clazz - the type of attribute value
        Returns:
        the attribute value
        See Also:
        createAttributeValueObject(QName, Class)
      • createAttributeValueObject

        public static <T extends XMLObject> T createAttributeValueObject​(QName schemaType,
                                                                         Class<T> clazz)
        Creates an AttributeValue object of the given class and schema type.

        After the object has been constructed, its setter methods should be called to setup the value object before adding it to the attribute itself.

        Type Parameters:
        T - the type
        Parameters:
        schemaType - the schema type that should be assigned to the attribute value, i.e., xsi:type="eidas:CurrentFamilyNameType"
        clazz - the type of the attribute value
        Returns:
        the attribute value
        See Also:
        createAttributeValueObject(Class)
      • addAttributeValue

        public static <T extends XMLObject> void addAttributeValue​(Attribute attribute,
                                                                   T value)
        Utility method that adds an XML object as a value to an Attribute.

        Example:

        
         Attribute attr = 
           AttributeUtils.createAttribute("http://eidas.europa.eu/attributes/naturalperson/CurrentFamilyName", "FamilyName");
         CurrentFamilyNameType value = AttributeUtils.createAttributeValueObject(CurrentFamilyNameType.class);
         value.setValue("Lindström");
         AttributeUtils.addAttributeValue(attr, value);
         
        Type Parameters:
        T - the type
        Parameters:
        attribute - the attribute to update
        value - the value to add