1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages; 28 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; 29 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 30 import org.apache.directory.ldapstudio.browser.core.model.IReferralHandler; 31 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 32 import org.apache.directory.ldapstudio.browser.core.model.SearchParameter; 33 import org.apache.directory.ldapstudio.browser.core.model.URL; 34 35 36 public class ReferralException extends ConnectionException 37 { 38 39 private static final long serialVersionUID = 1L; 40 41 private SearchParameter originalSearchParameter; 42 43 private String [] referrals; 44 45 46 public ReferralException( SearchParameter originalSearchParameter, String [] referrals, int ldapStatusCode, 47 String message, Throwable originalThrowable ) 48 { 49 super( ldapStatusCode, message, originalThrowable ); 50 this.originalSearchParameter = originalSearchParameter; 51 this.referrals = referrals; 52 } 53 54 55 public String [] getReferrals() 56 { 57 return referrals; 58 } 59 60 61 public ISearch[] getReferralSearches() throws ConnectionException 62 { 63 64 IReferralHandler referralHandler = BrowserCorePlugin.getDefault().getReferralHandler(); 66 if ( referralHandler == null ) 67 { 68 throw new ConnectionException( BrowserCoreMessages.model__no_referral_handler ); 69 } 70 71 List referralSearchList = new ArrayList ( getReferrals().length ); 72 73 for ( int i = 0; i < getReferrals().length; i++ ) 74 { 75 76 String referral = getReferrals()[i]; 78 URL referralUrl = new URL( referral ); 79 80 IConnection referralConnection = referralHandler.getReferralConnection( referralUrl ); 82 if ( referralConnection == null ) 83 { 84 continue; 87 } 88 89 try 91 { 92 ISearch referralSearch = new Search( 93 null, referralConnection, referralUrl.hasDn() ? referralUrl.getDn() : originalSearchParameter.getSearchBase(), referralUrl 96 .hasFilter() ? referralUrl.getFilter() : originalSearchParameter.getFilter(), 97 originalSearchParameter.getReturningAttributes(), referralUrl.hasScope() ? referralUrl.getScope() 98 : originalSearchParameter.getScope(), originalSearchParameter.getCountLimit(), 99 originalSearchParameter.getTimeLimit(), originalSearchParameter.getAliasesDereferencingMethod(), 100 originalSearchParameter.getReferralsHandlingMethod(), originalSearchParameter.isInitHasChildrenFlag(), 101 originalSearchParameter.isInitAliasAndReferralFlag(), originalSearchParameter.getControls() ); 102 referralSearchList.add( referralSearch ); 103 } 104 catch ( NoSuchFieldException nsfe ) 105 { 106 } 107 108 } 109 110 ISearch[] referralSearches = ( ISearch[] ) referralSearchList.toArray( new ISearch[referralSearchList.size()] ); 111 return referralSearches; 112 } 113 114 } 115 | Popular Tags |