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       * @param codec The LDAP Service to use
47       */
48      public CompareRequestDsml( LdapApiService codec )
49      {
50          super( codec, new CompareRequestImpl() );
51      }
52  
53  
54      /**
55       * Creates a new getDecoratedMessage() of CompareRequestDsml.
56       *
57       * @param codec The LDAP Service to use
58       * @param ldapMessage the message to decorate
59       */
60      public CompareRequestDsml( LdapApiService codec, CompareRequest ldapMessage )
61      {
62          super( codec, ldapMessage );
63      }
64  
65  
66      /**
67       * {@inheritDoc}
68       */
69      public MessageTypeEnum getType()
70      {
71          return getDecorated().getType();
72      }
73  
74  
75      /**
76       * {@inheritDoc}
77       */
78      public Element toDsml( Element root )
79      {
80          Element element = super.toDsml( root );
81  
82          CompareRequest request = getDecorated();
83  
84          // Dn
85          if ( request.getName() != null )
86          {
87              element.addAttribute( "dn", request.getName().getName() );
88          }
89  
90          // Assertion
91          Element assertionElement = element.addElement( "assertion" );
92          if ( request.getAttributeId() != null )
93          {
94              assertionElement.addAttribute( "name", request.getAttributeId() );
95          }
96          if ( request.getAssertionValue() != null )
97          {
98              assertionElement.addElement( "value" ).setText( request.getAssertionValue().getString() );
99          }
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 }