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 */ 020 package org.apache.directory.shared.ldap.message.internal; 021 022 import org.apache.directory.shared.ldap.codec.MessageTypeEnum; 023 import org.apache.directory.shared.ldap.message.LdapResultImpl; 024 025 026 /** 027 * Abstract base for a Lockable ResultResponse message. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 * @version $Revision: 910150 $ 031 */ 032 public abstract class InternalAbstractResultResponse extends InternalAbstractResponse implements InternalResultResponse 033 { 034 /** Response result components */ 035 private InternalLdapResult result = new LdapResultImpl(); 036 037 038 // ------------------------------------------------------------------------ 039 // Response Interface Method Implementations 040 // ------------------------------------------------------------------------ 041 042 /** 043 * Allows subclasses based on the abstract type to create a response to a 044 * request. 045 * 046 * @param id 047 * the response eliciting this Request 048 * @param type 049 * the message type of the response 050 */ 051 protected InternalAbstractResultResponse(final int id, final MessageTypeEnum type) 052 { 053 super( id, type ); 054 } 055 056 057 // ------------------------------------------------------------------------ 058 // Response Interface Method Implementations 059 // ------------------------------------------------------------------------ 060 061 /** 062 * Gets the LdapResult components of this Response. 063 * 064 * @return the LdapResult for this Response. 065 */ 066 public InternalLdapResult getLdapResult() 067 { 068 return result; 069 } 070 071 072 /** 073 * Checks to see if an object is equal to this AbstractResultResponse. First 074 * the object is checked to see if it is this AbstractResultResponse 075 * instance if so it returns true. Next it checks if the super method 076 * returns false and if it does false is returned. It then checks if the 077 * LDAPResult's are equal. If not false is returned and if they match true 078 * is returned. 079 * 080 * @param obj 081 * the object to compare to this LdapResult containing response 082 * @return true if they objects are equivalent false otherwise 083 */ 084 public boolean equals( Object obj ) 085 { 086 if ( obj == this ) 087 { 088 return true; 089 } 090 091 if ( !super.equals( obj ) ) 092 { 093 return false; 094 } 095 096 if ( !( obj instanceof InternalResultResponse ) ) 097 { 098 return false; 099 } 100 101 InternalResultResponse resp = ( InternalResultResponse ) obj; 102 103 if ( getLdapResult() != null && resp.getLdapResult() == null ) 104 { 105 return false; 106 } 107 108 if ( getLdapResult() == null && resp.getLdapResult() != null ) 109 { 110 return false; 111 } 112 113 if ( getLdapResult() != null && resp.getLdapResult() != null ) 114 { 115 if ( !getLdapResult().equals( resp.getLdapResult() ) ) 116 { 117 return false; 118 } 119 } 120 121 return true; 122 } 123 124 125 /** 126 * Get a String representation of an Response 127 * 128 * @return An Response String 129 */ 130 public String toString() 131 { 132 if ( result != null ) 133 { 134 return result.toString(); 135 } 136 else 137 { 138 return "No result"; 139 } 140 } 141 }