1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dispatchrecordersupplier.cxx,v $
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 //_________________________________________________________________________________________________________________
36 #include <recording/dispatchrecordersupplier.hxx>
37 #include <threadhelp/writeguard.hxx>
38 #include <threadhelp/readguard.hxx>
41 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/frame/XRecordableDispatch.hpp>
45 //_________________________________________________________________________________________________________________
46 // include other projects
47 #include <vcl/svapp.hxx>
49 //_________________________________________________________________________________________________________________
54 //_________________________________________________________________________________________________________________
57 //_________________________________________________________________________________________________________________
58 // non exported definitions
60 //_________________________________________________________________________________________________________________
63 //*****************************************************************************************************************
64 // XInterface, XTypeProvider
65 //*****************************************************************************************************************
67 DispatchRecorderSupplier
,
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
,
82 SERVICENAME_DISPATCHRECORDERSUPPLIER
,
83 IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER
)
86 DispatchRecorderSupplier
,
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 //_____________________________________________________________________________
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( )
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()
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()
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
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
)
147 WriteGuard
aWriteLock(m_aLock
);
148 m_xDispatchRecorder
=xRecorder
;
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
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
)
169 ReadGuard
aReadLock(m_aLock
);
170 return m_xDispatchRecorder
;
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
)
193 ReadGuard
aReadLock(m_aLock
);
194 css::uno::Reference
< css::frame::XDispatchRecorder
> xRecorder
= m_xDispatchRecorder
;
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));
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(
209 css::uno::UNO_QUERY
);
211 if (xRecordable
.is())
212 xRecordable
->dispatchAndRecord(aURL
,lArguments
,xRecorder
);
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
219 xDispatcher
->dispatch(aURL
,lArguments
);
220 xRecorder
->recordDispatch(aURL
,lArguments
);
224 } // namespace framework