1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import java.text.SimpleDateFormat ; 25 import java.util.Date ; 26 27 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry; 28 import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent; 29 import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer; 30 import org.apache.directory.ldapstudio.browser.core.model.Control; 31 import org.apache.directory.ldapstudio.browser.core.model.DN; 32 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 33 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 34 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 35 import org.apache.directory.ldapstudio.browser.core.model.SearchParameter; 36 import org.apache.directory.ldapstudio.browser.core.model.URL; 37 import org.eclipse.search.ui.ISearchPageScoreComputer; 38 39 40 46 public class Search implements ISearch 47 { 48 49 50 private static final long serialVersionUID = -3482673086666351174L; 51 52 53 private IConnection connection; 54 55 56 private ISearchResult[] searchResults; 57 58 59 private SearchParameter searchParameter; 60 61 62 private boolean countLimitExceeded; 63 64 65 84 public Search() 85 { 86 this( 87 new SimpleDateFormat ( "yyyy-MM-dd HH-mm-ss" ).format( new Date () ), null, EMPTY_SEARCH_BASE, FILTER_TRUE, NO_ATTRIBUTES, ISearch.SCOPE_ONELEVEL, 0, 0, 89 IConnection.DEREFERENCE_ALIASES_NEVER, IConnection.HANDLE_REFERRALS_IGNORE, false, false, null ); 90 } 91 92 93 99 public Search( IConnection conn, SearchParameter searchParameter ) 100 { 101 this.connection = conn; 102 this.searchResults = null; 103 this.searchParameter = searchParameter; 104 this.countLimitExceeded = false; 105 } 106 107 108 143 public Search( String searchName, IConnection conn, DN searchBase, String filter, String [] returningAttributes, 144 int scope, int countLimit, int timeLimit, int aliasesDereferencingMethod, int referralsHandlingMethod, 145 boolean initHasChildrenFlag, boolean initAliasAndReferralsFlag, Control[] controls ) 146 { 147 this.connection = conn; 148 this.searchResults = null; 149 this.countLimitExceeded = false; 150 151 this.searchParameter = new SearchParameter(); 152 this.searchParameter.setName( searchName ); 153 this.searchParameter.setSearchBase( searchBase ); 154 this.searchParameter.setFilter( filter ); 155 this.searchParameter.setReturningAttributes( returningAttributes ); 156 this.searchParameter.setScope( scope ); 157 this.searchParameter.setTimeLimit( timeLimit ); 158 this.searchParameter.setCountLimit( countLimit ); 159 this.searchParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod ); 160 this.searchParameter.setReferralsHandlingMethod( referralsHandlingMethod ); 161 this.searchParameter.setInitHasChildrenFlag( initHasChildrenFlag ); 162 this.searchParameter.setInitAliasAndReferralFlag( initAliasAndReferralsFlag ); 163 this.searchParameter.setControls( controls ); 164 } 165 166 167 170 public URL getUrl() 171 { 172 return new URL( this ); 173 } 174 175 176 181 private void fireSearchUpdated( SearchUpdateEvent.EventDetail detail ) 182 { 183 if ( this.getName() != null && !"".equals( this.getName() ) ) { EventRegistry.fireSearchUpdated( new SearchUpdateEvent( this, detail ), this ); 185 } 186 } 187 188 189 192 public boolean isInitHasChildrenFlag() 193 { 194 return this.searchParameter.isInitHasChildrenFlag(); 195 } 196 197 198 201 public boolean isInitAliasAndReferralFlag() 202 { 203 return this.searchParameter.isInitAliasAndReferralFlag(); 204 } 205 206 207 210 public Control[] getControls() 211 { 212 return this.searchParameter.getControls(); 213 } 214 215 216 219 public int getCountLimit() 220 { 221 return this.searchParameter.getCountLimit(); 222 } 223 224 225 228 public void setCountLimit( int countLimit ) 229 { 230 this.searchParameter.setCountLimit( countLimit ); 231 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 232 } 233 234 235 238 public String getFilter() 239 { 240 return this.searchParameter.getFilter(); 241 } 242 243 244 247 public void setFilter( String filter ) 248 { 249 this.searchParameter.setFilter( filter ); 250 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 251 } 252 253 254 257 public String [] getReturningAttributes() 258 { 259 return this.searchParameter.getReturningAttributes(); 260 } 261 262 263 266 public void setReturningAttributes( String [] returningAttributes ) 267 { 268 this.searchParameter.setReturningAttributes( returningAttributes ); 269 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 270 } 271 272 273 276 public int getScope() 277 { 278 return this.searchParameter.getScope(); 279 } 280 281 282 285 public void setScope( int scope ) 286 { 287 this.searchParameter.setScope( scope ); 288 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 289 } 290 291 292 295 public int getAliasesDereferencingMethod() 296 { 297 return this.searchParameter.getAliasesDereferencingMethod(); 298 } 299 300 301 304 public void setAliasesDereferencingMethod( int aliasesDereferencingMethod ) 305 { 306 this.searchParameter.setAliasesDereferencingMethod( aliasesDereferencingMethod ); 307 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 308 } 309 310 311 314 public int getReferralsHandlingMethod() 315 { 316 return this.searchParameter.getReferralsHandlingMethod(); 317 } 318 319 320 323 public void setReferralsHandlingMethod( int referralsHandlingMethod ) 324 { 325 this.searchParameter.setReferralsHandlingMethod( referralsHandlingMethod ); 326 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 327 } 328 329 330 333 public DN getSearchBase() 334 { 335 return this.searchParameter.getSearchBase(); 336 } 337 338 339 342 public void setSearchBase( DN searchBase ) 343 { 344 this.searchParameter.setSearchBase( searchBase ); 345 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 346 } 347 348 349 352 public int getTimeLimit() 353 { 354 return this.searchParameter.getTimeLimit(); 355 } 356 357 358 361 public void setTimeLimit( int timeLimit ) 362 { 363 this.searchParameter.setTimeLimit( timeLimit ); 364 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 365 } 366 367 368 371 public String getName() 372 { 373 return this.searchParameter.getName(); 374 } 375 376 377 380 public void setName( String searchName ) 381 { 382 this.searchParameter.setName( searchName ); 383 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_RENAMED ); 384 } 385 386 387 390 public ISearchResult[] getSearchResults() 391 { 392 return searchResults; 393 } 394 395 396 399 public void setSearchResults( ISearchResult[] searchResults ) 400 { 401 this.searchResults = searchResults; 402 if ( searchResults != null ) 403 { 404 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ); 405 } 406 } 407 408 409 412 public boolean isCountLimitExceeded() 413 { 414 return this.countLimitExceeded; 415 } 416 417 418 421 public void setCountLimitExceeded( boolean countLimitExceeded ) 422 { 423 this.countLimitExceeded = countLimitExceeded; 424 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ); 425 } 426 427 428 431 public IConnection getConnection() 432 { 433 return connection; 434 } 435 436 437 440 public void setConnection( IConnection connection ) 441 { 442 this.connection = connection; 443 this.searchParameter.setCountLimit( connection.getCountLimit() ); 444 this.searchParameter.setTimeLimit( connection.getTimeLimit() ); 445 this.searchParameter.setAliasesDereferencingMethod( connection.getAliasesDereferencingMethod() ); 446 this.searchParameter.setReferralsHandlingMethod( connection.getReferralsHandlingMethod() ); 447 this.fireSearchUpdated( SearchUpdateEvent.EventDetail.SEARCH_PARAMETER_UPDATED ); 448 } 449 450 451 454 public String toString() 455 { 456 return this.getName() + " (" + this.connection + ")"; } 458 459 460 463 public Object clone() 464 { 465 return new Search( this.getName(), this.getConnection(), this.getSearchBase(), this.getFilter(), this 466 .getReturningAttributes(), this.getScope(), this.getCountLimit(), this.getTimeLimit(), this 467 .getAliasesDereferencingMethod(), this.getReferralsHandlingMethod(), this.isInitHasChildrenFlag(), this 468 .isInitAliasAndReferralFlag(), this.getControls() ); 469 } 470 471 472 475 public SearchParameter getSearchParameter() 476 { 477 return searchParameter; 478 } 479 480 481 484 public void setSearchParameter( SearchParameter searchParameter ) 485 { 486 this.searchParameter = searchParameter; 487 } 488 489 490 493 public Object getAdapter( Class adapter ) 494 { 495 496 Class <?> clazz = ( Class <?> ) adapter; 497 if ( clazz.isAssignableFrom( ISearchPageScoreComputer.class ) ) 498 { 499 return new LdapSearchPageScoreComputer(); 500 } 501 if ( clazz.isAssignableFrom( IConnection.class ) ) 502 { 503 return getConnection(); 504 } 505 if ( clazz.isAssignableFrom( ISearch.class ) ) 506 { 507 return this; 508 } 509 510 return null; 511 } 512 513 } 514 | Popular Tags |