Class AttributeBuilder
- java.lang.Object
-
- se.litsec.opensaml.core.AbstractSAMLObjectBuilder<Attribute>
-
- se.litsec.opensaml.saml2.attribute.AttributeBuilder
-
- All Implemented Interfaces:
SAMLObjectBuilder<Attribute>
public class AttributeBuilder extends AbstractSAMLObjectBuilder<Attribute>
Implements the build pattern to createAttributeobjects.- Author:
- Martin Lindström (martin.lindstrom@litsec.se)
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_NAME_FORMATThe default name format for the attribute being built.
-
Constructor Summary
Constructors Constructor Description AttributeBuilder(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(Attribute template)Constructor setting up the builder given an attribute template.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Attributebuild()Returns theAttributeobject that has been built.static AttributeBuilderbuilder(InputStream resource)Static utility method that creates aAttributeBuildergiven a template attribute read from an input stream.static AttributeBuilderbuilder(String name)Static utility method that creates a defaultAttributeBuilder.static AttributeBuilderbuilder(Attribute attribute)Static utility method that creates aAttributeBuildergiven a template attribute.static <T extends XMLObject>
TcreateValueObject(Class<T> clazz)Creates anAttributeValueobject of the given class.static <T extends XMLObject>
TcreateValueObject(QName schemaType, Class<T> clazz)Creates anAttributeValueobject of the given class and schema type.AttributeBuilderfriendlyName(String friendlyName)Assigns the attribute friendly name.protected Class<Attribute>getObjectType()Returns the object type.AttributeBuildername(String name)Assigns the attribute name.AttributeBuildernameFormat(String nameFormat)Assigns the attribute name format.AttributeBuildervalue(String... values)Assigns one (or more) attribute string values.AttributeBuildervalue(List<String> values)<T extends XMLObject>
AttributeBuildervalue(T value)Assigns an attribute value.-
Methods inherited from class se.litsec.opensaml.core.AbstractSAMLObjectBuilder
getDefaultElementName, object
-
-
-
-
Field Detail
-
DEFAULT_NAME_FORMAT
public static final String DEFAULT_NAME_FORMAT
The default name format for the attribute being built.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AttributeBuilder
public AttributeBuilder(String name)
Constructor setting the attribute name.- Parameters:
name- the attribute name
-
AttributeBuilder
public AttributeBuilder(Attribute template) throws MarshallingException, UnmarshallingException
Constructor setting up the builder given an attribute template.- Parameters:
template- the attribute template- Throws:
UnmarshallingException- for unmarshalling errorsMarshallingException- for marshalling errors- See Also:
AbstractSAMLObjectBuilder(org.opensaml.saml.common.SAMLObject)
-
AttributeBuilder
public AttributeBuilder(InputStream resource) throws XMLParserException, UnmarshallingException
Constructor setting up the builder with a template attribute that is read from an input stream.- Parameters:
resource- the attribute template- Throws:
UnmarshallingException- for unmarshalling errorsXMLParserException- for XML parsing errors- See Also:
AbstractSAMLObjectBuilder(InputStream)
-
-
Method Detail
-
builder
public static AttributeBuilder builder(String name)
Static utility method that creates a defaultAttributeBuilder.- Parameters:
name- the attribute name- Returns:
- an AttributeBuilder instance.
- See Also:
AttributeBuilder(String)
-
builder
public static AttributeBuilder builder(Attribute attribute) throws MarshallingException, UnmarshallingException
Static utility method that creates aAttributeBuildergiven a template attribute.- Parameters:
attribute- the attribute template- Returns:
- an attribute builder
- Throws:
UnmarshallingException- for unmarshalling errorsMarshallingException- for marshalling errors
-
builder
public static AttributeBuilder builder(InputStream resource) throws XMLParserException, UnmarshallingException
Static utility method that creates aAttributeBuildergiven a template attribute read from an input stream.- Parameters:
resource- the attribute template- Returns:
- an attribute builder
- Throws:
UnmarshallingException- for unmarshalling errorsXMLParserException- for XML parsing errors
-
build
public Attribute build()
Returns theAttributeobject that has been built. If theNameFormatattribute has not been assigned, the method will inject the default value ("urn:oasis:names:tc:SAML:2.0:attrname-format:uri").- Specified by:
buildin interfaceSAMLObjectBuilder<Attribute>- Overrides:
buildin classAbstractSAMLObjectBuilder<Attribute>- Returns:
- the built object
-
name
public AttributeBuilder name(String name)
Assigns the attribute name.- Parameters:
name- the attribute name- Returns:
- the builder
-
friendlyName
public AttributeBuilder friendlyName(String friendlyName)
Assigns the attribute friendly name.- Parameters:
friendlyName- the friendly name- Returns:
- the builder
-
nameFormat
public AttributeBuilder nameFormat(String nameFormat)
Assigns the attribute name format.- Parameters:
nameFormat- the name format URI- Returns:
- the builder
-
value
public AttributeBuilder value(String... values)
Assigns one (or more) attribute string values.Note: if
nullis passed as a parameter, any previous attribute values are cleared.- Parameters:
values- the string value(s) to add- Returns:
- the builder
-
value
public AttributeBuilder value(List<String> values)
- Parameters:
values- the string value(s) to add- Returns:
- the builder
- See Also:
value(String...)
-
value
public <T extends 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
public static <T extends XMLObject> T createValueObject(Class<T> clazz)
Creates anAttributeValueobject of the given class. The type of the attribute value will be the field that is declared asTYPE_NAMEof 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(QName, Class)
-
createValueObject
public static <T extends XMLObject> T createValueObject(QName schemaType, Class<T> clazz)
Creates anAttributeValueobject 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:
createValueObject(Class)
-
getObjectType
protected Class<Attribute> getObjectType()
Returns the object type.- Specified by:
getObjectTypein classAbstractSAMLObjectBuilder<Attribute>- Returns:
- the object type
-
-