1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package complex.framework.recovery;
25 
26 import com.sun.star.frame.XController;
27 import com.sun.star.frame.XDispatch;
28 import com.sun.star.frame.XDispatchProvider;
29 import com.sun.star.frame.XModel;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.util.URL;
34 import com.sun.star.util.XURLTransformer;
35 
36 /**
37  * Thread to crash the office. This thread dies after the office process
38  * is nopt longer available.
39  */
40 public class CrashThread extends Thread {
41     public XComponent xDoc = null;
42     public XMultiServiceFactory msf = null;
43 
CrashThread(XComponent xDoc, XMultiServiceFactory msf)44     public CrashThread(XComponent xDoc, XMultiServiceFactory msf) {
45         this.xDoc = xDoc;
46         this.msf = msf;
47     }
48 
run()49     public void run() {
50         try{
51             XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xDoc);
52 
53             XController xController = xModel.getCurrentController();
54             XDispatchProvider xDispProv = (XDispatchProvider) UnoRuntime.queryInterface(
55                                                   XDispatchProvider.class,
56                                                   xController);
57             XURLTransformer xParser = (XURLTransformer) UnoRuntime.queryInterface(
58                                               XURLTransformer.class,
59                                               msf.createInstance(
60                                                       "com.sun.star.util.URLTransformer"));
61 
62             // Because it's an in/out parameter we must use an array of URL objects.
63             URL[] aParseURL = new URL[1];
64             aParseURL[0] = new URL();
65             aParseURL[0].Complete = ".uno:Crash";
66             xParser.parseStrict(aParseURL);
67 
68             URL aURL = aParseURL[0];
69             XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
70 
71             if (xDispatcher != null) {
72                 xDispatcher.dispatch(aURL, null);
73             }
74         } catch (Exception e){}
75     }
76 }
77