ucb/source/core/FileAccess.cxx                      |    4 
 ucb/source/core/ucb.cxx                             |    8 -
 ucb/source/core/ucbstore.cxx                        |    8 -
 ucb/source/ucp/cmis/cmis_content.cxx                |   32 ++---
 ucb/source/ucp/cmis/cmis_repo_content.cxx           |    2 
 ucb/source/ucp/cmis/std_inputstream.cxx             |    2 
 ucb/source/ucp/expand/ucpexpand.cxx                 |    6 -
 ucb/source/ucp/ext/ucpext_content.cxx               |    2 
 ucb/source/ucp/file/bc.cxx                          |    2 
 ucb/source/ucp/file/filrset.cxx                     |    2 
 ucb/source/ucp/file/filstr.cxx                      |    2 
 ucb/source/ucp/ftp/ftpcontent.cxx                   |   20 +--
 ucb/source/ucp/gio/gio_content.cxx                  |   28 ++--
 ucb/source/ucp/gio/gio_inputstream.cxx              |    2 
 ucb/source/ucp/gio/gio_outputstream.cxx             |    4 
 ucb/source/ucp/gio/gio_seekable.cxx                 |   10 -
 ucb/source/ucp/hierarchy/hierarchycontent.cxx       |   62 +++++-----
 ucb/source/ucp/hierarchy/hierarchydatasource.cxx    |    4 
 ucb/source/ucp/package/pkgcontent.cxx               |   72 ++++++------
 ucb/source/ucp/tdoc/tdoc_content.cxx                |   91 +++++++--------
 ucb/source/ucp/tdoc/tdoc_documentcontentfactory.cxx |    2 
 ucb/source/ucp/tdoc/tdoc_provider.cxx               |    6 -
 ucb/source/ucp/tdoc/tdoc_stgelems.cxx               |    6 -
 ucb/source/ucp/webdav-curl/webdavcontent.cxx        |  116 ++++++++++----------
 24 files changed, 242 insertions(+), 251 deletions(-)

New commits:
commit e693d340a86e4e5f16c3beda062aaec3a71e5e2e
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Apr 23 20:15:18 2023 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sat Jul 1 04:55:21 2023 +0200

    Use getXWeak in ucb
    
    Change-Id: Id94a89596bd473ed8c83d7be89ba673d8dc1bba1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150878
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/ucb/source/core/FileAccess.cxx b/ucb/source/core/FileAccess.cxx
index 24674ac07edd..5a83f9699bed 100644
--- a/ucb/source/core/FileAccess.cxx
+++ b/ucb/source/core/FileAccess.cxx
@@ -240,7 +240,7 @@ void OFileAccess::transferImpl( const OUString& rSource,
                 css::uno::Any anyEx = cppu::getCaughtException();
                 throw css::lang::WrappedTargetRuntimeException(
                     "OFileAccess::transferrImpl - Unable to obtain destination 
folder URL!",
-                    static_cast< cppu::OWeakObject * >( this ), anyEx );
+                    getXWeak(), anyEx );
             }
 
             transferImpl( rSource, aDestURL, bMoveData );
@@ -249,7 +249,7 @@ void OFileAccess::transferImpl( const OUString& rSource,
 
         throw RuntimeException(
                "OFileAccess::transferrImpl - Unable to obtain destination 
folder URL!",
-                static_cast< cppu::OWeakObject * >( this ) );
+                getXWeak() );
 
     }
 
diff --git a/ucb/source/core/ucb.cxx b/ucb/source/core/ucb.cxx
index 27c49c229c75..56dd74bb4d8a 100644
--- a/ucb/source/core/ucb.cxx
+++ b/ucb/source/core/ucb.cxx
@@ -319,7 +319,7 @@ void SAL_CALL UniversalContentBroker::initialize( const 
css::uno::Sequence< Any
             {
                 throw IllegalArgumentException(
                     "UCB reinitialized with different arguments",
-                    static_cast< cppu::OWeakObject * >(this), 0);
+                    getXWeak(), 0);
             }
             return;
         }
