View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    https://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.dsmlv2.request;
21  
22  
23  import org.apache.directory.api.dsmlv2.DsmlLiterals;
24  import org.apache.directory.api.ldap.codec.api.LdapApiService;
25  import org.apache.directory.api.ldap.model.entry.Value;
26  import org.apache.directory.api.ldap.model.message.CompareRequest;
27  import org.apache.directory.api.ldap.model.message.CompareRequestImpl;
28  import org.apache.directory.api.ldap.model.message.CompareResponse;
29  import org.apache.directory.api.ldap.model.message.Control;
30  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
31  import org.apache.directory.api.ldap.model.name.Dn;
32  import org.dom4j.Element;
33  
34  
35  /**
36   * DSML Decorator for CompareRequest
37   *
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  public class CompareRequestDsml
41      extends AbstractResultResponseRequestDsml<CompareRequest, CompareResponse>
42      implements CompareRequest
43  {
44      /**
45       * Creates a new getDecoratedMessage() of CompareRequestDsml.
46       * 
47       * @param codec The LDAP Service to use
48       */
49      public CompareRequestDsml( LdapApiService codec )
50      {
51          super( codec, new CompareRequestImpl() );
52      }
53  
54  
55      /**
56       * Creates a new getDecoratedMessage() of CompareRequestDsml.
57       *
58       * @param codec The LDAP Service to use
59       * @param ldapMessage the message to decorate
60       */
61      public CompareRequestDsml( LdapApiService codec, CompareRequest ldapMessage )
62      {
63          super( codec, ldapMessage );
64      }
65  
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public MessageTypeEnum getType()
72      {
73          return getDecorated().getType();
74      }
75  
76  
77      /**
78       * {@inheritDoc}
79       */
80      @Override
81      public Element toDsml( Element root )
82      {
83          Element element = super.toDsml( root );
84  
85          CompareRequest request = getDecorated();
86  
87          // Dn
88          if ( request.getName() != null )
89          {
90              element.addAttribute( DsmlLiterals.DN, request.getName().getName() );
91          }
92  
93          // Assertion
94          Element assertionElement = element.addElement( DsmlLiterals.ASSERTION );
95          if ( request.getAttributeId() != null )
96          {
97              assertionElement.addAttribute( DsmlLiterals.NAME, request.getAttributeId() );
98          }
99          if ( request.getAssertionValue() != null )
100         {
101             assertionElement.addElement( DsmlLiterals.VALUE ).setText( request.getAssertionValue().getString() );
102         }
103 
104         return element;
105     }
106 
107 
108     /**
109      * Get the entry to be compared
110      * 
111      * @return Returns the entry.
112      */
113     @Override
114     public Dn getName()
115     {
116         return getDecorated().getName();
117     }
118 
119 
120     /**
121      * Set the entry to be compared
122      * 
123      * @param entry The entry to set.
124      */
125     @Override
126     public CompareRequest setName( Dn entry )
127     {
128         getDecorated().setName( entry );
129 
130         return this;
131     }
132 
133 
134     /**
135      * Set the assertion value
136      * 
137      * @param assertionValue The assertionValue to set.
138      */
139     public void setAssertionValue( Object assertionValue )
140     {
141         if ( assertionValue instanceof String )
142         {
143             getDecorated().setAssertionValue( ( String ) assertionValue );
144         }
145         else
146         {
147             getDecorated().setAssertionValue( ( byte[] ) assertionValue );
148         }
149     }
150 
151 
152     /**
153      * Get the attribute description
154      * 
155      * @return Returns the attributeDesc.
156      */
157     public String getAttributeDesc()
158     {
159         return getDecorated().getAttributeId();
160     }
161 
162 
163     /**
164      * Set the attribute description
165      * 
166      * @param attributeDesc The attributeDesc to set.
167      */
168     public void setAttributeDesc( String attributeDesc )
169     {
170         getDecorated().setAttributeId( attributeDesc );
171     }
172 
173 
174     /**
175      * {@inheritDoc}
176      */
177     @Override
178     public MessageTypeEnum getResponseType()
179     {
180         return getDecorated().getResponseType();
181     }
182 
183 
184     /**
185      * {@inheritDoc}
186      */
187     @Override
188     public CompareRequest setAssertionValue( String value )
189     {
190         getDecorated().setAssertionValue( value );
191 
192         return this;
193     }
194 
195 
196     /**
197      * {@inheritDoc}
198      */
199     @Override
200     public CompareRequest setAssertionValue( byte[] value )
201     {
202         getDecorated().setAssertionValue( value );
203 
204         return this;
205     }
206 
207 
208     /**
209      * {@inheritDoc}
210      */
211     @Override
212     public String getAttributeId()
213     {
214         return getDecorated().getAttributeId();
215     }
216 
217 
218     /**
219      * {@inheritDoc}
220      */
221     @Override
222     public CompareRequest setAttributeId( String attrId )
223     {
224         getDecorated().setAttributeId( attrId );
225 
226         return this;
227     }
228 
229 
230     /**
231      * {@inheritDoc}
232      */
233     @Override
234     public Value getAssertionValue()
235     {
236         return getDecorated().getAssertionValue();
237     }
238 
239 
240     /**
241      * {@inheritDoc}
242      */
243     @Override
244     public CompareRequest setMessageId( int messageId )
245     {
246         super.setMessageId( messageId );
247 
248         return this;
249     }
250 
251 
252     /**
253      * {@inheritDoc}
254      */
255     @Override
256     public CompareRequest addControl( Control control )
257     {
258         return ( CompareRequest ) super.addControl( control );
259     }
260 
261 
262     /**
263      * {@inheritDoc}
264      */
265     @Override
266     public CompareRequest addAllControls( Control[] controls )
267     {
268         return ( CompareRequest ) super.addAllControls( controls );
269     }
270 
271 
272     /**
273      * {@inheritDoc}
274      */
275     @Override
276     public CompareRequest removeControl( Control control )
277     {
278         return ( CompareRequest ) super.removeControl( control );
279     }
280 }