2000-11-10 21:42:54 +00:00
/*************************************************************************
*
* $ RCSfile : providerimpl . cxx , v $
*
2002-06-12 15:28:27 +00:00
* $ Revision : 1.49 $
2000-11-10 21:42:54 +00:00
*
2002-06-12 15:28:27 +00:00
* last change : $ Author : jb $ $ Date : 2002 - 06 - 12 16 : 28 : 27 $
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"
2001-11-09 10:23:57 +00:00
# ifndef CONFIGMGR_MISC_OPTIONS_HXX_
2000-12-19 10:14:08 +00:00
# include "options.hxx"
2001-11-09 10:23:57 +00:00
# endif
# ifndef CONFIGMGR_API_FACTORYIMPL_HXX_
2000-11-10 21:42:54 +00:00
# include "apifactoryimpl.hxx"
2001-11-09 10:23:57 +00:00
# endif
# ifndef CONFIGMGR_API_TREEIMPLOBJECTS_HXX_
2000-11-10 21:42:54 +00:00
# include "apitreeimplobj.hxx"
2001-11-09 10:23:57 +00:00
# endif
# ifndef CONFIGMGR_API_TREEACCESS_HXX_
2000-11-10 21:42:54 +00:00
# include "apitreeaccess.hxx"
2001-11-09 10:23:57 +00:00
# endif
# ifndef CONFIGMGR_ROOTTREE_HXX_
2000-11-10 21:42:54 +00:00
# include "roottree.hxx"
2001-11-09 10:23:57 +00:00
# endif
# ifndef CONFIGMGR_CONFIGNODE_HXX_
2000-11-10 21:42:54 +00:00
# include "noderef.hxx"
2001-11-09 10:23:57 +00:00
# endif
# ifndef CONFIGMGR_API_OBJECTREGISTRY_HXX_
2000-11-10 21:42:54 +00:00
# include "objectregistry.hxx"
2001-11-09 10:23:57 +00:00
# endif
2000-11-10 21:42:54 +00:00
2000-12-03 10:45:59 +00:00
# ifndef CONFIGMGR_BOOTSTRAP_HXX_
# include "bootstrap.hxx"
# endif
2002-03-15 10:50:25 +00:00
# ifndef _CONFIGMGR_SESSION_CONFIGSESSION_HXX_
# include "configsession.hxx"
# endif
# ifndef CONFIGMGR_CACHEFACTORY_HXX_
# include "cachefactory.hxx"
# endif
2000-12-03 10:45:59 +00:00
2000-11-10 21:42:54 +00:00
# ifndef CONFIGMGR_API_PROVIDER_HXX_
# include "provider.hxx"
# endif
2002-03-28 07:20:59 +00:00
# ifndef CONFIGMGR_TREEPROVIDER_HXX
# include "treeprovider.hxx"
# endif
# ifndef CONFIGMGR_TREEMANAGER_HXX_
# include "treemanager.hxx"
2000-11-10 21:42:54 +00:00
# endif
2002-02-11 12:47:56 +00:00
# ifndef CONFIGMGR_TREEACCESSOR_HXX
# include "treeaccessor.hxx"
# endif
# ifndef CONFIGMGR_GROUPNODEACCESS_HXX
# include "groupnodeaccess.hxx"
# endif
2002-03-15 10:50:25 +00:00
# ifndef CONFIGMGR_VALUENODEACCESS_HXX
2002-02-11 12:47:56 +00:00
# include "valuenodeaccess.hxx"
2002-03-15 10:50:25 +00:00
# endif
2000-11-10 21:42:54 +00:00
# ifndef _CONFIGMGR_TRACER_HXX_
# include "tracer.hxx"
# endif
2001-11-09 10:23:57 +00:00
# ifndef _OSL_INTERLOCK_H_
2000-12-19 10:14:08 +00:00
# include <osl/interlck.h>
2001-11-09 10:23:57 +00:00
# endif
2000-11-10 21:42:54 +00:00
# ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
# include <com/sun/star/beans/PropertyValue.hpp>
# endif
2001-08-01 11:16:00 +00:00
# ifndef _RTL_LOGFILE_HXX_
# include <rtl/logfile.hxx>
# endif
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 ;
2001-04-19 14:46:27 +00:00
using configuration : : SpecialTemplateProvider ;
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 ;
public :
2001-04-19 14:46:27 +00:00
ApiProviderInstances ( OProviderImpl & rProviderImpl )
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 )
{
}
~ ApiProviderInstances ( )
{ }
2001-04-19 14:46:27 +00:00
ApiProvider & getReaderProvider ( ) { return m_aReaderProvider ; }
ApiProvider & getWriterProvider ( ) { return m_aWriterProvider ; }
Factory & getReaderFactory ( ) { return m_aReaderFactory ; }
Factory & getWriterFactory ( ) { return m_aWriterFactory ; }
2000-11-10 21:42:54 +00:00
} ;
}
2002-03-15 10:50:25 +00:00
//=============================================================================
2000-11-10 21:42:54 +00:00
//=============================================================================
//= OProviderImpl
//=============================================================================
//-----------------------------------------------------------------------------
2002-06-12 15:28:27 +00:00
OProviderImpl : : OProviderImpl ( OProvider * _pProvider , CreationContext const & _xContext )
: m_xContext ( _xContext )
, m_pNewProviders ( 0 )
2000-11-10 21:42:54 +00:00
, m_pProvider ( _pProvider )
2001-04-03 15:33:58 +00:00
, m_pSession ( NULL )
2001-05-18 15:20:59 +00:00
, m_pTreeMgr ( NULL )
2000-11-10 21:42:54 +00:00
{
2002-06-12 15:28:27 +00:00
OSL_ENSURE ( m_xContext . is ( ) , " Module::Module : missing service factory ! " ) ;
2002-03-28 07:20:59 +00:00
m_xTypeConverter = m_xTypeConverter . query (
2002-06-12 15:28:27 +00:00
m_xContext - > createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " com.sun.star.script.Converter " ) ) ) ) ;
2002-03-28 07:20:59 +00:00
OSL_ENSURE ( m_xTypeConverter . is ( ) , " Module::Module : could not create an instance of the type converter ! " ) ;
2001-02-15 16:25:17 +00:00
2002-03-28 07:20:59 +00:00
m_xDefaultOptions = new OOptions ( ) ;
2001-04-03 15:33:58 +00:00
}
//-----------------------------------------------------------------------------
2002-06-12 15:28:27 +00:00
IConfigSession * OProviderImpl : : getSession ( ) const
{
OSL_ENSURE ( m_pSession , " Trying to get the legacy session from a new-style provider " ) ;
return m_pSession ;
}
2001-04-03 15:33:58 +00:00
//-----------------------------------------------------------------------------
2002-06-12 15:28:27 +00:00
bool OProviderImpl : : initSession ( const ConnectionSettings & _rSettings )
2001-04-03 15:33:58 +00:00
{
2002-06-12 15:28:27 +00:00
bool bNeedProfile = false ;
if ( _rSettings . isUnoBackend ( ) )
{
this - > implInitFromSettings ( _rSettings , bNeedProfile ) ;
rtl : : Reference < TreeManager > xNewTreeManager =
CacheFactory : : instance ( ) . createCacheManager ( _rSettings , m_xContext ) ;
m_pTreeMgr = xNewTreeManager . get ( ) ;
m_pTreeMgr - > acquire ( ) ;
}
else
{
m_pSession = _rSettings . createConnection ( m_xContext ) ;
2001-02-15 16:25:17 +00:00
2002-06-12 15:28:27 +00:00
if ( ! m_pSession ) return false ;
2000-12-04 18:34:56 +00:00
2002-06-12 15:28:27 +00:00
// prepare the options
// 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 ( ! m_pSession - > allowsCaching_Hack ( ) )
m_xDefaultOptions - > setNoCache ( sal_True ) ;
2001-11-14 16:01:59 +00:00
2002-06-12 15:28:27 +00:00
// this is a hack to simulate 'finalized' where the backend doesn't support it
if ( _rSettings . isAdminSession ( ) & & ! m_pSession - > supportsFinalized_Hack ( ) )
m_xDefaultOptions - > setForceWritable ( true ) ;
2001-04-03 15:33:58 +00:00
2002-06-12 15:28:27 +00:00
this - > implInitFromSettings ( _rSettings , bNeedProfile ) ;
2002-03-15 10:50:25 +00:00
2002-06-12 15:28:27 +00:00
rtl : : Reference < TreeManager > xNewTreeManager =
CacheFactory : : instance ( ) . createCacheManager ( m_pSession , m_xTypeConverter ) ;
m_pTreeMgr = xNewTreeManager . get ( ) ;
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)
2001-04-19 14:46:27 +00:00
m_pNewProviders = new configapi : : ApiProviderInstances ( * this ) ;
2000-11-30 07:54:09 +00:00
2001-04-03 15:33:58 +00:00
// now complete our state from the user's profile, if necessary
if ( bNeedProfile )
2000-11-30 07:54:09 +00:00
try
{
2001-06-18 09:48:00 +00:00
static : : rtl : : OUString ssUserProfile ( RTL_CONSTASCII_USTRINGPARAM ( " org.openoffice.Setup " ) ) ;
2001-07-05 16:05:51 +00:00
AbsolutePath aProfileModule = AbsolutePath : : makeModulePath ( ssUserProfile , AbsolutePath : : NoValidate ( ) ) ;
2002-02-11 12:47:56 +00:00
data : : NodeAccess aProfileTree = m_pTreeMgr - > requestSubtree ( aProfileModule , m_xDefaultOptions ) ;
if ( aProfileTree . isValid ( ) )
implInitFromProfile ( aProfileTree ) ;
2001-04-03 15:33:58 +00:00
// should we clean this up ?
// m_pTreeMgr->releaseSubtree(ssUserProfile, m_xDefaultOptions);
}
2001-11-09 10:23:57 +00:00
catch ( uno : : Exception & e )
2001-04-03 15:33:58 +00:00
{
// could not read profile
2001-11-09 10:23:57 +00:00
CFG_TRACE_ERROR_NI ( " Provider bootstrapping: Caught an exception trying to get 'Setup' data: " , OUSTRING2ASCII ( e . Message ) ) ;
2001-04-03 15:33:58 +00:00
}
2002-06-12 15:28:27 +00:00
return true ;
2001-04-03 15:33:58 +00:00
}
//-----------------------------------------------------------------------------
// these can be overridden. default does nothing
void OProviderImpl : : initFromSettings ( const ConnectionSettings & , bool & )
{
}
//-----------------------------------------------------------------------------
2002-02-11 12:47:56 +00:00
void OProviderImpl : : initFromProfile ( data : : NodeAccess const & )
2001-04-03 15:33:58 +00:00
{
}
//-----------------------------------------------------------------------------
// these implement the base class behavior
void OProviderImpl : : implInitFromSettings ( const ConnectionSettings & _rSettings , bool & rNeedProfile )
{
bool bIntrinsicNeedProfile = true ;
// if we have a user name, we have to add and remember it for the session
if ( _rSettings . hasUser ( ) )
{
// the username is also part of the connection settings
rtl : : OUString sDefaultUser = _rSettings . getUser ( ) ;
m_xDefaultOptions - > setDefaultUser ( sDefaultUser ) ;
}
2000-12-03 10:45:59 +00:00
2001-04-03 15:33:58 +00:00
if ( _rSettings . hasLocale ( ) )
{
bIntrinsicNeedProfile = false ;
rtl : : OUString sDefaultLocale = _rSettings . getLocale ( ) ;
m_xDefaultOptions - > setDefaultLocale ( sDefaultLocale ) ;
}
2001-06-22 11:42:25 +00:00
else
OSL_ASSERT ( m_xDefaultOptions - > getDefaultLocale ( ) . getLength ( ) = = 0 ) ;
if ( _rSettings . hasAsyncSetting ( ) )
{
2001-07-05 16:05:51 +00:00
m_xDefaultOptions - > setLazyWrite ( ! ! _rSettings . getAsyncSetting ( ) ) ;
2001-06-22 11:42:25 +00:00
}
2001-04-03 15:33:58 +00:00
// call the template method
this - > initFromSettings ( _rSettings , rNeedProfile ) ;
if ( bIntrinsicNeedProfile )
rNeedProfile = true ; // to get locale
}
//-----------------------------------------------------------------------------
2002-02-11 12:47:56 +00:00
void OProviderImpl : : implInitFromProfile ( data : : NodeAccess const & aProfile )
2001-04-03 15:33:58 +00:00
{
2002-02-11 12:47:56 +00:00
OSL_ASSERT ( aProfile . isValid ( ) ) ;
data : : GroupNodeAccess aProfileNode ( aProfile ) ;
OSL_ASSERT ( aProfileNode . isValid ( ) ) ;
2001-04-03 15:33:58 +00:00
2001-06-22 11:42:25 +00:00
// read the default locale for the user
if ( m_xDefaultOptions - > getDefaultLocale ( ) . getLength ( ) = = 0 )
{
2002-02-11 12:47:56 +00:00
using configuration : : Name ;
using configuration : : makeNodeName ;
static Name ssSubGroup = makeNodeName ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " L10N " ) ) , Name : : NoValidate ( ) ) ;
static Name ssLocale = makeNodeName ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( " ooLocale " ) ) , Name : : NoValidate ( ) ) ;
2001-06-18 09:48:00 +00:00
2002-02-11 12:47:56 +00:00
data : : GroupNodeAccess aL10NNode ( aProfileNode . getChildNode ( ssSubGroup ) ) ;
if ( aL10NNode . isValid ( ) )
2000-11-30 07:54:09 +00:00
{
2002-02-11 12:47:56 +00:00
data : : ValueNodeAccess aValue ( aL10NNode . getChildNode ( ssLocale ) ) ;
if ( aValue . isValid ( ) )
2000-11-30 07:54:09 +00:00
{
2001-06-22 11:42:25 +00:00
rtl : : OUString sDefaultLocale ;
2002-02-11 12:47:56 +00:00
if ( aValue . getValue ( ) > > = sDefaultLocale )
2001-06-22 11:42:25 +00:00
{
m_xDefaultOptions - > setDefaultLocale ( sDefaultLocale ) ;
}
else
OSL_ENSURE ( false , " Could not extract locale parameter into string " ) ;
2000-11-30 07:54:09 +00:00
}
}
}
2001-04-03 15:33:58 +00:00
// call the template method
2002-02-11 12:47:56 +00:00
this - > initFromProfile ( aProfile ) ;
2000-11-10 21:42:54 +00:00
}
//-----------------------------------------------------------------------------
OProviderImpl : : ~ OProviderImpl ( )
{
2001-05-18 15:20:59 +00:00
if ( m_pTreeMgr )
{
m_pTreeMgr - > release ( ) ;
m_pTreeMgr = NULL ;
}
2001-02-15 16:25:17 +00:00
delete m_pNewProviders ;
delete m_pSession ;
2000-11-10 21:42:54 +00:00
}
2001-01-26 06:54:22 +00:00
// --------------------------------- disposing ---------------------------------
2001-02-15 16:25:17 +00:00
void SAL_CALL OProviderImpl : : dispose ( ) throw ( )
2001-01-26 06:54:22 +00:00
{
2001-11-09 10:23:57 +00:00
try
{
m_pTreeMgr - > dispose ( ) ;
m_pSession - > close ( ) ;
}
catch ( uno : : Exception & e )
{
CFG_TRACE_ERROR ( " Disposing the TreeManager or closing the session caused an exception: %s " , OUSTRING2ASCII ( e . Message ) ) ;
}
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 ( ) ; }
2001-09-28 11:44:40 +00:00
// DefaultProvider access
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------
2001-09-28 11:44:40 +00:00
IDefaultProvider & OProviderImpl : : getDefaultProvider ( ) const
{
return * m_pTreeMgr ;
}
2000-11-20 00:30:48 +00:00
2002-02-11 12:47:56 +00:00
// TemplateManager access
2001-09-28 11:44:40 +00:00
//-----------------------------------------------------------------------------
2002-02-11 12:47:56 +00:00
ITemplateManager & OProviderImpl : : getTemplateProvider ( ) const
2000-11-10 21:42:54 +00:00
{
2001-04-19 14:46:27 +00:00
return * m_pTreeMgr ;
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
//-----------------------------------------------------------------------------
2002-02-11 12:47:56 +00:00
data : : NodeAccess OProviderImpl : : requestSubtree ( AbsolutePath const & aSubtreePath , const vos : : ORef < OOptions > & _xOptions ,
sal_Int16 nMinLevels ) CFG_UNO_THROW_ALL ( )
2000-11-10 21:42:54 +00:00
{
2002-02-11 12:47:56 +00:00
data : : NodeAccess aTree = data : : NodeAccess : : emptyNode ( ) ;
2001-07-05 16:05:51 +00:00
try
{
2002-02-11 12:47:56 +00:00
aTree = m_pTreeMgr - > requestSubtree ( aSubtreePath , _xOptions , nMinLevels ) ;
2001-07-05 16:05:51 +00:00
}
catch ( uno : : Exception & e )
{
: : rtl : : OUString sMessage = getErrorMessage ( aSubtreePath , _xOptions ) ;
// append the error message given by the tree provider
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " \n \n The backend returned the following error: \n " ) ) ;
sMessage + = e . Message ;
throw lang : : WrappedTargetException ( sMessage , getProviderInstance ( ) , uno : : makeAny ( e ) ) ;
}
2002-02-11 12:47:56 +00:00
if ( ! aTree . isValid ( ) )
2001-07-05 16:05:51 +00:00
{
: : rtl : : OUString sMessage = getErrorMessage ( aSubtreePath , _xOptions ) ;
sMessage + = : : rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " \n \n No backend error message available \n " ) ) ;
throw uno : : Exception ( sMessage , getProviderInstance ( ) ) ;
}
2002-02-11 12:47:56 +00:00
return aTree ;
2000-11-10 21:42:54 +00:00
}
//-----------------------------------------------------------------------------
2002-02-11 12:47:56 +00:00
void OProviderImpl : : updateTree ( memory : : UpdateAccessor & _aAccessToken , TreeChangeList & aChanges ) CFG_UNO_THROW_ALL ( )
2000-12-04 08:20:27 +00:00
{
2002-02-11 12:47:56 +00:00
m_pTreeMgr - > updateTree ( _aAccessToken , aChanges ) ;
2000-12-04 08:20:27 +00:00
}
//-----------------------------------------------------------------------------
2001-11-09 10:23:57 +00:00
void OProviderImpl : : releaseSubtree ( AbsolutePath const & aSubtreePath , const vos : : ORef < OOptions > & _xOptions ) CFG_NOTHROW ( )
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
//-----------------------------------------------------------------------------
2001-11-09 10:23:57 +00:00
void OProviderImpl : : disposeData ( const vos : : ORef < OOptions > & _xOptions ) CFG_NOTHROW ( )
2000-12-14 15:12:44 +00:00
{
m_pTreeMgr - > disposeData ( _xOptions ) ;
}
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------
2002-03-28 07:20:59 +00:00
void OProviderImpl : : saveAndNotifyUpdate ( data : : Accessor const & _aChangedDataAccessor , TreeChangeList const & aChanges ) CFG_UNO_THROW_ALL ( )
2000-11-10 21:42:54 +00:00
{
2002-03-28 07:20:59 +00:00
m_pTreeMgr - > saveAndNotifyUpdate ( _aChangedDataAccessor , aChanges ) ;
2000-11-10 21:42:54 +00:00
}
2001-02-08 11:03:27 +00:00
//-----------------------------------------------------------------------------
2001-11-09 10:23:57 +00:00
void OProviderImpl : : fetchSubtree ( AbsolutePath const & aSubtreePath , const vos : : ORef < OOptions > & _xOptions , sal_Int16 nMinLevels ) CFG_NOTHROW ( )
2001-02-08 11:03:27 +00:00
{
m_pTreeMgr - > fetchSubtree ( aSubtreePath , _xOptions , nMinLevels ) ;
}
2001-09-28 11:44:40 +00:00
//-----------------------------------------------------------------------------
2002-02-11 12:47:56 +00:00
sal_Bool OProviderImpl : : fetchDefaultData ( memory : : UpdateAccessor & _aAccessToken , AbsolutePath const & aSubtreePath , const vos : : ORef < OOptions > & _xOptions , sal_Int16 nMinLevels ) CFG_UNO_THROW_ALL ( )
2001-09-28 11:44:40 +00:00
{
2002-02-11 12:47:56 +00:00
return m_pTreeMgr - > fetchDefaultData ( _aAccessToken , aSubtreePath , _xOptions , nMinLevels ) ;
2001-09-28 11:44:40 +00:00
}
2001-02-08 11:03:27 +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 ) ;
}
//-----------------------------------------------------------------------------
2002-02-11 12:47:56 +00:00
memory : : Segment * OProviderImpl : : getDataSegment ( AbsolutePath const & _rAccessor , const vos : : ORef < OOptions > & _xOptions )
2000-11-10 21:42:54 +00:00
{
2002-02-11 12:47:56 +00:00
return m_pTreeMgr - > getDataSegment ( _rAccessor , _xOptions ) ;
2000-11-10 21:42:54 +00:00
}
//-----------------------------------------------------------------------------------
2001-07-05 16:05:51 +00:00
OUString OProviderImpl : : getErrorMessage ( AbsolutePath const & _rAccessor , const vos : : ORef < OOptions > & _xOptions )
2000-11-10 21:42:54 +00:00
{
2001-07-05 16:05:51 +00:00
OUString const sAccessor = _rAccessor . toString ( ) ;
2000-11-10 21:42:54 +00:00
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 ( ) ) ;
2001-07-05 16:05:51 +00:00
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 ( sAccessor ) ) ;
sMessage + = sAccessor ;
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
//-----------------------------------------------------------------------------------
2001-11-09 10:23:57 +00:00
NodeElement * OProviderImpl : : buildReadAccess ( OUString const & _rAccessor , const vos : : ORef < OOptions > & _xOptions , sal_Int32 nMinLevels ) CFG_UNO_THROW_ALL ( )
2000-11-10 21:42:54 +00:00
{
CFG_TRACE_INFO ( " config provider: requesting the tree from the cache manager " ) ;
2001-07-05 16:05:51 +00:00
OSL_ASSERT ( sal_Int16 ( nMinLevels ) = = nMinLevels ) ;
2000-11-10 21:42:54 +00:00
try
{
2001-07-05 16:05:51 +00:00
using namespace configuration ;
2000-11-10 21:42:54 +00:00
2001-07-05 16:05:51 +00:00
AbsolutePath aAccessorPath = AbsolutePath : : parse ( _rAccessor ) ;
2000-11-10 21:42:54 +00:00
2002-02-11 12:47:56 +00:00
data : : NodeAccess aTree = this - > requestSubtree ( aAccessorPath , _xOptions , sal_Int16 ( nMinLevels ) ) ;
2000-11-10 21:42:54 +00:00
2001-07-05 16:05:51 +00:00
TreeDepth nDepth = ( nMinLevels = = ALL_LEVELS ) ? C_TreeDepthAll : TreeDepth ( nMinLevels ) ;
2000-11-10 21:42:54 +00:00
2001-07-05 16:05:51 +00:00
RootTree aRootTree ( createReadOnlyTree (
2002-02-11 12:47:56 +00:00
aAccessorPath , this - > getDataSegment ( aAccessorPath , _xOptions ) ,
aTree , nDepth ,
2001-07-05 16:05:51 +00:00
TemplateProvider ( this - > getTemplateProvider ( ) , _xOptions )
) ) ;
return m_pNewProviders - > getReaderFactory ( ) . makeAccessRoot ( aRootTree , _xOptions ) ;
}
catch ( configuration : : Exception & e )
{
configapi : : ExceptionMapper ec ( e ) ;
ec . setContext ( this - > getProviderInstance ( ) ) ;
//ec.unhandled();
throw lang : : WrappedTargetException ( ec . message ( ) , ec . context ( ) , uno : : Any ( ) ) ;
}
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 ,
2001-11-09 10:23:57 +00:00
sal_Int32 nMinLevels ) CFG_UNO_THROW_ALL ( )
2000-11-10 21:42:54 +00:00
{
CFG_TRACE_INFO ( " config provider: requesting the tree from the cache manager " ) ;
2001-07-05 16:05:51 +00:00
OSL_ASSERT ( sal_Int16 ( nMinLevels ) = = nMinLevels ) ;
2000-11-10 21:42:54 +00:00
try
{
2001-07-05 16:05:51 +00:00
using namespace configuration ;
2000-11-10 21:42:54 +00:00
2001-07-05 16:05:51 +00:00
AbsolutePath aAccessorPath = AbsolutePath : : parse ( _rAccessor ) ;
2000-11-10 21:42:54 +00:00
2002-02-11 12:47:56 +00:00
data : : NodeAccess aTree = requestSubtree ( aAccessorPath , _xOptions , sal_Int16 ( nMinLevels ) ) ;
2000-11-10 21:42:54 +00:00
2001-07-05 16:05:51 +00:00
TreeDepth nDepth = ( nMinLevels = = ALL_LEVELS ) ? C_TreeDepthAll : TreeDepth ( nMinLevels ) ;
2000-11-10 21:42:54 +00:00
2001-07-05 16:05:51 +00:00
RootTree aRootTree ( createUpdatableTree (
2002-02-11 12:47:56 +00:00
aAccessorPath , this - > getDataSegment ( aAccessorPath , _xOptions ) ,
aTree , nDepth ,
2001-07-05 16:05:51 +00:00
TemplateProvider ( this - > getTemplateProvider ( ) , _xOptions )
) ) ;
2000-11-10 21:42:54 +00:00
2001-07-05 16:05:51 +00:00
return m_pNewProviders - > getWriterFactory ( ) . makeAccessRoot ( aRootTree , _xOptions ) ;
}
catch ( configuration : : Exception & e )
{
configapi : : ExceptionMapper ec ( e ) ;
ec . setContext ( this - > getProviderInstance ( ) ) ;
//ec.unhandled();
throw lang : : WrappedTargetException ( ec . message ( ) , ec . context ( ) , uno : : Any ( ) ) ;
}
2000-11-10 21:42:54 +00:00
}
//=============================================================================
//= OProvider::FactoryArguments
//=============================================================================
2001-05-28 14:33:37 +00:00
sal_Char const * const OProviderImpl : : FactoryArguments : : asciiArgumentNames [ ] =
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
" nodepath " , // ARG_NODEPATH, // requested node path
" depth " , // ARG_DEPTH, // depth of the tree
" user " , // ARG_USER, // name of the user - only for admin
" locale " , // ARG_LOCALE, // desired locale
" nocache " , // ARG_NOCACHE, // cache disabling
" lazywrite " // ARG_ASYNC, // lasy write data
} ;
2001-11-09 10:23:57 +00:00
OUString OProviderImpl : : FactoryArguments : : getArgumentName ( Argument _which ) CFG_NOTHROW ( )
2001-05-28 14:33:37 +00:00
{
OSL_ASSERT ( sizeof asciiArgumentNames / sizeof 0 [ asciiArgumentNames ] = = _arg_count ) ;
OSL_PRECOND ( _which < _arg_count , " Illegal argument selector in OProviderImpl::FactoryArguments::getArgumentName " ) ;
return OUString : : createFromAscii ( asciiArgumentNames [ _which ] ) ;
}
OProviderImpl : : FactoryArguments : : Argument
OProviderImpl : : FactoryArguments : : lookupArgument ( const rtl : : OUString & rName )
2001-11-09 10:23:57 +00:00
CFG_NOTHROW ( )
2001-05-28 14:33:37 +00:00
{
OUString sCheck ( rName . toAsciiLowerCase ( ) ) ;
typedef sal_Char const * const * ArgNameIter ;
ArgNameIter const pFirst = asciiArgumentNames ;
ArgNameIter const pLast = pFirst + _arg_count ;
ArgNameIter it = pFirst ;
for ( ; it ! = pLast ; + + it )
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
if ( 0 = = sCheck . compareToAscii ( * it ) )
{
break ;
}
2000-11-10 21:42:54 +00:00
}
2001-05-28 14:33:37 +00:00
OSL_ASSERT ( Argument ( pLast - pFirst ) = = ARG_NOT_FOUND ) ;
return static_cast < Argument > ( it - pFirst ) ;
2000-11-10 21:42:54 +00:00
}
2001-05-28 14:33:37 +00:00
//-----------------------------------------------------------------------------------
2000-11-10 21:42:54 +00:00
2001-05-28 14:33:37 +00:00
bool OProviderImpl : : FactoryArguments : : extractOneArgument ( beans : : PropertyValue const & aCurrent ,
OUString & /* [out] */ _rNodeAccessor ,
sal_Int32 & /* [out] */ _nLevels ,
vos : : ORef < OOptions > /* [in/out] */ _xOptions )
2001-11-09 10:23:57 +00:00
CFG_NOTHROW ( )
2001-05-28 14:33:37 +00:00
{
switch ( lookupArgument ( aCurrent . Name ) )
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
case ARG_NODEPATH :
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
OUString sStringVal ;
if ( aCurrent . Value > > = sStringVal )
_rNodeAccessor = sStringVal ;
else
return false ;
}
break ;
case ARG_DEPTH :
{
sal_Int32 nIntVal ;
if ( aCurrent . Value > > = nIntVal )
_nLevels = nIntVal ;
else
return false ;
}
break ;
case ARG_USER :
{
OUString sStringVal ;
if ( aCurrent . Value > > = sStringVal )
_xOptions - > setUser ( sStringVal ) ;
else
return false ;
}
break ;
case ARG_LOCALE :
{
OUString sStringVal ;
if ( aCurrent . Value > > = sStringVal )
{
_xOptions - > setLocale ( sStringVal ) ;
break ;
}
#if 0
lang : : Locale aLocale ;
if ( aCurrent . Value > > = aLocale )
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
_xOptions - > setLocale ( aLocale ) ;
break ;
2000-11-10 21:42:54 +00:00
}
2001-05-28 14:33:37 +00:00
# endif
return false ;
2000-11-10 21:42:54 +00:00
}
2001-05-28 14:33:37 +00:00
break ;
case ARG_NOCACHE :
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
sal_Bool bBoolVal ;
if ( aCurrent . Value > > = bBoolVal )
_xOptions - > setNoCache ( ! ! bBoolVal ) ;
else
return false ;
2000-11-10 21:42:54 +00:00
}
2001-05-28 14:33:37 +00:00
break ;
case ARG_ASYNC :
2000-11-13 13:37:07 +00:00
{
2001-05-28 14:33:37 +00:00
sal_Bool bBoolVal ;
if ( aCurrent . Value > > = bBoolVal )
_xOptions - > setLazyWrite ( ! ! bBoolVal ) ;
else
return false ;
2000-11-13 13:37:07 +00:00
}
2001-05-28 14:33:37 +00:00
break ;
case ARG_NOT_FOUND :
{
rtl : : OString sMessage ( RTL_CONSTASCII_STRINGPARAM ( " Unknown argument \" " ) ) ;
sMessage + = rtl : : OUStringToOString ( aCurrent . Name , RTL_TEXTENCODING_ASCII_US ) ;
sMessage + = rtl : : OString ( RTL_CONSTASCII_STRINGPARAM ( " \" ! \n - Parameter will be ignored - \n " ) ) ;
CFG_TRACE_WARNING ( " provider: %s " , sMessage . getStr ( ) ) ;
# ifdef DBG_UTIL
OSL_ENSURE ( false , sMessage . getStr ( ) ) ;
# endif
}
break ;
default :
CFG_TRACE_ERROR ( " Known argument is not handled " ) ;
OSL_ENSURE ( false , " Known argument is not handled " ) ;
break ;
2000-11-10 21:42:54 +00:00
}
return true ;
}
2001-05-28 14:33:37 +00:00
//-----------------------------------------------------------------------------------
static
void failIllegal ( sal_Int32 _nArg = - 1 )
2001-11-09 10:23:57 +00:00
CFG_THROW1 ( lang : : IllegalArgumentException )
2001-05-28 14:33:37 +00:00
{
OSL_ENSURE ( sal_Int16 ( _nArg ) = = _nArg , " Argument number out of range. Raising imprecise exception. " ) ;
throw lang : : IllegalArgumentException (
OUString ( RTL_CONSTASCII_USTRINGPARAM ( " Configuration Provider: Arguments must be PropertyValues. " ) ) ,
uno : : Reference < uno : : XInterface > ( ) ,
sal_Int16 ( _nArg )
) ;
}
//-----------------------------------------------------------------------------------
static
bool extractLegacyArguments ( const uno : : Sequence < uno : : Any > & _rArgs ,
OUString & /* [out] */ _rNodeAccessor ,
sal_Int32 & /* [out] */ _nLevels )
2001-11-09 10:23:57 +00:00
CFG_NOTHROW ( )
2001-05-28 14:33:37 +00:00
{
// compatibility : formerly, you could specify the node path as first arg and the (optional) depth
// as second arg
switch ( _rArgs . getLength ( ) )
{
default :
return false ;
case 2 :
if ( ! ( _rArgs [ 1 ] > > = _nLevels ) )
return false ;
// fall thru
case 1 :
if ( ! ( _rArgs [ 0 ] > > = _rNodeAccessor ) )
return false ;
// fall thru
case 0 :
return true ;
}
}
2000-11-10 21:42:54 +00:00
//-----------------------------------------------------------------------------------
2001-05-28 14:33:37 +00:00
void OProviderImpl : : FactoryArguments : : extractArgs ( const uno : : Sequence < uno : : Any > & _rArgs ,
OUString & /* [out] */ _rNodeAccessor ,
sal_Int32 & /* [out] */ _nLevels ,
vos : : ORef < OOptions > /* [in/out] */ _xOptions )
2001-11-09 10:23:57 +00:00
CFG_THROW1 ( lang : : IllegalArgumentException )
2001-05-28 14:33:37 +00:00
{
_nLevels = ITreeProvider : : ALL_LEVELS ; // setting a fallback
// the args have to be a sequence of property values
bool bLegacyFormat = false ;
for ( sal_Int32 i = 0 ; i < _rArgs . getLength ( ) ; + + i )
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
beans : : PropertyValue aCurrent ;
if ( _rArgs [ i ] > > = aCurrent )
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
if ( ! extractOneArgument ( aCurrent , _rNodeAccessor , _nLevels , _xOptions ) )
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
OUString sMessage ( RTL_CONSTASCII_USTRINGPARAM ( " The argument " ) ) ;
sMessage + = aCurrent . Name ;
sMessage + = OUString ( RTL_CONSTASCII_USTRINGPARAM ( " has the wrong type. \n - Found type " ) ) ;
sMessage + = aCurrent . Value . getValueType ( ) . getTypeName ( ) ;
throw lang : : IllegalArgumentException ( sMessage , uno : : Reference < uno : : XInterface > ( ) , sal_Int16 ( i ) ) ;
2000-11-10 21:42:54 +00:00
}
2001-05-28 14:33:37 +00:00
}
else
{
if ( i = = 0 ) // try compatibility format
if ( extractLegacyArguments ( _rArgs , _rNodeAccessor , _nLevels ) )
break ;
2000-11-10 21:42:54 +00:00
2001-05-28 14:33:37 +00:00
failIllegal ( i ) ;
OSL_ASSERT ( false ) ;
2000-11-10 21:42:54 +00:00
}
}
2001-05-28 14:33:37 +00:00
if ( _rNodeAccessor . getLength ( ) = = 0 )
2000-11-10 21:42:54 +00:00
{
2001-05-28 14:33:37 +00:00
OUString sMessage ( RTL_CONSTASCII_USTRINGPARAM ( " Configuration Provider: Missing argument: no nodepath was provided " ) ) ;
throw lang : : IllegalArgumentException ( sMessage , uno : : Reference < uno : : XInterface > ( ) , - 1 ) ;
2000-11-10 21:42:54 +00:00
}
2000-12-19 10:14:08 +00:00
}
2000-11-13 12:14:49 +00:00
2000-11-10 21:42:54 +00:00
} // namespace configmgr