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 * A simple ExtendedResponse implementation. 025 * 026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 027 */ 028public class ExtendedResponseImpl extends AbstractResultResponse implements ExtendedResponse 029{ 030 static final long serialVersionUID = -6646752766410531060L; 031 032 /** Object identifier for the extended response */ 033 protected String responseName; 034 035 036 /** 037 * Creates an ExtendedResponse as a reply to an ExtendedRequest. 038 * 039 * @param responseName the ExtendedResponse's name 040 */ 041 public ExtendedResponseImpl( String responseName ) 042 { 043 super( -1, TYPE ); 044 this.responseName = responseName; 045 } 046 047 048 /** 049 * Creates an ExtendedResponse as a reply to an ExtendedRequest. 050 * 051 * @param id the session unique message id 052 * @param responseName the ExtendedResponse's name 053 */ 054 public ExtendedResponseImpl( final int id, String responseName ) 055 { 056 super( id, TYPE ); 057 this.responseName = responseName; 058 } 059 060 061 /** 062 * Creates an ExtendedResponse as a reply to an ExtendedRequest. 063 * 064 * @param id the session unique message id 065 */ 066 public ExtendedResponseImpl( int id ) 067 { 068 super( id, TYPE ); 069 } 070 071 072 // ------------------------------------------------------------------------ 073 // ExtendedResponse Interface Method Implementations 074 // ------------------------------------------------------------------------ 075 076 /** 077 * Gets the OID uniquely identifying this extended response (a.k.a. its 078 * name). 079 * 080 * @return the responseName of the extended response 081 */ 082 public String getResponseName() 083 { 084 return ( ( responseName == null ) ? "" : responseName ); 085 } 086 087 088 /** 089 * Sets the OID uniquely identifying this extended response (a.k.a. its 090 * name). 091 * 092 * @param responseName the OID of the extended response type. 093 */ 094 public void setResponseName( String responseName ) 095 { 096 this.responseName = responseName; 097 } 098 099 100 /** 101 * {@inheritDoc} 102 */ 103 @Override 104 public int hashCode() 105 { 106 int hash = 37; 107 108 if ( responseName != null ) 109 { 110 hash = hash * 17 + responseName.hashCode(); 111 } 112 113 hash = hash * 17 + super.hashCode(); 114 115 return hash; 116 } 117 118 119 /** 120 * Checks to see if an object equals this ExtendedRequest. 121 * 122 * @param obj 123 * the object to be checked for equality 124 * @return true if the obj equals this ExtendedRequest, false otherwise 125 */ 126 public boolean equals( Object obj ) 127 { 128 if ( obj == this ) 129 { 130 return true; 131 } 132 133 if ( !super.equals( obj ) ) 134 { 135 return false; 136 } 137 138 if ( !( obj instanceof ExtendedResponse ) ) 139 { 140 return false; 141 } 142 143 ExtendedResponse resp = ( ExtendedResponse ) obj; 144 145 if ( ( responseName != null ) && ( resp.getResponseName() == null ) ) 146 { 147 return false; 148 } 149 150 if ( ( responseName == null ) && ( resp.getResponseName() != null ) ) 151 { 152 return false; 153 } 154 155 if ( ( responseName != null ) && ( resp.getResponseName() != null ) 156 && !responseName.equals( resp.getResponseName() ) ) 157 { 158 return false; 159 } 160 161 return true; 162 } 163 164 165 /** 166 * Get a String representation of an ExtendedResponse 167 * 168 * @return An ExtendedResponse String 169 */ 170 public String toString() 171 { 172 StringBuilder sb = new StringBuilder(); 173 174 sb.append( " Extended Response\n" ); 175 176 if ( responseName != null ) 177 { 178 sb.append( " ResponseName :'" ).append( responseName ).append( "'\n" ); 179 } 180 181 sb.append( super.toString() ); 182 183 return super.toString( sb.toString() ); 184 } 185}