1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2000, 2010 Oracle and/or its affiliates. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 10 * OpenOffice.org is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License version 3 12 * only, as published by the Free Software Foundation. 13 * 14 * OpenOffice.org is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License version 3 for more details 18 * (a copy is included in the LICENSE file that accompanied this code). 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * version 3 along with OpenOffice.org. If not, see 22 * <http://www.openoffice.org/license.html> 23 * for a copy of the LGPLv3 License. 24 ************************************************************************/ 25 26 package com.sun.star.comp.test.deployment.active_java; 27 28 import com.sun.star.awt.MessageBoxButtons; 29 import com.sun.star.awt.Rectangle; 30 import com.sun.star.awt.XMessageBox; 31 import com.sun.star.awt.XMessageBoxFactory; 32 import com.sun.star.awt.XWindowPeer; 33 import com.sun.star.beans.PropertyValue; 34 import com.sun.star.frame.DispatchDescriptor; 35 import com.sun.star.frame.XDesktop; 36 import com.sun.star.frame.XDispatch; 37 import com.sun.star.frame.XStatusListener; 38 import com.sun.star.lang.WrappedTargetRuntimeException; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiComponentFactory; 41 import com.sun.star.lang.XServiceInfo; 42 import com.sun.star.lib.uno.helper.WeakBase; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XComponentContext; 45 import com.sun.star.util.URL; 46 47 public final class Dispatch extends WeakBase implements XServiceInfo, XDispatch 48 { 49 public Dispatch(XComponentContext context) { 50 this.context = context; 51 } 52 53 public String getImplementationName() { return implementationName; } 54 55 public boolean supportsService(String ServiceName) { 56 return false; //TODO 57 } 58 59 public String[] getSupportedServiceNames() { 60 return serviceNames; 61 } 62 63 public void dispatch(URL URL, PropertyValue[] Arguments) { 64 try { 65 XMultiComponentFactory smgr = UnoRuntime.queryInterface( 66 XMultiComponentFactory.class, context.getServiceManager()); 67 XMessageBox box = UnoRuntime.queryInterface( 68 XMessageBoxFactory.class, 69 smgr.createInstanceWithContext( 70 "com.sun.star.awt.Toolkit", context)). 71 createMessageBox( 72 UnoRuntime.queryInterface( 73 XWindowPeer.class, 74 (UnoRuntime.queryInterface( 75 XDesktop.class, 76 smgr.createInstanceWithContext( 77 "com.sun.star.frame.Desktop", context)). 78 getCurrentFrame().getComponentWindow())), 79 new Rectangle(), "infobox", MessageBoxButtons.BUTTONS_OK, 80 "active", "java"); 81 box.execute(); 82 UnoRuntime.queryInterface(XComponent.class, box).dispose(); 83 } catch (com.sun.star.uno.RuntimeException e) { 84 throw e; 85 } catch (com.sun.star.uno.Exception e) { 86 throw new WrappedTargetRuntimeException( 87 "wrapped: " + e.getMessage(), this, e); 88 } 89 } 90 91 public void addStatusListener(XStatusListener Control, URL URL) {} 92 93 public void removeStatusListener(XStatusListener Control, URL URL) {} 94 95 private final XComponentContext context; 96 97 static final String implementationName = 98 "com.sun.star.comp.test.deployment.active_java_singleton"; 99 100 static final String[] serviceNames = new String[0]; 101 } 102