1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package basicrunner.basichelper;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
26cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
27cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider;
28cdf0e10cSrcweir import com.sun.star.uno.Type;
29cdf0e10cSrcweir import com.sun.star.frame.XDispatchProviderInterceptor;
30cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider;
31cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
32cdf0e10cSrcweir import com.sun.star.frame.DispatchDescriptor;
33cdf0e10cSrcweir import com.sun.star.util.URL;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir  * This implementation provides an implementation of an interceptor.
37cdf0e10cSrcweir  * @see com.sun.star.lang.XSingleServiceFactory
38cdf0e10cSrcweir  * @see com.sun.star.lang.XServiceInfo
39cdf0e10cSrcweir  */
40cdf0e10cSrcweir public class DispatchProviderInterceptor implements XServiceInfo,
41cdf0e10cSrcweir                                                     XSingleServiceFactory {
42cdf0e10cSrcweir     /** The service name **/
43cdf0e10cSrcweir     static final String __serviceName =
44cdf0e10cSrcweir                             "basichelper.DispatchProviderInterceptor";
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     /** Create an instance of the interceptor
47cdf0e10cSrcweir      * Arguments are not supported here, so they will be ignored.
48cdf0e10cSrcweir      * @param args The arguments.
49cdf0e10cSrcweir      * @return A new instance of the interceptor.
50cdf0e10cSrcweir      **/
createInstanceWithArguments(Object[] args)51cdf0e10cSrcweir     public Object createInstanceWithArguments(Object[] args) {
52cdf0e10cSrcweir         return new InterceptorImpl();
53cdf0e10cSrcweir     }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /** Create an instance of the interceptor
56cdf0e10cSrcweir      * @return A new instance of the interceptor.
57cdf0e10cSrcweir      **/
createInstance()58cdf0e10cSrcweir     public Object createInstance() {
59cdf0e10cSrcweir         return createInstanceWithArguments(null);
60cdf0e10cSrcweir     }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     /** Get the unique id for this implementation
63cdf0e10cSrcweir      * @return The id.
64cdf0e10cSrcweir      */
getImplementationId()65cdf0e10cSrcweir     public byte[] getImplementationId() {
66cdf0e10cSrcweir         return toString().getBytes();
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     /** Get all implemented types.
70cdf0e10cSrcweir      * @return The implemented UNO types.
71cdf0e10cSrcweir      */
getTypes()72cdf0e10cSrcweir     public Type[] getTypes() {
73cdf0e10cSrcweir         Class interfaces[] = getClass().getInterfaces();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         Type types[] = new Type[interfaces.length];
76cdf0e10cSrcweir         for(int i = 0; i < interfaces.length; ++ i)
77cdf0e10cSrcweir             types[i] = new Type(interfaces[i]);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         return types;
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /**
83cdf0e10cSrcweir      * Is this service supported?
84cdf0e10cSrcweir      * @param name The name of a service.
85cdf0e10cSrcweir      * @return True, if the service is supported.
86cdf0e10cSrcweir      */
supportsService(String name)87cdf0e10cSrcweir     public boolean supportsService(String name) {
88cdf0e10cSrcweir         return __serviceName.equals(name);
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     /**
92cdf0e10cSrcweir      * Get all supported service names.
93cdf0e10cSrcweir      * @return All service names.
94cdf0e10cSrcweir      */
getSupportedServiceNames()95cdf0e10cSrcweir     public String[] getSupportedServiceNames() {
96cdf0e10cSrcweir         return new String[] {__serviceName};
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /**
100cdf0e10cSrcweir      * Get the implementation name of this class.
101cdf0e10cSrcweir      * @return The name.
102cdf0e10cSrcweir      */
getImplementationName()103cdf0e10cSrcweir     public String getImplementationName() {
104cdf0e10cSrcweir         return getClass().getName();
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir /**
109cdf0e10cSrcweir  * The actual implementation of the interceptor.
110cdf0e10cSrcweir  * @see com.sun.star.lang.XTypeProvider
111cdf0e10cSrcweir  * @see com.sun.star.frame.XDispatchProviderInterceptor
112cdf0e10cSrcweir  * @see com.sun.star.frame.XDispatchProvider
113cdf0e10cSrcweir  */
114cdf0e10cSrcweir class InterceptorImpl implements XDispatchProvider,
115cdf0e10cSrcweir                                 XDispatchProviderInterceptor, XTypeProvider {
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** A master dispatch provider **/
118cdf0e10cSrcweir     public XDispatchProvider master = null;
119cdf0e10cSrcweir     /** A slave dispatch provider **/
120cdf0e10cSrcweir     public XDispatchProvider slave = null;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     /** Get the slave dispatch provider
123cdf0e10cSrcweir      * @return The slave.
124cdf0e10cSrcweir      */
getSlaveDispatchProvider()125cdf0e10cSrcweir     public XDispatchProvider getSlaveDispatchProvider() {
126cdf0e10cSrcweir         return slave;
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir     /** Get the master dispatch provider
129cdf0e10cSrcweir      * @return The master.
130cdf0e10cSrcweir      */
getMasterDispatchProvider()131cdf0e10cSrcweir     public XDispatchProvider getMasterDispatchProvider() {
132cdf0e10cSrcweir         return master;
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     /** Set the slave dispatch provider
136cdf0e10cSrcweir      * @param prov The new slave.
137cdf0e10cSrcweir      */
setSlaveDispatchProvider(XDispatchProvider prov)138cdf0e10cSrcweir     public void setSlaveDispatchProvider(XDispatchProvider prov) {
139cdf0e10cSrcweir         slave = prov ;
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     /** Set the master dispatch provider
143cdf0e10cSrcweir      * @param prov The new master.
144cdf0e10cSrcweir      */
setMasterDispatchProvider(XDispatchProvider prov)145cdf0e10cSrcweir     public void setMasterDispatchProvider(XDispatchProvider prov) {
146cdf0e10cSrcweir         master = prov ;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     /** Searches for an <type>XDispatch</type> for the specified URL within
150cdf0e10cSrcweir      * the specified target frame.
151cdf0e10cSrcweir      * @param url The URL.
152cdf0e10cSrcweir      * @param frame The target frame
153cdf0e10cSrcweir      * @param flags Optional search flags.
154cdf0e10cSrcweir      * @return The dispatch object which provides the queried functionality
155cdf0e10cSrcweir      *         or null if no dispatch object is available.
156cdf0e10cSrcweir      * @see com.sun.star.frame.XDispatch
157cdf0e10cSrcweir      */
queryDispatch(URL url, String frame, int flags)158cdf0e10cSrcweir     public XDispatch queryDispatch(URL url, String frame, int flags) {
159cdf0e10cSrcweir         return master.queryDispatch(url, frame, flags) ;
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     /**
163cdf0e10cSrcweir      * Query for an array of <type>XDispatch</type>.
164cdf0e10cSrcweir      * @param desc A list of dipatch requests.
165cdf0e10cSrcweir      * @return A list of dispatch objects.
166cdf0e10cSrcweir      */
queryDispatches(DispatchDescriptor[] desc)167cdf0e10cSrcweir     public XDispatch[] queryDispatches(DispatchDescriptor[] desc) {
168cdf0e10cSrcweir         return master.queryDispatches(desc) ;
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     /** Get the unique id for this implementation
172cdf0e10cSrcweir      * @return The id.
173cdf0e10cSrcweir      */
getImplementationId()174cdf0e10cSrcweir     public byte[] getImplementationId() {
175cdf0e10cSrcweir         return toString().getBytes();
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /** Get all implemented types.
179cdf0e10cSrcweir      * @return The implemented UNO types.
180cdf0e10cSrcweir      */
getTypes()181cdf0e10cSrcweir     public Type[] getTypes() {
182cdf0e10cSrcweir         Class interfaces[] = getClass().getInterfaces();
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         Type types[] = new Type[interfaces.length];
185cdf0e10cSrcweir         for(int i = 0; i < interfaces.length; ++ i)
186cdf0e10cSrcweir             types[i] = new Type(interfaces[i]);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         return types;
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir }
191