xref: /AOO41X/main/framework/source/recording/dispatchrecordersupplier.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 
31 //_________________________________________________________________________________________________________________
32 // include own things
33 #include <recording/dispatchrecordersupplier.hxx>
34 #include <threadhelp/writeguard.hxx>
35 #include <threadhelp/readguard.hxx>
36 #include <services.h>
37 
38 //_________________________________________________________________________________________________________________
39 // include interfaces
40 #include <com/sun/star/frame/XRecordableDispatch.hpp>
41 
42 //_________________________________________________________________________________________________________________
43 // include other projects
44 #include <vcl/svapp.hxx>
45 
46 //_________________________________________________________________________________________________________________
47 // namespace
48 
49 namespace framework{
50 
51 //_________________________________________________________________________________________________________________
52 // non exported const
53 
54 //_________________________________________________________________________________________________________________
55 // non exported definitions
56 
57 //_________________________________________________________________________________________________________________
58 // declarations
59 
60 //*****************************************************************************************************************
61 //  XInterface, XTypeProvider
62 //*****************************************************************************************************************
63 DEFINE_XINTERFACE_3(
64     DispatchRecorderSupplier,
65     OWeakObject,
66     DIRECT_INTERFACE(css::lang::XTypeProvider),
67     DIRECT_INTERFACE(css::lang::XServiceInfo),
68     DIRECT_INTERFACE(css::frame::XDispatchRecorderSupplier))
69 
70 DEFINE_XTYPEPROVIDER_3(
71     DispatchRecorderSupplier,
72     css::lang::XTypeProvider,
73     css::lang::XServiceInfo,
74     css::frame::XDispatchRecorderSupplier)
75 
76 DEFINE_XSERVICEINFO_MULTISERVICE(
77     DispatchRecorderSupplier,
78     ::cppu::OWeakObject,
79     SERVICENAME_DISPATCHRECORDERSUPPLIER,
80     IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER)
81 
82 DEFINE_INIT_SERVICE(
83     DispatchRecorderSupplier,
84     {
85         /*Attention
86             I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
87             to create a new instance of this class by our own supported service factory.
88             see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
89         */
90     }
91 )
92 
93 //_____________________________________________________________________________
94 /**
95     @short  standard constructor to create instance
96     @descr  Because an instance will be initialized by her interface methods
97             it's not neccessary to do anything here.
98  */
99 DispatchRecorderSupplier::DispatchRecorderSupplier( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
100 		//	init baseclasses first!
101 		//	Attention: Don't change order of initialization!
102         : ThreadHelpBase     ( &Application::GetSolarMutex() )
103         , ::cppu::OWeakObject(                               )
104 		//	init member
105         , m_xDispatchRecorder( NULL                          )
106         , m_xFactory         ( xFactory                      )
107 {
108 }
109 
110 //_____________________________________________________________________________
111 /**
112     @short  standard destructor
113     @descr  We are a helper and not a real service. So we doesn't provide
114             dispose() functionality. This supplier dies by ref count mechanism
115             and should release all internal used ones too.
116  */
117 DispatchRecorderSupplier::~DispatchRecorderSupplier()
118 {
119     m_xFactory          = NULL;
120     m_xDispatchRecorder = NULL;
121 }
122 
123 //_____________________________________________________________________________
124 /**
125     @short      set a new dispatch recorder on this supplier
126     @descr      Because there can exist more then one recorder implementations
127                 (to generate java/basic/... scripts from recorded data) it must
128                 be possible to set it on a supplier.
129 
130     @see        getDispatchRecorder()
131 
132     @param      xRecorder
133                 the new recorder to set it
134                 <br><NULL/> isn't recommended, because recording without a
135                 valid recorder can't work. But it's not checked here. So user
136                 of this supplier can decide that without changing this
137                 implementation.
138 
139     @change     09.04.2002 by Andreas Schluens
140  */
141 void SAL_CALL DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder ) throw (css::uno::RuntimeException)
142 {
143     // SAFE =>
144     WriteGuard aWriteLock(m_aLock);
145     m_xDispatchRecorder=xRecorder;
146     // => SAFE
147 }
148 //_____________________________________________________________________________
149 /**
150     @short      provides access to the dispatch recorder of this supplier
151     @descr      Such recorder can be used outside to record dispatches.
152                 But normaly he is used internaly only. Of course he must used
153                 from outside to get the recorded data e.g. for saving it as a
154                 script.
155 
156     @see        setDispatchRecorder()
157 
158     @return     the internal used dispatch recorder
159                 <br>May it can be <NULL/> if no one was set before.
160 
161     @change     09.04.2002 by Andreas Schluens
162  */
163 css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL DispatchRecorderSupplier::getDispatchRecorder() throw (css::uno::RuntimeException)
164 {
165     // SAFE =>
166     ReadGuard aReadLock(m_aLock);
167     return m_xDispatchRecorder;
168     // => SAFE
169 }
170 
171 //_____________________________________________________________________________
172 /**
173     @short      execute a dispatch request and record it
174     @descr      If given dispatch object provides right recording interface it
175                 will be used. If it's not supported it record the pure dispatch
176                 parameters only. There is no code neither the possibility to
177                 check if recording is enabled or not.
178 
179     @param      aURL            the command URL
180     @param      lArguments      optional arguments (see com.sun.star.document.MediaDescriptor for further informations)
181     @param      xDispatcher     the original dispatch object which should be recorded
182 
183     @change     09.04.2002 by Andreas Schluens
184  */
185 void SAL_CALL DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL&                                  aURL        ,
186                                                            const css::uno::Sequence< css::beans::PropertyValue >& lArguments  ,
187                                                            const css::uno::Reference< css::frame::XDispatch >&    xDispatcher ) throw (css::uno::RuntimeException)
188 {
189     // SAFE =>
190     ReadGuard aReadLock(m_aLock);
191     css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = m_xDispatchRecorder;
192     aReadLock.unlock();
193     // => SAFE
194 
195     // clear unspecific situations
196     if (!xDispatcher.is())
197         throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: dispatcher is NULL"), static_cast< ::cppu::OWeakObject* >(this));
198 
199     if (!xRecorder.is())
200         throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: no valid dispatch recorder available"), static_cast< ::cppu::OWeakObject* >(this));
201 
202     // check, if given dispatch supports record functionality by itself ...
203     // or must be wrapped.
204     css::uno::Reference< css::frame::XRecordableDispatch > xRecordable(
205         xDispatcher,
206         css::uno::UNO_QUERY);
207 
208     if (xRecordable.is())
209         xRecordable->dispatchAndRecord(aURL,lArguments,xRecorder);
210     else
211     {
212         // There is no reason to wait for information about success
213         // of this request. Because status information of a dispatch
214         // are not guaranteed. So we execute it and record used
215         // parameters only.
216         xDispatcher->dispatch(aURL,lArguments);
217         xRecorder->recordDispatch(aURL,lArguments);
218     }
219 }
220 
221 }	// namespace framework
222