Class AttributeBuilder

java.lang.Object
se.swedenconnect.opensaml.common.builder.AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
se.swedenconnect.opensaml.saml2.attribute.AttributeBuilder
All Implemented Interfaces:
SAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>

public class AttributeBuilder extends AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
Implements the build pattern to create Attribute objects.
Author:
Martin Lindström (martin@idsec.se)
  • Field Details Link icon

    • DEFAULT_NAME_FORMAT Link icon

      public static final String DEFAULT_NAME_FORMAT
      The default name format for the attribute being built.
      See Also:
  • Constructor Details Link icon

    • AttributeBuilder Link icon

      public AttributeBuilder(String name)
      Constructor setting the attribute name.
      Parameters:
      name - the attribute name
    • AttributeBuilder Link icon

      public AttributeBuilder(org.opensaml.saml.saml2.core.Attribute template) throws org.opensaml.core.xml.io.MarshallingException, org.opensaml.core.xml.io.UnmarshallingException
      Constructor setting up the builder given an attribute template.
      Parameters:
      template - the attribute template
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      org.opensaml.core.xml.io.MarshallingException - for marshalling errors
      See Also:
    • AttributeBuilder Link icon

      public AttributeBuilder(InputStream resource) throws net.shibboleth.shared.xml.XMLParserException, org.opensaml.core.xml.io.UnmarshallingException
      Constructor setting up the builder with a template attribute that is read from an input stream.
      Parameters:
      resource - the attribute template
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      net.shibboleth.shared.xml.XMLParserException - for XML parsing errors
      See Also:
  • Method Details Link icon

    • builder Link icon

      public static AttributeBuilder builder(String name)
      Static utility method that creates a default AttributeBuilder.
      Parameters:
      name - the attribute name
      Returns:
      an AttributeBuilder instance.
      See Also:
    • builder Link icon

      public static AttributeBuilder builder(org.opensaml.saml.saml2.core.Attribute attribute) throws org.opensaml.core.xml.io.MarshallingException, org.opensaml.core.xml.io.UnmarshallingException
      Static utility method that creates a AttributeBuilder given a template attribute.
      Parameters:
      attribute - the attribute template
      Returns:
      an attribute builder
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      org.opensaml.core.xml.io.MarshallingException - for marshalling errors
    • builder Link icon

      public static AttributeBuilder builder(InputStream resource) throws net.shibboleth.shared.xml.XMLParserException, org.opensaml.core.xml.io.UnmarshallingException
      Static utility method that creates a AttributeBuilder given a template attribute read from an input stream.
      Parameters:
      resource - the attribute template
      Returns:
      an attribute builder
      Throws:
      org.opensaml.core.xml.io.UnmarshallingException - for unmarshalling errors
      net.shibboleth.shared.xml.XMLParserException - for XML parsing errors
    • build Link icon

      public org.opensaml.saml.saml2.core.Attribute build()
      Returns the Attribute object that has been built. If the NameFormat attribute has not been assigned, the method will inject the default value ("urn:oasis:names:tc:SAML:2.0:attrname-format:uri").
      Specified by:
      build in interface SAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
      Overrides:
      build in class AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
      Returns:
      the built object
    • name Link icon

      public AttributeBuilder name(String name)
      Assigns the attribute name.
      Parameters:
      name - the attribute name
      Returns:
      the builder
    • friendlyName Link icon

      public AttributeBuilder friendlyName(String friendlyName)
      Assigns the attribute friendly name.
      Parameters:
      friendlyName - the friendly name
      Returns:
      the builder
    • nameFormat Link icon

      public AttributeBuilder nameFormat(String nameFormat)
      Assigns the attribute name format.
      Parameters:
      nameFormat - the name format URI
      Returns:
      the builder
    • value Link icon

      public AttributeBuilder value(String... values)
      Assigns one (or more) attribute string values.

      Note: if null is passed as a parameter, any previous attribute values are cleared.

      Parameters:
      values - the string value(s) to add
      Returns:
      the builder
    • value Link icon

      public AttributeBuilder value(List<String> values)
      Parameters:
      values - the string value(s) to add
      Returns:
      the builder
      See Also:
    • value Link icon

      public <T extends org.opensaml.core.xml.XMLObject> AttributeBuilder value(T value)
      Assigns an attribute value.
      Type Parameters:
      T - the value type
      Parameters:
      value - the value to add
      Returns:
      the builder
    • createValueObject Link icon

      public static <T extends org.opensaml.core.xml.XMLObject> T createValueObject(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.

      Note: For attribute having string values, there is no need to explictly create an attribute value. Instead the value(String...) method may be used directly.

      Type Parameters:
      T - the type
      Parameters:
      clazz - the type of attribute value
      Returns:
      the attribute value
      See Also:
    • createValueObject Link icon

      public static <T extends org.opensaml.core.xml.XMLObject> T createValueObject(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.

      Note: For attribute having string values, there is no need to explictly create an attribute value. Instead the value(String...) method may be used directly.

      Type Parameters:
      T - the type
      Parameters:
      schemaType - the schema type that should be assigned to the attribute value, i.e., xsi:type="ns:ValueType"
      clazz - the type of the attribute value
      Returns:
      the attribute value
      See Also:
    • getObjectType Link icon

      protected Class<org.opensaml.saml.saml2.core.Attribute> getObjectType()
      Returns the object type.
      Specified by:
      getObjectType in class AbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
      Returns:
      the object type