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