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 023import org.apache.directory.api.ldap.model.entry.DefaultEntry; 024import org.apache.directory.api.ldap.model.entry.Entry; 025import org.apache.directory.api.ldap.model.name.Dn; 026 027 028/** 029 * Lockable SearchResponseEntry implementation 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public class SearchResultEntryImpl extends AbstractResponse implements SearchResultEntry 034{ 035 static final long serialVersionUID = -8357316233060886637L; 036 037 /** Entry returned in response to search */ 038 private Entry entry = new DefaultEntry(); 039 040 041 /** 042 * Creates a SearchResponseEntry as a reply to an SearchRequest to 043 * indicate the end of a search operation. 044 */ 045 public SearchResultEntryImpl() 046 { 047 super( -1, MessageTypeEnum.SEARCH_RESULT_ENTRY ); 048 } 049 050 051 /** 052 * Creates a SearchResponseEntry as a reply to an SearchRequest to 053 * indicate the end of a search operation. 054 * 055 * @param id the session unique message id 056 */ 057 public SearchResultEntryImpl( final int id ) 058 { 059 super( id, MessageTypeEnum.SEARCH_RESULT_ENTRY ); 060 } 061 062 063 // ------------------------------------------------------------------------ 064 // SearchResponseEntry Interface Method Implementations 065 // ------------------------------------------------------------------------ 066 067 /** 068 * Gets the entry 069 * 070 * @return the entry 071 */ 072 public Entry getEntry() 073 { 074 return entry; 075 } 076 077 078 /** 079 * Sets the entry. 080 * 081 * @param entry the entry 082 */ 083 public void setEntry( Entry entry ) 084 { 085 this.entry = entry; 086 } 087 088 089 /** 090 * Gets the distinguished name of the entry object returned. 091 * 092 * @return the Dn of the entry returned. 093 */ 094 public Dn getObjectName() 095 { 096 return ( entry == null ? null : entry.getDn() ); 097 } 098 099 100 /** 101 * Sets the distinguished name of the entry object returned. 102 * 103 * @param objectName the Dn of the entry returned. 104 */ 105 public void setObjectName( Dn objectName ) 106 { 107 if ( entry != null ) 108 { 109 entry.setDn( objectName ); 110 } 111 } 112 113 114 /** 115 * {@inheritDoc} 116 */ 117 @Override 118 public int hashCode() 119 { 120 int hash = 37; 121 if ( entry != null ) 122 { 123 hash = hash * 17 + entry.hashCode(); 124 } 125 hash = hash * 17 + super.hashCode(); 126 127 return hash; 128 } 129 130 131 /** 132 * Checks for equality by comparing the objectName, and attributes 133 * properties of this Message after delegating to the super.equals() method. 134 * 135 * @param obj 136 * the object to test for equality with this message 137 * @return true if the obj is equal false otherwise 138 */ 139 public boolean equals( Object obj ) 140 { 141 if ( this == obj ) 142 { 143 return true; 144 } 145 146 if ( !super.equals( obj ) ) 147 { 148 return false; 149 } 150 151 if ( !( obj instanceof SearchResultEntry ) ) 152 { 153 return false; 154 } 155 156 SearchResultEntry resp = ( SearchResultEntry ) obj; 157 158 return entry.equals( resp.getEntry() ); 159 } 160 161 162 /** 163 * Return a string representation of a SearchResultEntry request 164 */ 165 public String toString() 166 { 167 StringBuilder sb = new StringBuilder(); 168 169 sb.append( " Search Result Entry\n" ); 170 171 if ( entry != null ) 172 { 173 sb.append( entry ); 174 } 175 else 176 { 177 sb.append( " No entry\n" ); 178 } 179 180 return super.toString( sb.toString() ); 181 } 182}