@@ -581,7 +581,7 @@ Any SAL_CALL UniversalContentBroker::execute(
                 ucbhelper::cancelCommandExecution(
                     Any( IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                     Environment );
                 // Unreachable
@@ -605,7 +605,7 @@ Any SAL_CALL UniversalContentBroker::execute(
             ucbhelper::cancelCommandExecution(
                 Any( IllegalArgumentException(
                                 "Wrong argument type!",
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 -1 ) ),
                 Environment );
             // Unreachable
@@ -621,7 +621,7 @@ Any SAL_CALL UniversalContentBroker::execute(
         ucbhelper::cancelCommandExecution(
             Any( UnsupportedCommandException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
             Environment );
         // Unreachable
     }
diff --git a/ucb/source/core/ucbstore.cxx b/ucb/source/core/ucbstore.cxx
index 7f04a9a534ab..6800b5db0e96 100644
--- a/ucb/source/core/ucbstore.cxx
+++ b/ucb/source/core/ucbstore.cxx
@@ -1166,7 +1166,7 @@ void SAL_CALL PersistentPropertySet::setPropertyValue( 
const OUString& aProperty
                         xRootHierNameAccess->getByHierarchicalName( aValueName 
)
                             >>= nHandle;
 
-                        aEvt.Source         = static_cast<OWeakObject*>(this);
+                        aEvt.Source         = getXWeak();
                         aEvt.PropertyName   = aPropertyName;
                         aEvt.PropertyHandle = nHandle;
                         aEvt.Further        = false;
@@ -1416,7 +1416,7 @@ void SAL_CALL PersistentPropertySet::addProperty(
                 if ( m_aPropSetChangeListeners.getLength(aGuard) )
                 {
                     PropertySetInfoChangeEvent evt(
-                                    static_cast< OWeakObject * >( this ),
+                                    getXWeak(),
                                     Name,
                                     -1,
                                     PropertySetInfoChange::PROPERTY_INSERTED );
@@ -1572,7 +1572,7 @@ void SAL_CALL PersistentPropertySet::removeProperty( 
const OUString& Name )
                 if (  m_aPropSetChangeListeners.getLength(aGuard) )
                 {
                     PropertySetInfoChangeEvent evt(
-                                    static_cast< OWeakObject * >( this ),
+                                    getXWeak(),
                                     Name,
                                     nHandle,
                                     PropertySetInfoChange::PROPERTY_REMOVED );
@@ -1826,7 +1826,7 @@ void SAL_CALL PersistentPropertySet::setPropertyValues(
                         if ( 
m_aPropertyChangeListeners.hasContainedTypes(aCGuard) )
                         {
                             PropertyChangeEvent aEvt;
-                            aEvt.Source         = 
static_cast<OWeakObject*>(this);
+                            aEvt.Source         = getXWeak();
                             aEvt.PropertyName   = rNewValue.Name;
                             aEvt.PropertyHandle = rNewValue.Handle;
                             aEvt.Further        = false;
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx 
b/ucb/source/ucp/cmis/cmis_content.cxx
index a9781c233054..815d89502f2c 100644
--- a/ucb/source/ucp/cmis/cmis_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_content.cxx
@@ -598,7 +598,7 @@ namespace cmis
     {
         return uno::Any( lang::IllegalArgumentException(
             "Wrong argument type!",
-            static_cast< cppu::OWeakObject * >( this ), -1) );
+            getXWeak(), -1) );
     }
 
     libcmis::ObjectPtr Content::updateProperties(
@@ -971,7 +971,7 @@ namespace cmis
         {
             uno::Sequence< uno::Any > aArgs{ 
uno::Any(m_xIdentifier->getContentIdentifier()) };
             uno::Any aErr(
-                ucb::InteractiveAugmentedIOException(OUString(), static_cast< 
cppu::OWeakObject * >( this ),
+                ucb::InteractiveAugmentedIOException(OUString(), getXWeak(),
                     task::InteractionClassification_ERROR,
                     bIsFolder ? ucb::IOErrorCode_NOT_EXISTING_PATH : 
ucb::IOErrorCode_NOT_EXISTING, aArgs)
             );
@@ -1002,7 +1002,7 @@ namespace cmis
             {
                 ucbhelper::cancelCommandExecution(
                     uno::Any ( ucb::UnsupportedOpenModeException
-                        ( OUString(), static_cast< cppu::OWeakObject * >( this 
),
+                        ( OUString(), getXWeak(),
                           sal_Int16( rOpenCommand.Mode ) ) ),
                         xEnv );
             }
@@ -1016,7 +1016,7 @@ namespace cmis
 
                 ucbhelper::cancelCommandExecution(
                     uno::Any (ucb::UnsupportedDataSinkException
-                        ( OUString(), static_cast< cppu::OWeakObject * >( this 
),
+                        ( OUString(), getXWeak(),
                           rOpenCommand.Sink ) ),
                         xEnv );
             }
@@ -1262,7 +1262,7 @@ namespace cmis
                     uno::Any(
                         ucb::InteractiveBadTransferURLException(
                             "Unsupported URL scheme!",
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
                     xEnv );
             }
         }
@@ -1278,7 +1278,7 @@ namespace cmis
         {
             ucbhelper::cancelCommandExecution( uno::Any
                 ( ucb::MissingInputStreamException
-                  ( OUString(), static_cast< cppu::OWeakObject * >( this ) ) ),
+                  ( OUString(), getXWeak() ) ),
                 xEnv );
         }
 
@@ -1307,7 +1307,7 @@ namespace cmis
         {
             ucbhelper::cancelCommandExecution( uno::Any
                 ( uno::RuntimeException( "Missing name property",
-                    static_cast< cppu::OWeakObject * >( this ) ) ),
+                    getXWeak() ) ),
                 xEnv );
         }
         auto newName = it->second->getStrings( ).front( );
@@ -1335,7 +1335,7 @@ namespace cmis
             {
                 ucbhelper::cancelCommandExecution( uno::Any
                     ( uno::RuntimeException( "Can't change a folder into a 
document and vice-versa.",
-                        static_cast< cppu::OWeakObject * >( this ) ) ),
+                        getXWeak() ) ),
                     xEnv );
             }
 
@@ -1354,7 +1354,7 @@ namespace cmis
                 {
                     ucbhelper::cancelCommandExecution( uno::Any
                         ( uno::RuntimeException( "Error when setting document 
content",
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
                         xEnv );
                 }
             }
@@ -1376,7 +1376,7 @@ namespace cmis
                 {
                     ucbhelper::cancelCommandExecution( uno::Any
                         ( uno::RuntimeException( "Error when creating folder",
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
                         xEnv );
                 }
             }
@@ -1394,7 +1394,7 @@ namespace cmis
                 {
                     ucbhelper::cancelCommandExecution( uno::Any
                         ( uno::RuntimeException( "Error when creating 
document",
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
                         xEnv );
                 }
             }
@@ -1469,7 +1469,7 @@ namespace cmis
                  rValue.Name == "CreatableContentsInfo" )
             {
                 lang::IllegalAccessException e ( "Property is read-only!",
-                       static_cast< cppu::OWeakObject* >( this ) );
+                       getXWeak() );
                 aRetRange[ n ] <<= e;
             }
             else if ( rValue.Name == "Title" )
@@ -1479,7 +1479,7 @@ namespace cmis
                 {
                     aRetRange[ n ] <<= beans::IllegalTypeException
                         ( "Property value has wrong type!",
-                          static_cast< cppu::OWeakObject * >( this ) );
+                          getXWeak() );
                     continue;
                 }
 
@@ -1487,7 +1487,7 @@ namespace cmis
                 {
                     aRetRange[ n ] <<= lang::IllegalArgumentException
                         ( "Empty title not allowed!",
-                          static_cast< cppu::OWeakObject * >( this ), -1 );
+                          getXWeak(), -1 );
                     continue;
 
                 }
@@ -1499,7 +1499,7 @@ namespace cmis
             {
                 SAL_INFO( "ucb.ucp.cmis", "Couldn't set property: " << 
rValue.Name );
                 lang::IllegalAccessException e ( "Property is read-only!",
-                       static_cast< cppu::OWeakObject* >( this ) );
+                       getXWeak() );
                 aRetRange[ n ] <<= e;
             }
         }
@@ -1878,7 +1878,7 @@ namespace cmis
             ucbhelper::cancelCommandExecution
                 ( uno::Any( ucb::UnsupportedCommandException
                   ( OUString(),
-                    static_cast< cppu::OWeakObject * >( this ) ) ),
+                    getXWeak() ) ),
                   xEnv );
         }
 
diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx 
b/ucb/source/ucp/cmis/cmis_repo_content.cxx
index 0ffd6abf3769..56d11b5283a7 100644
--- a/ucb/source/ucp/cmis/cmis_repo_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx
@@ -73,7 +73,7 @@ namespace cmis
     {
         return uno::Any( lang::IllegalArgumentException(
             "Wrong argument type!",
-            static_cast< cppu::OWeakObject * >( this ), -1) );
+            getXWeak(), -1) );
     }
 
     uno::Reference< sdbc::XRow > RepoContent::getPropertyValues(
diff --git a/ucb/source/ucp/cmis/std_inputstream.cxx 
b/ucb/source/ucp/cmis/std_inputstream.cxx
index e73a3160b979..548e782088c7 100644
--- a/ucb/source/ucp/cmis/std_inputstream.cxx
+++ b/ucb/source/ucp/cmis/std_inputstream.cxx
@@ -143,7 +143,7 @@ namespace cmis
         if ( location < 0 || location > m_nLength )
             throw lang::IllegalArgumentException(
                     "Location can't be negative or greater than the length",
-                    static_cast< cppu::OWeakObject* >( this ), 0 );
+                    getXWeak(), 0 );
 
         if (!m_pStream)
             throw io::IOException( );
diff --git a/ucb/source/ucp/expand/ucpexpand.cxx 
b/ucb/source/ucp/expand/ucpexpand.cxx
index 829649ab8955..413100bc54f1 100644
--- a/ucb/source/ucp/expand/ucpexpand.cxx
+++ b/ucb/source/ucp/expand/ucpexpand.cxx
@@ -80,8 +80,7 @@ void ExpandContentProviderImpl::check() const
         throw lang::DisposedException(
             "expand content provider instance has "
             "already been disposed!",
-            static_cast< OWeakObject * >(
-                const_cast< ExpandContentProviderImpl * >(this) ) );
+            const_cast< ExpandContentProviderImpl * >(this)->getXWeak() );
     }
 }
 
@@ -116,8 +115,7 @@ OUString ExpandContentProviderImpl::expandUri(
     {
         throw ucb::IllegalIdentifierException(
             "expected protocol vnd.sun.star.expand!",
-            static_cast< OWeakObject * >(
-                const_cast< ExpandContentProviderImpl * >(this) ) );
+            const_cast< ExpandContentProviderImpl * >(this)->getXWeak() );
     }
     // decode uric class chars
     OUString str = ::rtl::Uri::decode(uri, rtl_UriDecodeWithCharset, 
RTL_TEXTENCODING_UTF8);
diff --git a/ucb/source/ucp/ext/ucpext_content.cxx 
b/ucb/source/ucp/ext/ucpext_content.cxx
index a1d2df55a092..24101016810f 100644
--- a/ucb/source/ucp/ext/ucpext_content.cxx
+++ b/ucb/source/ucp/ext/ucpext_content.cxx
@@ -488,7 +488,7 @@ namespace ucb::ucp::ext
         Sequence< Any > aRet( i_rValues.getLength() );
 
         PropertyChangeEvent aEvent;
-        aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
+        aEvent.Source         = getXWeak();
         aEvent.Further        = false;
         aEvent.PropertyHandle = -1;
 
diff --git a/ucb/source/ucp/file/bc.cxx b/ucb/source/ucp/file/bc.cxx
index c5e47c6b0b55..ddb44589d2c0 100644
--- a/ucb/source/ucp/file/bc.cxx
+++ b/ucb/source/ucp/file/bc.cxx
@@ -1042,7 +1042,7 @@ void BaseContent::insert( sal_Int32 nMyCommandIdentifier,
                         OUString(getTitle(m_aUncPath)),
                         rtl_UriDecodeWithCharset,
                         RTL_TEXTENCODING_UTF8),
