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