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.ldap.model.message; 021 022 023/** 024 * ExtendedRequest implementation. 025 * 026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 027 */ 028public class ExtendedRequestImpl extends AbstractRequest implements ExtendedRequest 029{ 030 static final long serialVersionUID = 7916990159044177480L; 031 032 /** Extended request's Object Identifier or <b>requestName</b> */ 033 private String oid; 034 035 /** The associated response */ 036 protected ExtendedResponseImpl response; 037 038 039 /** 040 * Creates an ExtendedRequest implementing object used to perform 041 * extended protocol operation on the server. 042 */ 043 public ExtendedRequestImpl() 044 { 045 super( -1, MessageTypeEnum.EXTENDED_REQUEST, true ); 046 } 047 048 049 // ----------------------------------------------------------------------- 050 // ExtendedRequest Interface Method Implementations 051 // ----------------------------------------------------------------------- 052 053 /** 054 * Gets the Object Identifier corresponding to the extended request type. 055 * This is the <b>requestName</b> portion of the ext. req. PDU. 056 * 057 * @return the dotted-decimal representation as a String of the OID 058 */ 059 @Override 060 public String getRequestName() 061 { 062 return oid; 063 } 064 065 066 /** 067 * Sets the Object Identifier corresponding to the extended request type. 068 * 069 * @param newOid the dotted-decimal representation as a String of the OID 070 */ 071 @Override 072 public ExtendedRequest setRequestName( String newOid ) 073 { 074 this.oid = newOid; 075 076 return this; 077 } 078 079 080 /** 081 * {@inheritDoc} 082 */ 083 @Override 084 public ExtendedRequest setMessageId( int messageId ) 085 { 086 super.setMessageId( messageId ); 087 088 return this; 089 } 090 091 092 /** 093 * {@inheritDoc} 094 */ 095 @Override 096 public ExtendedRequest addControl( Control control ) 097 { 098 return ( ExtendedRequest ) super.addControl( control ); 099 } 100 101 102 /** 103 * {@inheritDoc} 104 */ 105 @Override 106 public ExtendedRequest addAllControls( Control[] controls ) 107 { 108 return ( ExtendedRequest ) super.addAllControls( controls ); 109 } 110 111 112 /** 113 * {@inheritDoc} 114 */ 115 @Override 116 public ExtendedRequest removeControl( Control control ) 117 { 118 return ( ExtendedRequest ) super.removeControl( control ); 119 } 120 121 122 // ------------------------------------------------------------------------ 123 // SingleReplyRequest Interface Method Implementations 124 // ------------------------------------------------------------------------ 125 126 /** 127 * Gets the protocol response message type for this request which produces 128 * at least one response. 129 * 130 * @return the message type of the response. 131 */ 132 @Override 133 public MessageTypeEnum getResponseType() 134 { 135 return MessageTypeEnum.EXTENDED_RESPONSE; 136 } 137 138 139 /** 140 * The result containing response for this request. 141 * 142 * @return the result containing response for this request 143 */ 144 public ExtendedResponse getExtendedResponse() 145 { 146 if ( response == null ) 147 { 148 response = new ExtendedResponseImpl( getMessageId() ); 149 } 150 151 return response; 152 } 153 154 155 /** 156 * {@inheritDoc} 157 */ 158 @Override 159 public ExtendedResponse getResultResponse() 160 { 161 return getExtendedResponse(); 162 } 163 164 165 /** 166 * {@inheritDoc} 167 */ 168 @Override 169 public int hashCode() 170 { 171 int hash = 37; 172 if ( oid != null ) 173 { 174 hash = hash * 17 + oid.hashCode(); 175 } 176 hash = hash * 17 + super.hashCode(); 177 178 return hash; 179 } 180 181 182 /** 183 * Checks to see if an object equals this ExtendedRequest. 184 * 185 * @param obj the object to be checked for equality 186 * @return true if the obj equals this ExtendedRequest, false otherwise 187 */ 188 @Override 189 public boolean equals( Object obj ) 190 { 191 if ( obj == this ) 192 { 193 return true; 194 } 195 196 if ( !super.equals( obj ) ) 197 { 198 return false; 199 } 200 201 if ( !( obj instanceof ExtendedRequest ) ) 202 { 203 return false; 204 } 205 206 ExtendedRequest req = ( ExtendedRequest ) obj; 207 208 if ( ( oid != null ) && ( req.getRequestName() == null ) ) 209 { 210 return false; 211 } 212 213 if ( ( oid == null ) && ( req.getRequestName() != null ) ) 214 { 215 return false; 216 } 217 218 if ( ( oid != null ) && ( req.getRequestName() != null ) && !oid.equals( req.getRequestName() ) ) 219 { 220 return false; 221 } 222 223 return true; 224 } 225 226 227 /** 228 * Get a String representation of an Extended Request 229 * 230 * @return an Extended Request String 231 */ 232 @Override 233 public String toString() 234 { 235 StringBuilder sb = new StringBuilder(); 236 237 sb.append( " Extended request\n" ); 238 sb.append( " Request name : '" ).append( oid ).append( "'\n" ); 239 240 // The controls 241 sb.append( super.toString() ); 242 243 return super.toString( sb.toString() ); 244 } 245}