1*7c448b18SAndrew Rist /**************************************************************
2*7c448b18SAndrew Rist  *
3*7c448b18SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*7c448b18SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*7c448b18SAndrew Rist  * distributed with this work for additional information
6*7c448b18SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*7c448b18SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*7c448b18SAndrew Rist  * "License"); you may not use this file except in compliance
9*7c448b18SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*7c448b18SAndrew Rist  *
11*7c448b18SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*7c448b18SAndrew Rist  *
13*7c448b18SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*7c448b18SAndrew Rist  * software distributed under the License is distributed on an
15*7c448b18SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*7c448b18SAndrew Rist  * KIND, either express or implied.  See the License for the
17*7c448b18SAndrew Rist  * specific language governing permissions and limitations
18*7c448b18SAndrew Rist  * under the License.
19*7c448b18SAndrew Rist  *
20*7c448b18SAndrew Rist  *************************************************************/
21*7c448b18SAndrew Rist 
22*7c448b18SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.comp.test.deployment.passive_java;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.awt.MessageBoxButtons;
27cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
28cdf0e10cSrcweir import com.sun.star.awt.XMessageBox;
29cdf0e10cSrcweir import com.sun.star.awt.XMessageBoxFactory;
30cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
31cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
32cdf0e10cSrcweir import com.sun.star.frame.DispatchDescriptor;
33cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
34cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
35cdf0e10cSrcweir import com.sun.star.frame.XStatusListener;
36cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetRuntimeException;
37cdf0e10cSrcweir import com.sun.star.lang.XComponent;
38cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
39cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
40cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
41cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
42cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
43cdf0e10cSrcweir import com.sun.star.util.URL;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir public final class Dispatch extends WeakBase implements XServiceInfo, XDispatch
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     public Dispatch(XComponentContext context) {
48cdf0e10cSrcweir         this.context = context;
49cdf0e10cSrcweir     }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     public String getImplementationName() { return implementationName; }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     public boolean supportsService(String ServiceName) {
54cdf0e10cSrcweir         return false; //TODO
55cdf0e10cSrcweir     }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     public String[] getSupportedServiceNames() {
58cdf0e10cSrcweir         return serviceNames;
59cdf0e10cSrcweir     }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     public void dispatch(URL URL, PropertyValue[] Arguments) {
62cdf0e10cSrcweir         try {
63cdf0e10cSrcweir             XMultiComponentFactory smgr = UnoRuntime.queryInterface(
64cdf0e10cSrcweir                 XMultiComponentFactory.class, context.getServiceManager());
65cdf0e10cSrcweir             XMessageBox box = UnoRuntime.queryInterface(
66cdf0e10cSrcweir                 XMessageBoxFactory.class,
67cdf0e10cSrcweir                 smgr.createInstanceWithContext(
68cdf0e10cSrcweir                     "com.sun.star.awt.Toolkit", context)).
69cdf0e10cSrcweir                 createMessageBox(
70cdf0e10cSrcweir                     UnoRuntime.queryInterface(
71cdf0e10cSrcweir                         XWindowPeer.class,
72cdf0e10cSrcweir                         (UnoRuntime.queryInterface(
73cdf0e10cSrcweir                             XDesktop.class,
74cdf0e10cSrcweir                             smgr.createInstanceWithContext(
75cdf0e10cSrcweir                                 "com.sun.star.frame.Desktop", context)).
76cdf0e10cSrcweir                          getCurrentFrame().getComponentWindow())),
77cdf0e10cSrcweir                     new Rectangle(), "infobox", MessageBoxButtons.BUTTONS_OK,
78cdf0e10cSrcweir                     "passive", "java");
79cdf0e10cSrcweir             box.execute();
80cdf0e10cSrcweir             UnoRuntime.queryInterface(XComponent.class, box).dispose();
81cdf0e10cSrcweir         } catch (com.sun.star.uno.RuntimeException e) {
82cdf0e10cSrcweir             throw e;
83cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
84cdf0e10cSrcweir             throw new WrappedTargetRuntimeException(
85cdf0e10cSrcweir                 "wrapped: " + e.getMessage(), this, e);
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     public void addStatusListener(XStatusListener Control, URL URL) {}
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     public void removeStatusListener(XStatusListener Control, URL URL) {}
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     private final XComponentContext context;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     static final String implementationName =
96cdf0e10cSrcweir         "com.sun.star.comp.test.deployment.passive_java_singleton";
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     static final String[] serviceNames = new String[0];
99cdf0e10cSrcweir }
100