View Javadoc

1   /***
2   *
3   * The owl-s matcher software is subject to the GNU Lesser General
4   * Public License Version 2.1 (the "License"). You may not copy or use this
5   * file, in either source code or executable form, except in compliance
6   * with the License. You may obtain a copy of the License at
7   * http://www.fsf.org/licenses/lgpl.txt or http://www.opensource.org/.
8   *
9   * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied without
11  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  * PURPOSE. See the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this distribution; if not, write to the
17  *
18  * Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330,
20  * Boston, MA  02111-1307 USA
21  *
22  * Copyright (C) 2003-2004
23  * TU Berlin, FG IVS
24  * Stefan Tang,
25  * Christoph Liebetruth,
26  * Michael C. Jaeger, 
27  *
28  * More information available at http://ivs.tu-berlin.de/
29  *
30  * $Id$
31  *
32  */
33  package de.tuberlin.ivs.owl.gui;
34  
35  import de.tuberlin.ivs.owl.matching.*;
36  import de.tuberlin.ivs.owl.service.*;
37  import javax.swing.JOptionPane;
38  import java.io.PrintStream;
39  import java.net.URL;
40  
41  /***
42   * Thread that loads/parses a file.
43   *
44   * @author Stefan Tang (steftang@stanford.edu), Christoph Liebetruth (christophl@voelcker.com)
45   * @version 1.1
46   */
47  public class LoadThread extends Thread {
48  
49    /***
50     * The URL of the service that will be loaded.
51     */
52    URL url;
53  
54    /***
55     * The main frame.
56     */
57    MainFrame mainFrame;
58  
59    /***
60     * Denotes if the service that is loaded is the requested service (true) or
61     * not (false).
62     */
63    boolean request;
64  
65    /***
66     * The output stream that information will be written to.
67     */
68    PrintStream out;
69  
70    /***
71     * Constructor. Initializes the thread with the neccessary parameters.
72     * @param url The URL of the service that will be loaded/parsed.
73     * @param parent The main frame.
74     * @param request true if the service that will be loaded is the requested
75     * service, false if it is the advertised service.
76     * @param out The output stream that information will be written to.
77     */
78    public LoadThread(URL url, MainFrame parent, boolean request, PrintStream out) {
79     this.url = url;
80     mainFrame = parent;
81     this.request = request;
82     this.out = out;
83    }
84  
85    /***
86     * Run method of the thread. Loads and parses the service that was specified
87     * in the constructor.
88     */
89    public void run() {
90      OwlsParser parser = new OwlsParser(out);
91      Reasoner reasoner = new Reasoner(out);
92      Service service = null;
93      try {
94        service = parser.parse(url, reasoner);
95        mainFrame.addServicePanel(service, request, url);
96      } catch (OwlsParseException dpe) {
97        JOptionPane.showMessageDialog(mainFrame.getLoadDialog(),dpe.getMessage(),
98                 "Error while parsing the service",JOptionPane.WARNING_MESSAGE);
99      } catch (NullPointerException npe) {
100       JOptionPane.showMessageDialog(mainFrame.getLoadDialog(),"Error while parsing the service: NullPointerException",
101                "Error",JOptionPane.WARNING_MESSAGE);
102     }
103     mainFrame.stopFrameThread();
104 
105   }
106 
107 }