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 #ifndef _DBA_COREDATAACCESS_DATABASEDOCUMENT_HXX_ 28 #define _DBA_COREDATAACCESS_DATABASEDOCUMENT_HXX_ 29 30 #include "ModelImpl.hxx" 31 #include "documenteventnotifier.hxx" 32 33 /** === begin UNO includes === **/ 34 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> 35 #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp> 36 #include <com/sun/star/frame/XModel2.hpp> 37 #include <com/sun/star/frame/XTitle.hpp> 38 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp> 39 #include <com/sun/star/frame/XUntitledNumbers.hpp> 40 #include <com/sun/star/util/XModifiable.hpp> 41 #include <com/sun/star/frame/XStorable.hpp> 42 #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> 43 #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> 44 #include <com/sun/star/util/XCloseable.hpp> 45 #include <com/sun/star/view/XPrintable.hpp> 46 #include <com/sun/star/frame/XModuleManager.hpp> 47 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 48 #include <com/sun/star/lang/XServiceInfo.hpp> 49 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> 50 #include <com/sun/star/embed/XTransactionListener.hpp> 51 #include <com/sun/star/document/XStorageBasedDocument.hpp> 52 #include <com/sun/star/document/XEmbeddedScripts.hpp> 53 #include <com/sun/star/document/XEventsSupplier.hpp> 54 #include <com/sun/star/document/XScriptInvocationContext.hpp> 55 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp> 56 #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> 57 #include <com/sun/star/frame/XLoadable.hpp> 58 #include <com/sun/star/document/XEventBroadcaster.hpp> 59 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp> 60 #include <com/sun/star/document/XDocumentRecovery.hpp> 61 /** === end UNO includes === **/ 62 63 #if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17) 64 #define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_17 65 #define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 17 66 #include <comphelper/implbase_var.hxx> 67 #endif 68 69 #include <cppuhelper/compbase10.hxx> 70 #include <cppuhelper/implbase3.hxx> 71 #include <rtl/ref.hxx> 72 73 #include <boost/shared_ptr.hpp> 74 #include <boost/noncopyable.hpp> 75 76 namespace comphelper { 77 class NamedValueCollection; 78 } 79 80 //........................................................................ 81 namespace dbaccess 82 { 83 //........................................................................ 84 85 class DocumentEvents; 86 class DocumentEventExecutor; 87 class DocumentGuard; 88 89 typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > > Controllers; 90 91 //============================================================ 92 //= ViewMonitor 93 //============================================================ 94 /** helper class monitoring the views of a document, and firing appropriate events 95 when views are attached / detached 96 */ 97 class ViewMonitor : public boost::noncopyable 98 { 99 public: 100 ViewMonitor( DocumentEventNotifier& _rEventNotifier ) 101 :m_rEventNotifier( _rEventNotifier ) 102 ,m_bIsNewDocument( true ) 103 ,m_bEverHadController( false ) 104 ,m_bLastIsFirstEverController( false ) 105 ,m_xLastConnectedController() 106 { 107 } 108 109 void reset() 110 { 111 m_bEverHadController = false; 112 m_bLastIsFirstEverController = false; 113 m_xLastConnectedController.clear(); 114 } 115 116 /** to be called when a view (aka controller) has been connected to the document 117 @return 118 <TRUE/> if and only if this was the first-ever controller connected to the document 119 */ 120 bool onControllerConnected( 121 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController 122 ); 123 124 /** to be called when a controller is set as current controller 125 @return <TRUE/> 126 if and only if the controller connection indicates that loading the document is finished. This 127 is the case if the given controller has previously been connected, and it was the first controller 128 ever for which this happened. 129 */ 130 bool onSetCurrentController( 131 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& _rxController 132 ); 133 134 void onLoadedDocument() { m_bIsNewDocument = false; } 135 136 private: 137 DocumentEventNotifier& m_rEventNotifier; 138 bool m_bIsNewDocument; 139 bool m_bEverHadController; 140 bool m_bLastIsFirstEverController; 141 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > 142 m_xLastConnectedController; 143 }; 144 145 //============================================================ 146 //= ODatabaseDocument 147 //============================================================ 148 typedef ::comphelper::WeakComponentImplHelper17 < ::com::sun::star::frame::XModel2 149 , ::com::sun::star::util::XModifiable 150 , ::com::sun::star::frame::XStorable 151 , ::com::sun::star::document::XEventBroadcaster 152 , ::com::sun::star::document::XDocumentEventBroadcaster 153 , ::com::sun::star::view::XPrintable 154 , ::com::sun::star::util::XCloseable 155 , ::com::sun::star::lang::XServiceInfo 156 , ::com::sun::star::sdb::XOfficeDatabaseDocument 157 , ::com::sun::star::ui::XUIConfigurationManagerSupplier 158 , ::com::sun::star::document::XStorageBasedDocument 159 , ::com::sun::star::document::XEmbeddedScripts 160 , ::com::sun::star::document::XScriptInvocationContext 161 , ::com::sun::star::script::provider::XScriptProviderSupplier 162 , ::com::sun::star::document::XEventsSupplier 163 , ::com::sun::star::frame::XLoadable 164 , ::com::sun::star::document::XDocumentRecovery 165 > ODatabaseDocument_OfficeDocument; 166 167 typedef ::cppu::ImplHelper3< ::com::sun::star::frame::XTitle 168 , ::com::sun::star::frame::XTitleChangeBroadcaster 169 , ::com::sun::star::frame::XUntitledNumbers 170 > ODatabaseDocument_Title; 171 172 class ODatabaseDocument :public ModelDependentComponent // ModelDependentComponent must be first! 173 ,public ODatabaseDocument_OfficeDocument 174 ,public ODatabaseDocument_Title 175 { 176 enum InitState 177 { 178 NotInitialized, 179 Initializing, 180 Initialized 181 }; 182 183 DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::frame::XUntitledNumbers >,TNumberedController); 184 ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager> m_xUIConfigurationManager; 185 186 ::cppu::OInterfaceContainerHelper m_aModifyListeners; 187 ::cppu::OInterfaceContainerHelper m_aCloseListener; 188 ::cppu::OInterfaceContainerHelper m_aStorageListeners; 189 190 DocumentEvents* m_pEventContainer; 191 ::rtl::Reference< DocumentEventExecutor > m_pEventExecutor; 192 DocumentEventNotifier m_aEventNotifier; 193 194 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > m_xCurrentController; 195 Controllers m_aControllers; 196 ViewMonitor m_aViewMonitor; 197 198 ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xForms; 199 ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xReports; 200 ::com::sun::star::uno::WeakReference< ::com::sun::star::script::provider::XScriptProvider > m_xScriptProvider; 201 202 /** @short such module manager is used to classify new opened documents. */ 203 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > m_xModuleManager; 204 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitle > m_xTitleHelper; 205 TNumberedController m_aNumberedControllers; 206 207 /** true if and only if the DatabaseDocument's "initNew" or "load" have been called (or, well, 208 the document has be initialized implicitly - see storeAsURL 209 */ 210 InitState m_eInitState; 211 bool m_bClosing; 212 bool m_bAllowDocumentScripting; 213 bool m_bHasBeenRecovered; 214 215 enum StoreType { SAVE, SAVE_AS }; 216 /** stores the document to the given URL, rebases it to the respective new storage, if necessary, resets 217 the modified flag, and notifies any listeners as required 218 219 @param _rURL 220 the URL to store the document to 221 @param _rArguments 222 arguments for storing the document (MediaDescriptor) 223 @param _eType 224 the type of the store process (Save or SaveAs). The method will automatically 225 notify the proper events for this type. 226 @param _rGuard 227 the instance lock to be released before doing synchronous notifications 228 */ 229 void impl_storeAs_throw( 230 const ::rtl::OUString& _rURL, 231 const ::comphelper::NamedValueCollection& _rArguments, 232 const StoreType _eType, 233 DocumentGuard& _rGuard 234 ) 235 throw ( ::com::sun::star::io::IOException 236 , ::com::sun::star::uno::RuntimeException ); 237 238 /** notifies our storage change listeners that our underlying storage changed 239 240 @param _rxNewRootStorage 241 the new root storage to be notified. If <NULL/>, it is assumed that no storage change actually 242 happened, and the listeners are not notified. 243 */ 244 void impl_notifyStorageChange_nolck_nothrow( 245 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage 246 ); 247 248 /// write a single XML stream into the package 249 void WriteThroughComponent( 250 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > & xComponent, /// the component we export 251 const sal_Char* pStreamName, /// the stream name 252 const sal_Char* pServiceName, /// service name of the component 253 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> & rArguments, /// the argument (XInitialization) 254 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> & rMediaDesc,/// output descriptor 255 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _xStorageToSaveTo 256 ) const; 257 258 259 /// write a single output stream 260 /// (to be called either directly or by WriteThroughComponent(...)) 261 void WriteThroughComponent( 262 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutputStream, 263 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xComponent, 264 const sal_Char* pServiceName, 265 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArguments, 266 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> & rMediaDesc 267 ) const; 268 269 /** writes the content and settings 270 @param sURL 271 The URL 272 @param lArguments 273 The media descriptor 274 @param _xStorageToSaveTo 275 The storage which should be used for saving 276 */ 277 void impl_writeStorage_throw( 278 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxTargetStorage, 279 const ::comphelper::NamedValueCollection& _rMediaDescriptor 280 ) const; 281 282 // ModelDependentComponent overridables 283 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() const; 284 285 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitle > impl_getTitleHelper_throw(); 286 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XUntitledNumbers > impl_getUntitledHelper_throw( 287 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xComponent = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >()); 288 289 private: 290 ODatabaseDocument(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl); 291 // Do NOT create those documents directly, always use ODatabaseModelImpl::getModel. Reason is that 292 // ODatabaseDocument requires clear ownership, and in turn lifetime synchronisation with the ModelImpl. 293 // If you create a ODatabaseDocument directly, you might easily create a leak. 294 // #i50905# / 2005-06-20 / frank.schonheit@sun.com 295 296 protected: 297 virtual void SAL_CALL disposing(); 298 299 virtual ~ODatabaseDocument(); 300 301 public: 302 struct FactoryAccess { friend class ODatabaseModelImpl; private: FactoryAccess() { } }; 303 static ODatabaseDocument* createDatabaseDocument( const ::rtl::Reference<ODatabaseModelImpl>& _pImpl, FactoryAccess /*accessControl*/ ) 304 { 305 return new ODatabaseDocument( _pImpl ); 306 } 307 308 // XServiceInfo 309 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 310 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 311 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 312 313 // ::com::sun::star::lang::XServiceInfo - static methods 314 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(void) throw( ::com::sun::star::uno::RuntimeException ); 315 static ::rtl::OUString getImplementationName_static(void) throw( ::com::sun::star::uno::RuntimeException ); 316 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 317 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&); 318 319 // XInterface 320 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException); 321 virtual void SAL_CALL acquire( ) throw (); 322 virtual void SAL_CALL release( ) throw (); 323 324 // XTypeProvider 325 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); 326 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException); 327 328 // XEventListener 329 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 330 331 // XComponent 332 virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); 333 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 334 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 335 336 // XModel 337 virtual sal_Bool SAL_CALL attachResource( const ::rtl::OUString& URL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::uno::RuntimeException) ; 338 virtual ::rtl::OUString SAL_CALL getURL( ) throw (::com::sun::star::uno::RuntimeException) ; 339 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getArgs( ) throw (::com::sun::star::uno::RuntimeException) ; 340 virtual void SAL_CALL connectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& Controller ) throw (::com::sun::star::uno::RuntimeException) ; 341 virtual void SAL_CALL disconnectController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& Controller ) throw (::com::sun::star::uno::RuntimeException) ; 342 virtual void SAL_CALL lockControllers( ) throw (::com::sun::star::uno::RuntimeException) ; 343 virtual void SAL_CALL unlockControllers( ) throw (::com::sun::star::uno::RuntimeException) ; 344 virtual sal_Bool SAL_CALL hasControllersLocked( ) throw (::com::sun::star::uno::RuntimeException) ; 345 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL getCurrentController( ) throw (::com::sun::star::uno::RuntimeException) ; 346 virtual void SAL_CALL setCurrentController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >& Controller ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException) ; 347 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getCurrentSelection( ) throw (::com::sun::star::uno::RuntimeException) ; 348 349 // XModel2 350 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL getControllers( ) throw (::com::sun::star::uno::RuntimeException) ; 351 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableViewControllerNames( ) throw (::com::sun::star::uno::RuntimeException) ; 352 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 > SAL_CALL createDefaultViewController( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& Frame ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) ; 353 virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 > SAL_CALL createViewController( const ::rtl::OUString& ViewName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& Frame ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) ; 354 355 // XStorable 356 virtual sal_Bool SAL_CALL hasLocation( ) throw (::com::sun::star::uno::RuntimeException) ; 357 virtual ::rtl::OUString SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException) ; 358 virtual sal_Bool SAL_CALL isReadonly( ) throw (::com::sun::star::uno::RuntimeException) ; 359 virtual void SAL_CALL store( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) ; 360 virtual void SAL_CALL storeAsURL( const ::rtl::OUString& sURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) ; 361 virtual void SAL_CALL storeToURL( const ::rtl::OUString& sURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) ; 362 363 // XModifyBroadcaster 364 virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 365 virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 366 367 // ::com::sun::star::util::XModifiable 368 virtual sal_Bool SAL_CALL isModified( ) throw (::com::sun::star::uno::RuntimeException) ; 369 virtual void SAL_CALL setModified( sal_Bool bModified ) throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException) ; 370 371 // XEventBroadcaster 372 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 373 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 374 375 // XDocumentEventBroadcaster 376 virtual void SAL_CALL addDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException); 377 virtual void SAL_CALL removeDocumentEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentEventListener >& _Listener ) throw (::com::sun::star::uno::RuntimeException); 378 virtual void SAL_CALL notifyDocumentEvent( const ::rtl::OUString& _EventName, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController2 >& _ViewController, const ::com::sun::star::uno::Any& _Supplement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException); 379 380 // XPrintable 381 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getPrinter( ) throw (::com::sun::star::uno::RuntimeException) ; 382 virtual void SAL_CALL setPrinter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aPrinter ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) ; 383 virtual void SAL_CALL print( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& xOptions ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) ; 384 385 // XFormDocumentsSupplier 386 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getFormDocuments( ) throw (::com::sun::star::uno::RuntimeException); 387 388 // XReportDocumentsSupplier 389 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getReportDocuments( ) throw (::com::sun::star::uno::RuntimeException); 390 391 // XCloseable 392 virtual void SAL_CALL close( sal_Bool DeliverOwnership ) throw (::com::sun::star::util::CloseVetoException, ::com::sun::star::uno::RuntimeException); 393 virtual void SAL_CALL addCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 394 virtual void SAL_CALL removeCloseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 395 396 // XUIConfigurationManagerSupplier 397 virtual ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > SAL_CALL getUIConfigurationManager( ) throw (::com::sun::star::uno::RuntimeException); 398 399 // XDocumentSubStorageSupplier 400 virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode ) throw (::com::sun::star::uno::RuntimeException); 401 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getDocumentSubStoragesNames( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); 402 403 // XOfficeDatabaseDocument 404 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource > SAL_CALL getDataSource() throw (::com::sun::star::uno::RuntimeException); 405 406 // XStorageBasedDocument 407 virtual void SAL_CALL loadFromStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescriptor ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 408 virtual void SAL_CALL storeToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescriptor ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 409 virtual void SAL_CALL switchToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 410 virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL getDocumentStorage( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 411 virtual void SAL_CALL addStorageChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XStorageChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 412 virtual void SAL_CALL removeStorageChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XStorageChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 413 414 // XEmbeddedScripts 415 virtual ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > SAL_CALL getBasicLibraries() throw (::com::sun::star::uno::RuntimeException); 416 virtual ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > SAL_CALL getDialogLibraries() throw (::com::sun::star::uno::RuntimeException); 417 virtual ::sal_Bool SAL_CALL getAllowMacroExecution() throw (::com::sun::star::uno::RuntimeException); 418 419 // XScriptInvocationContext 420 virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > SAL_CALL getScriptContainer() throw (::com::sun::star::uno::RuntimeException); 421 422 // XScriptProviderSupplier 423 virtual ::com::sun::star::uno::Reference< ::com::sun::star::script::provider::XScriptProvider > SAL_CALL getScriptProvider( ) throw (::com::sun::star::uno::RuntimeException); 424 425 // XEventsSupplier 426 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameReplace > SAL_CALL getEvents( ) throw (::com::sun::star::uno::RuntimeException); 427 428 // XLoadable 429 virtual void SAL_CALL initNew( ) throw (::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 430 virtual void SAL_CALL load( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArguments ) throw (::com::sun::star::frame::DoubleInitializationException, ::com::sun::star::io::IOException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 431 432 // css.document.XDocumentRecovery 433 virtual ::sal_Bool SAL_CALL wasModifiedSinceLastSave() throw ( ::com::sun::star::uno::RuntimeException ); 434 virtual void SAL_CALL storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); 435 virtual void SAL_CALL recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_MediaDescriptor ) throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::io::IOException, ::com::sun::star::lang::WrappedTargetException ); 436 437 // XTitle 438 virtual ::rtl::OUString SAL_CALL getTitle( ) throw (::com::sun::star::uno::RuntimeException); 439 virtual void SAL_CALL setTitle( const ::rtl::OUString& sTitle ) throw (::com::sun::star::uno::RuntimeException); 440 441 // XTitleChangeBroadcaster 442 virtual void SAL_CALL addTitleChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitleChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 443 virtual void SAL_CALL removeTitleChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XTitleChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 444 445 // XUntitledNumbers 446 virtual ::sal_Int32 SAL_CALL leaseNumber( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xComponent ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 447 virtual void SAL_CALL releaseNumber( ::sal_Int32 nNumber ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 448 virtual void SAL_CALL releaseNumberForComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xComponent ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 449 virtual ::rtl::OUString SAL_CALL getUntitledPrefix( ) throw (::com::sun::star::uno::RuntimeException); 450 451 /** clears the given object container 452 453 Clearing is done via disposal - the method calls XComponent::dispose at the given object, 454 which must be one of our impl's or our object containers (m_xForms, m_xReports, 455 m_xTableDefinitions, m_xCommandDefinitions) 456 457 @param _rxContainer 458 the container to clear 459 */ 460 static void clearObjectContainer( 461 ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess >& _rxContainer); 462 463 /** checks whether the component is already initialized, throws a NotInitializedException if not 464 */ 465 inline void checkInitialized() const 466 { 467 if ( !impl_isInitialized() ) 468 throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); 469 } 470 471 /** checks the document is currently in the initialization phase, or already initialized. 472 Throws NotInitializedException if not so. 473 */ 474 inline void checkNotUninitilized() const 475 { 476 if ( impl_isInitialized() || impl_isInitializing() ) 477 // fine 478 return; 479 480 throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); 481 } 482 483 /** checks whether the document is currently being initialized, or already initialized, 484 throws a DoubleInitializationException if so 485 */ 486 inline void checkNotInitialized() const 487 { 488 if ( impl_isInitializing() || impl_isInitialized() ) 489 throw ::com::sun::star::frame::DoubleInitializationException( ::rtl::OUString(), getThis() ); 490 } 491 492 private: 493 /** returns whether the model is currently being initialized 494 */ 495 bool impl_isInitializing() const { return m_eInitState == Initializing; } 496 497 /** returns whether the model is already initialized, i.e. the XModel's "initNew" or "load" methods have been called 498 */ 499 bool impl_isInitialized() const { return m_eInitState == Initialized; } 500 501 /// tells the model it is being initialized now 502 void impl_setInitializing() { m_eInitState = Initializing; } 503 504 /// tells the model its initialization is done 505 void impl_setInitialized(); 506 507 /** closes the frames of all connected controllers 508 509 @param _bDeliverOwnership 510 determines if the ownership should be transfered to the component which 511 possibly vetos the closing 512 513 @raises ::com::sun::star::util::CloseVetoException 514 if the closing was vetoed by any instance 515 */ 516 void impl_closeControllerFrames_nolck_throw( sal_Bool _bDeliverOwnership ); 517 518 /** disposes the frames of all controllers which are still left in m_aControllers. 519 */ 520 void impl_disposeControllerFrames_nothrow(); 521 522 /** does a reparenting at the given object container to ourself 523 524 Calls XChild::setParent at the given object, which must be one of our impl's or our 525 object containers (m_xForms, m_xReports, m_xTableDefinitions, m_xCommandDefinitions) 526 */ 527 void impl_reparent_nothrow( const ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess >& _rxContainer ); 528 529 /** retrieves the forms or reports contained, creates and initializes it, if necessary 530 531 @raises DisposedException 532 if the instance is already disposed 533 @raises IllegalArgumentException 534 if <arg>_eType</arg> is not ODatabaseModelImpl::E_FORM and not ODatabaseModelImpl::E_REPORT 535 */ 536 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > 537 impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType _eType ); 538 539 /** resets everything 540 541 @precond 542 m_pImpl is not <NULLL/> 543 */ 544 void 545 impl_reset_nothrow(); 546 547 /** imports the document from the given resource. 548 */ 549 static void 550 impl_import_nolck_throw( 551 const ::comphelper::ComponentContext _rContext, 552 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxTargetComponent, 553 const ::comphelper::NamedValueCollection& _rResource 554 ); 555 556 /** creates a storage for the given URL, truncating it if a file with this name already exists 557 558 @throws Exception 559 if creating the storage failed 560 561 @return 562 the newly created storage for the file at the given URL 563 */ 564 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 565 impl_createStorageFor_throw( 566 const ::rtl::OUString& _rURL 567 ) const; 568 569 /** sets our "modified" flag 570 571 will notify all our respective listeners, if the "modified" state actually changed 572 573 @param _bModified 574 the (new) flag indicating whether the document is currently modified or not 575 @param _rGuard 576 the guard for our instance. At method entry, the guard must hold the lock. At the moment 577 of method leave, the lock will be released. 578 @precond 579 our mutex is locked 580 @postcond 581 our mutex is not locked 582 */ 583 void impl_setModified_nothrow( sal_Bool _bModified, DocumentGuard& _rGuard ); 584 585 /** stores the document to the given storage 586 587 Note that the document is actually not rebased to this storage, it just stores a copy of itself 588 to the given target storage. 589 590 @param _rxTargetStorage 591 denotes the storage to store the document into 592 @param _rMediaDescriptor 593 contains additional parameters for storing the document 594 @param _rDocGuard 595 a guard which holds the (only) lock to the document, and which will be temporarily 596 released where necessary (e.g. for notifications, or calling into other components) 597 598 @throws ::com::sun::star::uno::IllegalArgumentException 599 if the given storage is <NULL/>. 600 601 @throws ::com::sun::star::uno::RuntimeException 602 when any of the used operations throws it 603 604 @throws ::com::sun::star::io::IOException 605 when any of the used operations throws it, or any other exception occurs which is no 606 RuntimeException and no IOException 607 */ 608 void impl_storeToStorage_throw( 609 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxTargetStorage, 610 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, 611 DocumentGuard& _rDocGuard 612 ) const; 613 614 615 /** impl-version of attachResource 616 617 @param i_rLogicalDocumentURL 618 denotes the logical URL of the document, to be reported by getURL/getLocation 619 @param i_rMediaDescriptor 620 denotes additional document parameters 621 @param _rDocGuard 622 is the guard which currently protects the document instance 623 624 */ 625 sal_Bool impl_attachResource( 626 const ::rtl::OUString& i_rLogicalDocumentURL, 627 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& i_rMediaDescriptor, 628 DocumentGuard& _rDocGuard 629 ); 630 631 /** throws an IOException with the message as defined in the RID_STR_ERROR_WHILE_SAVING resource, wrapping 632 the given caught non-IOException error 633 */ 634 void impl_throwIOExceptionCausedBySave_throw( 635 const ::com::sun::star::uno::Any& i_rError, 636 const ::rtl::OUString& i_rTargetURL 637 ) const; 638 }; 639 640 /** an extended version of the ModelMethodGuard, which also cares for the initialization state 641 of the document 642 */ 643 class DocumentGuard : private ModelMethodGuard 644 { 645 public: 646 enum MethodType 647 { 648 // a method which is to initialize the document 649 InitMethod, 650 // a default method 651 DefaultMethod, 652 // a method which is used (externally) during the initialization phase 653 MethodUsedDuringInit, 654 // a method which does not need initialization - use with care! 655 MethodWithoutInit 656 }; 657 658 /** constructs the guard 659 660 @param _document 661 the ODatabaseDocument instance 662 663 @throws ::com::sun::star::lang::DisposedException 664 If the given component is already disposed 665 666 @throws ::com::sun::star::frame::DoubleInitializationException 667 if _eType is InitMethod, and the given component is already initialized, or currently being initialized. 668 669 @throws ::com::sun::star::lang::NotInitializedException 670 if _eType is DefaultMethod, and the given component is not yet initialized; or if _eType 671 is MethodUsedDuringInit, and the component is still uninitialized, and not in the initialization 672 phase currently. 673 */ 674 DocumentGuard( const ODatabaseDocument& _document, MethodType _eType = DefaultMethod ) 675 :ModelMethodGuard( _document ) 676 ,m_document( _document ) 677 { 678 switch ( _eType ) 679 { 680 case InitMethod: m_document.checkNotInitialized(); break; 681 case DefaultMethod: m_document.checkInitialized(); break; 682 case MethodUsedDuringInit: m_document.checkNotUninitilized(); break; 683 case MethodWithoutInit: break; 684 } 685 } 686 687 ~DocumentGuard() 688 { 689 } 690 691 void clear() 692 { 693 ModelMethodGuard::clear(); 694 } 695 void reset() 696 { 697 ModelMethodGuard::reset(); 698 m_document.checkDisposed(); 699 } 700 701 private: 702 703 const ODatabaseDocument& m_document; 704 }; 705 706 //........................................................................ 707 } // namespace dbaccess 708 //........................................................................ 709 #endif // _DBA_COREDATAACCESS_DATABASEDOCUMENT_HXX_ 710