Java Code Examples for org.apache.directory.api.ldap.model.schema.AttributeType#isRelaxed()

The following examples show how to use org.apache.directory.api.ldap.model.schema.AttributeType#isRelaxed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Value.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a schema aware StringValue with an initial user provided String value and 
 * its normalized Value
 *
 * @param attributeType the schema type associated with this StringValue
 * @param upValue the value to wrap
 * @param normValue the normalized value to wrap
 * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly
 * to the schema
 */
public Value( AttributeType attributeType, String upValue, String normValue ) throws LdapInvalidAttributeValueException
{
    init( attributeType );
    this.upValue = upValue;
    
    if ( upValue != null )
    {
        bytes = Strings.getBytesUtf8( upValue );
    }
    else
    {
        bytes = null;
    }
    
    this.normValue = normValue;
    
    if ( !attributeType.isRelaxed() )
    {
        // Check the value
        if ( attributeType.getSyntax().getSyntaxChecker() != null )
        {
            if ( !attributeType.getSyntax().getSyntaxChecker().isValidSyntax( upValue ) )
            {
                throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, 
                    I18n.err( I18n.ERR_13246_INVALID_VALUE_PER_SYNTAX ) );
            }
        }
        else
        {
            // We should always have a SyntaxChecker
            throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) );
        }
    }
    
    hashCode();
}
 
Example 2
Source File: Value.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a schema aware binary Value with an initial value.
 *
 * @param attributeType the schema type associated with this Value
 * @param upValue the value to wrap
 * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly
 * to the schema
 */
public Value( AttributeType attributeType, byte[] upValue ) throws LdapInvalidAttributeValueException
{
    init( attributeType );
    
    if ( upValue != null )
    {
        bytes = new byte[upValue.length];
        System.arraycopy( upValue, 0, bytes, 0, upValue.length );

        if ( isHR )
        {
            this.upValue = Strings.utf8ToString( upValue );
        }
    }
    else
    {
        bytes = null;
    }
    
    if ( ( attributeType != null ) && !attributeType.isRelaxed() )
    {
        // Check the value
        SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker();

        if ( syntaxChecker != null )
        {
            if ( !syntaxChecker.isValidSyntax( bytes ) )
            {
                throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, 
                    I18n.err( I18n.ERR_13246_INVALID_VALUE_PER_SYNTAX ) );
            }
        }
        else
        {
            // We should always have a SyntaxChecker
            throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) );
        }
    }

    hashCode();
}
 
Example 3
Source File: Value.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a schema aware StringValue with an initial user provided String value.
 *
 * @param attributeType the schema type associated with this StringValue
 * @param upValue the value to wrap
 * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly
 * to the schema
 */
public Value( AttributeType attributeType, String upValue ) throws LdapInvalidAttributeValueException
{
    init( attributeType );
    this.upValue = upValue;
    
    if ( upValue != null )
    {
        bytes = Strings.getBytesUtf8( upValue );
    }
    else
    {
        bytes = null;
    }
    
    try
    {
        computeNormValue();
    }
    catch ( LdapException le )
    {
        LOG.error( le.getMessage() );
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13247_INVALID_VALUE_CANT_NORMALIZE, upValue ) );
    }
    
    if ( !attributeType.isRelaxed() )
    {
        // Check the value
        LdapSyntax syntax = attributeType.getSyntax();
        
        if ( ( syntax != null ) && ( syntax.getSyntaxChecker() != null ) ) 
        {
            if ( !attributeType.getSyntax().getSyntaxChecker().isValidSyntax( upValue ) )
            {
                throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, 
                    I18n.err( I18n.ERR_13246_INVALID_VALUE_PER_SYNTAX ) );
            }
        }
        else
        {
            // We should always have a SyntaxChecker
            throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) );
        }
    }
    
    hashCode();
}
 
Example 4
Source File: Value.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a Value from an existing Value with an AttributeType
 *
 * @param attributeType the schema attribute type associated with this StringValue
 * @param value the original Value
 * @throws LdapInvalidAttributeValueException If the value is invalid
 */
public Value( AttributeType attributeType, Value value ) throws LdapInvalidAttributeValueException
{
    init( attributeType );
    
    if ( isHR )
    {
        if ( value.isHR )
        {
            this.upValue = value.upValue;
        }
        else
        {
            this.upValue = Strings.utf8ToString( value.bytes );
        }
    }

    try
    {
        computeNormValue();
    }
    catch ( LdapException le )
    {
        LOG.error( le.getMessage() );
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13247_INVALID_VALUE_CANT_NORMALIZE, upValue ) );
    }
    
    // Check the normValue
    if ( !attributeType.isRelaxed() )
    {
        // Check the value
        if ( attributeType.getSyntax().getSyntaxChecker() != null )
        {
            attributeType.getSyntax().getSyntaxChecker().isValidSyntax( value.normValue );
        }
        else
        {
            // We should always have a SyntaxChecker
            throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) );
        }
    }
        
    // We have to copy the byte[], they are just referenced by super.clone()
    if ( value.bytes != null )
    {
        bytes = new byte[value.bytes.length];
        System.arraycopy( value.bytes, 0, bytes, 0, value.bytes.length );
    }

    hashCode();
}