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   *    http://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.ldap.codec.api.LdapApiService;
24  import org.apache.directory.api.ldap.model.entry.Value;
25  import org.apache.directory.api.ldap.model.message.CompareRequest;
26  import org.apache.directory.api.ldap.model.message.CompareRequestImpl;
27  import org.apache.directory.api.ldap.model.message.CompareResponse;
28  import org.apache.directory.api.ldap.model.message.Control;
29  import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
30  import org.apache.directory.api.ldap.model.name.Dn;
31  import org.dom4j.Element;
32  
33  
34  /**
35   * DSML Decorator for CompareRequest
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class CompareRequestDsml
40      extends AbstractResultResponseRequestDsml<CompareRequest, CompareResponse>
41      implements CompareRequest
42  {
43      /**
44       * Creates a new getDecoratedMessage() of CompareRequestDsml.
45       */
46      public CompareRequestDsml( LdapApiService codec )
47      {
48          super( codec, new CompareRequestImpl() );
49      }
50  
51  
52      /**
53       * Creates a new getDecoratedMessage() of CompareRequestDsml.
54       *
55       * @param ldapMessage
56       *      the message to decorate
57       */
58      public CompareRequestDsml( LdapApiService codec, CompareRequest ldapMessage )
59      {
60          super( codec, ldapMessage );
61      }
62  
63  
64      /**
65       * {@inheritDoc}
66       */
67      public MessageTypeEnum getType()
68      {
69          return getDecorated().getType();
70      }
71  
72  
73      /**
74       * {@inheritDoc}
75       */
76      public Element toDsml( Element root )
77      {
78          Element element = super.toDsml( root );
79  
80          CompareRequest request = getDecorated();
81  
82          // Dn
83          if ( request.getName() != null )
84          {
85              element.addAttribute( "dn", request.getName().getName() );
86          }
87  
88          // Assertion
89          Element assertionElement = element.addElement( "assertion" );
90          if ( request.getAttributeId() != null )
91          {
92              assertionElement.addAttribute( "name", request.getAttributeId() );
93          }
94          if ( request.getAssertionValue() != null )
95          {
96              assertionElement.addElement( "value" ).setText( request.getAssertionValue().getString() );
97          }
98  
99          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 }