update dev300-m58
[ooovba.git] / framework / source / recording / dispatchrecordersupplier.cxx
blob8c7b601b4abf5ae7517b39a0470c40e359c79687
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: dispatchrecordersupplier.cxx,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // include own things
36 #include <recording/dispatchrecordersupplier.hxx>
37 #include <threadhelp/writeguard.hxx>
38 #include <threadhelp/readguard.hxx>
39 #include <services.h>
41 //_________________________________________________________________________________________________________________
42 // include interfaces
43 #include <com/sun/star/frame/XRecordableDispatch.hpp>
45 //_________________________________________________________________________________________________________________
46 // include other projects
47 #include <vcl/svapp.hxx>
49 //_________________________________________________________________________________________________________________
50 // namespace
52 namespace framework{
54 //_________________________________________________________________________________________________________________
55 // non exported const
57 //_________________________________________________________________________________________________________________
58 // non exported definitions
60 //_________________________________________________________________________________________________________________
61 // declarations
63 //*****************************************************************************************************************
64 // XInterface, XTypeProvider
65 //*****************************************************************************************************************
66 DEFINE_XINTERFACE_3(
67 DispatchRecorderSupplier,
68 OWeakObject,
69 DIRECT_INTERFACE(css::lang::XTypeProvider),
70 DIRECT_INTERFACE(css::lang::XServiceInfo),
71 DIRECT_INTERFACE(css::frame::XDispatchRecorderSupplier))
73 DEFINE_XTYPEPROVIDER_3(
74 DispatchRecorderSupplier,
75 css::lang::XTypeProvider,
76 css::lang::XServiceInfo,
77 css::frame::XDispatchRecorderSupplier)
79 DEFINE_XSERVICEINFO_MULTISERVICE(
80 DispatchRecorderSupplier,
81 ::cppu::OWeakObject,
82 SERVICENAME_DISPATCHRECORDERSUPPLIER,
83 IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER)
85 DEFINE_INIT_SERVICE(
86 DispatchRecorderSupplier,
88 /*Attention
89 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
90 to create a new instance of this class by our own supported service factory.
91 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
96 //_____________________________________________________________________________
97 /**
98 @short standard constructor to create instance
99 @descr Because an instance will be initialized by her interface methods
100 it's not neccessary to do anything here.
102 DispatchRecorderSupplier::DispatchRecorderSupplier( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
103 // init baseclasses first!
104 // Attention: Don't change order of initialization!
105 : ThreadHelpBase ( &Application::GetSolarMutex() )
106 , ::cppu::OWeakObject( )
107 // init member
108 , m_xDispatchRecorder( NULL )
109 , m_xFactory ( xFactory )
113 //_____________________________________________________________________________
115 @short standard destructor
116 @descr We are a helper and not a real service. So we doesn't provide
117 dispose() functionality. This supplier dies by ref count mechanism
118 and should release all internal used ones too.
120 DispatchRecorderSupplier::~DispatchRecorderSupplier()
122 m_xFactory = NULL;
123 m_xDispatchRecorder = NULL;
126 //_____________________________________________________________________________
128 @short set a new dispatch recorder on this supplier
129 @descr Because there can exist more then one recorder implementations
130 (to generate java/basic/... scripts from recorded data) it must
131 be possible to set it on a supplier.
133 @see getDispatchRecorder()
135 @param xRecorder
136 the new recorder to set it
137 <br><NULL/> isn't recommended, because recording without a
138 valid recorder can't work. But it's not checked here. So user
139 of this supplier can decide that without changing this
140 implementation.
142 @change 09.04.2002 by Andreas Schluens
144 void SAL_CALL DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder ) throw (css::uno::RuntimeException)
146 // SAFE =>
147 WriteGuard aWriteLock(m_aLock);
148 m_xDispatchRecorder=xRecorder;
149 // => SAFE
151 //_____________________________________________________________________________
153 @short provides access to the dispatch recorder of this supplier
154 @descr Such recorder can be used outside to record dispatches.
155 But normaly he is used internaly only. Of course he must used
156 from outside to get the recorded data e.g. for saving it as a
157 script.
159 @see setDispatchRecorder()
161 @return the internal used dispatch recorder
162 <br>May it can be <NULL/> if no one was set before.
164 @change 09.04.2002 by Andreas Schluens
166 css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL DispatchRecorderSupplier::getDispatchRecorder() throw (css::uno::RuntimeException)
168 // SAFE =>
169 ReadGuard aReadLock(m_aLock);
170 return m_xDispatchRecorder;
171 // => SAFE
174 //_____________________________________________________________________________
176 @short execute a dispatch request and record it
177 @descr If given dispatch object provides right recording interface it
178 will be used. If it's not supported it record the pure dispatch
179 parameters only. There is no code neither the possibility to
180 check if recording is enabled or not.
182 @param aURL the command URL
183 @param lArguments optional arguments (see com.sun.star.document.MediaDescriptor for further informations)
184 @param xDispatcher the original dispatch object which should be recorded
186 @change 09.04.2002 by Andreas Schluens
188 void SAL_CALL DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL& aURL ,
189 const css::uno::Sequence< css::beans::PropertyValue >& lArguments ,
190 const css::uno::Reference< css::frame::XDispatch >& xDispatcher ) throw (css::uno::RuntimeException)
192 // SAFE =>
193 ReadGuard aReadLock(m_aLock);
194 css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = m_xDispatchRecorder;
195 aReadLock.unlock();
196 // => SAFE
198 // clear unspecific situations
199 if (!xDispatcher.is())
200 throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: dispatcher is NULL"), static_cast< ::cppu::OWeakObject* >(this));
202 if (!xRecorder.is())
203 throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: no valid dispatch recorder available"), static_cast< ::cppu::OWeakObject* >(this));
205 // check, if given dispatch supports record functionality by itself ...
206 // or must be wrapped.
207 css::uno::Reference< css::frame::XRecordableDispatch > xRecordable(
208 xDispatcher,
209 css::uno::UNO_QUERY);
211 if (xRecordable.is())
212 xRecordable->dispatchAndRecord(aURL,lArguments,xRecorder);
213 else
215 // There is no reason to wait for information about success
216 // of this request. Because status information of a dispatch
217 // are not guaranteed. So we execute it and record used
218 // parameters only.
219 xDispatcher->dispatch(aURL,lArguments);
220 xRecorder->recordDispatch(aURL,lArguments);
224 } // namespace framework