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 *    http://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.reponse;
021
022
023import org.apache.directory.api.ldap.codec.api.LdapApiService;
024import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
025import org.apache.directory.api.ldap.model.message.SearchResultDone;
026import org.apache.directory.api.ldap.model.message.SearchResultDoneImpl;
027import org.dom4j.Element;
028import org.dom4j.tree.DefaultElement;
029
030
031/**
032 * DSML Decorator for SearchResultDone
033 *
034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
035 */
036public class SearchResultDoneDsml extends AbstractResultResponseDsml<SearchResultDone>
037    implements SearchResultDone
038{
039    private static final String SEARCH_RESULT_DONE_TAG = "searchResultDone";
040
041
042    /**
043     * Creates a new getDecoratedMessage() of SearchResultDoneDsml.
044     */
045    public SearchResultDoneDsml( LdapApiService codec )
046    {
047        super( codec, new SearchResultDoneImpl() );
048    }
049
050
051    /**
052     * Creates a new getDecoratedMessage() of SearchResultDoneDsml.
053     *
054     * @param ldapMessage
055     *      the message to decorate
056     */
057    public SearchResultDoneDsml( LdapApiService codec, SearchResultDone ldapMessage )
058    {
059        super( codec, ldapMessage );
060    }
061
062
063    /**
064     * {@inheritDoc}
065     */
066    public MessageTypeEnum getType()
067    {
068        return getDecorated().getType();
069    }
070
071
072    /**
073     * {@inheritDoc}
074     */
075    public Element toDsml( Element root )
076    {
077        Element element = null;
078
079        if ( root != null )
080        {
081            element = root.addElement( SEARCH_RESULT_DONE_TAG );
082        }
083        else
084        {
085            element = new DefaultElement( SEARCH_RESULT_DONE_TAG );
086        }
087
088        LdapResultDsml ldapResultDsml =
089            new LdapResultDsml( getCodecService(), getDecorated().getLdapResult(), getDecorated() );
090        if ( ldapResultDsml != null )
091        {
092            ldapResultDsml.toDsml( element );
093        }
094
095        return element;
096    }
097}