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