1 20 21 package org.apache.directory.ldapstudio.browser.core.internal.model; 22 23 24 import java.util.ArrayList ; 25 26 import org.apache.directory.ldapstudio.browser.core.internal.search.LdapSearchPageScoreComputer; 27 import org.apache.directory.ldapstudio.browser.core.model.AttributeHierarchy; 28 import org.apache.directory.ldapstudio.browser.core.model.DN; 29 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 30 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 31 import org.apache.directory.ldapstudio.browser.core.model.IEntry; 32 import org.apache.directory.ldapstudio.browser.core.model.ISearch; 33 import org.apache.directory.ldapstudio.browser.core.model.ISearchResult; 34 import org.eclipse.search.ui.ISearchPageScoreComputer; 35 36 37 public class SearchResult implements ISearchResult 38 { 39 40 private static final long serialVersionUID = -5658803569872619432L; 41 42 private ISearch search; 43 44 private IEntry entry; 45 46 47 protected SearchResult() 48 { 49 } 50 51 52 public SearchResult( IEntry entry, ISearch search ) 53 { 54 this.entry = entry; 55 this.search = search; 56 } 57 58 59 public DN getDn() 60 { 61 return this.entry.getDn(); 62 } 63 64 65 public IAttribute[] getAttributes() 66 { 67 ArrayList attributeList = new ArrayList (); 68 for ( int i = 0; i < this.search.getReturningAttributes().length; i++ ) 69 { 70 if ( this.entry.getAttribute( this.search.getReturningAttributes()[i] ) != null ) 71 { 72 attributeList.add( this.entry.getAttribute( this.search.getReturningAttributes()[i] ) ); 73 } 74 } 75 return ( IAttribute[] ) attributeList.toArray( new IAttribute[attributeList.size()] ); 76 } 77 78 79 public IAttribute getAttribute( String attributeDescription ) 80 { 81 return this.entry.getAttribute( attributeDescription ); 82 } 83 84 85 public AttributeHierarchy getAttributeWithSubtypes( String attributeDescription ) 86 { 87 return this.entry.getAttributeWithSubtypes( attributeDescription ); 88 } 89 90 91 public IEntry getEntry() 92 { 93 return this.entry; 94 } 95 96 97 public Object getAdapter( Class adapter ) 98 { 99 if ( adapter.isAssignableFrom( ISearchPageScoreComputer.class ) ) 100 { 101 return new LdapSearchPageScoreComputer(); 102 } 103 if ( adapter == IConnection.class ) 104 { 105 return this.getConnection(); 106 } 107 if ( adapter == IEntry.class ) 108 { 109 return this.getEntry(); 110 } 111 return null; 112 } 113 114 115 public IConnection getConnection() 116 { 117 return this.search.getConnection(); 118 } 119 120 121 public ISearch getSearch() 122 { 123 return this.search; 124 } 125 126 127 public void setSearch( ISearch search ) 128 { 129 this.search = search; 130 } 131 132 } 133 | Popular Tags |