1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <recording/dispatchrecordersupplier.hxx>
23 #include <com/sun/star/frame/XRecordableDispatch.hpp>
25 #include <vcl/svapp.hxx>
29 // XInterface, XTypeProvider
31 DEFINE_XSERVICEINFO_MULTISERVICE(
32 DispatchRecorderSupplier
,
34 "com.sun.star.frame.DispatchRecorderSupplier",
35 IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER
)
38 DispatchRecorderSupplier
,
41 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
42 to create a new instance of this class by our own supported service factory.
43 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
49 @short standard constructor to create instance
50 @descr Because an instance will be initialized by her interface methods
51 it's not necessary to do anything here.
53 DispatchRecorderSupplier::DispatchRecorderSupplier( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& )
54 : m_xDispatchRecorder( NULL
)
59 @short standard destructor
60 @descr We are a helper and not a real service. So we don't provide
61 dispose() functionality. This supplier dies by ref count mechanism
62 and should release all internal used ones too.
64 DispatchRecorderSupplier::~DispatchRecorderSupplier()
66 m_xDispatchRecorder
= NULL
;
70 @short set a new dispatch recorder on this supplier
71 @descr Because there can exist more than one recorder implementations
72 (to generate java/basic/... scripts from recorded data) it must
73 be possible to set it on a supplier.
75 @see getDispatchRecorder()
78 the new recorder to set it
79 <br><NULL/> isn't recommended, because recording without a
80 valid recorder can't work. But it's not checked here. So user
81 of this supplier can decide that without changing this
84 @change 09.04.2002 by Andreas Schluens
86 void SAL_CALL
DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference
< css::frame::XDispatchRecorder
>& xRecorder
) throw (css::uno::RuntimeException
, std::exception
)
89 m_xDispatchRecorder
=xRecorder
;
93 @short provides access to the dispatch recorder of this supplier
94 @descr Such recorder can be used outside to record dispatches.
95 But normally he is used internally only. Of course he must used
96 from outside to get the recorded data e.g. for saving it as a
99 @see setDispatchRecorder()
101 @return the internal used dispatch recorder
102 <br>May it can be <NULL/> if no one was set before.
104 @change 09.04.2002 by Andreas Schluens
106 css::uno::Reference
< css::frame::XDispatchRecorder
> SAL_CALL
DispatchRecorderSupplier::getDispatchRecorder() throw (css::uno::RuntimeException
, std::exception
)
109 return m_xDispatchRecorder
;
113 @short execute a dispatch request and record it
114 @descr If given dispatch object provides right recording interface it
115 will be used. If it's not supported it record the pure dispatch
116 parameters only. There is no code neither the possibility to
117 check if recording is enabled or not.
119 @param aURL the command URL
120 @param lArguments optional arguments (see com.sun.star.document.MediaDescriptor for further information)
121 @param xDispatcher the original dispatch object which should be recorded
123 @change 09.04.2002 by Andreas Schluens
125 void SAL_CALL
DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL
& aURL
,
126 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
127 const css::uno::Reference
< css::frame::XDispatch
>& xDispatcher
) throw (css::uno::RuntimeException
, std::exception
)
129 SolarMutexClearableGuard aReadLock
;
130 css::uno::Reference
< css::frame::XDispatchRecorder
> xRecorder
= m_xDispatchRecorder
;
133 // clear unspecific situations
134 if (!xDispatcher
.is())
135 throw css::uno::RuntimeException("specification violation: dispatcher is NULL", static_cast< ::cppu::OWeakObject
* >(this));
138 throw css::uno::RuntimeException("specification violation: no valid dispatch recorder available", static_cast< ::cppu::OWeakObject
* >(this));
140 // check, if given dispatch supports record functionality by itself ...
141 // or must be wrapped.
142 css::uno::Reference
< css::frame::XRecordableDispatch
> xRecordable(
144 css::uno::UNO_QUERY
);
146 if (xRecordable
.is())
147 xRecordable
->dispatchAndRecord(aURL
,lArguments
,xRecorder
);
150 // There is no reason to wait for information about success
151 // of this request. Because status information of a dispatch
152 // are not guaranteed. So we execute it and record used
154 xDispatcher
->dispatch(aURL
,lArguments
);
155 xRecorder
->recordDispatch(aURL
,lArguments
);
159 } // namespace framework
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */