2000-11-10 21:42:54 +00:00
/*************************************************************************
*
* $ RCSfile : providerimpl . cxx , v $
*
2001-02-01 14:49:36 +00:00
* $ Revision : 1.22 $
2000-11-10 21:42:54 +00:00
*
2001-02-01 14:49:36 +00:00
* last change : $ Author : lla $ $ Date : 2001 - 02 - 01 15 : 49 : 36 $
2000-11-10 21:42:54 +00:00
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc . , October , 2000
*
* GNU Lesser General Public License Version 2.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* Copyright 2000 by Sun Microsystems , Inc .
* 901 San Antonio Road , Palo Alto , CA 94303 , USA
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 , as published by the Free Software Foundation .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston ,
* MA 02111 - 1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 ( the " License " ) ; You may not use this file
* except in compliance with the License . You may obtain a copy of the
* License at http : //www.openoffice.org/license.html.
*
* Software provided under this License is provided on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , EITHER EXPRESSED OR IMPLIED , INCLUDING ,
* WITHOUT LIMITATION , WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS ,
* MERCHANTABLE , FIT FOR A PARTICULAR PURPOSE , OR NON - INFRINGING .
* See the License for the specific provisions governing your rights and
* obligations concerning the Software .
*
* The Initial Developer of the Original Code is : Sun Microsystems , Inc .
*
* Copyright : 2000 by Sun Microsystems , Inc .
*
* All Rights Reserved .
*
* Contributor ( s ) : _______________________________________
*
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <stdio.h>
2000-12-19 10:14:08 +00:00
# include "providerimpl.hxx"
# include "options.hxx"
2000-11-10 21:42:54 +00:00
# include "apifactoryimpl.hxx"
# include "apitreeimplobj.hxx"
# include "apitreeaccess.hxx"
# include "roottree.hxx"
# include "noderef.hxx"
# include "objectregistry.hxx"
2000-12-03 10:45:59 +00:00
# ifndef CONFIGMGR_BOOTSTRAP_HXX_
# include "bootstrap.hxx"
# endif
2000-11-10 21:42:54 +00:00
# ifndef CONFIGMGR_API_PROVIDER_HXX_
# include "provider.hxx"
# endif
# ifndef CONFIGMGR_MODULE_HXX_
# include "configmodule.hxx"
# endif
# ifndef _CONFIGMGR_TREECACHE_HXX_
# include "treecache.hxx"
# endif
# ifndef _CONFIGMGR_TRACER_HXX_
# include "tracer.hxx"
# endif
2000-12-19 10:14:08 +00:00
# include <osl/interlck.h>
2000-11-10 21:42:54 +00:00
# ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
# include <com/sun/star/beans/PropertyValue.hpp>
# endif
2000-11-30 07:54:09 +00:00
static : : rtl : : OUString ssUserProfile ( RTL_CONSTASCII_USTRINGPARAM ( " org.openoffice.UserProfile " ) ) ;
static : : rtl : : OUString ssDefaultLocale ( RTL_CONSTASCII_USTRINGPARAM ( " en-US " ) ) ;
static : : rtl : : OUString ssInternational ( RTL_CONSTASCII_USTRINGPARAM ( " International " ) ) ;
static : : rtl : : OUString ssLocale ( RTL_CONSTASCII_USTRINGPARAM ( " Locale " ) ) ;
2000-11-10 21:42:54 +00:00
namespace configmgr
{
namespace css = : : com : : sun : : star ;
namespace uno = css : : uno ;
namespace beans = css : : beans ;
using : : rtl : : OUString ;
using configapi : : NodeElement ;
using configuration : : RootTree ;
2000-11-20 00:30:48 +00:00
using configuration : : TemplateProvider ;
2000-11-10 21:42:54 +00:00
namespace configapi
{
2000-11-20 00:30:48 +00:00
2000-11-10 21:42:54 +00:00
class ApiProviderInstances
{
ObjectRegistryHolder m_aObjectRegistry ;
ReadOnlyObjectFactory m_aReaderFactory ;
UpdateObjectFactory m_aWriterFactory ;
ApiProvider m_aReaderProvider ;
ApiProvider m_aWriterProvider ;
2000-11-20 00:30:48 +00:00
TemplateProvider m_aTemplateProvider ;
2000-11-10 21:42:54 +00:00
public :
2000-11-20 00:30:48 +00:00
ApiProviderInstances ( OProviderImpl & rProviderImpl , ITemplateProvider & rTemplateProvider )
2000-11-10 21:42:54 +00:00
: m_aObjectRegistry ( new ObjectRegistry ( ) )
, m_aReaderFactory ( m_aReaderProvider , m_aObjectRegistry )
, m_aWriterFactory ( m_aWriterProvider , m_aObjectRegistry )
, m_aReaderProvider ( m_aReaderFactory , rProviderImpl )
, m_aWriterProvider ( m_aWriterFactory , rProviderImpl )
2000-11-20 00:30:48 +00:00
, m_aTemplateProvider ( rTemplateProvider )
2000-11-10 21:42:54 +00:00
{
}
~ ApiProviderInstances ( )
{ }
ApiProvider & getReaderProvider ( ) { return m_aReaderProvider ; }
ApiProvider & getWriterProvider ( ) { return m_aWriterProvider ; }
Factory & getReaderFactory ( ) { return m_aReaderFactory ; }
Factory & getWriterFactory ( ) { return m_aWriterFactory ; }
2000-11-20 00:30:48 +00:00
TemplateProvider & getTemplateProvider ( ) { return m_aTemplateProvider ; }
2000-11-10 21:42:54 +00:00
} ;
}
//=============================================================================
//= OProviderImpl
//=============================================================================
//-----------------------------------------------------------------------------
OProviderImpl : : OProviderImpl ( OProvider * _pProvider ,
IConfigSession * _pSession ,
2000-12-03 10:45:59 +00:00
Module & _rModule , const ConnectionSettings & _rSettings )
2000-11-30 07:54:09 +00:00
: m_xDefaultOptions ( new OOptions ( _rModule . getConverter ( ) ) )
2000-11-20 00:30:48 +00:00
, m_pNewProviders ( 0 )
2000-11-10 21:42:54 +00:00
, m_pProvider ( _pProvider )
{
2001-01-29 07:47:27 +00:00
// this is a hack asking the session if caching should be supported or not
// at the time we have complete notification support this hack isn't necessary anymore
if ( ! _pSession - > allowsCachingHack ( ) )
m_xDefaultOptions - > setNoCache ( sal_True ) ;
2000-12-04 18:34:56 +00:00
m_pTreeMgr = new TreeManager ( _pSession , new OOptions ( _rModule . getConverter ( ) ) ) ;
2000-11-30 07:54:09 +00:00
m_pTreeMgr - > acquire ( ) ;
2000-11-20 00:30:48 +00:00
// put out of line to get rid of the order dependency (and to have a acquired configuration)
2000-11-30 07:54:09 +00:00
m_pNewProviders = new configapi : : ApiProviderInstances ( * this , * m_pTreeMgr ) ;
// read the default locale for the user
rtl : : OUString sDefaultLocale ( ssDefaultLocale ) ;
2000-12-04 18:34:56 +00:00
rtl : : OUString sDefaultUser ;
2000-11-30 07:54:09 +00:00
try
{
2000-12-03 10:45:59 +00:00
// if we have a user name, we have to add it for the request and we remember it for the session
if ( _rSettings . hasUser ( ) )
{
// the username is also part of the connection settings
2000-12-04 18:34:56 +00:00
sDefaultUser = _rSettings . getUser ( ) ;
2000-12-03 10:45:59 +00:00
}
2000-12-04 18:34:56 +00:00
ISubtree * pSubTree = m_pTreeMgr - > requestSubtree ( ssUserProfile , m_xDefaultOptions ) ;
2000-11-30 07:54:09 +00:00
if ( pSubTree )
{
INode * pNode = pSubTree - > getChild ( ssInternational ) ;
pSubTree = pNode ? pNode - > asISubtree ( ) : NULL ;
if ( pSubTree )
{
pNode = pSubTree - > getChild ( ssLocale ) ;
ValueNode * pValueNode = pNode ? pNode - > asValueNode ( ) : NULL ;
if ( pValueNode )
pValueNode - > getValue ( ) > > = sDefaultLocale ;
}
2000-12-19 16:35:00 +00:00
// should we clean this up ?
// m_pTreeMgr->releaseSubtree(ssUserProfile, m_xDefaultOptions);
2000-11-30 07:54:09 +00:00
}
}
2001-01-17 14:02:34 +00:00
catch ( uno : : Exception & )
2000-11-30 07:54:09 +00:00
{
// could not read default locale
// default locale is en-US
}
m_xDefaultOptions - > setDefaultLocale ( sDefaultLocale ) ;
2000-12-04 18:34:56 +00:00
m_xDefaultOptions - > setDefaultUser ( sDefaultUser ) ;
2001-01-26 06:54:22 +00:00
2001-02-01 14:49:36 +00:00
OProviderImplDisposingListener * pListener = new OProviderImplDisposingListener ( this ) ;
2001-01-26 06:54:22 +00:00
m_xEventListener = pListener ;
uno : : Reference < com : : sun : : star : : lang : : XComponent > xComponent ( _rModule . getServiceManager ( ) , uno : : UNO_QUERY ) ;
2001-02-01 14:49:36 +00:00
m_xComponent = xComponent ;
2001-01-26 06:54:22 +00:00
if ( xComponent . is ( ) )
{
xComponent - > addEventListener ( m_xEventListener ) ;
// CFG_TRACE_INFO("insert disposeListener.");
}
2000-11-10 21:42:54 +00:00
}
//-----------------------------------------------------------------------------
OProviderImpl : : ~ OProviderImpl ( )
{
delete m_pNewProviders ;
2000-11-30 07:54:09 +00:00
m_pTreeMgr - > release ( ) ;
m_pTreeMgr = NULL ;
2001-02-01 14:49:36 +00:00
// Second fall, Providerimpl will be destroyed befor ServiceMgr send disposing
if ( m_xEventListener . is ( ) & & m_xComponent . is ( ) )
{
m_xComponent - > removeEventListener ( m_xEventListener ) ;
}
2000-11-10 21:42:54 +00:00
}
2001-01-26 06:54:22 +00:00
// --------------------------------- disposing ---------------------------------
void SAL_CALL OProviderImpl : : disposing ( com : : sun : : star : : lang : : EventObject const & rEvt ) throw ( )
{
// stop lasy writing
2001-02-01 14:49:36 +00:00
if ( m_pTreeMgr )
{
m_pTreeMgr - > disableAsync ( ) ;
// first fall, ServiceMgr send disposing
// if (m_xComponent.is())
// {
// m_xComponent->removeEventListener(m_xEventListener);
// }
m_xComponent = NULL ;
m_xEventListener = NULL ;
}
2001-01-26 06:54:22 +00:00
}
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------
// access to the factory for writable elements
configapi : : Factory & OProviderImpl : : getWriterFactory ( ) { return m_pNewProviders - > getWriterFactory ( ) ; }
2000-12-04 08:20:27 +00:00
//-----------------------------------------------------------------------------
// access to the raw notifications
IConfigBroadcaster * OProviderImpl : : getNotifier ( ) { OSL_ASSERT ( m_pTreeMgr ) ; return m_pTreeMgr - > getBroadcaster ( ) ; }
2000-11-20 00:30:48 +00:00
// TemplateProvider access
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------
2000-11-20 00:30:48 +00:00
TemplateProvider OProviderImpl : : getTemplateProvider ( ) const
2000-11-10 21:42:54 +00:00
{
2000-11-20 00:30:48 +00:00
return m_pNewProviders - > getTemplateProvider ( ) ;
2000-11-10 21:42:54 +00:00
}
2000-12-04 08:20:27 +00:00
// ITreeProvider /ITreeManager
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------
2000-11-30 07:54:09 +00:00
ISubtree * OProviderImpl : : requestSubtree ( OUString const & aSubtreePath , const vos : : ORef < OOptions > & _xOptions ,
2001-01-17 14:02:34 +00:00
sal_Int16 nMinLevels ) throw ( uno : : Exception )
2000-11-10 21:42:54 +00:00
{
2000-11-30 07:54:09 +00:00
return m_pTreeMgr - > requestSubtree ( aSubtreePath , _xOptions , nMinLevels ) ;
2000-11-10 21:42:54 +00:00
}
//-----------------------------------------------------------------------------
2001-01-18 13:54:04 +00:00
void OProviderImpl : : updateTree ( TreeChangeList & aChanges ) throw ( uno : : Exception )
2000-12-04 08:20:27 +00:00
{
m_pTreeMgr - > updateTree ( aChanges ) ;
}
//-----------------------------------------------------------------------------
void OProviderImpl : : releaseSubtree ( OUString const & aSubtreePath , const vos : : ORef < OOptions > & _xOptions ) throw ( )
2000-11-10 21:42:54 +00:00
{
2000-12-04 08:20:27 +00:00
m_pTreeMgr - > releaseSubtree ( aSubtreePath , _xOptions ) ;
2000-11-10 21:42:54 +00:00
}
2000-12-14 15:12:44 +00:00
//-----------------------------------------------------------------------------
void OProviderImpl : : disposeData ( const vos : : ORef < OOptions > & _xOptions ) throw ( )
{
m_pTreeMgr - > disposeData ( _xOptions ) ;
}
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------
2000-12-04 08:20:27 +00:00
void OProviderImpl : : notifyUpdate ( TreeChangeList const & aChanges ) throw ( uno : : RuntimeException )
2000-11-10 21:42:54 +00:00
{
2000-11-30 07:54:09 +00:00
m_pTreeMgr - > notifyUpdate ( aChanges ) ;
2000-11-10 21:42:54 +00:00
}
2000-12-04 08:20:27 +00:00
// IInterface
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------
void SAL_CALL OProviderImpl : : acquire ( ) throw ( )
{
m_pProvider - > acquire ( ) ;
}
//-----------------------------------------------------------------------------
void SAL_CALL OProviderImpl : : release ( ) throw ( )
{
m_pProvider - > release ( ) ;
}
//-----------------------------------------------------------------------------
uno : : XInterface * OProviderImpl : : getProviderInstance ( )
{
return static_cast < com : : sun : : star : : lang : : XMultiServiceFactory * > ( m_pProvider ) ;
}
//-----------------------------------------------------------------------------
ISynchronizedData & OProviderImpl : : getTreeLock ( )
{
2000-11-30 07:54:09 +00:00
return * m_pTreeMgr ;
2000-11-10 21:42:54 +00:00
}
//-----------------------------------------------------------------------------
ISynchronizedData const & OProviderImpl : : getTreeLock ( ) const
{
2000-11-30 07:54:09 +00:00
return * m_pTreeMgr ;
2000-11-10 21:42:54 +00:00
}
// ISyncronizedData
//-----------------------------------------------------------------------------
void OProviderImpl : : acquireReadAccess ( ) const
{
getTreeLock ( ) . acquireReadAccess ( ) ;
}
//-----------------------------------------------------------------------------
void OProviderImpl : : releaseReadAccess ( ) const
{
getTreeLock ( ) . releaseReadAccess ( ) ;
}
//-----------------------------------------------------------------------------
void OProviderImpl : : acquireWriteAccess ( )
{
getTreeLock ( ) . acquireWriteAccess ( ) ;
}
//-----------------------------------------------------------------------------
void OProviderImpl : : releaseWriteAccess ( )
{
getTreeLock ( ) . releaseWriteAccess ( ) ;
}
//-----------------------------------------------------------------------------------
OUString OProviderImpl : : getBasePath ( OUString const & _rAccessor )
{
sal_Int32 nNameStart = _rAccessor . lastIndexOf ( ConfigurationName : : delimiter ) ;
if ( nNameStart = = ( _rAccessor . getLength ( ) - 1 ) )
nNameStart = _rAccessor . lastIndexOf ( ConfigurationName : : delimiter , nNameStart ) ;
return nNameStart > 0 ? _rAccessor . copy ( 0 , nNameStart ) : ConfigurationName : : rootname ( ) ;
}
2000-11-30 07:54:09 +00:00
//-----------------------------------------------------------------------------------
2000-12-04 18:34:56 +00:00
OUString OProviderImpl : : getErrorMessage ( OUString const & _rAccessor , const vos : : ORef < OOptions > & _xOptions )
2000-11-30 07:54:09 +00:00
{
CFG_TRACE_ERROR ( " config provider: the cache manager could not provide the tree (neither from the cache nor from the session) " ) ;
2000-12-04 18:34:56 +00:00
: : rtl : : OUString sMessage ;
: : rtl : : OUString sUser ( _xOptions - > getUser ( ) ) ;
: : rtl : : OUString sLocale ( _xOptions - > getLocale ( ) ) ;
CFG_TRACE_INFO_NI ( " config provider: the user we tried this for is \" %s \" , the locale \" %s \" , the path \" %s \" " , OUSTRING2ASCII ( sUser ) , OUSTRING2ASCII ( sLocale ) , OUSTRING2ASCII ( _rAccessor ) ) ;
sMessage + = _rAccessor ;
2000-11-30 07:54:09 +00:00
if ( sUser . getLength ( ) )
{
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " (and for user " ) ) ;
sMessage + = sUser ;
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ) " ) ) ;
}
if ( sLocale . getLength ( ) )
{
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " (and for locale " ) ) ;
sMessage + = sLocale ;
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ) " ) ) ;
}
sMessage + = : : rtl : : OUString : : createFromAscii ( " could not be created. Unable to retrieve the node from the configuration server. " ) ;
return sMessage ;
}
2000-11-10 21:42:54 +00:00
// actual factory methods
//-----------------------------------------------------------------------------------
2000-11-30 07:54:09 +00:00
NodeElement * OProviderImpl : : buildReadAccess ( OUString const & _rAccessor , const vos : : ORef < OOptions > & _xOptions , sal_Int32 nMinLevels ) throw ( uno : : Exception , uno : : RuntimeException )
2000-11-10 21:42:54 +00:00
{
CFG_TRACE_INFO ( " config provider: requesting the tree from the cache manager " ) ;
ISubtree * pTree = NULL ;
: : rtl : : OUString sErrorMessage ;
try
{
2000-11-20 00:30:48 +00:00
OSL_ASSERT ( sal_Int16 ( nMinLevels ) = = nMinLevels ) ;
2000-11-30 07:54:09 +00:00
pTree = requestSubtree ( _rAccessor , _xOptions , sal_Int16 ( nMinLevels ) ) ;
2000-11-10 21:42:54 +00:00
}
2001-01-17 14:02:34 +00:00
catch ( uno : : Exception & e )
2000-11-10 21:42:54 +00:00
{
sErrorMessage = e . Message ;
}
if ( ! pTree )
{
2000-12-04 18:34:56 +00:00
: : rtl : : OUString sMessage = getErrorMessage ( _rAccessor , _xOptions ) ;
2000-11-10 21:42:54 +00:00
// append the error message given by the tree provider
if ( sErrorMessage . getLength ( ) )
{
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " \n \n The server returned the following error: \n " ) ) ;
sMessage + = sErrorMessage ;
}
throw uno : : Exception ( sMessage , getProviderInstance ( ) ) ;
}
using namespace configuration ;
2000-11-14 09:53:36 +00:00
TreeDepth nDepth = ( nMinLevels = = ALL_LEVELS ) ? C_TreeDepthAll : TreeDepth ( nMinLevels ) ;
2000-11-10 21:42:54 +00:00
RootTree aRootTree ( createReadOnlyTree (
AbsolutePath ( getBasePath ( _rAccessor ) , Path : : NoValidate ( ) ) ,
2000-11-20 00:30:48 +00:00
* pTree , nDepth , getTemplateProvider ( )
2000-11-10 21:42:54 +00:00
) ) ;
2000-11-30 07:54:09 +00:00
return m_pNewProviders - > getReaderFactory ( ) . makeAccessRoot ( aRootTree , _xOptions ) ;
2000-11-10 21:42:54 +00:00
}
//-----------------------------------------------------------------------------------
2000-11-30 07:54:09 +00:00
NodeElement * OProviderImpl : : buildUpdateAccess ( OUString const & _rAccessor , const vos : : ORef < OOptions > & _xOptions ,
sal_Int32 nMinLevels ) throw ( uno : : Exception , uno : : RuntimeException )
2000-11-10 21:42:54 +00:00
{
CFG_TRACE_INFO ( " config provider: requesting the tree from the cache manager " ) ;
ISubtree * pTree = NULL ;
: : rtl : : OUString sErrorMessage ;
try
{
2000-11-20 00:30:48 +00:00
OSL_ASSERT ( sal_Int16 ( nMinLevels ) = = nMinLevels ) ;
2000-11-30 07:54:09 +00:00
pTree = requestSubtree ( _rAccessor , _xOptions , sal_Int16 ( nMinLevels ) ) ;
2000-11-10 21:42:54 +00:00
}
2001-01-17 14:02:34 +00:00
catch ( uno : : Exception & e )
2000-11-10 21:42:54 +00:00
{
sErrorMessage = e . Message ;
}
if ( ! pTree )
{
2000-12-04 18:34:56 +00:00
: : rtl : : OUString sMessage = getErrorMessage ( _rAccessor , _xOptions ) ;
2000-11-10 21:42:54 +00:00
// append the error message given by the tree provider
if ( sErrorMessage . getLength ( ) )
{
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " \n \n The server returned the following error: \n " ) ) ;
sMessage + = sErrorMessage ;
}
throw uno : : Exception ( sMessage , getProviderInstance ( ) ) ;
}
//ConfigurationName aPathToUpdateRoot(getBasePath(_rAccessor), ConfigurationName::Absolute());
using namespace configuration ;
2000-11-14 09:53:36 +00:00
TreeDepth nDepth = ( nMinLevels = = ALL_LEVELS ) ? C_TreeDepthAll : TreeDepth ( nMinLevels ) ;
2000-11-10 21:42:54 +00:00
RootTree aRootTree ( createUpdatableTree (
AbsolutePath ( getBasePath ( _rAccessor ) , Path : : NoValidate ( ) ) ,
2000-11-20 00:30:48 +00:00
* pTree , nDepth , getTemplateProvider ( )
2000-11-10 21:42:54 +00:00
) ) ;
2000-11-30 07:54:09 +00:00
return m_pNewProviders - > getWriterFactory ( ) . makeAccessRoot ( aRootTree , _xOptions ) ;
2000-11-10 21:42:54 +00:00
}
//=============================================================================
//= OProvider::FactoryArguments
//=============================================================================
rtl : : OUString OProviderImpl : : FactoryArguments : : sUser ( ASCII ( " user " ) ) ;
rtl : : OUString OProviderImpl : : FactoryArguments : : sNodePath ( ASCII ( " nodepath " ) ) ;
rtl : : OUString OProviderImpl : : FactoryArguments : : sDepth ( ASCII ( " depth " ) ) ;
rtl : : OUString OProviderImpl : : FactoryArguments : : sLocale ( ASCII ( " locale " ) ) ;
2000-12-19 10:14:08 +00:00
rtl : : OUString OProviderImpl : : FactoryArguments : : sNoCache ( ASCII ( " nocache " ) ) ;
2001-01-26 14:01:57 +00:00
rtl : : OUString OProviderImpl : : FactoryArguments : : sLazyWrite ( ASCII ( " lazywrite " ) ) ;
2000-11-10 21:42:54 +00:00
# ifdef DBG_UTIL
//-----------------------------------------------------------------------------
bool lookup ( const rtl : : OUString & rName )
{
// allowed arguments
static HashSet aArgs ;
if ( aArgs . empty ( ) )
{
aArgs . insert ( OProviderImpl : : FactoryArguments : : sUser ) ;
aArgs . insert ( OProviderImpl : : FactoryArguments : : sNodePath ) ;
aArgs . insert ( OProviderImpl : : FactoryArguments : : sDepth ) ;
aArgs . insert ( OProviderImpl : : FactoryArguments : : sLocale ) ;
2000-12-19 10:14:08 +00:00
aArgs . insert ( OProviderImpl : : FactoryArguments : : sNoCache ) ;
2001-01-26 14:01:57 +00:00
aArgs . insert ( OProviderImpl : : FactoryArguments : : sLazyWrite ) ;
2000-11-10 21:42:54 +00:00
}
HashSet : : const_iterator it = aArgs . find ( rName ) ;
return it ! = aArgs . end ( ) ? true : false ;
}
//-----------------------------------------------------------------------------
bool checkArgs ( const uno : : Sequence < uno : : Any > & _rArgs ) throw ( lang : : IllegalArgumentException )
{
// PRE: a Sequence with some possible arguments
beans : : PropertyValue aCurrent ;
const uno : : Any * pCurrent = _rArgs . getConstArray ( ) ;
bool bParamOk = false ;
for ( sal_Int32 i = 0 ; i < _rArgs . getLength ( ) ; + + i , + + pCurrent )
{
if ( * pCurrent > > = aCurrent )
{
if ( ! lookup ( aCurrent . Name ) )
{
rtl : : OString aStr = " The argument ' " ;
aStr + = rtl : : OUStringToOString ( aCurrent . Name , RTL_TEXTENCODING_ASCII_US ) . getStr ( ) ;
aStr + = " ' could not be extracted. " ;
OSL_ENSHURE ( false , aStr . getStr ( ) ) ;
}
}
2000-11-13 13:37:07 +00:00
else if ( i > 0 | | pCurrent - > getValueTypeClass ( ) ! = uno : : TypeClass_STRING )
2000-11-10 21:42:54 +00:00
{
OSL_ENSHURE ( false , " operator >>= failed. " ) ;
}
2000-11-13 13:37:07 +00:00
else
{
2000-12-13 11:22:22 +00:00
OSL_ENSHURE ( _rArgs . getLength ( ) < = 2 , " Too many arguments for legacy parameters. " ) ;
2000-11-13 13:37:07 +00:00
break ;
}
2000-11-10 21:42:54 +00:00
}
return true ;
}
# endif
//-----------------------------------------------------------------------------------
void OProviderImpl : : FactoryArguments : : extractArgs ( const uno : : Sequence < uno : : Any > & _rArgs ,
2000-11-29 12:59:56 +00:00
OUString & /* [out] */ _rNodeAccessor ,
OUString & /* [out] */ _rUser ,
OUString & /* [out] */ _rLocale ,
2000-12-19 10:14:08 +00:00
sal_Int32 & /* [out] */ _nLevels ,
2001-01-26 06:54:22 +00:00
bool & /* [out] */ _bNoCache ,
2001-01-26 14:01:57 +00:00
bool & /* [out] */ _bLazyWrite )
2000-11-10 21:42:54 +00:00
throw ( lang : : IllegalArgumentException )
{
# ifdef DBG_UTIL
checkArgs ( _rArgs ) ;
# endif
: : rtl : : OUString sUser , sPath , sLocale ;
sal_Int32 nLevelDepth = ITreeProvider : : ALL_LEVELS ;
2000-12-19 10:14:08 +00:00
sal_Bool bNoCache = sal_False ;
2001-01-26 14:01:57 +00:00
sal_Bool bLazyWrite = sal_False ;
2000-11-10 21:42:54 +00:00
// the args have to be a sequence of property values, currently three property names are recognized
beans : : PropertyValue aCurrent ;
sal_Bool bAnyPropValue = sal_False ;
const uno : : Any * pCurrent = _rArgs . getConstArray ( ) ;
for ( sal_Int32 i = 0 ; i < _rArgs . getLength ( ) ; + + i , + + pCurrent )
{
if ( * pCurrent > > = aCurrent )
{
sal_Bool bExtractSuccess = sal_True ; // defaulted to TRUE, so we skip unknown arguments
if ( aCurrent . Name . equalsIgnoreCase ( OProviderImpl : : FactoryArguments : : sNodePath ) )
bExtractSuccess = ( aCurrent . Value > > = sPath ) ;
else if ( aCurrent . Name . equalsIgnoreCase ( OProviderImpl : : FactoryArguments : : sUser ) )
bExtractSuccess = ( aCurrent . Value > > = sUser ) ;
else if ( aCurrent . Name . equalsIgnoreCase ( OProviderImpl : : FactoryArguments : : sDepth ) )
bExtractSuccess = ( aCurrent . Value > > = nLevelDepth ) ;
else if ( aCurrent . Name . equalsIgnoreCase ( OProviderImpl : : FactoryArguments : : sLocale ) )
bExtractSuccess = ( aCurrent . Value > > = sLocale ) ;
2000-12-19 10:14:08 +00:00
else if ( aCurrent . Name . equalsIgnoreCase ( OProviderImpl : : FactoryArguments : : sNoCache ) )
bExtractSuccess = ( aCurrent . Value > > = bNoCache ) ;
2001-01-26 14:01:57 +00:00
else if ( aCurrent . Name . equalsIgnoreCase ( OProviderImpl : : FactoryArguments : : sLazyWrite ) )
bExtractSuccess = ( aCurrent . Value > > = bLazyWrite ) ;
2000-11-13 12:14:49 +00:00
/*
2000-11-10 21:42:54 +00:00
# ifdef DBG_UTIL
else
{
: : rtl : : OString sMessage ( RTL_CONSTASCII_STRINGPARAM ( " OProviderImpl::extractArgs : unknown argument name: " ) ) ;
sMessage + = : : rtl : : OString ( aCurrent . Name . getStr ( ) , aCurrent . Name . getLength ( ) , RTL_TEXTENCODING_ASCII_US ) ;
sMessage + = : : rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " ! " ) ) ;
OSL_ENSHURE ( sal_False , sMessage . getStr ( ) ) ;
}
# endif
2000-11-13 12:14:49 +00:00
*/
2000-11-10 21:42:54 +00:00
if ( ! bExtractSuccess )
throw lang : : IllegalArgumentException (
( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " The argument " ) ) + = aCurrent . Name ) + = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " could not be extracted. " ) ) ,
uno : : Reference < uno : : XInterface > ( ) ,
2000-11-20 00:30:48 +00:00
sal_Int16 ( i )
2000-11-10 21:42:54 +00:00
) ;
bAnyPropValue = sal_True ;
}
}
if ( ! bAnyPropValue )
{
// compatibility : formerly, you could specify the node path as first arg and the (optional) depth
// as second arg
if ( _rArgs . getLength ( ) > 0 )
if ( ! ( _rArgs [ 0 ] > > = sPath ) )
throw lang : : IllegalArgumentException (
OUString ( RTL_CONSTASCII_USTRINGPARAM ( " The node path specified is invalid. " ) ) ,
uno : : Reference < uno : : XInterface > ( ) ,
0
) ;
if ( _rArgs . getLength ( ) > 1 )
if ( ! ( _rArgs [ 1 ] > > = nLevelDepth ) )
throw lang : : IllegalArgumentException (
OUString ( RTL_CONSTASCII_USTRINGPARAM ( " The fetch depth specified is invalid. " ) ) ,
uno : : Reference < uno : : XInterface > ( ) ,
1
) ;
}
_rNodeAccessor = sPath ; //IConfigSession::composeNodeAccessor(sPath, sUser);
_nLevels = nLevelDepth ;
_rLocale = sLocale ;
_rUser = sUser ;
2000-12-19 10:14:08 +00:00
_bNoCache = ( bNoCache ! = sal_False ) ;
2001-01-26 14:01:57 +00:00
_bLazyWrite = bLazyWrite ;
2000-12-19 10:14:08 +00:00
}
// class OOptions
//..........................................................................
static sal_Int32 getNextCacheID ( )
{
static oslInterlockedCount nNextID = 0 ;
oslInterlockedCount nNewID = osl_incrementInterlockedCount ( & nNextID ) ;
if ( nNewID = = 0 )
{
CFG_TRACE_WARNING ( " Cache ID overflow - restarting sequence ! " ) ;
OSL_ENSURE ( false , " Cache ID overflow - restarting sequence ! " ) ;
}
return static_cast < sal_Int32 > ( nNewID ) ;
}
void OOptions : : setNoCache ( bool _bNoCache )
{
if ( _bNoCache )
{
m_nCacheID = getNextCacheID ( ) ;
}
else
{
m_nCacheID = 0 ;
}
2000-11-10 21:42:54 +00:00
}
2000-11-13 12:14:49 +00:00
2000-11-10 21:42:54 +00:00
} // namespace configmgr