-                    static_cast<cppu::OWeakObject*>(this),
+                    getXWeak(),
                     m_pMyShell,nMyCommandIdentifier);
             uno::Reference<task::XInteractionRequest> const& 
xReq(aRequestImpl.getRequest());
 
diff --git a/ucb/source/ucp/file/filrset.cxx b/ucb/source/ucp/file/filrset.cxx
index 5f0d4ec3a25c..2990df183bc5 100644
--- a/ucb/source/ucp/file/filrset.cxx
+++ b/ucb/source/ucp/file/filrset.cxx
@@ -509,7 +509,7 @@ XResultSet_impl::setListener(
 
     Listener->notify(
         ucb::ListEvent(
-            static_cast< cppu::OWeakObject * >( this ), aActions ) );
+            getXWeak(), aActions ) );
 }
 
 
diff --git a/ucb/source/ucp/file/filstr.cxx b/ucb/source/ucp/file/filstr.cxx
index 85222141d5a3..2e49a7c8f8c2 100644
--- a/ucb/source/ucp/file/filstr.cxx
+++ b/ucb/source/ucp/file/filstr.cxx
@@ -283,7 +283,7 @@ void XStream_impl::waitForCompletion()
     if (m_nIsOpen && m_aFile.sync() != osl::FileBase::E_None) {
         throw io::IOException(
             "could not synchronize file to disc",
-            static_cast< OWeakObject * >(this));
+            getXWeak());
     }
 }
 
diff --git a/ucb/source/ucp/ftp/ftpcontent.cxx 
b/ucb/source/ucp/ftp/ftpcontent.cxx
index 65e2b86f8f21..5f9097f6de38 100644
--- a/ucb/source/ucp/ftp/ftpcontent.cxx
+++ b/ucb/source/ucp/ftp/ftpcontent.cxx
@@ -392,7 +392,7 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
                 {
                     aRet <<= IllegalArgumentException(
                                 "Wrong argument type!",
-                                static_cast< cppu::OWeakObject * >(this),
+                                getXWeak(),
                                 -1);
                     ucbhelper::cancelCommandExecution(aRet,Environment);
                 }
@@ -406,7 +406,7 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
                 if( ! ( aCommand.Argument >>= propertyValues ) ) {
                     aRet <<= IllegalArgumentException(
                                 "Wrong argument type!",
-                                static_cast< cppu::OWeakObject * >(this),
+                                getXWeak(),
                                 -1);
                     ucbhelper::cancelCommandExecution(aRet,Environment);
                 }
@@ -427,7 +427,7 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
                 if ( ! ( aCommand.Argument >>= aInsertArgument ) ) {
                     aRet <<= IllegalArgumentException(
                                 "Wrong argument type!",
-                                static_cast< cppu::OWeakObject * >(this),
+                                getXWeak(),
                                 -1);
                     ucbhelper::cancelCommandExecution(aRet,Environment);
                 }
@@ -442,7 +442,7 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
                 if ( !( aCommand.Argument >>= aOpenCommand ) ) {
                     aRet <<= IllegalArgumentException(
                                 "Wrong argument type!",
-                                static_cast< cppu::OWeakObject * >(this),
+                                getXWeak(),
                                 -1);
 
                     ucbhelper::cancelCommandExecution(aRet,Environment);
@@ -484,7 +484,7 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
                     else {
                         aRet <<= UnsupportedDataSinkException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >(this),
+                            getXWeak(),
                             aOpenCommand.Sink);
                         ucbhelper::cancelCommandExecution(aRet,Environment);
                     }
@@ -511,14 +511,14 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
                     // Unsupported OpenMode
                     aRet <<= UnsupportedOpenModeException(
                         OUString(),
-                        static_cast< cppu::OWeakObject * >(this),
+                        getXWeak(),
                         static_cast< sal_Int16 >(aOpenCommand.Mode));
                     ucbhelper::cancelCommandExecution(aRet,Environment);
                 }
                 else {
                     aRet <<= IllegalArgumentException(
                                 "Unexpected OpenMode!",
-                                static_cast< cppu::OWeakObject * >(this),
+                                getXWeak(),
                                 -1);
 
                     ucbhelper::cancelCommandExecution(aRet,Environment);
@@ -530,7 +530,7 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
                         Any(
                             IllegalArgumentException(
                                 "Wrong argument type!",
-                                static_cast< cppu::OWeakObject * >(this),
+                                getXWeak(),
                                 -1)),
                         Environment);
                     // Unreachable
@@ -539,7 +539,7 @@ Any SAL_CALL FTPContent::execute( const Command& aCommand,
             } else {
                 aRet <<= UnsupportedCommandException(
                     aCommand.Name,
-                    static_cast< cppu::OWeakObject * >(this));
+                    getXWeak());
                 ucbhelper::cancelCommandExecution(aRet,Environment);
             }
 
@@ -836,7 +836,7 @@ Sequence<Any> FTPContent::setPropertyValues(
                         //props[j].Attributes & PropertyAttribute::READONLY
                         //    ? "Property is read-only!"
                         //    : "Access denied!"),
-                    static_cast< cppu::OWeakObject * >( this ));
+                    getXWeak());
             }
         }
     }
diff --git a/ucb/source/ucp/gio/gio_content.cxx 
b/ucb/source/ucp/gio/gio_content.cxx
index 5c225a951dbd..f7e1fd11a3f0 100644
--- a/ucb/source/ucp/gio/gio_content.cxx
+++ b/ucb/source/ucp/gio/gio_content.cxx
@@ -296,14 +296,14 @@ css::uno::Any Content::mapGIOError( GError *pError )
     if (!pError)
         return getBadArgExcept();
 
-    return convertToException(pError, static_cast< cppu::OWeakObject * 
>(this), false);
+    return convertToException(pError, getXWeak(), false);
 }
 
 css::uno::Any Content::getBadArgExcept()
 {
     return css::uno::Any( css::lang::IllegalArgumentException(
         "Wrong argument type!",
-        static_cast< cppu::OWeakObject * >( this ), -1) );
+        getXWeak(), -1) );
 }
 
 namespace {
@@ -681,7 +681,7 @@ css::uno::Sequence< css::uno::Any > 
Content::setPropertyValues(
     sal_Int32 nCount = rValues.getLength();
 
     css::beans::PropertyChangeEvent aEvent;
-    aEvent.Source = static_cast< cppu::OWeakObject * >( this );
+    aEvent.Source = getXWeak();
     aEvent.Further = false;
     aEvent.PropertyHandle = -1;
 
@@ -704,7 +704,7 @@ css::uno::Sequence< css::uno::Any > 
Content::setPropertyValues(
              rValue.Name == "Size" ||
              rValue.Name == "CreatableContentsInfo" )
         {
-            aRetRange[ n ] <<= getReadOnlyException( static_cast< 
cppu::OWeakObject * >(this) );
+            aRetRange[ n ] <<= getReadOnlyException( getXWeak() );
         }
         else if ( rValue.Name == "Title" )
         {
@@ -712,7 +712,7 @@ css::uno::Sequence< css::uno::Any > 
Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= css::beans::IllegalTypeException
                     ( "Property value has wrong type!",
-                      static_cast< cppu::OWeakObject * >( this ) );
+                      getXWeak() );
                 continue;
             }
 
@@ -720,7 +720,7 @@ css::uno::Sequence< css::uno::Any > 
Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= css::lang::IllegalArgumentException
                     ( "Empty title not allowed!",
-                      static_cast< cppu::OWeakObject * >( this ), -1 );
+                      getXWeak(), -1 );
                 continue;
 
             }
@@ -746,7 +746,7 @@ css::uno::Sequence< css::uno::Any > 
Content::setPropertyValues(
         else
         {
             SAL_WARN("ucb.ucp.gio", "Unknown property " << rValue.Name);
-            aRetRange[ n ] <<= getReadOnlyException( static_cast< 
cppu::OWeakObject * >(this) );
+            aRetRange[ n ] <<= getReadOnlyException( getXWeak() );
         }
     }
 
