diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-04-09 09:37:17 +0200 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-04-09 09:37:17 +0200 |
commit | 5d5e24f5bc71d413f051746063573a72db65ab7d (patch) | |
tree | aaad06c8859ffd54160a928ab8b753a9d4d1faca /unotools | |
parent | 0768a7d2726ce4f0772b52d95eeb23143336655c (diff) | |
parent | bc05d94bb339e0f25bb329ad0c6b27d779d3e664 (diff) |
slidecopy: merge CWS wth MWS-m76
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/inc/unotools/confignode.hxx | 56 | ||||
-rw-r--r-- | unotools/source/config/confignode.cxx | 235 | ||||
-rw-r--r-- | unotools/source/config/configvaluecontainer.cxx | 2 |
3 files changed, 122 insertions, 171 deletions
diff --git a/unotools/inc/unotools/confignode.hxx b/unotools/inc/unotools/confignode.hxx index 8745508375a1..57c3d4070feb 100644 --- a/unotools/inc/unotools/confignode.hxx +++ b/unotools/inc/unotools/confignode.hxx @@ -35,6 +35,11 @@ #include <com/sun/star/util/XChangesBatch.hpp> #include <unotools/eventlisteneradapter.hxx> +namespace comphelper +{ + class ComponentContext; +} + //........................................................................ namespace utl { @@ -59,19 +64,23 @@ namespace utl m_xReplaceAccess; /// replacing child values ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xContainerAccess; /// modifying set nodes (optional interface of our UNO object) - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > - m_xProvider; /// the configuration provider which supplied the nodes of the hierarchy we're a part of + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + m_xDummy; sal_Bool m_bEscapeNames; /// escape names before accessing children ? ::rtl::OUString m_sCompletePath; OConfigurationNode insertNode(const ::rtl::OUString& _rName,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xNode) const throw(); + protected: /// constructs a node object with an interface representing a node OConfigurationNode( - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxNode, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxProvider); + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxNode + ); + + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& + getUNONode() const { return m_xDirectAccess; } public: /// constructs an empty and invalid node object @@ -186,14 +195,6 @@ namespace utl */ sal_Bool getEscape() const { return m_bEscapeNames; } - /** clone the object, creating a new hierarchy where the root represents the same node as the object - where this method is called does.<p/> - The new hierarchy does not share any updates with the one the object is a part of, i.e. any changes made - in the existing hierarchy are not visible to the newly created one until committed (and vice versa). - @param _rRoot out parameter. upon return, contains the object representing the root of the new hierarchy. - */ - OConfigurationTreeRoot cloneAsRoot() const throw(); - /// invalidate the object virtual void clear() throw(); @@ -246,22 +247,23 @@ namespace utl /** ctor<p/> */ OConfigurationTreeRoot( - const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch >& _rxRootNode, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxProvider); + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesBatch >& _rxRootNode + ); /** ctor for a readonly node */ OConfigurationTreeRoot( - const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxRootNode, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxProvider); + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxRootNode + ); public: - /// modes to used when creating a top-level node object + /// modes to use when creating a top-level node object enum CREATION_MODE { - CM_READONLY, /// open the node (i.e. sub tree) for read access only - CM_UPDATABLE, /// open the node (i.e. sub tree) for read and write access - CM_PREFER_UPDATABLE /// open the node (i.e. sub tree) for read and write access, if this fails, open it for read acces + /// open the node (i.e. sub tree) for read access only + CM_READONLY, + /// open the node (i.e. sub tree) for read and write access, fall back to read-only if write access is not possible + CM_UPDATABLE }; public: @@ -270,6 +272,14 @@ namespace utl */ OConfigurationTreeRoot() :OConfigurationNode() { } + /** creates a configuration tree for the given path in the given mode + */ + OConfigurationTreeRoot( + const ::comphelper::ComponentContext& i_rContext, + const sal_Char* i_pAsciiNodePath, + const bool i_bUpdatable + ); + /// copy ctor OConfigurationTreeRoot(const OConfigurationTreeRoot& _rSource) :OConfigurationNode(_rSource), m_xCommitter(_rSource.m_xCommitter) { } @@ -293,7 +303,7 @@ namespace utl const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxConfProvider, const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, - CREATION_MODE _eMode = CM_PREFER_UPDATABLE, + CREATION_MODE _eMode = CM_UPDATABLE, sal_Bool _bLazyWrite = sal_True ); @@ -310,7 +320,7 @@ namespace utl @param _eMode specifies which privileges should be applied when retrieving the node */ static OConfigurationTreeRoot createWithServiceFactory(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, - const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_PREFER_UPDATABLE, sal_Bool _bLazyWrite = sal_True); + const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_UPDATABLE, sal_Bool _bLazyWrite = sal_True); /** tolerant version of the <member>createWithServiceFactory</member> @@ -319,7 +329,7 @@ namespace utl given node path does not exist) are still asserted.</p> */ static OConfigurationTreeRoot tryCreateWithServiceFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, - const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_PREFER_UPDATABLE, sal_Bool _bLazyWrite = sal_True ); + const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_UPDATABLE, sal_Bool _bLazyWrite = sal_True ); /** commit all changes made on the subtree the object is the root for<p/> All changes made on any <type>OConfigurationNode</type> object retrieved (maybe indirect) from this root diff --git a/unotools/source/config/confignode.cxx b/unotools/source/config/confignode.cxx index 802a63782cf9..5db9f8db4313 100644 --- a/unotools/source/config/confignode.cxx +++ b/unotools/source/config/confignode.cxx @@ -40,6 +40,8 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/container/XNamed.hpp> #include <comphelper/extract.hxx> +#include <comphelper/componentcontext.hxx> +#include <comphelper/namedvaluecollection.hxx> #include <rtl/string.hxx> #if OSL_DEBUG_LEVEL > 0 #include <rtl/strbuf.hxx> @@ -60,9 +62,8 @@ namespace utl //= OConfigurationNode //======================================================================== //------------------------------------------------------------------------ - OConfigurationNode::OConfigurationNode(const Reference< XInterface >& _rxNode, const Reference< XMultiServiceFactory >& _rxProvider) - :m_xProvider(_rxProvider) - ,m_bEscapeNames(sal_False) + OConfigurationNode::OConfigurationNode(const Reference< XInterface >& _rxNode ) + :m_bEscapeNames(sal_False) { OSL_ENSURE(_rxNode.is(), "OConfigurationNode::OConfigurationNode: invalid node interface!"); if (_rxNode.is()) @@ -98,7 +99,6 @@ namespace utl ,m_xDirectAccess(_rSource.m_xDirectAccess) ,m_xReplaceAccess(_rSource.m_xReplaceAccess) ,m_xContainerAccess(_rSource.m_xContainerAccess) - ,m_xProvider(_rSource.m_xProvider) ,m_bEscapeNames(_rSource.m_bEscapeNames) ,m_sCompletePath(_rSource.m_sCompletePath) { @@ -116,7 +116,6 @@ namespace utl m_xDirectAccess = _rSource.m_xDirectAccess; m_xContainerAccess = _rSource.m_xContainerAccess; m_xReplaceAccess = _rSource.m_xReplaceAccess; - m_xProvider = _rSource.m_xProvider; m_bEscapeNames = _rSource.m_bEscapeNames; m_sCompletePath = _rSource.m_sCompletePath; @@ -244,7 +243,7 @@ namespace utl ::rtl::OUString sName = normalizeName(_rName, NO_CALLER); m_xContainerAccess->insertByName(sName, makeAny(_xNode)); // if we're here, all was ok ... - return OConfigurationNode(_xNode, m_xProvider); + return OConfigurationNode( _xNode ); } catch(const Exception&) { @@ -308,7 +307,7 @@ namespace utl OSL_ENSURE(sal_False, "OConfigurationNode::openNode: could not open the node!"); } if (xNode.is()) - return OConfigurationNode(xNode, m_xProvider); + return OConfigurationNode( xNode ); } catch(NoSuchElementException& e) { @@ -470,63 +469,102 @@ namespace utl } //------------------------------------------------------------------------ - OConfigurationTreeRoot OConfigurationNode::cloneAsRoot() const throw() + void OConfigurationNode::clear() throw() + { + m_xHierarchyAccess.clear(); + m_xDirectAccess.clear(); + m_xReplaceAccess.clear(); + m_xContainerAccess.clear(); + } + + //======================================================================== + //= helper + //======================================================================== + namespace { - OSL_ENSURE(m_xHierarchyAccess.is(), "OConfigurationNode::cloneAsRoot: object is invalid!"); - if (m_xHierarchyAccess.is()) + //-------------------------------------------------------------------- + static const ::rtl::OUString& lcl_getProviderServiceName( ) { - // first get the complete path of the node we represent - ::rtl::OUString sCompletePath; - Reference< XHierarchicalName > xNodeNameAccess(m_xHierarchyAccess, UNO_QUERY); - if (xNodeNameAccess.is()) + static ::rtl::OUString s_sProviderServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ); + return s_sProviderServiceName; + } + + //-------------------------------------------------------------------- + Reference< XMultiServiceFactory > lcl_getConfigProvider( const ::comphelper::ComponentContext& i_rContext ) + { + try { - try - { - sCompletePath = xNodeNameAccess->getHierarchicalName(); - OSL_ENSURE(sCompletePath.getLength(), "OConfigurationNode::cloneAsRoot: invalid path retrieved!"); - } - catch(Exception&) - { - DBG_UNHANDLED_EXCEPTION(); - } + Reference< XMultiServiceFactory > xProvider( i_rContext.createComponent( lcl_getProviderServiceName() ), UNO_QUERY_THROW ); + return xProvider; } - - // then create a new tree root object with that path and our provider - OSL_ENSURE(m_xProvider.is(), "OConfigurationNode::cloneAsRoot: have an invalid provider!"); - if (sCompletePath.getLength() && m_xProvider.is()) + catch ( const Exception& ) { - return OConfigurationTreeRoot::createWithProvider(m_xProvider, sCompletePath, -1, isReadonly() ? OConfigurationTreeRoot::CM_READONLY : OConfigurationTreeRoot::CM_PREFER_UPDATABLE); + DBG_UNHANDLED_EXCEPTION(); } + return NULL; } - return OConfigurationTreeRoot(); - } - //------------------------------------------------------------------------ - void OConfigurationNode::clear() throw() - { - m_xHierarchyAccess.clear(); - m_xDirectAccess.clear(); - m_xReplaceAccess.clear(); - m_xContainerAccess.clear(); + //-------------------------------------------------------------------- + Reference< XInterface > lcl_createConfigurationRoot( const Reference< XMultiServiceFactory >& i_rxConfigProvider, + const ::rtl::OUString& i_rNodePath, const bool i_bUpdatable, const sal_Int32 i_nDepth, const bool i_bLazyWrite ) + { + ENSURE_OR_RETURN( i_rxConfigProvider.is(), "invalid provider", NULL ); + try + { + ::comphelper::NamedValueCollection aArgs; + aArgs.put( "nodepath", i_rNodePath ); + aArgs.put( "lazywrite", i_bLazyWrite ); + aArgs.put( "depth", i_nDepth ); + + ::rtl::OUString sAccessService = ::rtl::OUString::createFromAscii( + i_bUpdatable + ? "com.sun.star.configuration.ConfigurationUpdateAccess" + : "com.sun.star.configuration.ConfigurationAccess" ); + + Reference< XInterface > xRoot( + i_rxConfigProvider->createInstanceWithArguments( sAccessService, aArgs.getWrappedPropertyValues() ), + UNO_SET_THROW + ); + return xRoot; + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return NULL; + } } - //======================================================================== //= OConfigurationTreeRoot //======================================================================== //------------------------------------------------------------------------ - OConfigurationTreeRoot::OConfigurationTreeRoot(const Reference< XChangesBatch >& _rxRootNode, const Reference< XMultiServiceFactory >& _rxProvider) - :OConfigurationNode(_rxRootNode.get(), _rxProvider) + OConfigurationTreeRoot::OConfigurationTreeRoot( const Reference< XChangesBatch >& _rxRootNode ) + :OConfigurationNode( _rxRootNode.get() ) ,m_xCommitter(_rxRootNode) { } //------------------------------------------------------------------------ - OConfigurationTreeRoot::OConfigurationTreeRoot(const Reference< XInterface >& _rxRootNode, const Reference< XMultiServiceFactory >& _rxProvider) - :OConfigurationNode(_rxRootNode.get(), _rxProvider) + OConfigurationTreeRoot::OConfigurationTreeRoot( const Reference< XInterface >& _rxRootNode ) + :OConfigurationNode( _rxRootNode ) + ,m_xCommitter( _rxRootNode, UNO_QUERY ) { } //------------------------------------------------------------------------ + OConfigurationTreeRoot::OConfigurationTreeRoot( const ::comphelper::ComponentContext& i_rContext, const sal_Char* i_pAsciiNodePath, const bool i_bUpdatable ) + :OConfigurationNode( lcl_createConfigurationRoot( lcl_getConfigProvider( i_rContext.getLegacyServiceFactory() ), + ::rtl::OUString::createFromAscii( i_pAsciiNodePath ), i_bUpdatable, -1, false ).get() ) + ,m_xCommitter() + { + if ( i_bUpdatable ) + { + m_xCommitter.set( getUNONode(), UNO_QUERY ); + OSL_ENSURE( m_xCommitter.is(), "OConfigurationTreeRoot::OConfigurationTreeRoot: could not create an updatable node!" ); + } + } + + //------------------------------------------------------------------------ void OConfigurationTreeRoot::clear() throw() { OConfigurationNode::clear(); @@ -555,117 +593,20 @@ namespace utl return sal_False; } - namespace - { - static const ::rtl::OUString& lcl_getProviderServiceName( ) - { - static ::rtl::OUString s_sProviderServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ); - return s_sProviderServiceName; - } - } - //------------------------------------------------------------------------ OConfigurationTreeRoot OConfigurationTreeRoot::createWithProvider(const Reference< XMultiServiceFactory >& _rxConfProvider, const ::rtl::OUString& _rPath, sal_Int32 _nDepth, CREATION_MODE _eMode, sal_Bool _bLazyWrite) { - OSL_ENSURE(_rxConfProvider.is(), "OConfigurationTreeRoot::createWithProvider: invalid provider!"); - -#ifdef DBG_UTIL - if (_rxConfProvider.is()) - { - try - { - Reference< XServiceInfo > xSI(_rxConfProvider, UNO_QUERY); - if (!xSI.is()) - { - OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithProvider: no XServiceInfo interface on the provider!"); - } - else - { - OSL_ENSURE(xSI->supportsService( lcl_getProviderServiceName( ) ), - "OConfigurationTreeRoot::createWithProvider: sure this is a provider? Missing the ConfigurationProvider service!"); - } - } - catch(const Exception&) - { - DBG_UNHANDLED_EXCEPTION(); - } - } -#endif - - sal_Bool bTryAgain(sal_False); - do - { - if (_rxConfProvider.is()) - { - try - { - Sequence< Any > aCreationArgs(3); - aCreationArgs[0] = makeAny(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")), 0, makeAny(_rPath), PropertyState_DIRECT_VALUE)); - aCreationArgs[1] = makeAny(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("depth")), 0, makeAny((sal_Int32)_nDepth), PropertyState_DIRECT_VALUE)); - aCreationArgs[2] = makeAny(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("lazywrite")), 0, ::cppu::bool2any(_bLazyWrite), PropertyState_DIRECT_VALUE)); - - ::rtl::OUString sAccessService = ::rtl::OUString::createFromAscii(CM_READONLY == _eMode - ? "com.sun.star.configuration.ConfigurationAccess" - : "com.sun.star.configuration.ConfigurationUpdateAccess"); - - Reference< XInterface > xRoot = _rxConfProvider->createInstanceWithArguments(sAccessService, aCreationArgs); - if (!xRoot.is()) - { - OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithProvider: could not create the node access!"); - } - else if (CM_READONLY == _eMode) - { - return OConfigurationTreeRoot(xRoot, _rxConfProvider); - } - else - { // get the changes batch interface - Reference< XChangesBatch > xCommitter(xRoot, UNO_QUERY); - if (xCommitter.is()) - return OConfigurationTreeRoot(xCommitter, _rxConfProvider); - else - OSL_ENSURE(sal_False, "OConfigurationTreeRoot::createWithProvider: invalid root object (missing interface XChangesBatch)!"); - - // dispose the object if it is already created, but unusable - Reference< XComponent > xComp(xRoot, UNO_QUERY); - if (xComp.is()) - try { xComp->dispose(); } catch(Exception&) { } - } - } - catch(const Exception&) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - bTryAgain = CM_PREFER_UPDATABLE == _eMode; - if (bTryAgain) - _eMode = CM_READONLY; - } - while (bTryAgain); - + Reference< XInterface > xRoot( lcl_createConfigurationRoot( + _rxConfProvider, _rPath, _eMode != CM_READONLY, _nDepth, _bLazyWrite ) ); + if ( xRoot.is() ) + return OConfigurationTreeRoot( xRoot ); return OConfigurationTreeRoot(); } //------------------------------------------------------------------------ - OConfigurationTreeRoot OConfigurationTreeRoot::createWithServiceFactory(const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rPath, sal_Int32 _nDepth, CREATION_MODE _eMode, sal_Bool _bLazyWrite) + OConfigurationTreeRoot OConfigurationTreeRoot::createWithServiceFactory( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rPath, sal_Int32 _nDepth, CREATION_MODE _eMode, sal_Bool _bLazyWrite ) { - OSL_ENSURE(_rxORB.is(), "OConfigurationTreeRoot::createWithServiceFactory: invalid service factory!"); - if (_rxORB.is()) - { - try - { - Reference< XInterface > xProvider = _rxORB->createInstance( lcl_getProviderServiceName( ) ); - OSL_ENSURE(xProvider.is(), "OConfigurationTreeRoot::createWithServiceFactory: could not instantiate the config provider service!"); - Reference< XMultiServiceFactory > xProviderAsFac(xProvider, UNO_QUERY); - OSL_ENSURE(xProviderAsFac.is() || !xProvider.is(), "OConfigurationTreeRoot::createWithServiceFactory: the provider is missing an interface!"); - if (xProviderAsFac.is()) - return createWithProvider(xProviderAsFac, _rPath, _nDepth, _eMode, _bLazyWrite); - } - catch(const Exception&) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - return OConfigurationTreeRoot(); + return createWithProvider( lcl_getConfigProvider( _rxORB ), _rPath, _nDepth, _eMode, _bLazyWrite ); } //------------------------------------------------------------------------ @@ -681,9 +622,9 @@ namespace utl if ( xConfigFactory.is() ) return createWithProvider( xConfigFactory, _rPath, _nDepth, _eMode, _bLazyWrite ); } - catch(Exception&) + catch(const Exception&) { - // silent this, 'cause the contract of this method states "no assertions" + // silence this, 'cause the contract of this method states "no assertions" } } return OConfigurationTreeRoot(); diff --git a/unotools/source/config/configvaluecontainer.cxx b/unotools/source/config/configvaluecontainer.cxx index c04f29428bf5..653305f92f74 100644 --- a/unotools/source/config/configvaluecontainer.cxx +++ b/unotools/source/config/configvaluecontainer.cxx @@ -331,7 +331,7 @@ namespace utl m_pImpl->xORB, _rConfigLocation, _nLevels, - ( _nAccessFlags & CVC_UPDATE_ACCESS ) ? OConfigurationTreeRoot::CM_PREFER_UPDATABLE : OConfigurationTreeRoot::CM_READONLY, + ( _nAccessFlags & CVC_UPDATE_ACCESS ) ? OConfigurationTreeRoot::CM_UPDATABLE : OConfigurationTreeRoot::CM_READONLY, ( _nAccessFlags & CVC_IMMEDIATE_UPDATE ) ? sal_False : sal_True ); #ifdef DBG_UTIL |