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.request;
021
022
023import org.apache.directory.api.ldap.codec.api.LdapApiService;
024import org.apache.directory.api.ldap.model.entry.Value;
025import org.apache.directory.api.ldap.model.message.CompareRequest;
026import org.apache.directory.api.ldap.model.message.CompareRequestImpl;
027import org.apache.directory.api.ldap.model.message.CompareResponse;
028import org.apache.directory.api.ldap.model.message.Control;
029import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
030import org.apache.directory.api.ldap.model.name.Dn;
031import org.dom4j.Element;
032
033
034/**
035 * DSML Decorator for CompareRequest
036 *
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 */
039public class CompareRequestDsml
040    extends AbstractResultResponseRequestDsml<CompareRequest, CompareResponse>
041    implements CompareRequest
042{
043    /**
044     * Creates a new getDecoratedMessage() of CompareRequestDsml.
045     * 
046     * @param codec The LDAP Service to use
047     */
048    public CompareRequestDsml( LdapApiService codec )
049    {
050        super( codec, new CompareRequestImpl() );
051    }
052
053
054    /**
055     * Creates a new getDecoratedMessage() of CompareRequestDsml.
056     *
057     * @param codec The LDAP Service to use
058     * @param ldapMessage the message to decorate
059     */
060    public CompareRequestDsml( LdapApiService codec, CompareRequest ldapMessage )
061    {
062        super( codec, ldapMessage );
063    }
064
065
066    /**
067     * {@inheritDoc}
068     */
069    public MessageTypeEnum getType()
070    {
071        return getDecorated().getType();
072    }
073
074
075    /**
076     * {@inheritDoc}
077     */
078    public Element toDsml( Element root )
079    {
080        Element element = super.toDsml( root );
081
082        CompareRequest request = getDecorated();
083
084        // Dn
085        if ( request.getName() != null )
086        {
087            element.addAttribute( "dn", request.getName().getName() );
088        }
089
090        // Assertion
091        Element assertionElement = element.addElement( "assertion" );
092        if ( request.getAttributeId() != null )
093        {
094            assertionElement.addAttribute( "name", request.getAttributeId() );
095        }
096        if ( request.getAssertionValue() != null )
097        {
098            assertionElement.addElement( "value" ).setText( request.getAssertionValue().getString() );
099        }
100
101        return element;
102    }
103
104
105    /**
106     * Get the entry to be compared
107     * 
108     * @return Returns the entry.
109     */
110    public Dn getName()
111    {
112        return getDecorated().getName();
113    }
114
115
116    /**
117     * Set the entry to be compared
118     * 
119     * @param entry The entry to set.
120     */
121    public CompareRequest setName( Dn entry )
122    {
123        getDecorated().setName( entry );
124
125        return this;
126    }
127
128
129    /**
130     * Set the assertion value
131     * 
132     * @param assertionValue The assertionValue to set.
133     */
134    public void setAssertionValue( Object assertionValue )
135    {
136        if ( assertionValue instanceof String )
137        {
138            getDecorated().setAssertionValue( ( String ) assertionValue );
139        }
140        else
141        {
142            getDecorated().setAssertionValue( ( byte[] ) assertionValue );
143        }
144    }
145
146
147    /**
148     * Get the attribute description
149     * 
150     * @return Returns the attributeDesc.
151     */
152    public String getAttributeDesc()
153    {
154        return getDecorated().getAttributeId();
155    }
156
157
158    /**
159     * Set the attribute description
160     * 
161     * @param attributeDesc The attributeDesc to set.
162     */
163    public void setAttributeDesc( String attributeDesc )
164    {
165        getDecorated().setAttributeId( attributeDesc );
166    }
167
168
169    /**
170     * {@inheritDoc}
171     */
172    public MessageTypeEnum getResponseType()
173    {
174        return getDecorated().getResponseType();
175    }
176
177
178    /**
179     * {@inheritDoc}
180     */
181    public CompareRequest setAssertionValue( String value )
182    {
183        getDecorated().setAssertionValue( value );
184
185        return this;
186    }
187
188
189    /**
190     * {@inheritDoc}
191     */
192    public CompareRequest setAssertionValue( byte[] value )
193    {
194        getDecorated().setAssertionValue( value );
195
196        return this;
197    }
198
199
200    /**
201     * {@inheritDoc}
202     */
203    public String getAttributeId()
204    {
205        return getDecorated().getAttributeId();
206    }
207
208
209    /**
210     * {@inheritDoc}
211     */
212    public CompareRequest setAttributeId( String attrId )
213    {
214        getDecorated().setAttributeId( attrId );
215
216        return this;
217    }
218
219
220    /**
221     * {@inheritDoc}
222     */
223    public Value<?> getAssertionValue()
224    {
225        return getDecorated().getAssertionValue();
226    }
227
228
229    /**
230     * {@inheritDoc}
231     */
232    public CompareRequest setMessageId( int messageId )
233    {
234        super.setMessageId( messageId );
235
236        return this;
237    }
238
239
240    /**
241     * {@inheritDoc}
242     */
243    public CompareRequest addControl( Control control )
244    {
245        return ( CompareRequest ) super.addControl( control );
246    }
247
248
249    /**
250     * {@inheritDoc}
251     */
252    public CompareRequest addAllControls( Control[] controls )
253    {
254        return ( CompareRequest ) super.addAllControls( controls );
255    }
256
257
258    /**
259     * {@inheritDoc}
260     */
261    public CompareRequest removeControl( Control control )
262    {
263        return ( CompareRequest ) super.removeControl( control );
264    }
265}