@@ -778,7 +778,7 @@ css::uno::Sequence< css::uno::Any > 
Content::setPropertyValues(
                 {
                     aRetRange[ nTitlePos ] <<= css::uno::Exception
                         ( "Exchange failed!",
-                          static_cast< cppu::OWeakObject * >( this ) );
+                          getXWeak() );
                 }
             }
 
@@ -855,7 +855,7 @@ bool Content::feedSink( const css::uno::Reference< 
css::uno::XInterface >& xSink
     GError *pError=nullptr;
     GFileInputStream *pStream = g_file_read(getGFile(), nullptr, &pError);
     if (!pStream)
-       convertToException(pError, static_cast< cppu::OWeakObject * >(this));
+       convertToException(pError, getXWeak());
 
     css::uno::Reference< css::io::XInputStream > xIn(
         new comphelper::OSeekableInputWrapper(
@@ -880,7 +880,7 @@ css::uno::Any Content::open(const 
css::ucb::OpenCommandArgument2 & rOpenCommand,
         css::uno::Sequence< css::uno::Any > aArgs{ css::uno::Any(
             m_xIdentifier->getContentIdentifier()) };
         css::uno::Any aErr(
-            css::ucb::InteractiveAugmentedIOException(OUString(), static_cast< 
cppu::OWeakObject * >( this ),
+            css::ucb::InteractiveAugmentedIOException(OUString(), getXWeak(),
                 css::task::InteractionClassification_ERROR,
                 bIsFolder ? css::ucb::IOErrorCode_NOT_EXISTING_PATH : 
css::ucb::IOErrorCode_NOT_EXISTING, aArgs)
         );
@@ -911,7 +911,7 @@ css::uno::Any Content::open(const 
css::ucb::OpenCommandArgument2 & rOpenCommand,
         {
             ucbhelper::cancelCommandExecution(
                 css::uno::Any ( css::ucb::UnsupportedOpenModeException
-                    ( OUString(), static_cast< cppu::OWeakObject * >( this ),
+                    ( OUString(), getXWeak(),
                       sal_Int16( rOpenCommand.Mode ) ) ),
                     xEnv );
         }
@@ -925,7 +925,7 @@ css::uno::Any Content::open(const 
css::ucb::OpenCommandArgument2 & rOpenCommand,
 
             ucbhelper::cancelCommandExecution(
                 css::uno::Any (css::ucb::UnsupportedDataSinkException
-                    ( OUString(), static_cast< cppu::OWeakObject * >( this ),
+                    ( OUString(), getXWeak(),
                       rOpenCommand.Sink ) ),
                     xEnv );
         }
@@ -1016,7 +1016,7 @@ css::uno::Any SAL_CALL Content::execute(
         ucbhelper::cancelCommandExecution
             ( css::uno::Any( css::ucb::UnsupportedCommandException
               ( OUString(),
-                static_cast< cppu::OWeakObject * >( this ) ) ),
+                getXWeak() ) ),
               xEnv );
     }
 
@@ -1058,7 +1058,7 @@ void Content::insert(const css::uno::Reference< 
css::io::XInputStream > &xInputS
     {
         ucbhelper::cancelCommandExecution( css::uno::Any
             ( css::ucb::MissingInputStreamException
-              ( OUString(), static_cast< cppu::OWeakObject * >( this ) ) ),
+              ( OUString(), getXWeak() ) ),
             xEnv );
     }
 
diff --git a/ucb/source/ucp/gio/gio_inputstream.cxx 
b/ucb/source/ucp/gio/gio_inputstream.cxx
index c6df4572b55e..5d07586ec66f 100644
--- a/ucb/source/ucp/gio/gio_inputstream.cxx
+++ b/ucb/source/ucp/gio/gio_inputstream.cxx
@@ -76,7 +76,7 @@ sal_Int32 SAL_CALL InputStream::readBytes( 
css::uno::Sequence< sal_Int8 >& aData
     gsize nBytesRead = 0;
     GError *pError=nullptr;
     if (!g_input_stream_read_all(G_INPUT_STREAM(mpStream), aData.getArray(), 
nBytesToRead, &nBytesRead, nullptr, &pError))
-        convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
+        convertToIOException(pError, getXWeak());
     aData.realloc(nBytesRead);
     return nBytesRead;
 }
diff --git a/ucb/source/ucp/gio/gio_outputstream.cxx 
b/ucb/source/ucp/gio/gio_outputstream.cxx
index 1f334f4df8d8..0da373c0df5d 100644
--- a/ucb/source/ucp/gio/gio_outputstream.cxx
+++ b/ucb/source/ucp/gio/gio_outputstream.cxx
@@ -46,7 +46,7 @@ void SAL_CALL OutputStream::writeBytes( const 
css::uno::Sequence< sal_Int8 >& rD
 
     GError *pError=nullptr;
     if (!g_output_stream_write_all(G_OUTPUT_STREAM(mpStream), 
rData.getConstArray(), rData.getLength(), nullptr, nullptr, &pError))
-        convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
+        convertToIOException(pError, getXWeak());
 }
 
 void SAL_CALL OutputStream::flush()
@@ -56,7 +56,7 @@ void SAL_CALL OutputStream::flush()
 
     GError *pError=nullptr;
     if (!g_output_stream_flush(G_OUTPUT_STREAM(mpStream), nullptr, &pError))
-        convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
+        convertToIOException(pError, getXWeak());
 }
 
 void SAL_CALL OutputStream::closeOutput()
diff --git a/ucb/source/ucp/gio/gio_seekable.cxx 
b/ucb/source/ucp/gio/gio_seekable.cxx
index 1f1da5948d8c..a04185225603 100644
--- a/ucb/source/ucp/gio/gio_seekable.cxx
+++ b/ucb/source/ucp/gio/gio_seekable.cxx
@@ -46,11 +46,11 @@ void SAL_CALL Seekable::truncate()
 
     if (!g_seekable_can_truncate(mpStream))
         throw css::io::IOException("Truncate unsupported",
-            static_cast< cppu::OWeakObject * >(this));
+            getXWeak());
 
     GError *pError=nullptr;
     if (!g_seekable_truncate(mpStream, 0, nullptr, &pError))
-        convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
+        convertToIOException(pError, getXWeak());
 }
 
 void SAL_CALL Seekable::seek( sal_Int64 location )
@@ -60,11 +60,11 @@ void SAL_CALL Seekable::seek( sal_Int64 location )
 
     if (!g_seekable_can_seek(mpStream))
         throw css::io::IOException("Seek unsupported",
-            static_cast< cppu::OWeakObject * >(this));
+            getXWeak());
 
     GError *pError=nullptr;
     if (!g_seekable_seek(mpStream, location, G_SEEK_SET, nullptr, &pError))
-        convertToIOException(pError, static_cast< cppu::OWeakObject * >(this));
+        convertToIOException(pError, getXWeak());
 }
 
 sal_Int64 SAL_CALL Seekable::getPosition()
@@ -102,7 +102,7 @@ sal_Int64 SAL_CALL Seekable::getLength()
         GError *pError=nullptr;
         sal_Int64 nCurr = getPosition();
         if (!g_seekable_seek(mpStream, 0, G_SEEK_END, nullptr, &pError))
-            convertToIOException(pError, static_cast< cppu::OWeakObject * 
>(this));
+            convertToIOException(pError, getXWeak());
         nSize = getPosition();
         seek(nCurr);
     }
diff --git a/ucb/source/ucp/hierarchy/hierarchycontent.cxx 
b/ucb/source/ucp/hierarchy/hierarchycontent.cxx
index 798ba88ea079..7dbfd1deef26 100644
--- a/ucb/source/ucp/hierarchy/hierarchycontent.cxx
+++ b/ucb/source/ucp/hierarchy/hierarchycontent.cxx
@@ -312,7 +312,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -332,7 +332,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -343,7 +343,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "No properties!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -379,7 +379,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -402,7 +402,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -457,7 +457,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -479,7 +479,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -496,7 +496,7 @@ uno::Any SAL_CALL HierarchyContent::execute(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             Environment );
         // Unreachable
     }
@@ -993,7 +993,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
     sal_Int32 nChanged = 0;
 
     beans::PropertyChangeEvent aEvent;
