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 .
21 #include <sal/config.h>
26 #include <ModelImpl.hxx>
27 #include "documenteventnotifier.hxx"
29 #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
30 #include <com/sun/star/frame/DoubleInitializationException.hpp>
31 #include <com/sun/star/frame/XModel2.hpp>
32 #include <com/sun/star/frame/XTitle.hpp>
33 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
34 #include <com/sun/star/frame/XUntitledNumbers.hpp>
35 #include <com/sun/star/frame/XStorable.hpp>
36 #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
37 #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
38 #include <com/sun/star/view/XPrintable.hpp>
39 #include <com/sun/star/frame/XModuleManager2.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/NotInitializedException.hpp>
43 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
44 #include <com/sun/star/embed/XTransactionListener.hpp>
45 #include <com/sun/star/document/XStorageBasedDocument.hpp>
46 #include <com/sun/star/document/XEmbeddedScripts.hpp>
47 #include <com/sun/star/document/XEventsSupplier.hpp>
48 #include <com/sun/star/document/XScriptInvocationContext.hpp>
49 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
50 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
51 #include <com/sun/star/frame/XLoadable.hpp>
52 #include <com/sun/star/document/XEventBroadcaster.hpp>
53 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
54 #include <com/sun/star/document/XDocumentRecovery.hpp>
55 #include <com/sun/star/ui/XUIConfigurationManager2.hpp>
56 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
57 #include <com/sun/star/util/XCloseable.hpp>
58 #include <com/sun/star/util/XModifiable.hpp>
60 #include <cppuhelper/compbase.hxx>
61 #include <cppuhelper/implbase3.hxx>
62 #include <rtl/ref.hxx>
64 namespace comphelper
{
65 class NamedValueCollection
;
72 class DocumentEventExecutor
;
75 typedef std::vector
< css::uno::Reference
< css::frame::XController
> > Controllers
;
78 /** helper class monitoring the views of a document, and firing appropriate events
79 when views are attached / detached
84 explicit ViewMonitor( DocumentEventNotifier
& _rEventNotifier
)
85 :m_rEventNotifier( _rEventNotifier
)
86 ,m_bIsNewDocument( true )
87 ,m_bEverHadController( false )
88 ,m_bLastIsFirstEverController( false )
89 ,m_xLastConnectedController()
93 ViewMonitor(const ViewMonitor
&) = delete;
94 const ViewMonitor
& operator=(const ViewMonitor
&) = delete;
98 m_bEverHadController
= false;
99 m_bLastIsFirstEverController
= false;
100 m_xLastConnectedController
.clear();
103 /** to be called when a view (aka controller) has been connected to the document
105 <TRUE/> if and only if this was the first-ever controller connected to the document
107 bool onControllerConnected(
108 const css::uno::Reference
< css::frame::XController
>& _rxController
111 /** to be called when a controller is set as current controller
113 if and only if the controller connection indicates that loading the document is finished. This
114 is the case if the given controller has previously been connected, and it was the first controller
115 ever for which this happened.
117 bool onSetCurrentController(
118 const css::uno::Reference
< css::frame::XController
>& _rxController
121 void onLoadedDocument() { m_bIsNewDocument
= false; }
124 DocumentEventNotifier
& m_rEventNotifier
;
125 bool m_bIsNewDocument
;
126 bool m_bEverHadController
;
127 bool m_bLastIsFirstEverController
;
128 css::uno::Reference
< css::frame::XController
>
129 m_xLastConnectedController
;
133 typedef cppu::PartialWeakComponentImplHelper
< css::frame::XModel2
134 , css::util::XModifiable
135 , css::frame::XStorable
136 , css::document::XEventBroadcaster
137 , css::document::XDocumentEventBroadcaster
138 , css::view::XPrintable
139 , css::util::XCloseable
140 , css::lang::XServiceInfo
141 , css::sdb::XOfficeDatabaseDocument
142 , css::ui::XUIConfigurationManagerSupplier
143 , css::document::XStorageBasedDocument
144 , css::document::XEmbeddedScripts
145 , css::document::XScriptInvocationContext
146 , css::script::provider::XScriptProviderSupplier
147 , css::document::XEventsSupplier
148 , css::frame::XLoadable
149 , css::document::XDocumentRecovery
150 > ODatabaseDocument_OfficeDocument
;
152 typedef ::cppu::ImplHelper3
< css::frame::XTitle
153 , css::frame::XTitleChangeBroadcaster
154 , css::frame::XUntitledNumbers
155 > ODatabaseDocument_Title
;
157 class ODatabaseDocument
:public ModelDependentComponent
// ModelDependentComponent must be first!
158 ,public ODatabaseDocument_OfficeDocument
159 ,public ODatabaseDocument_Title
168 typedef std::map
< OUString
, css::uno::Reference
< css::frame::XUntitledNumbers
> > TNumberedController
;
169 css::uno::Reference
< css::ui::XUIConfigurationManager2
> m_xUIConfigurationManager
;
171 ::comphelper::OInterfaceContainerHelper2 m_aModifyListeners
;
172 ::comphelper::OInterfaceContainerHelper2 m_aCloseListener
;
173 ::comphelper::OInterfaceContainerHelper2 m_aStorageListeners
;
175 std::unique_ptr
<DocumentEvents
> m_pEventContainer
;
176 ::rtl::Reference
< DocumentEventExecutor
> m_pEventExecutor
;
177 DocumentEventNotifier m_aEventNotifier
;
179 css::uno::Reference
< css::frame::XController
> m_xCurrentController
;
180 Controllers m_aControllers
;
181 ViewMonitor m_aViewMonitor
;
183 css::uno::WeakReference
< css::container::XNameAccess
> m_xForms
;
184 css::uno::WeakReference
< css::container::XNameAccess
> m_xReports
;
185 css::uno::WeakReference
< css::script::provider::XScriptProvider
> m_xScriptProvider
;
187 /** @short such module manager is used to classify new opened documents. */
188 css::uno::Reference
< css::frame::XModuleManager2
> m_xModuleManager
;
189 css::uno::Reference
< css::frame::XTitle
> m_xTitleHelper
;
190 TNumberedController m_aNumberedControllers
;
192 /** true if and only if the DatabaseDocument's "initNew" or "load" have been called (or, well,
193 the document has be initialized implicitly - see storeAsURL
195 InitState m_eInitState
;
197 bool m_bAllowDocumentScripting
;
198 bool m_bHasBeenRecovered
;
199 /// If XModel::attachResource() was called to inform us that the document is embedded into another one.
202 enum StoreType
{ SAVE
, SAVE_AS
};
203 /** stores the document to the given URL, rebases it to the respective new storage, if necessary, resets
204 the modified flag, and notifies any listeners as required
207 the URL to store the document to
209 arguments for storing the document (MediaDescriptor)
211 the type of the store process (Save or SaveAs). The method will automatically
212 notify the proper events for this type.
214 the instance lock to be released before doing synchronous notifications
215 @throws css::io::IOException
216 @throws css::uno::RuntimeException
218 void impl_storeAs_throw(
219 const OUString
& _rURL
,
220 const ::comphelper::NamedValueCollection
& _rArguments
,
221 const StoreType _eType
,
222 DocumentGuard
& _rGuard
225 /** notifies our storage change listeners that our underlying storage changed
227 @param _rxNewRootStorage
228 the new root storage to be notified. If <NULL/>, it is assumed that no storage change actually
229 happened, and the listeners are not notified.
231 void impl_notifyStorageChange_nolck_nothrow(
232 const css::uno::Reference
< css::embed::XStorage
>& _rxNewRootStorage
235 /// write a single XML stream into the package
236 void WriteThroughComponent(
237 const css::uno::Reference
< css::lang::XComponent
> & xComponent
, /// the component we export
238 const char* pStreamName
, /// the stream name
239 const char* pServiceName
, /// service name of the component
240 const css::uno::Sequence
< css::uno::Any
> & rArguments
, /// the argument (XInitialization)
241 const css::uno::Sequence
< css::beans::PropertyValue
> & rMediaDesc
,/// output descriptor
242 const css::uno::Reference
< css::embed::XStorage
>& _xStorageToSaveTo
245 /// write a single output stream
246 /// (to be called either directly or by WriteThroughComponent(...))
247 void WriteThroughComponent(
248 const css::uno::Reference
< css::io::XOutputStream
>& xOutputStream
,
249 const css::uno::Reference
< css::lang::XComponent
>& xComponent
,
250 const char* pServiceName
,
251 const css::uno::Sequence
< css::uno::Any
>& rArguments
,
252 const css::uno::Sequence
< css::beans::PropertyValue
> & rMediaDesc
255 /** writes the content and settings
260 @param _xStorageToSaveTo
261 The storage which should be used for saving
263 void impl_writeStorage_throw(
264 const css::uno::Reference
< css::embed::XStorage
>& _rxTargetStorage
,
265 const ::comphelper::NamedValueCollection
& _rMediaDescriptor
268 // ModelDependentComponent overridables
269 virtual css::uno::Reference
< css::uno::XInterface
> getThis() const override
;
271 css::uno::Reference
< css::frame::XTitle
> const & impl_getTitleHelper_throw();
272 css::uno::Reference
< css::frame::XUntitledNumbers
> impl_getUntitledHelper_throw(
273 const css::uno::Reference
< css::uno::XInterface
>& _xComponent
= css::uno::Reference
< css::uno::XInterface
>());
276 explicit ODatabaseDocument(const ::rtl::Reference
<ODatabaseModelImpl
>& _pImpl
);
277 // Do NOT create those documents directly, always use ODatabaseModelImpl::getModel. Reason is that
278 // ODatabaseDocument requires clear ownership, and in turn lifetime synchronisation with the ModelImpl.
279 // If you create a ODatabaseDocument directly, you might easily create a leak.
283 virtual void SAL_CALL
disposing() override
;
285 virtual ~ODatabaseDocument() override
;
288 struct FactoryAccess
{ friend class ODatabaseModelImpl
; private: FactoryAccess() { } };
289 static ODatabaseDocument
* createDatabaseDocument( const ::rtl::Reference
<ODatabaseModelImpl
>& _pImpl
, FactoryAccess
/*accessControl*/ )
291 return new ODatabaseDocument( _pImpl
);
295 virtual OUString SAL_CALL
getImplementationName( ) override
;
296 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
297 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
300 virtual css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& _rType
) override
;
301 virtual void SAL_CALL
acquire( ) throw () override
;
302 virtual void SAL_CALL
release( ) throw () override
;
305 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
306 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) override
;
309 virtual void SAL_CALL
dispose( ) override
;
310 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
311 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
314 virtual sal_Bool SAL_CALL
attachResource( const OUString
& URL
, const css::uno::Sequence
< css::beans::PropertyValue
>& Arguments
) override
;
315 virtual OUString SAL_CALL
getURL( ) override
;
316 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getArgs( ) override
;
317 virtual void SAL_CALL
connectController( const css::uno::Reference
< css::frame::XController
>& Controller
) override
;
318 virtual void SAL_CALL
disconnectController( const css::uno::Reference
< css::frame::XController
>& Controller
) override
;
319 virtual void SAL_CALL
lockControllers( ) override
;
320 virtual void SAL_CALL
unlockControllers( ) override
;
321 virtual sal_Bool SAL_CALL
hasControllersLocked( ) override
;
322 virtual css::uno::Reference
< css::frame::XController
> SAL_CALL
getCurrentController( ) override
;
323 virtual void SAL_CALL
setCurrentController( const css::uno::Reference
< css::frame::XController
>& Controller
) override
;
324 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getCurrentSelection( ) override
;
327 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
getControllers( ) override
;
328 virtual css::uno::Sequence
< OUString
> SAL_CALL
getAvailableViewControllerNames( ) override
;
329 virtual css::uno::Reference
< css::frame::XController2
> SAL_CALL
createDefaultViewController( const css::uno::Reference
< css::frame::XFrame
>& Frame
) override
;
330 virtual css::uno::Reference
< css::frame::XController2
> SAL_CALL
createViewController( const OUString
& ViewName
, const css::uno::Sequence
< css::beans::PropertyValue
>& Arguments
, const css::uno::Reference
< css::frame::XFrame
>& Frame
) override
;
331 virtual void SAL_CALL
setArgs(const css::uno::Sequence
<css::beans::PropertyValue
>& aArgs
) override
;
334 virtual sal_Bool SAL_CALL
hasLocation( ) override
;
335 virtual OUString SAL_CALL
getLocation( ) override
;
336 virtual sal_Bool SAL_CALL
isReadonly( ) override
;
337 virtual void SAL_CALL
store( ) override
;
338 virtual void SAL_CALL
storeAsURL( const OUString
& sURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) override
;
339 virtual void SAL_CALL
storeToURL( const OUString
& sURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) override
;
341 // XModifyBroadcaster
342 virtual void SAL_CALL
addModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
343 virtual void SAL_CALL
removeModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
345 // css::util::XModifiable
346 virtual sal_Bool SAL_CALL
isModified( ) override
;
347 virtual void SAL_CALL
setModified( sal_Bool bModified
) override
;
350 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::document::XEventListener
>& aListener
) override
;
351 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::document::XEventListener
>& aListener
) override
;
353 // XDocumentEventBroadcaster
354 virtual void SAL_CALL
addDocumentEventListener( const css::uno::Reference
< css::document::XDocumentEventListener
>& Listener
) override
;
355 virtual void SAL_CALL
removeDocumentEventListener( const css::uno::Reference
< css::document::XDocumentEventListener
>& Listener
) override
;
356 virtual void SAL_CALL
notifyDocumentEvent( const OUString
& EventName
, const css::uno::Reference
< css::frame::XController2
>& ViewController
, const css::uno::Any
& Supplement
) override
;
359 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
getPrinter( ) override
;
360 virtual void SAL_CALL
setPrinter( const css::uno::Sequence
< css::beans::PropertyValue
>& aPrinter
) override
;
361 virtual void SAL_CALL
print( const css::uno::Sequence
< css::beans::PropertyValue
>& xOptions
) override
;
363 // XFormDocumentsSupplier
364 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getFormDocuments( ) override
;
366 // XReportDocumentsSupplier
367 virtual css::uno::Reference
< css::container::XNameAccess
> SAL_CALL
getReportDocuments( ) override
;
370 virtual void SAL_CALL
close( sal_Bool DeliverOwnership
) override
;
371 virtual void SAL_CALL
addCloseListener( const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
372 virtual void SAL_CALL
removeCloseListener( const css::uno::Reference
< css::util::XCloseListener
>& Listener
) override
;
374 // XUIConfigurationManagerSupplier
375 virtual css::uno::Reference
< css::ui::XUIConfigurationManager
> SAL_CALL
getUIConfigurationManager( ) override
;
377 // XDocumentSubStorageSupplier
378 virtual css::uno::Reference
< css::embed::XStorage
> SAL_CALL
getDocumentSubStorage( const OUString
& aStorageName
, sal_Int32 nMode
) override
;
379 virtual css::uno::Sequence
< OUString
> SAL_CALL
getDocumentSubStoragesNames( ) override
;
381 // XOfficeDatabaseDocument
382 virtual css::uno::Reference
< css::sdbc::XDataSource
> SAL_CALL
getDataSource() override
;
384 // XStorageBasedDocument
385 virtual void SAL_CALL
loadFromStorage( const css::uno::Reference
< css::embed::XStorage
>& xStorage
, const css::uno::Sequence
< css::beans::PropertyValue
>& aMediaDescriptor
) override
;
386 virtual void SAL_CALL
storeToStorage( const css::uno::Reference
< css::embed::XStorage
>& xStorage
, const css::uno::Sequence
< css::beans::PropertyValue
>& aMediaDescriptor
) override
;
387 virtual void SAL_CALL
switchToStorage( const css::uno::Reference
< css::embed::XStorage
>& xStorage
) override
;
388 virtual css::uno::Reference
< css::embed::XStorage
> SAL_CALL
getDocumentStorage( ) override
;
389 virtual void SAL_CALL
addStorageChangeListener( const css::uno::Reference
< css::document::XStorageChangeListener
>& xListener
) override
;
390 virtual void SAL_CALL
removeStorageChangeListener( const css::uno::Reference
< css::document::XStorageChangeListener
>& xListener
) override
;
393 virtual css::uno::Reference
< css::script::XStorageBasedLibraryContainer
> SAL_CALL
getBasicLibraries() override
;
394 virtual css::uno::Reference
< css::script::XStorageBasedLibraryContainer
> SAL_CALL
getDialogLibraries() override
;
395 virtual sal_Bool SAL_CALL
getAllowMacroExecution() override
;
397 // XScriptInvocationContext
398 virtual css::uno::Reference
< css::document::XEmbeddedScripts
> SAL_CALL
getScriptContainer() override
;
400 // XScriptProviderSupplier
401 virtual css::uno::Reference
< css::script::provider::XScriptProvider
> SAL_CALL
getScriptProvider( ) override
;
404 virtual css::uno::Reference
< css::container::XNameReplace
> SAL_CALL
getEvents( ) override
;
407 virtual void SAL_CALL
initNew( ) override
;
408 virtual void SAL_CALL
load( const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) override
;
410 // css.document.XDocumentRecovery
411 virtual sal_Bool SAL_CALL
wasModifiedSinceLastSave() override
;
412 virtual void SAL_CALL
storeToRecoveryFile( const OUString
& i_TargetLocation
, const css::uno::Sequence
< css::beans::PropertyValue
>& i_MediaDescriptor
) override
;
413 virtual void SAL_CALL
recoverFromFile( const OUString
& i_SourceLocation
, const OUString
& i_SalvagedFile
, const css::uno::Sequence
< css::beans::PropertyValue
>& i_MediaDescriptor
) override
;
416 virtual OUString SAL_CALL
getTitle( ) override
;
417 virtual void SAL_CALL
setTitle( const OUString
& sTitle
) override
;
419 // XTitleChangeBroadcaster
420 virtual void SAL_CALL
addTitleChangeListener( const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
) override
;
421 virtual void SAL_CALL
removeTitleChangeListener( const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
) override
;
424 virtual ::sal_Int32 SAL_CALL
leaseNumber( const css::uno::Reference
< css::uno::XInterface
>& xComponent
) override
;
425 virtual void SAL_CALL
releaseNumber( ::sal_Int32 nNumber
) override
;
426 virtual void SAL_CALL
releaseNumberForComponent( const css::uno::Reference
< css::uno::XInterface
>& xComponent
) override
;
427 virtual OUString SAL_CALL
getUntitledPrefix( ) override
;
429 /** clears the given object container
431 Clearing is done via disposal - the method calls XComponent::dispose at the given object,
432 which must be one of our impl's or our object containers (m_xForms, m_xReports,
433 m_xTableDefinitions, m_xCommandDefinitions)
436 the container to clear
438 static void clearObjectContainer(
439 css::uno::WeakReference
< css::container::XNameAccess
>& _rxContainer
);
441 /** checks whether the component is already initialized, throws a NotInitializedException if not
443 void checkInitialized() const
445 if ( !impl_isInitialized() )
446 throw css::lang::NotInitializedException( OUString(), getThis() );
449 /** checks the document is currently in the initialization phase, or already initialized.
450 Throws NotInitializedException if not so.
452 void checkNotUninitialized() const
454 if ( impl_isInitialized() || impl_isInitializing() )
458 throw css::lang::NotInitializedException( OUString(), getThis() );
461 /** checks whether the document is currently being initialized, or already initialized,
462 throws a DoubleInitializationException if so
464 void checkNotInitialized() const
466 if ( impl_isInitializing() || impl_isInitialized() )
467 throw css::frame::DoubleInitializationException( OUString(), getThis() );
471 /// @throws css::uno::RuntimeException
472 css::uno::Reference
< css::ui::XUIConfigurationManager2
> const & getUIConfigurationManager2();
474 /** returns whether the model is currently being initialized
476 bool impl_isInitializing() const { return m_eInitState
== Initializing
; }
478 /** returns whether the model is already initialized, i.e. the XModel's "initNew" or "load" methods have been called
480 bool impl_isInitialized() const { return m_eInitState
== Initialized
; }
482 /// tells the model it is being initialized now
483 void impl_setInitializing() { m_eInitState
= Initializing
; }
485 /// tells the model its initialization is done
486 void impl_setInitialized();
488 /** closes the frames of all connected controllers
490 @param _bDeliverOwnership
491 determines if the ownership should be transferred to the component which
492 possibly vetos the closing
494 @throws css::util::CloseVetoException
495 if the closing was vetoed by any instance
497 void impl_closeControllerFrames_nolck_throw( bool _bDeliverOwnership
);
499 /** disposes the frames of all controllers which are still left in m_aControllers.
501 void impl_disposeControllerFrames_nothrow();
503 /** does a reparenting at the given object container to ourself
505 Calls XChild::setParent at the given object, which must be one of our impl's or our
506 object containers (m_xForms, m_xReports, m_xTableDefinitions, m_xCommandDefinitions)
508 void impl_reparent_nothrow( const css::uno::WeakReference
< css::container::XNameAccess
>& _rxContainer
);
510 /** retrieves the forms or reports contained, creates and initializes it, if necessary
512 @throws DisposedException
513 if the instance is already disposed
514 @throws IllegalArgumentException
515 if <arg>_eType</arg> is not ODatabaseModelImpl::E_FORM and not ODatabaseModelImpl::E_REPORT
517 css::uno::Reference
< css::container::XNameAccess
>
518 impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType _eType
);
520 /** resets everything
523 m_pImpl is not <NULL/>
526 impl_reset_nothrow();
528 /** imports the document from the given resource.
531 impl_import_nolck_throw(
532 const css::uno::Reference
< css::uno::XComponentContext
>& _rContext
,
533 const css::uno::Reference
< css::uno::XInterface
>& _rxTargetComponent
,
534 const ::comphelper::NamedValueCollection
& _rResource
537 /** creates a storage for the given URL, truncating it if a file with this name already exists
540 if creating the storage failed
543 the newly created storage for the file at the given URL
545 css::uno::Reference
< css::embed::XStorage
>
546 impl_createStorageFor_throw(
547 const OUString
& _rURL
550 /** Extracts storage from arguments, or creates for the given URL, truncating it if a file with
551 this name already exists
554 if creating the storage failed
557 the storage that is either extracted from arguments, or newly created for the file at
560 css::uno::Reference
<css::embed::XStorage
> impl_GetStorageOrCreateFor_throw(
561 const ::comphelper::NamedValueCollection
& _rArguments
, const OUString
& _rURL
) const;
563 /** sets our "modified" flag
565 will notify all our respective listeners, if the "modified" state actually changed
568 the (new) flag indicating whether the document is currently modified or not
570 the guard for our instance. At method entry, the guard must hold the lock. At the moment
571 of method leave, the lock will be released.
575 our mutex is not locked
577 void impl_setModified_nothrow( bool _bModified
, DocumentGuard
& _rGuard
);
579 /** stores the document to the given storage
581 Note that the document is actually not rebased to this storage, it just stores a copy of itself
582 to the given target storage.
584 @param _rxTargetStorage
585 denotes the storage to store the document into
586 @param _rMediaDescriptor
587 contains additional parameters for storing the document
589 a guard which holds the (only) lock to the document, and which will be temporarily
590 released where necessary (e.g. for notifications, or calling into other components)
592 @throws css::uno::IllegalArgumentException
593 if the given storage is <NULL/>.
595 @throws css::uno::RuntimeException
596 when any of the used operations throws it
598 @throws css::io::IOException
599 when any of the used operations throws it, or any other exception occurs which is no
600 RuntimeException and no IOException
602 void impl_storeToStorage_throw(
603 const css::uno::Reference
< css::embed::XStorage
>& _rxTargetStorage
,
604 const css::uno::Sequence
< css::beans::PropertyValue
>& _rMediaDescriptor
,
605 DocumentGuard
& _rDocGuard
608 /** impl-version of attachResource
610 @param i_rLogicalDocumentURL
611 denotes the logical URL of the document, to be reported by getURL/getLocation
612 @param i_rMediaDescriptor
613 denotes additional document parameters
615 is the guard which currently protects the document instance
617 bool impl_attachResource(
618 const OUString
& i_rLogicalDocumentURL
,
619 const css::uno::Sequence
< css::beans::PropertyValue
>& i_rMediaDescriptor
,
620 DocumentGuard
& _rDocGuard
623 /** throws an IOException with the message as defined in the RID_STR_ERROR_WHILE_SAVING resource, wrapping
624 the given caught non-IOException error
626 void impl_throwIOExceptionCausedBySave_throw(
627 const css::uno::Any
& i_rError
,
628 std::u16string_view i_rTargetURL
632 /** an extended version of the ModelMethodGuard, which also cares for the initialization state
635 class DocumentGuard
: private ModelMethodGuard
640 // a method which is to initialize the document
650 enum MethodUsedDuringInit_
652 // a method which is used (externally) during the initialization phase
656 enum MethodWithoutInit_
658 // a method which does not need initialization - use with care!
663 /** constructs the guard
666 the ODatabaseDocument instance
668 @throws css::lang::DisposedException
669 If the given component is already disposed
671 @throws css::lang::NotInitializedException
672 if the given component is not yet initialized
674 DocumentGuard(const ODatabaseDocument
& _document
, DefaultMethod_
)
675 : ModelMethodGuard(_document
)
676 , m_document(_document
)
678 m_document
.checkInitialized();
681 /** constructs the guard
684 the ODatabaseDocument instance
686 @throws css::lang::DisposedException
687 If the given component is already disposed
689 @throws css::frame::DoubleInitializationException
690 if the given component is already initialized, or currently being initialized.
692 DocumentGuard(const ODatabaseDocument
& _document
, InitMethod_
)
693 : ModelMethodGuard(_document
)
694 , m_document(_document
)
696 m_document
.checkNotInitialized();
699 /** constructs the guard
702 the ODatabaseDocument instance
704 @throws css::lang::DisposedException
705 If the given component is already disposed
707 @throws css::lang::NotInitializedException
708 if the component is still uninitialized, and not in the initialization
711 DocumentGuard(const ODatabaseDocument
& _document
, MethodUsedDuringInit_
)
712 : ModelMethodGuard(_document
)
713 , m_document(_document
)
715 m_document
.checkNotUninitialized();
718 /** constructs the guard
721 the ODatabaseDocument instance
723 @throws css::lang::DisposedException
724 If the given component is already disposed
726 DocumentGuard(const ODatabaseDocument
& _document
, MethodWithoutInit_
)
727 : ModelMethodGuard( _document
)
728 , m_document( _document
)
734 ModelMethodGuard::clear();
738 ModelMethodGuard::reset();
739 m_document
.checkDisposed();
744 const ODatabaseDocument
& m_document
;
747 } // namespace dbaccess
749 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */