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