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 Summary
Modifier and TypeFieldDescriptionstatic final String
The default name format for the attribute being built. -
Constructor Summary
ConstructorDescriptionAttributeBuilder
(InputStream resource) Constructor setting up the builder with a template attribute that is read from an input stream.AttributeBuilder
(String name) Constructor setting the attribute name.AttributeBuilder
(org.opensaml.saml.saml2.core.Attribute template) Constructor setting up the builder given an attribute template. -
Method Summary
Modifier and TypeMethodDescriptionorg.opensaml.saml.saml2.core.Attribute
build()
Returns theAttribute
object that has been built.static AttributeBuilder
builder
(InputStream resource) Static utility method that creates aAttributeBuilder
given a template attribute read from an input stream.static AttributeBuilder
Static utility method that creates a defaultAttributeBuilder
.static AttributeBuilder
builder
(org.opensaml.saml.saml2.core.Attribute attribute) Static utility method that creates aAttributeBuilder
given a template attribute.static <T extends org.opensaml.core.xml.XMLObject>
TcreateValueObject
(Class<T> clazz) Creates anAttributeValue
object of the given class.static <T extends org.opensaml.core.xml.XMLObject>
TcreateValueObject
(QName schemaType, Class<T> clazz) Creates anAttributeValue
object of the given class and schema type.friendlyName
(String friendlyName) Assigns the attribute friendly name.protected Class
<org.opensaml.saml.saml2.core.Attribute> Returns the object type.Assigns the attribute name.nameFormat
(String nameFormat) Assigns the attribute name format.Assigns one (or more) attribute string values.<T extends org.opensaml.core.xml.XMLObject>
AttributeBuildervalue
(T value) Assigns an attribute value.Methods inherited from class se.swedenconnect.opensaml.common.builder.AbstractSAMLObjectBuilder
getDefaultElementName, object
-
Field Details
-
DEFAULT_NAME_FORMAT
The default name format for the attribute being built.- See Also:
-
-
Constructor Details
-
AttributeBuilder
Constructor setting the attribute name.- Parameters:
name
- the attribute name
-
AttributeBuilder
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 errorsorg.opensaml.core.xml.io.MarshallingException
- for marshalling errors- See Also:
-
AttributeBuilder
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 errorsnet.shibboleth.shared.xml.XMLParserException
- for XML parsing errors- See Also:
-
-
Method Details
-
builder
Static utility method that creates a defaultAttributeBuilder
.- Parameters:
name
- the attribute name- Returns:
- an AttributeBuilder instance.
- See Also:
-
builder
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 aAttributeBuilder
given a template attribute.- Parameters:
attribute
- the attribute template- Returns:
- an attribute builder
- Throws:
org.opensaml.core.xml.io.UnmarshallingException
- for unmarshalling errorsorg.opensaml.core.xml.io.MarshallingException
- for marshalling errors
-
builder
public static AttributeBuilder builder(InputStream resource) throws net.shibboleth.shared.xml.XMLParserException, org.opensaml.core.xml.io.UnmarshallingException Static utility method that creates aAttributeBuilder
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 errorsnet.shibboleth.shared.xml.XMLParserException
- for XML parsing errors
-
build
public org.opensaml.saml.saml2.core.Attribute build()Returns theAttribute
object that has been built. If theNameFormat
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 interfaceSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
- Overrides:
build
in classAbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
- Returns:
- the built object
-
name
Assigns the attribute name.- Parameters:
name
- the attribute name- Returns:
- the builder
-
friendlyName
Assigns the attribute friendly name.- Parameters:
friendlyName
- the friendly name- Returns:
- the builder
-
nameFormat
Assigns the attribute name format.- Parameters:
nameFormat
- the name format URI- Returns:
- the builder
-
value
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
- Parameters:
values
- the string value(s) to add- Returns:
- the builder
- See Also:
-
value
Assigns an attribute value.- Type Parameters:
T
- the value type- Parameters:
value
- the value to add- Returns:
- the builder
-
createValueObject
Creates anAttributeValue
object of the given class. The type of the attribute value will be the field that is declared asTYPE_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
public static <T extends org.opensaml.core.xml.XMLObject> T createValueObject(QName schemaType, Class<T> clazz) Creates anAttributeValue
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
Returns the object type.- Specified by:
getObjectType
in classAbstractSAMLObjectBuilder<org.opensaml.saml.saml2.core.Attribute>
- Returns:
- the object type
-