-    aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
+    aEvent.Source         = getXWeak();
     aEvent.Further        = false;
 //    aEvent.PropertyName   =
     aEvent.PropertyHandle = -1;
@@ -1020,28 +1020,28 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "IsDocument" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "IsFolder" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "CreatableContentsInfo" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "Title" )
         {
@@ -1049,7 +1049,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
             {
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else
             {
@@ -1084,7 +1084,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
                     {
                         aRetRange[ n ] <<= lang::IllegalArgumentException(
                                     "Empty title not allowed!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 );
                     }
                 }
@@ -1092,7 +1092,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
                 {
                     aRetRange[ n ] <<= beans::IllegalTypeException(
                                 "Property value has wrong type!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                 }
             }
         }
@@ -1102,7 +1102,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
             {
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else
             {
@@ -1132,7 +1132,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
                         {
                             aRetRange[ n ] <<= lang::IllegalArgumentException(
                                     "Empty target URL not allowed!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 );
                         }
                     }
@@ -1140,14 +1140,14 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
                     {
                         aRetRange[ n ] <<= beans::IllegalTypeException(
                                 "Property value has wrong type!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                     }
                 }
                 else
                 {
                     aRetRange[ n ] <<= beans::UnknownPropertyException(
                                 "TargetURL only supported by links!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                 }
             }
         }
@@ -1201,7 +1201,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
             {
                 aRetRange[ n ] <<= uno::Exception(
                                 "No property set for storing the value!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
         }
     }
@@ -1235,7 +1235,7 @@ uno::Sequence< uno::Any > 
HierarchyContent::setPropertyValues(
             // Set error .
             aRetRange[ nTitlePos ] <<= uno::Exception(
                     "Exchange failed!",
-                    static_cast< cppu::OWeakObject * >( this ) );
+                    getXWeak() );
         }
         aGuard.reset();
     }
@@ -1293,7 +1293,7 @@ void HierarchyContent::insert( sal_Int32 
nNameClashResolve,
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not supported by root folder!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1305,7 +1305,7 @@ void HierarchyContent::insert( sal_Int32 
nNameClashResolve,
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::MissingPropertiesException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 aProps ) ),
             xEnv );
         // Unreachable
@@ -1328,7 +1328,7 @@ void HierarchyContent::insert( sal_Int32 
nNameClashResolve,
                     uno::Any(
                         ucb::NameClashException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ),
+                            getXWeak(),
                             task::InteractionClassification_ERROR,
                             m_aProps.getTitle() ) ),
                     xEnv );
@@ -1359,7 +1359,7 @@ void HierarchyContent::insert( sal_Int32 
nNameClashResolve,
                         uno::Any(
                             ucb::UnsupportedNameClashException(
                                 "Unable to resolve name clash!",
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 nNameClashResolve ) ),
                     xEnv );
                 // Unreachable
@@ -1381,7 +1381,7 @@ void HierarchyContent::insert( sal_Int32 
nNameClashResolve,
                     uno::Any(
                         ucb::UnsupportedNameClashException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 nNameClashResolve ) ),
                     xEnv );
                 // Unreachable
@@ -1435,7 +1435,7 @@ void HierarchyContent::destroy( bool bDeletePhysical,
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not persistent!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1446,7 +1446,7 @@ void HierarchyContent::destroy( bool bDeletePhysical,
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not supported by root folder!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1483,7 +1483,7 @@ void HierarchyContent::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not persistent!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1494,7 +1494,7 @@ void HierarchyContent::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::InteractiveBadTransferURLException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
             xEnv );
         // Unreachable
     }
diff --git a/ucb/source/ucp/hierarchy/hierarchydatasource.cxx 
b/ucb/source/ucp/hierarchy/hierarchydatasource.cxx
index 43703b758c79..ec8b5d8229ca 100644
--- a/ucb/source/ucp/hierarchy/hierarchydatasource.cxx
+++ b/ucb/source/ucp/hierarchy/hierarchydatasource.cxx
@@ -403,9 +403,7 @@ HierarchyDataSource::createInstanceWithArguments(
         return xConfigAccess;
     }
 
-    return uno::Reference< uno::XInterface >(
-                static_cast< cppu::OWeakObject * >(
-                    new HierarchyDataAccess( xConfigAccess, bReadOnly ) ) );
+    return cppu::getXWeak(new HierarchyDataAccess(xConfigAccess, bReadOnly));
 }
 
 
diff --git a/ucb/source/ucp/package/pkgcontent.cxx 
b/ucb/source/ucp/package/pkgcontent.cxx
index a0cff94b9c4b..de7b9c16ed97 100644
--- a/ucb/source/ucp/package/pkgcontent.cxx
+++ b/ucb/source/ucp/package/pkgcontent.cxx
@@ -404,7 +404,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -424,7 +424,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -435,7 +435,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "No properties!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -473,7 +473,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -493,7 +493,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -546,7 +546,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -568,7 +568,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -607,7 +607,7 @@ uno::Any SAL_CALL Content::execute(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             Environment );
         // Unreachable
     }
@@ -957,7 +957,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
     sal_Int32 nChanged = 0;
 
     beans::PropertyChangeEvent aEvent;
-    aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
+    aEvent.Source         = getXWeak();
     aEvent.Further        = false;
 //    aEvent.PropertyName   =
     aEvent.PropertyHandle = -1;
@@ -983,28 +983,28 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "IsDocument" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "IsFolder" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "CreatableContentsInfo" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "Title" )
         {
@@ -1013,7 +1013,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 // Read-only property!
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else
             {
@@ -1042,7 +1042,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                         aRetRange[ n ] <<=
                             lang::IllegalArgumentException(
                                 "Empty title not allowed!",
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 -1 );
                     }
                 }
@@ -1051,7 +1051,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                     aRetRange[ n ] <<=
                         beans::IllegalTypeException(
                             "Property value has wrong type!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
                 }
             }
         }
@@ -1076,7 +1076,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= beans::IllegalTypeException(
                                 "Property value has wrong type!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
         }
         else if ( rValue.Name == "Size" )
@@ -1084,7 +1084,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "Compressed" )
         {
@@ -1110,14 +1110,14 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 {
                     aRetRange[ n ] <<= beans::IllegalTypeException(
                                 "Property value has wrong type!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                 }
             }
             else
             {
                 aRetRange[ n ] <<= beans::UnknownPropertyException(
                                 "Compressed only supported by streams!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
         }
         else if ( rValue.Name == "Encrypted" )
@@ -1144,14 +1144,14 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 {
                     aRetRange[ n ] <<= beans::IllegalTypeException(
                                 "Property value has wrong type!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                 }
             }
             else
             {
                 aRetRange[ n ] <<= beans::UnknownPropertyException(
                                 "Encrypted only supported by streams!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
         }
         else if ( rValue.Name == "HasEncryptedEntries" )
@@ -1159,7 +1159,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "EncryptionKey" )
         {
@@ -1189,14 +1189,14 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 {
                     aRetRange[ n ] <<= beans::IllegalTypeException(
                                 "Property value has wrong type!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                 }
             }
             else
             {
                 aRetRange[ n ] <<= beans::UnknownPropertyException(
                         "EncryptionKey not supported by non-root folder!",
-                        static_cast< cppu::OWeakObject * >( this ) );
+                        getXWeak() );
             }
         }
         else
@@ -1249,7 +1249,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= uno::Exception(
                                 "No property set for storing the value!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
         }
     }
@@ -1282,7 +1282,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Set error .
             aRetRange[ nTitlePos ] <<= uno::Exception(
                     "Exchange failed!",
-                    static_cast< cppu::OWeakObject * >( this ) );
+                    getXWeak() );
         }
     }
 
@@ -1358,7 +1358,7 @@ uno::Any Content::open(
             ucbhelper::cancelCommandExecution(
                 uno::Any( ucb::UnsupportedOpenModeException(
                                     OUString(),
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     sal_Int16( rArg.Mode ) ) ),
                 xEnv );
             // Unreachable
@@ -1455,7 +1455,7 @@ uno::Any Content::open(
                     uno::Any(
                         ucb::UnsupportedDataSinkException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 rArg.Sink ) ),
                     xEnv );
                 // Unreachable
