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