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 com.sun.star.comp.test.deployment.active_java;
25 
26 import com.sun.star.awt.MessageBoxButtons;
27 import com.sun.star.awt.MessageBoxType;
28 import com.sun.star.awt.Rectangle;
29 import com.sun.star.awt.XMessageBox;
30 import com.sun.star.awt.XMessageBoxFactory;
31 import com.sun.star.awt.XWindowPeer;
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.frame.DispatchDescriptor;
34 import com.sun.star.frame.XDesktop;
35 import com.sun.star.frame.XDispatch;
36 import com.sun.star.frame.XStatusListener;
37 import com.sun.star.lang.WrappedTargetRuntimeException;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.lang.XMultiComponentFactory;
40 import com.sun.star.lang.XServiceInfo;
41 import com.sun.star.lib.uno.helper.WeakBase;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XComponentContext;
44 import com.sun.star.util.URL;
45 
46 public final class Dispatch extends WeakBase implements XServiceInfo, XDispatch
47 {
Dispatch(XComponentContext context)48     public Dispatch(XComponentContext context) {
49         this.context = context;
50     }
51 
getImplementationName()52     public String getImplementationName() { return implementationName; }
53 
supportsService(String ServiceName)54     public boolean supportsService(String ServiceName) {
55         return false; //TODO
56     }
57 
getSupportedServiceNames()58     public String[] getSupportedServiceNames() {
59         return serviceNames;
60     }
61 
dispatch(URL URL, PropertyValue[] Arguments)62     public void dispatch(URL URL, PropertyValue[] Arguments) {
63         try {
64             XMultiComponentFactory smgr = UnoRuntime.queryInterface(
65                 XMultiComponentFactory.class, context.getServiceManager());
66             XMessageBox box = UnoRuntime.queryInterface(
67                 XMessageBoxFactory.class,
68                 smgr.createInstanceWithContext(
69                     "com.sun.star.awt.Toolkit", context)).
70                 createMessageBox(
71                     UnoRuntime.queryInterface(
72                         XWindowPeer.class,
73                         (UnoRuntime.queryInterface(
74                             XDesktop.class,
75                             smgr.createInstanceWithContext(
76                                 "com.sun.star.frame.Desktop", context)).
77                          getCurrentFrame().getComponentWindow())),
78                     MessageBoxType.INFOBOX, MessageBoxButtons.BUTTONS_OK,
79                     "active", "java");
80             box.execute();
81             UnoRuntime.queryInterface(XComponent.class, box).dispose();
82         } catch (com.sun.star.uno.RuntimeException e) {
83             throw e;
84         } catch (com.sun.star.uno.Exception e) {
85             throw new WrappedTargetRuntimeException(
86                 "wrapped: " + e.getMessage(), this, e);
87         }
88     }
89 
addStatusListener(XStatusListener Control, URL URL)90     public void addStatusListener(XStatusListener Control, URL URL) {}
91 
removeStatusListener(XStatusListener Control, URL URL)92     public void removeStatusListener(XStatusListener Control, URL URL) {}
93 
94     private final XComponentContext context;
95 
96     static final String implementationName =
97         "com.sun.star.comp.test.deployment.active_java_singleton";
98 
99     static final String[] serviceNames = new String[0];
100 }
101