/** * Returns an {@link EmptyAttributeValue} or {@link ByteAttributeValue} as appropriate. This method should be * preferred over the constructor when the value may be null or empty. * * @param value to inspect * @return {@link EmptyAttributeValue} or {@link ByteAttributeValue} */ @Nonnull public static IdPAttributeValue<?> valueOf(@Nullable final byte[] value) { if (value == null) { return EmptyAttributeValue.NULL; } else if (value.length == 0) { return EmptyAttributeValue.ZERO_LENGTH; } else { return new ByteAttributeValue(value); } } }
/** {@inheritDoc} */ @Override @Nullable protected XMLObject encodeValue(@Nonnull final IdPAttribute attribute, @Nonnull final ByteAttributeValue value) throws AttributeEncodingException { return SAMLEncoderSupport.encodeByteArrayValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(), encodeType()); } }
/** {@inheritDoc} */ @Nullable protected IdPAttributeValue<?> decodeValue(@Nonnull final XMLObject object) { final String value = getStringValue(object); if (null == value) { return null; } final byte[] decoded = Base64Support.decode(value); if (null == decoded) { return null; } return ByteAttributeValue.valueOf(decoded); }
/** {@inheritDoc} */ @Override @Nullable protected XMLObject encodeValue(@Nonnull final IdPAttribute attribute, @Nonnull final ByteAttributeValue value) throws AttributeEncodingException { return SAMLEncoderSupport.encodeByteArrayValue(attribute, AttributeValue.DEFAULT_ELEMENT_NAME, value.getValue(), encodeType()); }