@@ -1491,7 +1491,7 @@ void Content::insert(
             ucbhelper::cancelCommandExecution(
                 uno::Any( ucb::MissingInputStreamException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
                 xEnv );
             // Unreachable
         }
@@ -1518,7 +1518,7 @@ void Content::insert(
                 ucbhelper::cancelCommandExecution(
                     uno::Any( ucb::NameClashException(
                                     OUString(),
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     task::InteractionClassification_ERROR,
                                     m_aProps.aTitle ) ),
                     xEnv );
@@ -1549,7 +1549,7 @@ void Content::insert(
                         uno::Any(
                             ucb::UnsupportedNameClashException(
                                 "Unable to resolve name clash!",
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 nNameClashResolve ) ),
                     xEnv );
                     // Unreachable
@@ -1571,7 +1571,7 @@ void Content::insert(
                     uno::Any(
                         ucb::UnsupportedNameClashException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ),
+                            getXWeak(),
                             nNameClashResolve ) ),
                     xEnv );
                 // Unreachable
@@ -1636,7 +1636,7 @@ void Content::destroy(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not persistent!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1673,7 +1673,7 @@ void Content::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not persistent!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1686,7 +1686,7 @@ void Content::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::InteractiveBadTransferURLException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
diff --git a/ucb/source/ucp/tdoc/tdoc_content.cxx 
b/ucb/source/ucp/tdoc/tdoc_content.cxx
index 5bc1f79ffb59..606bbcdbbce4 100644
--- a/ucb/source/ucp/tdoc/tdoc_content.cxx
+++ b/ucb/source/ucp/tdoc/tdoc_content.cxx
@@ -340,7 +340,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -360,7 +360,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -371,7 +371,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "No properties!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -407,7 +407,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -428,7 +428,7 @@ uno::Any SAL_CALL Content::execute(
                 uno::Any( ucb::UnsupportedCommandException(
                                 "insert command only supported by "
                                 "folders and streams!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
                 Environment );
             // Unreachable
         }
@@ -444,8 +444,7 @@ uno::Any SAL_CALL Content::execute(
                                     "insert command not supported by "
                                     "streams that are direct children "
                                     "of document root!",
-                                    static_cast< cppu::OWeakObject * >(
-                                        this ) ) ),
+                                    getXWeak() ) ),
                     Environment );
                 // Unreachable
             }
@@ -457,7 +456,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -484,8 +483,7 @@ uno::Any SAL_CALL Content::execute(
                     uno::Any( ucb::UnsupportedCommandException(
                                     "delete command only supported by "
                                     "folders and streams!",
-                                    static_cast< cppu::OWeakObject * >(
-                                        this ) ) ),
+                                    getXWeak() ) ),
                     Environment );
                 // Unreachable
             }
@@ -530,8 +528,7 @@ uno::Any SAL_CALL Content::execute(
                     uno::Any( ucb::UnsupportedCommandException(
                                     "transfer command only supported "
                                     "by folders and documents!",
-                                    static_cast< cppu::OWeakObject * >(
-                                        this ) ) ),
+                                    getXWeak() ) ),
                     Environment );
                 // Unreachable
             }
@@ -544,7 +541,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -569,8 +566,7 @@ uno::Any SAL_CALL Content::execute(
                                     "createNewContent command only "
                                     "supported by folders and "
                                     "documents!",
-                                    static_cast< cppu::OWeakObject * >(
-                                        this ) ) ),
+                                    getXWeak() ) ),
                     Environment );
                 // Unreachable
             }
@@ -583,7 +579,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -600,7 +596,7 @@ uno::Any SAL_CALL Content::execute(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             Environment );
         // Unreachable
     }
@@ -1077,7 +1073,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
     sal_Int32 nChanged = 0;
 
     beans::PropertyChangeEvent aEvent;
-    aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
+    aEvent.Source         = getXWeak();
     aEvent.Further        = false;
     //    aEvent.PropertyName   =
     aEvent.PropertyHandle = -1;
@@ -1103,28 +1099,28 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "IsDocument" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "IsFolder" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "CreatableContentsInfo" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rValue.Name == "Title" )
         {
@@ -1134,7 +1130,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else
             {
@@ -1164,7 +1160,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                     {
                         aRetRange[ n ] <<= lang::IllegalArgumentException(
                                     "Empty Title not allowed!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 );
                     }
                 }
@@ -1172,7 +1168,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 {
                     aRetRange[ n ] <<= beans::IllegalTypeException(
                                 "Title Property value has wrong type!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                 }
             }
         }
@@ -1183,14 +1179,14 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else
             {
                 // Storage is only supported by folders.
                 aRetRange[ n ] <<= beans::UnknownPropertyException(
                             "Storage property only supported by folders",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
             }
         }
         else if ( rValue.Name == "DocumentModel" )
@@ -1200,14 +1196,14 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else
             {
                 // Storage is only supported by folders.
                 aRetRange[ n ] <<= beans::UnknownPropertyException(
                             "DocumentModel property only supported by 
documents",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
             }
         }
         else
@@ -1260,7 +1256,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= uno::Exception(
                                 "No property set for storing the value!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
         }
     }
@@ -1291,7 +1287,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Set error .
             aRetRange[ nTitlePos ] <<= uno::Exception(
                     "Exchange failed!",
-                    static_cast< cppu::OWeakObject * >( this ) );
+                    getXWeak() );
         }
     }
 
@@ -1365,7 +1361,7 @@ uno::Any Content::open(
             ucbhelper::cancelCommandExecution(
                 uno::Any( ucb::UnsupportedOpenModeException(
                                     OUString(),
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     sal_Int16( rArg.Mode ) ) ),
                 xEnv );
             // Unreachable
@@ -1493,7 +1489,7 @@ uno::Any Content::open(
                         uno::Any(
                             ucb::UnsupportedDataSinkException(
                                     OUString(),
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     rArg.Sink ) ),
                         xEnv );
                     // Unreachable
@@ -1547,7 +1543,7 @@ void Content::insert( const uno::Reference< 
io::XInputStream >& xData,
             ucbhelper::cancelCommandExecution(
                 uno::Any( ucb::MissingInputStreamException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
                 xEnv );
             // Unreachable
         }
@@ -1570,7 +1566,7 @@ void Content::insert( const uno::Reference< 
io::XInputStream >& xData,
                 ucbhelper::cancelCommandExecution(
                     uno::Any( ucb::NameClashException(
                                     OUString(),
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     task::InteractionClassification_ERROR,
                                     m_aProps.getTitle() ) ),
                     xEnv );
@@ -1600,7 +1596,7 @@ void Content::insert( const uno::Reference< 
io::XInputStream >& xData,
                         uno::Any(
                             ucb::UnsupportedNameClashException(
                                 "Unable to resolve name clash!",
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 nNameClashResolve ) ),
                         xEnv );
                     // Unreachable
@@ -1621,7 +1617,7 @@ void Content::insert( const uno::Reference< 
io::XInputStream >& xData,
                     uno::Any(
                         ucb::UnsupportedNameClashException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ),
+                            getXWeak(),
                             nNameClashResolve ) ),
                     xEnv );
                 // Unreachable
@@ -1686,7 +1682,7 @@ void Content::destroy( bool bDeletePhysical,
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not persistent!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1777,7 +1773,7 @@ void Content::notifyChildRemoved( std::u16string_view 
rRelativeChildUri )
 
     // Notify "REMOVED" event.
     ucb::ContentEvent aEvt(
-        static_cast< cppu::OWeakObject * >( this ),
+        getXWeak(),
         ucb::ContentAction::REMOVED,
         xChild,
         getIdentifier() );
@@ -1801,7 +1797,7 @@ void Content::notifyChildInserted( std::u16string_view 
rRelativeChildUri )
 
     // Notify "INSERTED" event.
     ucb::ContentEvent aEvt(
-        static_cast< cppu::OWeakObject * >( this ),
+        getXWeak(),
         ucb::ContentAction::INSERTED,
         xChild,
         getIdentifier() );
@@ -1821,7 +1817,7 @@ void Content::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                                 "Not persistent!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1834,7 +1830,7 @@ void Content::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::InteractiveBadTransferURLException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1848,7 +1844,7 @@ void Content::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::InteractiveBadTransferURLException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
             xEnv );
         // Unreachable
     }
