KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > jobs > SearchJob


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.jobs;
22
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages;
29 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
30 import org.apache.directory.ldapstudio.browser.core.events.SearchUpdateEvent;
31 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
32 import org.apache.directory.ldapstudio.browser.core.model.ISearch;
33
34
35 public class SearchJob extends AbstractAsyncBulkJob
36 {
37
38     private ISearch[] searches;
39
40
41     public SearchJob( ISearch[] searches )
42     {
43         this.searches = searches;
44         setName( BrowserCoreMessages.jobs__search_name );
45     }
46
47
48     protected IConnection[] getConnections()
49     {
50         IConnection[] connections = new IConnection[searches.length];
51         for ( int i = 0; i < connections.length; i++ )
52         {
53             connections[i] = searches[i].getConnection();
54         }
55         return connections;
56     }
57
58
59     protected Object JavaDoc[] getLockedObjects()
60     {
61         List JavaDoc l = new ArrayList JavaDoc();
62         l.addAll( Arrays.asList( searches ) );
63         return l.toArray();
64     }
65
66
67     protected void executeBulkJob( ExtendedProgressMonitor monitor )
68     {
69
70         monitor.beginTask( " ", searches.length + 1 ); //$NON-NLS-1$
71
monitor.reportProgress( " " ); //$NON-NLS-1$
72

73         for ( int pi = 0; pi < searches.length; pi++ )
74         {
75             ISearch search = searches[pi];
76
77             monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__search_task, new String JavaDoc[]
78                 { search.getName() } ) );
79             monitor.worked( 1 );
80
81             if ( search.getConnection() != null && search.getConnection().isOpened() )
82             {
83
84                 // // clear search result attributes
85
// if(search.getSearchResults() != null) {
86
// ISearchResult[] srs = search.getSearchResults();
87
// for (int s = 0; s < srs.length; s++) {
88
// IEntry entry = srs[s].getEntry();
89
// entry.setAttributesInitialized(false, entry.getConnection());
90
// }
91
// }
92

93                 search.getConnection().search( search, monitor );
94             }
95         }
96     }
97
98
99     protected void runNotification()
100     {
101         for ( int pi = 0; pi < searches.length; pi++ )
102         {
103             EventRegistry.fireSearchUpdated( new SearchUpdateEvent( searches[pi], SearchUpdateEvent.EventDetail.SEARCH_PERFORMED ),
104                 this );
105         }
106     }
107
108
109     protected String JavaDoc getErrorMessage()
110     {
111         return searches.length == 1 ? BrowserCoreMessages.jobs__search_error_1
112             : BrowserCoreMessages.jobs__search_error_n;
113     }
114
115 }
116
Popular Tags