KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > internal > model > SearchResult


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.core.internal.model;
22
23
24 import java.util.ArrayList JavaDoc;
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 JavaDoc attributeList = new ArrayList JavaDoc();
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 JavaDoc attributeDescription )
80     {
81         return this.entry.getAttribute( attributeDescription );
82     }
83
84
85     public AttributeHierarchy getAttributeWithSubtypes( String JavaDoc 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 JavaDoc getAdapter( Class JavaDoc 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