@@ -1860,7 +1856,7 @@ void Content::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( lang::IllegalArgumentException(
                                 "Invalid source URI! Syntax!",
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 -1 ) ),
             xEnv );
         // Unreachable
@@ -1871,7 +1867,7 @@ void Content::transfer(
         ucbhelper::cancelCommandExecution(
             uno::Any( lang::IllegalArgumentException(
                                 "Invalid source URI! Must describe a folder or 
stream!",
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 -1 ) ),
             xEnv );
         // Unreachable
@@ -1922,8 +1918,7 @@ void Content::transfer(
                                         "Invalid source URI! "
                                         "Streams cannot be created as "
                                         "children of document root!",
-                                        static_cast< cppu::OWeakObject * >(
-                                            this ),
+                                        getXWeak(),
                                         -1 ) ),
                         xEnv );
                     // Unreachable
@@ -1949,7 +1944,7 @@ void Content::transfer(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Invalid source URI! Unable to determine 
source type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 xEnv );
             // Unreachable
diff --git a/ucb/source/ucp/tdoc/tdoc_documentcontentfactory.cxx 
b/ucb/source/ucp/tdoc/tdoc_documentcontentfactory.cxx
index 12177c41ab80..5b45df4bb989 100644
--- a/ucb/source/ucp/tdoc/tdoc_documentcontentfactory.cxx
+++ b/ucb/source/ucp/tdoc/tdoc_documentcontentfactory.cxx
@@ -98,7 +98,7 @@ DocumentContentFactory::createDocumentContent(
 
     throw uno::RuntimeException(
         "Unable to obtain document content factory!",
-        static_cast< cppu::OWeakObject * >( this ) );
+        getXWeak() );
 }
 
 
diff --git a/ucb/source/ucp/tdoc/tdoc_provider.cxx 
b/ucb/source/ucp/tdoc/tdoc_provider.cxx
index 5e036e0d76c4..f9aaa139547d 100644
--- a/ucb/source/ucp/tdoc/tdoc_provider.cxx
+++ b/ucb/source/ucp/tdoc/tdoc_provider.cxx
@@ -137,7 +137,7 @@ ContentProvider::createDocumentContentIdentifier(
     {
         throw lang::IllegalArgumentException(
             "No Document Manager!",
-            static_cast< cppu::OWeakObject * >( this ),
+            getXWeak(),
             1 );
     }
 
@@ -146,7 +146,7 @@ ContentProvider::createDocumentContentIdentifier(
     {
         throw lang::IllegalArgumentException(
             "Unable to obtain document id from model!",
-            static_cast< cppu::OWeakObject * >( this ),
+            getXWeak(),
             1 );
     }
 
@@ -184,7 +184,7 @@ ContentProvider::createDocumentContent(
     // no content.
     throw lang::IllegalArgumentException(
         "Illegal Content Identifier!",
-        static_cast< cppu::OWeakObject * >( this ),
+        getXWeak(),
         1 );
 }
 
diff --git a/ucb/source/ucp/tdoc/tdoc_stgelems.cxx 
b/ucb/source/ucp/tdoc/tdoc_stgelems.cxx
index 9b1159fc2c41..dff9bf590902 100644
--- a/ucb/source/ucp/tdoc/tdoc_stgelems.cxx
+++ b/ucb/source/ucp/tdoc/tdoc_stgelems.cxx
@@ -108,7 +108,7 @@ Storage::Storage( const uno::Reference< 
uno::XComponentContext > & rxContext,
         // is completed (See impl. of XInterface::release())!
 
         m_xAggProxy->setDelegator(
-            static_cast< cppu::OWeakObject * >( this ) );
+            getXWeak() );
     }
     osl_atomic_decrement( &m_refCount );
 }
@@ -498,7 +498,7 @@ OutputStream::OutputStream(
         // is completed (See impl. of XInterface::release())!
 
         m_xAggProxy->setDelegator(
-            static_cast< cppu::OWeakObject * >( this ) );
+            getXWeak() );
     }
     osl_atomic_decrement( &m_refCount );
 }
@@ -666,7 +666,7 @@ Stream::Stream(
         // is completed (See impl. of XInterface::release())!
 
         m_xAggProxy->setDelegator(
-            static_cast< cppu::OWeakObject * >( this ) );
+            getXWeak() );
     }
     osl_atomic_decrement( &m_refCount );
 }
diff --git a/ucb/source/ucp/webdav-curl/webdavcontent.cxx 
b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
index acd850a24e9b..26fa01d16027 100644
--- a/ucb/source/ucp/webdav-curl/webdavcontent.cxx
+++ b/ucb/source/ucp/webdav-curl/webdavcontent.cxx
@@ -450,7 +450,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -470,7 +470,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -481,7 +481,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "No properties!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -521,7 +521,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -551,7 +551,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -615,7 +615,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                   "Wrong argument type!",
-                                  static_cast< cppu::OWeakObject * >( this ),
+                                  getXWeak(),
                                   -1 ) ),
                 Environment );
             // Unreachable
@@ -635,7 +635,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -685,7 +685,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
             // Unreachable
@@ -701,7 +701,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
         }
@@ -733,7 +733,7 @@ uno::Any SAL_CALL Content::execute(
             ucbhelper::cancelCommandExecution(
                 uno::Any( lang::IllegalArgumentException(
                                     "Wrong argument type!",
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     -1 ) ),
                 Environment );
         }
@@ -762,7 +762,7 @@ uno::Any SAL_CALL Content::execute(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::UnsupportedCommandException(
                               aCommand.Name,
-                              static_cast< cppu::OWeakObject * >( this ) ) ),
+                              getXWeak() ) ),
             Environment );
         // Unreachable
     }
@@ -811,20 +811,20 @@ void Content::addProperty( const 
css::ucb::PropertyCommandArgument &aCmdArg,
     if ( !aProperty.Name.getLength() )
         throw lang::IllegalArgumentException(
             "\"addProperty\" with empty Property.Name",
-            static_cast< ::cppu::OWeakObject * >( this ),
+            getXWeak(),
             -1 );
 
     // Check property type.
     if ( !UCBDeadPropertyValue::supportsType( aProperty.Type ) )
         throw beans::IllegalTypeException(
             "\"addProperty\" unsupported Property.Type",
-            static_cast< ::cppu::OWeakObject * >( this ) );
+            getXWeak() );
 
     // check default value
     if ( aDefaultValue.hasValue() && aDefaultValue.getValueType() != 
aProperty.Type )
         throw beans::IllegalTypeException(
             "\"addProperty\" DefaultValue does not match Property.Type",
-            static_cast< ::cppu::OWeakObject * >( this ) );
+            getXWeak() );
 
 
     // Make sure a property with the requested name does not already
@@ -873,7 +873,7 @@ void Content::addProperty( const 
css::ucb::PropertyCommandArgument &aCmdArg,
 
         // Notify propertyset info change listeners.
         beans::PropertySetInfoChangeEvent evt(
-            static_cast< cppu::OWeakObject * >( this ),
+            getXWeak(),
             bIsSpecial ? aSpecialName : aProperty.Name,
             -1, // No handle available
             beans::PropertySetInfoChange::PROPERTY_INSERTED );
@@ -983,7 +983,7 @@ void Content::removeProperty( const OUString& Name,
 
         // Notify propertyset info change listeners.
         beans::PropertySetInfoChangeEvent evt(
-            static_cast< cppu::OWeakObject * >( this ),
+            getXWeak(),
             Name,
             -1, // No handle available
             beans::PropertySetInfoChange::PROPERTY_REMOVED );
@@ -1736,7 +1736,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
     sal_Int32 nChanged = 0;
 
     beans::PropertyChangeEvent aEvent;
-    aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
+    aEvent.Source         = getXWeak();
     aEvent.Further        = false;
     // aEvent.PropertyName =
     aEvent.PropertyHandle = -1;
@@ -1771,7 +1771,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
             continue;
         }
 
@@ -1784,21 +1784,21 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                 "Property is read-only!",
-                static_cast< cppu::OWeakObject * >( this ) );
+                getXWeak() );
         }
         else if ( rName == "IsDocument" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                 "Property is read-only!",
-                static_cast< cppu::OWeakObject * >( this ) );
+                getXWeak() );
         }
         else if ( rName == "IsFolder" )
         {
             // Read-only property!
             aRetRange[ n ] <<= lang::IllegalAccessException(
                             "Property is read-only!",
-                            static_cast< cppu::OWeakObject * >( this ) );
+                            getXWeak() );
         }
         else if ( rName == "Title" )
         {
@@ -1831,7 +1831,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                     {
                         aRetRange[ n ] <<= lang::IllegalArgumentException(
                             "Invalid content identifier!",
-                            static_cast< cppu::OWeakObject * >( this ),
+                            getXWeak(),
                             -1 );
                     }
                 }
