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