KickJava   Java API By Example, From Geeks To Geeks.

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


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.ConnectionUpdateEvent;
30 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
31 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
32
33
34 public class ReloadSchemasJob extends AbstractAsyncBulkJob
35 {
36
37     private IConnection[] connections;
38
39
40     public ReloadSchemasJob( IConnection[] connections )
41     {
42         this.connections = connections;
43         setName( connections.length == 1 ? BrowserCoreMessages.jobs__reload_schemas_name_1
44             : BrowserCoreMessages.jobs__reload_schemas_name_n );
45     }
46
47
48     protected IConnection[] getConnections()
49     {
50         return connections;
51     }
52
53
54     protected Object JavaDoc[] getLockedObjects()
55     {
56         List JavaDoc l = new ArrayList JavaDoc();
57         l.addAll( Arrays.asList( connections ) );
58         return l.toArray();
59     }
60
61
62     protected void executeBulkJob( ExtendedProgressMonitor monitor )
63     {
64
65         monitor.beginTask( " ", connections.length + 1 ); //$NON-NLS-1$
66
monitor.reportProgress( " " ); //$NON-NLS-1$
67

68         for ( int i = 0; i < connections.length; i++ )
69         {
70
71             monitor.setTaskName( BrowserCoreMessages.bind( BrowserCoreMessages.jobs__reload_schemas_task, new String JavaDoc[]
72                 { connections[i].getName() } ) );
73             monitor.worked( 1 );
74
75             if ( connections[i].isOpened() )
76             {
77                 connections[i].reloadSchema( monitor );
78             }
79         }
80     }
81
82
83     protected void runNotification()
84     {
85         for ( int i = 0; i < connections.length; i++ )
86         {
87             EventRegistry.fireConnectionUpdated( new ConnectionUpdateEvent( connections[i],
88                 ConnectionUpdateEvent.EventDetail.SCHEMA_LOADED ), this );
89         }
90     }
91
92
93     protected String JavaDoc getErrorMessage()
94     {
95         return connections.length == 1 ? BrowserCoreMessages.jobs__reload_schemas_error_1
96             : BrowserCoreMessages.jobs__reload_schemas_error_n;
97     }
98 }
99
Popular Tags