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