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 public String getRequestName() 060 { 061 return oid; 062 } 063 064 065 /** 066 * Sets the Object Identifier corresponding to the extended request type. 067 * 068 * @param newOid the dotted-decimal representation as a String of the OID 069 */ 070 public ExtendedRequest setRequestName( String newOid ) 071 { 072 this.oid = newOid; 073 074 return this; 075 } 076 077 078 /** 079 * {@inheritDoc} 080 */ 081 public ExtendedRequest setMessageId( int messageId ) 082 { 083 super.setMessageId( messageId ); 084 085 return this; 086 } 087 088 089 /** 090 * {@inheritDoc} 091 */ 092 public ExtendedRequest addControl( Control control ) 093 { 094 return ( ExtendedRequest ) super.addControl( control ); 095 } 096 097 098 /** 099 * {@inheritDoc} 100 */ 101 public ExtendedRequest addAllControls( Control[] controls ) 102 { 103 return ( ExtendedRequest ) super.addAllControls( controls ); 104 } 105 106 107 /** 108 * {@inheritDoc} 109 */ 110 public ExtendedRequest removeControl( Control control ) 111 { 112 return ( ExtendedRequest ) super.removeControl( control ); 113 } 114 115 116 // ------------------------------------------------------------------------ 117 // SingleReplyRequest Interface Method Implementations 118 // ------------------------------------------------------------------------ 119 120 /** 121 * Gets the protocol response message type for this request which produces 122 * at least one response. 123 * 124 * @return the message type of the response. 125 */ 126 public MessageTypeEnum getResponseType() 127 { 128 return MessageTypeEnum.EXTENDED_RESPONSE; 129 } 130 131 132 /** 133 * The result containing response for this request. 134 * 135 * @return the result containing response for this request 136 */ 137 public ExtendedResponse getExtendedResponse() 138 { 139 if ( response == null ) 140 { 141 response = new ExtendedResponseImpl( getMessageId() ); 142 } 143 144 return response; 145 } 146 147 148 /** 149 * {@inheritDoc} 150 */ 151 public ExtendedResponse getResultResponse() 152 { 153 return getExtendedResponse(); 154 } 155 156 157 /** 158 * {@inheritDoc} 159 */ 160 @Override 161 public int hashCode() 162 { 163 int hash = 37; 164 if ( oid != null ) 165 { 166 hash = hash * 17 + oid.hashCode(); 167 } 168 hash = hash * 17 + super.hashCode(); 169 170 return hash; 171 } 172 173 174 /** 175 * Checks to see if an object equals this ExtendedRequest. 176 * 177 * @param obj the object to be checked for equality 178 * @return true if the obj equals this ExtendedRequest, false otherwise 179 */ 180 public boolean equals( Object obj ) 181 { 182 if ( obj == this ) 183 { 184 return true; 185 } 186 187 if ( !super.equals( obj ) ) 188 { 189 return false; 190 } 191 192 if ( !( obj instanceof ExtendedRequest ) ) 193 { 194 return false; 195 } 196 197 ExtendedRequest req = ( ExtendedRequest ) obj; 198 199 if ( ( oid != null ) && ( req.getRequestName() == null ) ) 200 { 201 return false; 202 } 203 204 if ( ( oid == null ) && ( req.getRequestName() != null ) ) 205 { 206 return false; 207 } 208 209 if ( ( oid != null ) && ( req.getRequestName() != null ) && !oid.equals( req.getRequestName() ) ) 210 { 211 return false; 212 } 213 214 return true; 215 } 216 217 218 /** 219 * Get a String representation of an Extended Request 220 * 221 * @return an Extended Request String 222 */ 223 public String toString() 224 { 225 StringBuffer sb = new StringBuffer(); 226 227 sb.append( " Extended request\n" ); 228 sb.append( " Request name : '" ).append( oid ).append( "'\n" ); 229 230 // The controls 231 sb.append( super.toString() ); 232 233 return super.toString( sb.toString() ); 234 } 235}