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