Java Code Examples for org.apache.directory.api.ldap.model.message.ModifyRequest#getName()

The following examples show how to use org.apache.directory.api.ldap.model.message.ModifyRequest#getName() . 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: AddModifyRequestAttribute.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void action( LdapMessageContainer<ModifyRequest> container ) throws DecoderException
{
    ModifyRequest modifyRequest = container.getMessage();

    TLV tlv = container.getCurrentTLV();

    // Store the value. It can't be null
    String type;

    if ( tlv.getLength() == 0 )
    {
        String msg = I18n.err( I18n.ERR_05123_TYPE_CANT_BE_NULL );
        LOG.error( msg );

        ModifyResponseImpl response = new ModifyResponseImpl( modifyRequest.getMessageId() );
        throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX,
            modifyRequest.getName(), null );
    }
    else
    {
        type = Strings.utf8ToString( tlv.getValue().getData() );
        Attribute currentAttribute = new DefaultAttribute( type );
        container.setCurrentAttribute( currentAttribute );
        container.getCurrentModification().setAttribute( currentAttribute );
    }

    // We can have an END transition if the operation was INCREMENT
    if ( container.getCurrentModification().getOperation() == ModificationOperation.INCREMENT_ATTRIBUTE )
    {
        container.setGrammarEndAllowed( true );
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_05128_MODIFYING_TYPE, type ) );
    }
}
 
Example 2
Source File: ModifyRequestDsml.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    ModifyRequest request = getDecorated();

    // Dn
    if ( request.getName() != null )
    {
        element.addAttribute( "dn", request.getName().getName() );
    }

    // Modifications
    Collection<Modification> modifications = request.getModifications();

    for ( Modification modification : modifications )
    {
        Element modElement = element.addElement( "modification" );

        if ( modification.getAttribute() != null )
        {
            modElement.addAttribute( "name", modification.getAttribute().getId() );

            for ( Value value : modification.getAttribute() )
            {
                if ( value.getString() != null )
                {
                    if ( ParserUtils.needsBase64Encoding( value.getString() ) )
                    {
                        Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
                        Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
                        element.getDocument().getRootElement().add( xsdNamespace );
                        element.getDocument().getRootElement().add( xsiNamespace );

                        Element valueElement = modElement.addElement( "value" ).addText(
                            ParserUtils.base64Encode( value.getString() ) );
                        valueElement.addAttribute( new QName( "type", xsiNamespace ), "xsd:"
                            + ParserUtils.BASE64BINARY );
                    }
                    else
                    {
                        modElement.addElement( "value" ).setText( value.getString() );
                    }
                }
            }
        }

        ModificationOperation operation = modification.getOperation();

        if ( operation == ModificationOperation.ADD_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "add" );
        }
        else if ( operation == ModificationOperation.REPLACE_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "replace" );
        }
        else if ( operation == ModificationOperation.REMOVE_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "delete" );
        }
        else if ( operation == ModificationOperation.INCREMENT_ATTRIBUTE )
        {
            modElement.addAttribute( "operation", "increment" );
        }
    }

    return element;
}