001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    https://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.api.dsmlv2.response;
021
022
023import org.apache.directory.api.dsmlv2.DsmlLiterals;
024import org.apache.directory.api.ldap.codec.api.LdapApiService;
025import org.apache.directory.api.ldap.model.message.AddResponse;
026import org.apache.directory.api.ldap.model.message.AddResponseImpl;
027import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
028import org.dom4j.Element;
029import org.dom4j.tree.DefaultElement;
030
031
032/**
033 * DSML Decorator for AddResponse
034 *
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 */
037public class AddResponseDsml extends AbstractResultResponseDsml<AddResponse>
038    implements AddResponse
039{
040    /**
041     * Creates a new getDecoratedMessage() of AddResponseDsml.
042     * 
043     * @param codec The LDAP Service to use
044     */
045    public AddResponseDsml( LdapApiService codec )
046    {
047        super( codec, new AddResponseImpl() );
048    }
049
050
051    /**
052     * Creates a new getDecoratedMessage() of AddResponseDsml.
053     *
054     * @param codec The LDAP Service to use
055     * @param ldapMessage the message to decorate
056     */
057    public AddResponseDsml( LdapApiService codec, AddResponse ldapMessage )
058    {
059        super( codec, ldapMessage );
060    }
061
062
063    /**
064     * {@inheritDoc}
065     */
066    @Override
067    public MessageTypeEnum getType()
068    {
069        return getDecorated().getType();
070    }
071
072
073    /**
074     * {@inheritDoc}
075     */
076    @Override
077    public Element toDsml( Element root )
078    {
079        Element element;
080
081        if ( root != null )
082        {
083            element = root.addElement( DsmlLiterals.ADD_RESPONSE );
084        }
085        else
086        {
087            element = new DefaultElement( DsmlLiterals.ADD_RESPONSE );
088        }
089
090        LdapResultDsml ldapResultDsml = new LdapResultDsml( getCodecService(),
091            getDecorated().getLdapResult(), getDecorated() );
092        ldapResultDsml.toDsml( element );
093        return element;
094    }
095}