@@ -1839,7 +1839,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 {
                     aRetRange[ n ] <<= lang::IllegalArgumentException(
                         "Empty title not allowed!",
-                        static_cast< cppu::OWeakObject * >( this ),
+                        getXWeak(),
                         -1 );
                 }
             }
@@ -1847,7 +1847,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
             {
                 aRetRange[ n ] <<= beans::IllegalTypeException(
                     "Property value has wrong type!",
-                    static_cast< cppu::OWeakObject * >( this ) );
+                    getXWeak() );
             }
         }
         else
@@ -1870,7 +1870,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 // is not allowed for "setPropertyValues" command!
                 aRetRange[ n ] <<= beans::UnknownPropertyException(
                                 "Property is unknown!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                 continue;
             }
 
@@ -1879,21 +1879,21 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 // Read-only property!
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else if ( rName == "DateCreated" )
             {
                 // Read-only property!
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else if ( rName == "DateModified" )
             {
                 // Read-only property!
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else if ( rName == "MediaType" )
             {
@@ -1901,14 +1901,14 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 // (but could be writable, if 'getcontenttype' would be)
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             if ( rName == "CreatableContentsInfo" )
             {
                 // Read-only property!
                 aRetRange[ n ] <<= lang::IllegalAccessException(
                                 "Property is read-only!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
             }
             else
             {
@@ -1973,7 +1973,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                     {
                         aRetRange[ n ] <<= uno::Exception(
                                 "No property set for storing the value!",
-                                static_cast< cppu::OWeakObject * >( this ) );
+                                getXWeak() );
                     }
                 }
             }
@@ -2084,7 +2084,7 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
                 // Set error .
                 aRetRange[ nTitlePos ] <<= uno::Exception(
                     "Exchange failed!",
-                    static_cast< cppu::OWeakObject * >( this ) );
+                    getXWeak() );
             }
         }
         catch ( DAVException const & e )
@@ -2153,7 +2153,7 @@ uno::Any Content::open(
                 uno::Any(
                     lang::IllegalArgumentException(
                         "Non-folder resource cannot be opened as folder! Wrong 
Open Mode!",
-                        static_cast< cppu::OWeakObject * >( this ),
+                        getXWeak(),
                         -1 ) ),
                 xEnv );
             // Unreachable
@@ -2172,7 +2172,7 @@ uno::Any Content::open(
                 uno::Any(
                     ucb::UnsupportedOpenModeException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ),
+                            getXWeak(),
                             sal_Int16( rArg.Mode ) ) ),
                 xEnv );
             // Unreachable
@@ -2300,7 +2300,7 @@ uno::Any Content::open(
                     uno::Any(
                         ucb::UnsupportedDataSinkException(
                             OUString(),
-                            static_cast< cppu::OWeakObject * >( this ),
+                            getXWeak(),
                             rArg.Sink ) ),
                     xEnv );
                 // Unreachable
@@ -2388,7 +2388,7 @@ void Content::post(
                 uno::Any(
                     ucb::UnsupportedDataSinkException(
                         OUString(),
-                        static_cast< cppu::OWeakObject * >( this ),
+                        getXWeak(),
                         rArg.Sink ) ),
                 xEnv );
             // Unreachable
@@ -2472,7 +2472,7 @@ void Content::insert(
         ucbhelper::cancelCommandExecution(
             uno::Any( ucb::MissingPropertiesException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 aProps ) ),
             Environment );
         // Unreachable
@@ -2501,7 +2501,7 @@ void Content::insert(
 #undef ERROR
             ucb::UnsupportedNameClashException aEx(
                 "Unable to write without overwrite!",
-                static_cast< cppu::OWeakObject * >( this ),
+                getXWeak(),
                 ucb::NameClash::ERROR );
 
             uno::Reference< task::XInteractionHandler > xIH;
@@ -2648,7 +2648,7 @@ void Content::insert(
                             uno::Any(
                                 ucb::NameClashException(
                                     OUString(),
-                                    static_cast< cppu::OWeakObject * >( this ),
+                                    getXWeak(),
                                     task::InteractionClassification_ERROR,
                                     aTitle ) ),
                             Environment );
@@ -2682,7 +2682,7 @@ void Content::insert(
                 uno::Any(
                     ucb::MissingInputStreamException(
                         OUString(),
-                        static_cast< cppu::OWeakObject * >( this ) ) ),
+                        getXWeak() ) ),
                 Environment );
             // Unreachable
         }
@@ -2772,7 +2772,7 @@ void Content::transfer(
                     uno::Any(
                         ucb::InteractiveBadTransferURLException(
                             "Unsupported URL scheme!",
-                            static_cast< cppu::OWeakObject * >( this ) ) ),
+                            getXWeak() ) ),
                     Environment );
                 // Unreachable
             }
@@ -2804,7 +2804,7 @@ void Content::transfer(
             ucbhelper::cancelCommandExecution(
                 uno::Any( ucb::InteractiveBadTransferURLException(
                                 "Different hosts!",
-                                static_cast< cppu::OWeakObject * >( this ) ) ),
+                                getXWeak() ) ),
                 Environment );
             // Unreachable
         }
@@ -2929,7 +2929,7 @@ void Content::transfer(
                         uno::Any(
                             ucb::NameClashException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 task::InteractionClassification_ERROR,
                                 aTargetURI ) ),
                         Environment );
@@ -2949,7 +2949,7 @@ void Content::transfer(
                         uno::Any(
                             ucb::UnsupportedNameClashException(
                                 OUString(),
-                                static_cast< cppu::OWeakObject * >( this ),
+                                getXWeak(),
                                 rArgs.NameClash ) ),
                         Environment );
                     // Unreachable
@@ -3278,7 +3278,7 @@ void Content::lock(
                 throw
                     ucb::InteractiveLockingLockedException(
                         "Locked!",
-                        static_cast< cppu::OWeakObject * >( this ),
+                        getXWeak(),
                         task::InteractionClassification_ERROR,
                         aURL,
                         false );
@@ -3302,7 +3302,7 @@ void Content::lock(
                 throw
                     ucb::InteractiveNetworkWriteException(
                         "Authentication error while trying to lock! Write only 
WebDAV perhaps?",
-                        static_cast< cppu::OWeakObject * >( this ),
+                        getXWeak(),
                         task::InteractionClassification_ERROR,
                         e.getData() );
             }
@@ -3555,7 +3555,7 @@ uno::Any Content::MapDAVException( const DAVException & 
e, bool bWrite )
             aException <<=
                 ucb::InteractiveAugmentedIOException(
                     "Not found!",
-                    static_cast< cppu::OWeakObject * >( this ),
+                    getXWeak(),
                     task::InteractionClassification_ERROR,
                     ucb::IOErrorCode_NOT_EXISTING,
                     aArgs );
@@ -3573,14 +3573,14 @@ uno::Any Content::MapDAVException( const DAVException & 
e, bool bWrite )
                 aException <<=
                     ucb::InteractiveNetworkWriteException(
                         e.getData(),
-                        static_cast< cppu::OWeakObject * >( this ),
+                        getXWeak(),
                         task::InteractionClassification_ERROR,
                         e.getData() );
             else
                 aException <<=

... etc. - the rest is truncated

Reply via email to