1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package basicrunner.basichelper; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 30*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 31*cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 32*cdf0e10cSrcweir import com.sun.star.uno.Type; 33*cdf0e10cSrcweir import com.sun.star.frame.XDispatchProviderInterceptor; 34*cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider; 35*cdf0e10cSrcweir import com.sun.star.frame.XDispatch; 36*cdf0e10cSrcweir import com.sun.star.frame.DispatchDescriptor; 37*cdf0e10cSrcweir import com.sun.star.util.URL; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /** 40*cdf0e10cSrcweir * This implementation provides an implementation of an interceptor. 41*cdf0e10cSrcweir * @see com.sun.star.lang.XSingleServiceFactory 42*cdf0e10cSrcweir * @see com.sun.star.lang.XServiceInfo 43*cdf0e10cSrcweir */ 44*cdf0e10cSrcweir public class DispatchProviderInterceptor implements XServiceInfo, 45*cdf0e10cSrcweir XSingleServiceFactory { 46*cdf0e10cSrcweir /** The service name **/ 47*cdf0e10cSrcweir static final String __serviceName = 48*cdf0e10cSrcweir "basichelper.DispatchProviderInterceptor"; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir /** Create an instance of the interceptor 51*cdf0e10cSrcweir * Arguments are not supported here, so they will be ignored. 52*cdf0e10cSrcweir * @param args The arguments. 53*cdf0e10cSrcweir * @return A new instance of the interceptor. 54*cdf0e10cSrcweir **/ 55*cdf0e10cSrcweir public Object createInstanceWithArguments(Object[] args) { 56*cdf0e10cSrcweir return new InterceptorImpl(); 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir /** Create an instance of the interceptor 60*cdf0e10cSrcweir * @return A new instance of the interceptor. 61*cdf0e10cSrcweir **/ 62*cdf0e10cSrcweir public Object createInstance() { 63*cdf0e10cSrcweir return createInstanceWithArguments(null); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir /** Get the unique id for this implementation 67*cdf0e10cSrcweir * @return The id. 68*cdf0e10cSrcweir */ 69*cdf0e10cSrcweir public byte[] getImplementationId() { 70*cdf0e10cSrcweir return toString().getBytes(); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir /** Get all implemented types. 74*cdf0e10cSrcweir * @return The implemented UNO types. 75*cdf0e10cSrcweir */ 76*cdf0e10cSrcweir public Type[] getTypes() { 77*cdf0e10cSrcweir Class interfaces[] = getClass().getInterfaces(); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir Type types[] = new Type[interfaces.length]; 80*cdf0e10cSrcweir for(int i = 0; i < interfaces.length; ++ i) 81*cdf0e10cSrcweir types[i] = new Type(interfaces[i]); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir return types; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir /** 87*cdf0e10cSrcweir * Is this service supported? 88*cdf0e10cSrcweir * @param name The name of a service. 89*cdf0e10cSrcweir * @return True, if the service is supported. 90*cdf0e10cSrcweir */ 91*cdf0e10cSrcweir public boolean supportsService(String name) { 92*cdf0e10cSrcweir return __serviceName.equals(name); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir /** 96*cdf0e10cSrcweir * Get all supported service names. 97*cdf0e10cSrcweir * @return All service names. 98*cdf0e10cSrcweir */ 99*cdf0e10cSrcweir public String[] getSupportedServiceNames() { 100*cdf0e10cSrcweir return new String[] {__serviceName}; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir /** 104*cdf0e10cSrcweir * Get the implementation name of this class. 105*cdf0e10cSrcweir * @return The name. 106*cdf0e10cSrcweir */ 107*cdf0e10cSrcweir public String getImplementationName() { 108*cdf0e10cSrcweir return getClass().getName(); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir /** 113*cdf0e10cSrcweir * The actual implementation of the interceptor. 114*cdf0e10cSrcweir * @see com.sun.star.lang.XTypeProvider 115*cdf0e10cSrcweir * @see com.sun.star.frame.XDispatchProviderInterceptor 116*cdf0e10cSrcweir * @see com.sun.star.frame.XDispatchProvider 117*cdf0e10cSrcweir */ 118*cdf0e10cSrcweir class InterceptorImpl implements XDispatchProvider, 119*cdf0e10cSrcweir XDispatchProviderInterceptor, XTypeProvider { 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir /** A master dispatch provider **/ 122*cdf0e10cSrcweir public XDispatchProvider master = null; 123*cdf0e10cSrcweir /** A slave dispatch provider **/ 124*cdf0e10cSrcweir public XDispatchProvider slave = null; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir /** Get the slave dispatch provider 127*cdf0e10cSrcweir * @return The slave. 128*cdf0e10cSrcweir */ 129*cdf0e10cSrcweir public XDispatchProvider getSlaveDispatchProvider() { 130*cdf0e10cSrcweir return slave; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir /** Get the master dispatch provider 133*cdf0e10cSrcweir * @return The master. 134*cdf0e10cSrcweir */ 135*cdf0e10cSrcweir public XDispatchProvider getMasterDispatchProvider() { 136*cdf0e10cSrcweir return master; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir /** Set the slave dispatch provider 140*cdf0e10cSrcweir * @param prov The new slave. 141*cdf0e10cSrcweir */ 142*cdf0e10cSrcweir public void setSlaveDispatchProvider(XDispatchProvider prov) { 143*cdf0e10cSrcweir slave = prov ; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir /** Set the master dispatch provider 147*cdf0e10cSrcweir * @param prov The new master. 148*cdf0e10cSrcweir */ 149*cdf0e10cSrcweir public void setMasterDispatchProvider(XDispatchProvider prov) { 150*cdf0e10cSrcweir master = prov ; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir /** Searches for an <type>XDispatch</type> for the specified URL within 154*cdf0e10cSrcweir * the specified target frame. 155*cdf0e10cSrcweir * @param url The URL. 156*cdf0e10cSrcweir * @param frame The target frame 157*cdf0e10cSrcweir * @param flags Optional search flags. 158*cdf0e10cSrcweir * @return The dispatch object which provides the queried functionality 159*cdf0e10cSrcweir * or null if no dispatch object is available. 160*cdf0e10cSrcweir * @see com.sun.star.frame.XDispatch 161*cdf0e10cSrcweir */ 162*cdf0e10cSrcweir public XDispatch queryDispatch(URL url, String frame, int flags) { 163*cdf0e10cSrcweir return master.queryDispatch(url, frame, flags) ; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir /** 167*cdf0e10cSrcweir * Query for an array of <type>XDispatch</type>. 168*cdf0e10cSrcweir * @param desc A list of dipatch requests. 169*cdf0e10cSrcweir * @return A list of dispatch objects. 170*cdf0e10cSrcweir */ 171*cdf0e10cSrcweir public XDispatch[] queryDispatches(DispatchDescriptor[] desc) { 172*cdf0e10cSrcweir return master.queryDispatches(desc) ; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir /** Get the unique id for this implementation 176*cdf0e10cSrcweir * @return The id. 177*cdf0e10cSrcweir */ 178*cdf0e10cSrcweir public byte[] getImplementationId() { 179*cdf0e10cSrcweir return toString().getBytes(); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir /** Get all implemented types. 183*cdf0e10cSrcweir * @return The implemented UNO types. 184*cdf0e10cSrcweir */ 185*cdf0e10cSrcweir public Type[] getTypes() { 186*cdf0e10cSrcweir Class interfaces[] = getClass().getInterfaces(); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir Type types[] = new Type[interfaces.length]; 189*cdf0e10cSrcweir for(int i = 0; i < interfaces.length; ++ i) 190*cdf0e10cSrcweir types[i] = new Type(interfaces[i]); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir return types; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir } 195