diff options
Diffstat (limited to 'configmgr/source/misc')
22 files changed, 0 insertions, 5927 deletions
diff --git a/configmgr/source/misc/anypair.cxx b/configmgr/source/misc/anypair.cxx deleted file mode 100644 index eea9167aaaff..000000000000 --- a/configmgr/source/misc/anypair.cxx +++ /dev/null @@ -1,691 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: anypair.cxx,v $ - * $Revision: 1.13 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include <anypair.hxx> -#include <uno/any2.h> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/uno/Type.hxx> - -#define CFG_PRECOND( expr ) OSL_PRECOND ( expr, "Violated Precondition: " #expr) -#define CFG_POSTCOND( expr ) OSL_POSTCOND( expr, "Violated Postcondition: " #expr) - -namespace configmgr -{ - namespace css = com::sun::star; - namespace uno = css::uno; - -// ----------------------------------------------------------------------------- - static inline bool impl_Any_hasValue(uno_Any const * _pData) - { return (typelib_TypeClass_VOID != _pData->pType->eTypeClass); } - -// ----------------------------------------------------------------------------- - static inline bool impl_Any_storesData(uno_Any const * _pData) - { - const void * pAnyData = _pData->pData; - - const bool bSelfReferential = (pAnyData == &_pData->pReserved); - OSL_ENSURE( bSelfReferential == ( _pData <= pAnyData && pAnyData < _pData+1 ), - "uno_Any layout changed: Unreckognized self-referentiality" ); - - return bSelfReferential; - } - -// ----------------------------------------------------------------------------- - static inline void * impl_getDataPointer(const void * const * _pAnyPairData) - { - const void * const pResult = *_pAnyPairData; - - return const_cast<void*>(pResult); - } - -// ----------------------------------------------------------------------------- - static inline void * impl_getData(const void * const * _pAnyPairData, bool _bStoredData) - { - const void * const pResult = _bStoredData ? _pAnyPairData : *_pAnyPairData; - - return const_cast<void*>(pResult); - } - -// ----------------------------------------------------------------------------- - static inline void impl_setDataPointer(const void * * _pAnyPairData, void* _pData) - { - *_pAnyPairData = _pData; - } -// ----------------------------------------------------------------------------- - static const unsigned SHIFT_DATA_FLAG = 4; -// ----------------------------------------------------------------------------- - static - inline void impl_state_setState(sal_uInt8* _pState, sal_uInt8 _nState, sal_uInt8 _nSelect) - { - sal_uInt8 const nSelectMask = _nSelect | (_nSelect<<SHIFT_DATA_FLAG); - OSL_ENSURE( (_nState & nSelectMask) == _nState, "State specified does not belong to the selector"); - - *_pState &= ~nSelectMask; - *_pState |= _nState; - } - -// ----------------------------------------------------------------------------- - static - inline void impl_state_setNull(sal_uInt8* _pState, sal_uInt8 _nSelect) - { - sal_uInt8 const nSelectMask = _nSelect | (_nSelect<<SHIFT_DATA_FLAG); - *_pState &= ~nSelectMask; - } - -// ----------------------------------------------------------------------------- - static inline - void impl_state_setData(sal_uInt8* _pState, sal_uInt8 _nSelect) - { - sal_uInt8 const nSelectMask = _nSelect | (_nSelect<<SHIFT_DATA_FLAG); - *_pState |= nSelectMask; - } - -// ----------------------------------------------------------------------------- - static inline - void impl_state_setValue(sal_uInt8* _pState, sal_uInt8 _nSelect, bool _bStoresData) - { - *_pState |= _nSelect; - - _nSelect <<= SHIFT_DATA_FLAG; - if (_bStoresData) - *_pState |= _nSelect; - else - *_pState &= ~_nSelect; - } - -// ----------------------------------------------------------------------------- - static - inline bool impl_state_isNull(sal_uInt8 const _nState, sal_uInt8 _nSelect) - { - return 0 == (_nState & _nSelect); - } - -// ----------------------------------------------------------------------------- - static - inline bool impl_state_isData(sal_uInt8 const _nState, sal_uInt8 _nSelect) - { - return 0 != (_nState & (_nSelect<<SHIFT_DATA_FLAG)); - } - - -// ----------------------------------------------------------------------------- - static - typelib_TypeDescriptionReference * impl_getVoidType() - { - static const uno::Type aNullType; - return aNullType.getTypeLibType(); - } - -// ----------------------------------------------------------------------------- - static inline - void anypair_type_construct_Desc( cfgmgr_AnyPair_Desc* _pAnyPairDesc, - typelib_TypeDescriptionReference * _pType) - { - _pAnyPairDesc->nState = 0; - _pAnyPairDesc->pType = _pType; - - typelib_typedescriptionreference_acquire( _pAnyPairDesc->pType ); - } - -// ----------------------------------------------------------------------------- - static inline - void anypair_default_construct_Desc( cfgmgr_AnyPair_Desc* _pAnyPairDesc ) - { - anypair_type_construct_Desc(_pAnyPairDesc, impl_getVoidType()); - } - -// ----------------------------------------------------------------------------- - static inline - void anypair_empty_set_Data( const void ** _pAnyPairData ) - { - impl_setDataPointer(_pAnyPairData, NULL); - OSL_DEBUG_ONLY( impl_setDataPointer(_pAnyPairData, reinterpret_cast<void*>(0xdeadbeef)) ); - } - -// ----------------------------------------------------------------------------- - // returns a state for the specified selector - static inline - sal_uInt8 anypair_any_set_Data( const void ** _pAnyPairData, - sal_uInt8 _nSelect, - uno_Any const *_pUnoAny) - { - sal_uInt8 nState = 0; - - bool bValue = impl_Any_hasValue(_pUnoAny); - if (bValue) - { - uno_Any aTmpAny; - uno_type_any_construct(&aTmpAny, _pUnoAny->pData, _pUnoAny->pType, reinterpret_cast< uno_AcquireFunc >( uno::cpp_acquire )); - - bool bData = impl_Any_storesData(&aTmpAny); - - impl_setDataPointer(_pAnyPairData, bData ? aTmpAny.pReserved : aTmpAny.pData); - - impl_state_setValue(&nState, _nSelect, bData); - } - else - anypair_empty_set_Data(_pAnyPairData); - - return nState; - } - -// ----------------------------------------------------------------------------- - static inline - sal_uInt8 anypair_copy_Data( const void ** _pAnyPairData, - sal_uInt8 _nSelect, - cfgmgr_AnyPair_Desc const* _pAnyPairDescFrom, - const void * const* _pAnyPairDataFrom ) - { - sal_uInt8 nState = 0; - - if (impl_state_isNull(_pAnyPairDescFrom->nState, _nSelect)) - { - anypair_empty_set_Data(_pAnyPairData); - } - - else - { - bool bOldIsData = impl_state_isData(_pAnyPairDescFrom->nState, _nSelect); - - void * pFromData = impl_getData(_pAnyPairDataFrom, bOldIsData); - - uno_Any aTmpAny; - uno_type_any_construct(&aTmpAny, pFromData, _pAnyPairDescFrom->pType, reinterpret_cast< uno_AcquireFunc >( uno::cpp_acquire )); - - bool bNewIsData = impl_Any_storesData(&aTmpAny); - OSL_ENSURE(bOldIsData == bNewIsData, "INFO [safe to ignore]: Copy of uno_Any changes directness !?"); - - impl_setDataPointer(_pAnyPairData, bNewIsData ? aTmpAny.pReserved : aTmpAny.pData); - - impl_state_setValue(&nState, _nSelect, bNewIsData); - } - - return nState; - } - -// ----------------------------------------------------------------------------- - static inline - void anypair_destruct_Desc(cfgmgr_AnyPair_Desc* _pAnyPairDesc) - { - typelib_typedescriptionreference_release( _pAnyPairDesc->pType ); - OSL_DEBUG_ONLY(_pAnyPairDesc->nState = 0xDD); - OSL_DEBUG_ONLY(_pAnyPairDesc->pType = (typelib_TypeDescriptionReference*)0xdeadbeef); - } - -// ----------------------------------------------------------------------------- - static - void anypair_clear_Data( const void ** _pAnyPairData, - sal_uInt8 _nSelect, - cfgmgr_AnyPair_Desc const* _pAnyPairDesc - ) - { - if (!impl_state_isNull(_pAnyPairDesc->nState,_nSelect)) - { - uno_Any aTmpAny; - aTmpAny.pType = _pAnyPairDesc->pType; - - if (impl_state_isData(_pAnyPairDesc->nState,_nSelect)) - { - aTmpAny.pReserved = impl_getDataPointer(_pAnyPairData); - aTmpAny.pData = &aTmpAny.pReserved; - } - else - { - aTmpAny.pReserved = NULL; - aTmpAny.pData = impl_getDataPointer(_pAnyPairData); - } - - typelib_typedescriptionreference_acquire( aTmpAny.pType ); - uno_any_destruct(&aTmpAny, reinterpret_cast< uno_ReleaseFunc >( uno::cpp_release )); - - impl_setDataPointer(_pAnyPairData, NULL); - OSL_DEBUG_ONLY(impl_setDataPointer(_pAnyPairData, reinterpret_cast<void*>(0xDeadBeef))); - } - } - -// ----------------------------------------------------------------------------- - static - void anypair_Data_fill_Any( uno_Any* _pUnoAny, - cfgmgr_AnyPair_Desc const* _pAnyPairDesc, - const void * const* _pAnyPairData, - sal_uInt8 _nSelect ) - { - if (impl_state_isNull(_pAnyPairDesc->nState,_nSelect)) - { - _pUnoAny->pType = impl_getVoidType(); - _pUnoAny->pReserved = NULL; - _pUnoAny->pData = NULL; - } - else if (impl_state_isData(_pAnyPairDesc->nState,_nSelect)) - { - _pUnoAny->pType = _pAnyPairDesc->pType; - _pUnoAny->pReserved = impl_getDataPointer(_pAnyPairData); - _pUnoAny->pData = &_pUnoAny->pReserved; - } - else - { - _pUnoAny->pType = _pAnyPairDesc->pType; - _pUnoAny->pReserved = NULL; - _pUnoAny->pData = impl_getDataPointer(_pAnyPairData); - } - } - -// ----------------------------------------------------------------------------- - static inline - typelib_TypeDescriptionReference* - anypair_test_assigned_type( typelib_TypeDescriptionReference* _pOldType, - typelib_TypeDescriptionReference* _pNewType) - { - typelib_TypeDescriptionReference* pResult; - if ( _pNewType->eTypeClass == typelib_TypeClass_VOID) - pResult = _pOldType; - - else if (_pOldType->eTypeClass == typelib_TypeClass_VOID || _pOldType->eTypeClass == typelib_TypeClass_ANY ) - pResult = _pNewType; - - else if ( typelib_typedescriptionreference_equals(_pOldType,_pNewType) ) - pResult = _pOldType; - - else - pResult = NULL; - - return pResult; - } - -// ----------------------------------------------------------------------------- - static - sal_Bool anypair_any_assign_Data( cfgmgr_AnyPair_Desc* _pAnyPairDesc, - const void ** _pAnyPairData, - sal_uInt8 _nSelect, - uno_Any const *_pUnoAny) - { - typelib_TypeDescriptionReference* pOldType = _pAnyPairDesc->pType; - typelib_TypeDescriptionReference* pNewType = anypair_test_assigned_type(pOldType,_pUnoAny->pType); - - if (pNewType != NULL) - { - uno_Any aTmpAny; - anypair_Data_fill_Any(&aTmpAny,_pAnyPairDesc,_pAnyPairData,_nSelect); - - typelib_typedescriptionreference_acquire(aTmpAny.pType); - - uno_type_any_assign(&aTmpAny, - _pUnoAny->pData, - _pUnoAny->pType, - reinterpret_cast< uno_AcquireFunc >( uno::cpp_acquire ), - reinterpret_cast< uno_AcquireFunc >( uno::cpp_release )); - - sal_uInt8 nNewState = anypair_any_set_Data(_pAnyPairData,_nSelect,&aTmpAny); - impl_state_setState(&_pAnyPairDesc->nState, nNewState, _nSelect); - - uno_any_destruct( - &aTmpAny, - reinterpret_cast< uno_ReleaseFunc >(uno::cpp_release)); - - if (pNewType != pOldType) - { - typelib_typedescriptionreference_acquire(pNewType); - typelib_typedescriptionreference_release(pOldType); - _pAnyPairDesc->pType = pNewType; - } - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(_pAnyPairDesc,_nSelect) == !impl_Any_hasValue(_pUnoAny) ); - CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPairDesc->pType,pNewType) ); - } - else - OSL_ENSURE(false, "anypair_assign_XXX(): Cannot assign - Type mismatch"); - - return (pNewType != NULL); - } - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - void anypair_construct_default(cfgmgr_AnyPair * _pAnyPair) - { - CFG_PRECOND( _pAnyPair != NULL ); - - anypair_default_construct_Desc(&_pAnyPair->desc); - anypair_empty_set_Data(&_pAnyPair->first); - anypair_empty_set_Data(&_pAnyPair->second); - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_BOTH) ); - CFG_POSTCOND( cfgmgr_AnyPair_isEmpty(&_pAnyPair->desc) ); - } - -// ----------------------------------------------------------------------------- - void anypair_construct_type(cfgmgr_AnyPair * _pAnyPair, typelib_TypeDescriptionReference* _pType) - { - CFG_PRECOND( _pAnyPair != NULL ); - CFG_PRECOND( _pType != NULL ); - - anypair_type_construct_Desc(&_pAnyPair->desc, _pType); - anypair_empty_set_Data(&_pAnyPair->first); - anypair_empty_set_Data(&_pAnyPair->second); - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_BOTH) ); - CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pType) ); - } - -// ----------------------------------------------------------------------------- - void anypair_construct_first(cfgmgr_AnyPair * _pAnyPair, uno_Any const *_pUnoAny) - { - CFG_PRECOND( _pAnyPair != NULL ); - CFG_PRECOND( _pUnoAny != NULL ); - - anypair_type_construct_Desc(&_pAnyPair->desc, _pUnoAny->pType); - - _pAnyPair->desc.nState = anypair_any_set_Data (&_pAnyPair->first, cfgmgr_SELECT_FIRST, _pUnoAny); - - anypair_empty_set_Data(&_pAnyPair->second); - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) == !impl_Any_hasValue(_pUnoAny) ); - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) ); - CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pUnoAny ->pType) ); - } - -// ----------------------------------------------------------------------------- - void anypair_construct_second(cfgmgr_AnyPair * _pAnyPair, uno_Any const *_pUnoAny) - { - CFG_PRECOND( _pAnyPair != NULL ); - CFG_PRECOND( _pUnoAny != NULL ); - - anypair_type_construct_Desc(&_pAnyPair->desc, _pUnoAny->pType); - - anypair_empty_set_Data(&_pAnyPair->first); - - _pAnyPair->desc.nState = anypair_any_set_Data (&_pAnyPair->second, cfgmgr_SELECT_SECOND, _pUnoAny); - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) ); - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) == !impl_Any_hasValue(_pUnoAny) ); - CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pUnoAny ->pType) ); - } - -// ----------------------------------------------------------------------------- - // if type not equal, you got false and the struct contains undefined values - sal_Bool anypair_construct(cfgmgr_AnyPair * _pAnyPair, uno_Any const * _pFirstAny, uno_Any const *_pSecondAny) - { - CFG_PRECOND( _pAnyPair != NULL ); - CFG_PRECOND( _pFirstAny != NULL ); - CFG_PRECOND( _pSecondAny != NULL ); - - bool bHasFirst = impl_Any_hasValue(_pFirstAny); - bool bHasSecond = impl_Any_hasValue(_pSecondAny); - - if (bHasFirst && bHasSecond) - { - if ( ! typelib_typedescriptionreference_equals(_pFirstAny->pType,_pSecondAny->pType)) - { - OSL_ENSURE(false, "anypair_construct(): Cannot construct - Different types"); - return false; - } - } - - anypair_type_construct_Desc(&_pAnyPair->desc, bHasFirst ? _pFirstAny->pType : _pSecondAny->pType); - - sal_uInt8 nState = 0; - - nState |= anypair_any_set_Data (&_pAnyPair->first, cfgmgr_SELECT_FIRST, _pFirstAny); - nState |= anypair_any_set_Data (&_pAnyPair->second, cfgmgr_SELECT_SECOND, _pSecondAny); - - _pAnyPair->desc.nState = nState; - - CFG_POSTCOND((bHasFirst || bHasSecond) == !cfgmgr_AnyPair_isEmpty(&_pAnyPair->desc) ); - CFG_POSTCOND( bHasFirst == !cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) ); - CFG_POSTCOND( bHasSecond == !cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) ); - CFG_POSTCOND( !bHasFirst || typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pFirstAny ->pType) ); - CFG_POSTCOND( !bHasSecond || typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pSecondAny->pType) ); - - return true; - } - -// ----------------------------------------------------------------------------- - void anypair_copy_construct(cfgmgr_AnyPair* _pAnyPair, cfgmgr_AnyPair const * _pAnyPairFrom) - { - CFG_PRECOND( _pAnyPair != NULL ); - CFG_PRECOND( _pAnyPairFrom != NULL ); - - anypair_type_construct_Desc(&_pAnyPair->desc, _pAnyPairFrom->desc.pType); - - sal_uInt8 nState = 0; - - nState |= anypair_copy_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST, - &_pAnyPairFrom->desc, &_pAnyPairFrom->first ); - - nState |= anypair_copy_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND, - &_pAnyPairFrom->desc, &_pAnyPairFrom->second ); - - _pAnyPair->desc.nState = nState; - - OSL_ENSURE(_pAnyPairFrom->desc.nState == nState, "Unexpected: Copy changes state"); - CFG_POSTCOND( typelib_typedescriptionreference_equals(_pAnyPair->desc.pType,_pAnyPairFrom->desc.pType) ); - } - -// ----------------------------------------------------------------------------- - void anypair_destruct(cfgmgr_AnyPair* _pAnyPair) - { - CFG_PRECOND( _pAnyPair != NULL ); - - anypair_clear_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST, &_pAnyPair->desc); - anypair_clear_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND, &_pAnyPair->desc); - anypair_destruct_Desc(&_pAnyPair->desc ); - } - -// ----------------------------------------------------------------------------- - sal_Bool anypair_assign_first(cfgmgr_AnyPair* _pAnyPair, uno_Any const * _pUnoAny) - { - CFG_PRECOND( _pAnyPair != NULL ); - CFG_PRECOND( _pUnoAny != NULL ); - - return anypair_any_assign_Data(&_pAnyPair->desc, &_pAnyPair->first, cfgmgr_SELECT_FIRST, _pUnoAny); - } - -// ----------------------------------------------------------------------------- - sal_Bool anypair_assign_second(cfgmgr_AnyPair* _pAnyPair, uno_Any const * _pUnoAny) - { - CFG_PRECOND( _pAnyPair != NULL ); - CFG_PRECOND( _pUnoAny != NULL ); - - return anypair_any_assign_Data(&_pAnyPair->desc, &_pAnyPair->second, cfgmgr_SELECT_SECOND, _pUnoAny); - } - -// ----------------------------------------------------------------------------- - void anypair_assign(cfgmgr_AnyPair* _pAnyPair, cfgmgr_AnyPair const * _pAnyPairFrom) - { - if (_pAnyPair != _pAnyPairFrom) - { - anypair_destruct(_pAnyPair); - anypair_copy_construct(_pAnyPair, _pAnyPairFrom); - } - } - -// ----------------------------------------------------------------------------- - void anypair_clear_first(cfgmgr_AnyPair* _pAnyPair) - { - CFG_PRECOND( _pAnyPair != NULL ); - - anypair_clear_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST, &_pAnyPair->desc); - impl_state_setNull(&_pAnyPair->desc.nState, cfgmgr_SELECT_FIRST); - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_FIRST) ); - } - -// ----------------------------------------------------------------------------- - void anypair_clear_second(cfgmgr_AnyPair* _pAnyPair) - { - CFG_PRECOND( _pAnyPair != NULL ); - - anypair_clear_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND, &_pAnyPair->desc ); - impl_state_setNull(&_pAnyPair->desc.nState, cfgmgr_SELECT_SECOND); - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_SECOND) ); - } - -// ----------------------------------------------------------------------------- - void anypair_clear_values(cfgmgr_AnyPair* _pAnyPair) - { - CFG_PRECOND( _pAnyPair != NULL ); - - anypair_clear_Data(&_pAnyPair->first, cfgmgr_SELECT_FIRST, &_pAnyPair->desc); - anypair_clear_Data(&_pAnyPair->second, cfgmgr_SELECT_SECOND, &_pAnyPair->desc ); - impl_state_setNull(&_pAnyPair->desc.nState, cfgmgr_SELECT_BOTH); - - CFG_POSTCOND( cfgmgr_AnyPair_isNull(&_pAnyPair->desc,cfgmgr_SELECT_BOTH) ); - } - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - static - inline - uno::Any anypair_Data_toAny(cfgmgr_AnyPair_Desc const* _pAnyPairDesc, - const void * const* _pAnyPairData, - sal_uInt8 _nSelect) - { - uno_Any aTmpAny; - anypair_Data_fill_Any(&aTmpAny,_pAnyPairDesc,_pAnyPairData,_nSelect); - - return uno::Any( aTmpAny.pData, aTmpAny.pType ); - } - -// ----------------------------------------------------------------------------- - AnyPair::AnyPair(uno::Type const& _aType) // one Type, any's are null - { - anypair_construct_type(&m_aAnyPair, _aType.getTypeLibType()); - } - -// ----------------------------------------------------------------------------- - AnyPair::AnyPair(uno::Any const& _aAny, SelectMember _select) - { - switch (_select) - { - case SELECT_FIRST: anypair_construct_first(&m_aAnyPair,&_aAny); break; - case SELECT_SECOND: anypair_construct_second(&m_aAnyPair,&_aAny); break; - case SELECT_BOTH: OSL_VERIFY( anypair_construct(&m_aAnyPair,&_aAny,&_aAny) ); break; - - default: OSL_ENSURE(false, "AnyPair: Unknown member selector"); - anypair_construct_default(&m_aAnyPair); break; - } - } - -// ----------------------------------------------------------------------------- - AnyPair::AnyPair(uno::Any const& _aAny, uno::Any const& _aAny2) SAL_THROW((lang::IllegalArgumentException)) - { - if (!anypair_construct(&m_aAnyPair,&_aAny, &_aAny2)) - { - throw lang::IllegalArgumentException(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AnyPair: Type mismatch in constructor.")),NULL,-1); - } - } - -// ----------------------------------------------------------------------------- - // copy-ctor - AnyPair::AnyPair(AnyPair const& _aOther) - { - anypair_copy_construct(&m_aAnyPair, &_aOther.m_aAnyPair); - } - -// ----------------------------------------------------------------------------- - // assign operator - AnyPair& AnyPair::operator=(AnyPair const& _aOther) - { - anypair_assign(&m_aAnyPair, &_aOther.m_aAnyPair); - return *this; - } - -// ----------------------------------------------------------------------------- - // d-tor - AnyPair::~AnyPair() - { - anypair_destruct(&m_aAnyPair); - } - - -// ----------------------------------------------------------------------------- - sal_Bool AnyPair::setFirst(uno::Any const& _aAny) - { - return anypair_assign_first(&m_aAnyPair,&_aAny); - } - -// ----------------------------------------------------------------------------- - sal_Bool AnyPair::setSecond(uno::Any const& _aAny) - { - return anypair_assign_second(&m_aAnyPair,&_aAny); - } - -// ----------------------------------------------------------------------------- - void AnyPair::clear(SelectMember _select) - { - switch (_select) - { - case SELECT_FIRST: anypair_clear_first(&m_aAnyPair); break; - case SELECT_SECOND: anypair_clear_second(&m_aAnyPair); break; - case SELECT_BOTH: anypair_clear_values(&m_aAnyPair); break; - - default: OSL_ENSURE(false, "AnyPair: Unknown member selector"); - break; - } - } - -// ----------------------------------------------------------------------------- - uno::Type AnyPair::getValueType() const - { - return uno::Type(m_aAnyPair.desc.pType); - } - -// ----------------------------------------------------------------------------- - uno::Any AnyPair::getFirst() const - { - return anypair_Data_toAny( &m_aAnyPair.desc, &m_aAnyPair.first, cfgmgr_SELECT_FIRST ); - } -// ----------------------------------------------------------------------------- - uno::Any AnyPair::getSecond() const - { - return anypair_Data_toAny( &m_aAnyPair.desc, &m_aAnyPair.second, cfgmgr_SELECT_SECOND ); - } - -// ----------------------------------------------------------------------------- - uno::Any AnyPair::getValue(SelectMember _select) const - { - switch (_select) - { - case SELECT_FIRST: return getFirst(); - case SELECT_SECOND: return getSecond(); - - default: OSL_ENSURE(false, "AnyPair: Unknown member selector"); - case SELECT_BOTH: OSL_ENSURE(false, "AnyPair: Cannot get value - Invalid selector"); - return uno::Any(); - } - } - -// ----------------------------------------------------------------------------- - -} // namespace - diff --git a/configmgr/source/misc/bootstrap.cxx b/configmgr/source/misc/bootstrap.cxx deleted file mode 100644 index 4e747153d32c..000000000000 --- a/configmgr/source/misc/bootstrap.cxx +++ /dev/null @@ -1,704 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: bootstrap.cxx,v $ - * $Revision: 1.35 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include <stdio.h> - -#include "bootstrap.hxx" - -#ifndef CONFIGMGR_API_FACTORY_HXX_ -#include "confapifactory.hxx" -#endif -#include "serviceinfohelper.hxx" -#include "matchlocale.hxx" -#include "tracer.hxx" -#include <cppuhelper/component_context.hxx> -#include <rtl/bootstrap.hxx> -#include <rtl/ustring.hxx> -#include <rtl/ustrbuf.hxx> -#include <osl/file.hxx> -#include <osl/process.h> -#include <osl/diagnose.h> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/configuration/MissingBootstrapFileException.hpp> -#include <com/sun/star/configuration/InvalidBootstrapFileException.hpp> -#include <com/sun/star/configuration/InstallationIncompleteException.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> - -// --------------------------------------------------------------------------------------- -// legacy argument names -#define ARGUMENT_LOCALE_COMPAT "locale" -#define ARGUMENT_ASYNC_COMPAT "lazywrite" -#define ARGUMENT_SERVERTYPE_COMPAT "servertype" - -// legacy servertype setting -#define SETTING_SERVERTYPE_COMPAT "ServerType" -#define BOOTSTRAP_SERVERTYPE_COMPAT CONTEXT_ITEM_PREFIX_ SETTING_SERVERTYPE_COMPAT - -#define SERVERTYPE_UNO_COMPAT "uno" -#define SERVERTYPE_PLUGIN_COMPAT "plugin" -// --------------------------------------------------------------------------------------- - -#define NAME( N ) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(N)) -#define ITEM( N ) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(N)) -// --------------------------------------------------------------------------------------- -// ------------------------------------------------------------------------- - -// --------------------------------------------------------------------------------------- -namespace configmgr -{ -// --------------------------------------------------------------------------------------- -// --------------------------------------------------------------------------------------- - static void convertToBool(const uno::Any& aValue, sal_Bool& bValue) - { - rtl::OUString aStrValue; - if (aValue >>= aStrValue) - { - if (aStrValue.equalsIgnoreAsciiCaseAscii("true")) - { - bValue = sal_True; - } - else if (aStrValue.equalsIgnoreAsciiCaseAscii("false")) - { - bValue = sal_False; - } - } - } - // ---------------------------------------------------------------------------------- - const sal_Char k_BootstrapContextImplName[] = "com.sun.star.comp.configuration.bootstrap.BootstrapContext" ; - const sal_Char k_BootstrapContextServiceName[] = "com.sun.star.configuration.bootstrap.BootstrapContext" ; - - // ------------------------------------------------------------------------- - static sal_Char const * const k_BootstrapContextServiceNames [] = - { - k_BootstrapContextServiceName, - 0 - }; - static const ServiceImplementationInfo k_BootstrapContextServiceInfo = - { - k_BootstrapContextImplName, - k_BootstrapContextServiceNames, - 0 - }; - static const SingletonRegistrationInfo k_BootstrapContextSingletonInfo = - { - A_BootstrapContextSingletonName, - k_BootstrapContextImplName, - k_BootstrapContextServiceName, - 0 - }; -// --------------------------------------------------------------------------------------- -// --------------------------------------------------------------------------------------- - uno::Reference<uno::XInterface> SAL_CALL - instantiateBootstrapContext( uno::Reference< uno::XComponentContext > const& xTargetContext ) - { - uno::Reference< uno::XComponentContext > xContext = UnoContextTunnel::recoverContext(xTargetContext); - - BootstrapContext * pContext = new BootstrapContext(xContext); - uno::Reference< uno::XComponentContext > xResult(pContext); - - pContext->initialize(); - - return uno::Reference< uno::XInterface >( xResult, uno::UNO_QUERY ); - } - - const SingletonRegistrationInfo * getBootstrapContextSingletonInfo() - { - return &k_BootstrapContextSingletonInfo; - } - const ServiceRegistrationInfo * getBootstrapContextServiceInfo() - { - return getRegistrationInfo(&k_BootstrapContextServiceInfo); - } -// --------------------------------------------------------------------------------------- -// --------------------------------------------------------------------------- - - static - inline - cppu::ContextEntry_Init makeEntry(beans::NamedValue const & aOverride) - { - return cppu::ContextEntry_Init(aOverride.Name,aOverride.Value); - } -// --------------------------------------------------------------------------- - - static - cppu::ContextEntry_Init makeSingleton(SingletonRegistrationInfo const * pSingletonInfo) - { - OSL_ASSERT( pSingletonInfo && - pSingletonInfo->singletonName && - pSingletonInfo->instantiatedServiceName ); - - rtl::OUStringBuffer aSingletonName; - aSingletonName.appendAscii( RTL_CONSTASCII_STRINGPARAM(SINGLETON_) ); - aSingletonName.appendAscii(pSingletonInfo->singletonName); - - rtl::OUString const aServiceName = rtl::OUString::createFromAscii(pSingletonInfo->instantiatedServiceName); - - return cppu::ContextEntry_Init(aSingletonName.makeStringAndClear(), uno::makeAny(aServiceName), true); - } -// --------------------------------------------------------------------------- - -uno::Reference< uno::XComponentContext > BootstrapContext::createWrapper(uno::Reference< uno::XComponentContext > const & _xContext, uno::Sequence < beans::NamedValue > const & _aOverrides) -{ - std::vector< cppu::ContextEntry_Init > aContextEntries; - aContextEntries.reserve(_aOverrides.getLength() + 5); - - // marker + bootstrap context - aContextEntries.push_back( cppu::ContextEntry_Init(NAME(CONTEXT_ITEM_IS_WRAPPER_CONTEXT), uno::makeAny(sal_True)) ); - aContextEntries.push_back( cppu::ContextEntry_Init(NAME(CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT), uno::makeAny(sal_False)) ); - - aContextEntries.push_back( makeSingleton(getBootstrapContextSingletonInfo()) ); - - // singletons except for passthrough - if (!isPassthrough(_xContext)) - { - aContextEntries.push_back( makeSingleton(getDefaultProviderSingletonInfo()) ); - aContextEntries.push_back( makeSingleton(backend::getDefaultBackendSingletonInfo()) ); - } - - for (sal_Int32 i = 0; i<_aOverrides.getLength(); ++i) - aContextEntries.push_back( makeEntry(_aOverrides[i]) ); - - return cppu::createComponentContext(&aContextEntries.front(),aContextEntries.size(),_xContext); -} -// --------------------------------------------------------------------------- - -sal_Bool BootstrapContext::isWrapper(uno::Reference< uno::XComponentContext > const & _xContext) -{ - OSL_ASSERT(_xContext.is()); - if (!_xContext.is()) return false; - - uno::Any aSetting = _xContext->getValueByName( NAME(CONTEXT_ITEM_IS_WRAPPER_CONTEXT) ); - - if (!aSetting.hasValue()) return false; - - sal_Bool bValue = false; - OSL_VERIFY(aSetting >>= bValue); - - return bValue; -} -// --------------------------------------------------------------------------- -// --------------------------------------------------------------------------- - -BootstrapContext::BootstrapContext(uno::Reference< uno::XComponentContext > const & _xContext) -: ComponentContext(_xContext) -{ -} -// --------------------------------------------------------------------------- - -BootstrapContext::~BootstrapContext() -{ -} -// --------------------------------------------------------------------------- - -void BootstrapContext::initialize() -{ - // get default Bootstrap URL - rtl::OUString sURL; - uno::Any aExplicitURL; - if ( this->lookupInContext(aExplicitURL,NAME(CONTEXT_ITEM_PREFIX_ SETTING_INIFILE)) ) - { - OSL_VERIFY(aExplicitURL >>= sURL); - } - else if (!rtl::Bootstrap::get(NAME(BOOTSTRAP_ITEM_INIFILE),sURL)) - { - sURL = getDefaultConfigurationBootstrapURL(); - } - - ComponentContext::initialize(sURL); -} -// --------------------------------------------------------------------------------------- - -rtl::OUString BootstrapContext::getDefaultConfigurationBootstrapURL() -{ - rtl::OUString url( - RTL_CONSTASCII_USTRINGPARAM( - "$OOO_BASE_DIR/program/" SAL_CONFIGFILE("configmgr"))); - rtl::Bootstrap::expandMacros(url); //TODO: detect failure - return url; -} -// --------------------------------------------------------------------------------------- - -rtl::OUString BootstrapContext::makeContextName(rtl::OUString const & _aName) -{ - // check that it isn't long already - OSL_ENSURE(!_aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_MODULE_PREFIX_) ), - "configmgr::BootstrapContext: passing argument in long context form won't work"); - - return NAME(CONTEXT_ITEM_PREFIX_).concat(_aName); -} -// --------------------------------------------------------------------------- - -rtl::OUString BootstrapContext::makeBootstrapName(rtl::OUString const & _aName) -{ - // check if already is short - if (!_aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_) ) ) - { - OSL_TRACE( "configmgr: Cannot map name to bootstrap name: %s", - rtl::OUStringToOString(_aName,RTL_TEXTENCODING_ASCII_US).getStr() ); - return _aName; - } - return NAME(BOOTSTRAP_ITEM_PREFIX_).concat(_aName.copy(RTL_CONSTASCII_LENGTH(CONTEXT_ITEM_PREFIX_))); -} -// --------------------------------------------------------------------------- - -uno::Any SAL_CALL - BootstrapContext::getValueByName( const rtl::OUString& aName ) - throw (uno::RuntimeException) -{ - sal_Bool const bOurName = aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_MODULE_PREFIX_) ); - - if (bOurName) - { - if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_BOOTSTRAP_ERROR) ) ) - return this->makeBootstrapException(); - - if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_INIFILE) ) ) - return uno::makeAny( this->getBootstrapURL() ); - - if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_IS_BOOTSTRAP_CONTEXT) ) ) - return uno::makeAny( sal_True ); - } - else if (aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(SINGLETON_ A_BootstrapContextSingletonName) ) ) - { - return uno::makeAny( uno::Reference< uno::XComponentContext >(this) ); - } - - uno::Any aResult; - - bool bFound = lookupInContext ( aResult, aName ); - - if (!bFound && bOurName) // requires: CONTEXT_ITEM_PREFIX_ starts with CONTEXT_MODULE_PREFIX_ - { - if ( aName.matchIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_) ) ) - { - bFound = lookupInBootstrap( aResult, makeBootstrapName(aName) ); - } - } - return aResult; -} - -// --------------------------------------------------------------------------- -// class ContextReader -// --------------------------------------------------------------------------- - - ContextReader::ContextReader(uno::Reference< uno::XComponentContext > const & context) - : m_basecontext(context) - , m_fullcontext() - { - OSL_ENSURE(context.is(), "ERROR: trying to create reader on NULL context\n"); - if (context.is()) - { - uno::Any aBootstrapContext = context->getValueByName( SINGLETON(A_BootstrapContextSingletonName) ); - aBootstrapContext >>= m_fullcontext; - } - } -// --------------------------------------------------------------------------- - - uno::Reference< lang::XMultiComponentFactory > ContextReader::getServiceManager() const - { - OSL_ASSERT(m_basecontext.is()); - return m_basecontext->getServiceManager(); - } -// --------------------------------------------------------------------------- - inline - uno::Any ContextReader::getSetting(rtl::OUString const & _aSetting) const - { - OSL_ASSERT(m_basecontext.is()); - return getBestContext()->getValueByName(_aSetting); - } - - inline - sal_Bool ContextReader::hasSetting(rtl::OUString const & _aSetting) const - { - return getSetting(_aSetting).hasValue(); - } - - inline - sal_Bool ContextReader::getBoolSetting(rtl::OUString const & _aSetting, sal_Bool bValue = false) const - { - uno::Any aValue = getSetting(_aSetting); - if (!(aValue >>= bValue)) - convertToBool(aValue, bValue); - - return bValue; - } - - inline - rtl::OUString ContextReader::getStringSetting(rtl::OUString const & _aSetting, rtl::OUString aValue = rtl::OUString()) const - { - getSetting(_aSetting) >>= aValue; - return aValue; - } -// --------------------------------------------------------------------------------------- - - sal_Bool ContextReader::isUnoBackend() const - { - rtl::OUString aSettingName = NAME(BOOTSTRAP_SERVERTYPE_COMPAT); - - rtl::OUString aValue; - if (getSetting(aSettingName) >>= aValue) - { - return aValue.equalsAscii(SERVERTYPE_UNO_COMPAT); - } - else - { - return true; - } - } -// --------------------------------------------------------------------------------------- - - sal_Bool ContextReader::hasUnoBackendService() const - { - return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOSERVICE) ); - } - sal_Bool ContextReader::hasUnoBackendWrapper() const - { - return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOWRAPPER) ); - } - - sal_Bool ContextReader::hasLocale() const - { - return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW) ); - } - sal_Bool ContextReader::hasAsyncSetting() const - { - return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW) ); - } - sal_Bool ContextReader::hasOfflineSetting() const - { - return hasSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_OFFLINE) ); - } -// --------------------------------------------------------------------------------------- - - rtl::OUString ContextReader::getUnoBackendService() const - { - return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOSERVICE) ); - } - rtl::OUString ContextReader::getUnoBackendWrapper() const - { - return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_UNOWRAPPER) ); - } - - rtl::OUString ContextReader::getLocale() const - { - return getStringSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW) ); - } - sal_Bool ContextReader::getAsyncSetting() const - { - return getBoolSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW) ); - } - sal_Bool ContextReader::getOfflineSetting() const - { - return getBoolSetting( NAME(CONTEXT_ITEM_PREFIX_ SETTING_OFFLINE) ); - } - - // get a special setting - sal_Bool ContextReader::isAdminService() const - { - return getBoolSetting( NAME(CONTEXT_ITEM_ADMINFLAG) ); - } - - sal_Bool ContextReader::isBootstrapValid() const - { - return this->isUnoBackend() && - this->hasUnoBackendService() && - (this->hasUnoBackendWrapper() || !this->getOfflineSetting()); - } - - uno::Any ContextReader::getBootstrapError() const - { - return getSetting( NAME(CONTEXT_ITEM_BOOTSTRAP_ERROR) ); - } -// --------------------------------------------------------------------------------------- - - bool ContextReader::testAdminService(uno::Reference< uno::XComponentContext > const & context, bool bAdmin) - { - OSL_ASSERT(context.is()); - if (!context.is()) return false; - - uno::Any aSetting = context->getValueByName( NAME(CONTEXT_ITEM_ADMINFLAG) ); - - sal_Bool bValue = false; - bool bTest = (aSetting >>= bValue) && bValue; - - return bTest == bAdmin; - } -// --------------------------------------------------------------------------- -// --------------------------------------------------------------------------------------- - - bool ArgumentHelper::extractArgument(beans::NamedValue & rValue, const uno::Any & aOverride) - { - if ( ! (aOverride >>= rValue) ) - { - // it must be a PropertyValue, if it isn't a NamedValue - beans::PropertyValue aPV; - if ( !(aOverride >>= aPV) ) - return false; - - rValue.Name = aPV.Name; - rValue.Value = aPV.Value; - } - - return true; - } - -// --------------------------------------------------------------------------------------- - - bool ArgumentHelper::checkBackendArgument(beans::NamedValue const & aAdjustedValue) - { - bool isWrappable = - aAdjustedValue.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_ASYNC_NEW)) || - aAdjustedValue.Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ SETTING_LOCALE_NEW)); - - if (isWrappable) return false; - - m_bHasBackendArguments = true; - return true; - } -// --------------------------------------------------------------------------------------- - - bool ArgumentHelper::filterAndAdjustArgument(beans::NamedValue & rValue) - { - // handle old servertype argument and filter the 'plugin' value - if (rValue.Name.equalsAscii(ARGUMENT_SERVERTYPE_COMPAT)) - { - rtl::OUString aServertype; - if (! (rValue.Value >>= aServertype)) - return false; - - if (aServertype.equalsAscii(SERVERTYPE_PLUGIN_COMPAT)) - return false; - - rValue.Name = NAME(BOOTSTRAP_SERVERTYPE_COMPAT); - // check, if it is already there - uno::Any const aExistingValue = m_context->getValueByName(rValue.Name); - - if (aExistingValue.hasValue()) - return !(aExistingValue == rValue.Value); - - else - return !aServertype.equalsAscii(SERVERTYPE_UNO_COMPAT); - } - - // map old argument names for comatibility - else if (rValue.Name.equalsAscii(ARGUMENT_LOCALE_COMPAT)) - rValue.Name = NAME(SETTING_LOCALE_NEW); - - else if (rValue.Name.equalsAscii(ARGUMENT_ASYNC_COMPAT)) - rValue.Name = NAME(SETTING_ASYNC_NEW); - - // give the item a long name - rValue.Name = BootstrapContext::makeContextName(rValue.Name); - - // check, if it is already there - uno::Any const aExistingValue = m_context->getValueByName(rValue.Name); - - return ! (aExistingValue == rValue.Value); - } -// --------------------------------------------------------------------------------------- - - beans::NamedValue ArgumentHelper::makeAdminServiceOverride(sal_Bool bAdmin) - { - return beans::NamedValue( NAME(CONTEXT_ITEM_ADMINFLAG), uno::makeAny(bAdmin) ); - } -// --------------------------------------------------------------------------------------- -// --------------------------------------------------------------------------------------- -// - bootstrapping error checking helper -// --------------------------------------------------------------------------------------- -namespace { -// --------------------------------------------------------------------------------------- -// error handling -// --------------------------------------------------------------------------------------- - enum BootstrapResult - { - BOOTSTRAP_DATA_OK, - INCOMPLETE_BOOTSTRAP_DATA, - INCOMPLETE_BOOTSTRAP_FILE, - MISSING_BOOTSTRAP_FILE, - BOOTSTRAP_FAILURE - }; -// --------------------------------------------------------------------------------------- - static - rtl::OUString getFallbackErrorMessage( BootstrapResult _rc ) - { - rtl::OUString sMessage(RTL_CONSTASCII_USTRINGPARAM("The program cannot start. ")); - - switch (_rc) - { - case MISSING_BOOTSTRAP_FILE: - sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("A main configuration file is missing")); - break; - - case INCOMPLETE_BOOTSTRAP_FILE: - sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("A main configuration file is invalid")); - break; - - case INCOMPLETE_BOOTSTRAP_DATA: - sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Required bootstrap data is not available")); - break; - - default: - sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Unexpected bootstrap failure")); - break; - - case BOOTSTRAP_DATA_OK: - break; - } - sMessage += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" (No detailed error message available.)")); - - return sMessage; - } -// --------------------------------------------------------------------------------------- - - static - uno::Any impl_makeBootstrapException( BootstrapResult _rc, rtl::OUString const& _sMessage, rtl::OUString const& _sURL, uno::Reference< uno::XInterface > _xContext ) - { - rtl::OUString sMessage(_sMessage); - // ensure a message - if (sMessage.getLength()== 0) - { - OSL_ENSURE(false, "Bootstrap error message missing"); - - sMessage = getFallbackErrorMessage(_rc); - } - - // raise the error - switch (_rc) - { - case MISSING_BOOTSTRAP_FILE: - return uno::makeAny( com::sun::star::configuration::MissingBootstrapFileException(sMessage, _xContext, _sURL) ); - - case INCOMPLETE_BOOTSTRAP_FILE: - return uno::makeAny( com::sun::star::configuration::InvalidBootstrapFileException(sMessage, _xContext, _sURL) ); - - default: OSL_ENSURE(false, "Undefined BootstrapResult code"); - case INCOMPLETE_BOOTSTRAP_DATA: - case BOOTSTRAP_FAILURE: - return uno::makeAny( com::sun::star::configuration::CannotLoadConfigurationException(sMessage, _xContext) ); - - case BOOTSTRAP_DATA_OK: - break; - } - return uno::Any(); - } -// --------------------------------------------------------------------------------------- - - static - inline - bool urlExists(rtl::OUString const& _sURL) - { - osl::DirectoryItem aCheck; - return (osl::DirectoryItem::get(_sURL,aCheck) == osl::DirectoryItem::E_None); - } -// --------------------------------------------------------------------------------------- - - static - rtl::OUString buildBootstrapError( sal_Char const* _sWhat, rtl::OUString const& _sName, sal_Char const* _sHow) - { - rtl::OUStringBuffer sMessage; - - sMessage.appendAscii(RTL_CONSTASCII_STRINGPARAM("The program cannot start. ")); - sMessage.appendAscii(_sWhat); - sMessage.appendAscii(RTL_CONSTASCII_STRINGPARAM(" '")).append(_sName).appendAscii(RTL_CONSTASCII_STRINGPARAM("' ")); - sMessage.appendAscii(_sHow).appendAscii(". "); - - return sMessage.makeStringAndClear(); - } -// --------------------------------------------------------------------------------------- - - BootstrapResult getBootstrapErrorMessage(BootstrapContext const & aContext, ContextReader const & aSettings, rtl::OUString& _rMessage, rtl::OUString& _rIniFile ) - { - BootstrapResult eResult = BOOTSTRAP_DATA_OK; - - _rIniFile = aContext.getBootstrapURL(); - - if ( !urlExists(_rIniFile) ) - { - _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is missing"); - eResult = MISSING_BOOTSTRAP_FILE; - } - else if (!aSettings.isUnoBackend()) - { - _rMessage = buildBootstrapError("The configuration file ",_rIniFile.copy(1+_rIniFile.lastIndexOf('/')),"is for an older version of the configuration database"); - eResult = INCOMPLETE_BOOTSTRAP_FILE; - } - else if (!aSettings.isBootstrapValid() ) - { - _rMessage = buildBootstrapError("Needed information to access",rtl::OUString::createFromAscii("application"), "configuration data is missing"); - eResult = INCOMPLETE_BOOTSTRAP_DATA; - } - - return eResult; - } -// --------------------------------------------------------------------------------------- -} // anonymous namespace -// --------------------------------------------------------------------------------------- -uno::Any BootstrapContext::makeBootstrapException() -{ - ContextReader aReader(this); - - if (aReader.isBootstrapValid()) return uno::Any(); - - rtl::OUString sMessage,sURL; - - BootstrapResult rc = getBootstrapErrorMessage(*this,aReader,sMessage,sURL); - - return impl_makeBootstrapException(rc,sMessage,sURL,*this); -} -// --------------------------------------------------------------------------- -rtl::OUString SAL_CALL - BootstrapContext::getImplementationName(void) - throw (uno::RuntimeException) -{ - return ServiceInfoHelper(&k_BootstrapContextServiceInfo).getImplementationName() ; -} -//------------------------------------------------------------------------------ - -sal_Bool SAL_CALL - BootstrapContext::supportsService(const rtl::OUString& aServiceName) - throw (uno::RuntimeException) -{ - return ServiceInfoHelper(&k_BootstrapContextServiceInfo).supportsService(aServiceName) ; -} -//------------------------------------------------------------------------------ -uno::Sequence<rtl::OUString> SAL_CALL - BootstrapContext::getSupportedServiceNames(void) - throw (uno::RuntimeException) -{ - return ServiceInfoHelper(&k_BootstrapContextServiceInfo).getSupportedServiceNames() ; -} -// --------------------------------------------------------------------------------------- -} // namespace configmgr - - diff --git a/configmgr/source/misc/bootstrapcontext.cxx b/configmgr/source/misc/bootstrapcontext.cxx deleted file mode 100644 index 07447fe835d5..000000000000 --- a/configmgr/source/misc/bootstrapcontext.cxx +++ /dev/null @@ -1,417 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: bootstrapcontext.cxx,v $ - * $Revision: 1.9 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "bootstrapcontext.hxx" -#include "datalock.hxx" -#include <uno/current_context.hxx> -#include <cppuhelper/implbase2.hxx> -#include <cppuhelper/exc_hlp.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include "utility.hxx" - -namespace configmgr -{ -// --------------------------------------------------------------------------- -#define IMPL_ITEM_PREFIX_ "/implementations/com.sun.star.com.configuration.bootstrap.ComponentContext/" -#define IMPL_ITEM_PASSTHRU IMPL_ITEM_PREFIX_"isPassthrough" -#define IMPL_ITEM_BASECONTEXT IMPL_ITEM_PREFIX_"theBaseContext" -#define A_SERVICEMANAGER "com.sun.star.lang.theServiceManager" -// --------------------------------------------------------------------------- - -#define OUSTR( text ) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( text ) ) -#define OU2ASCII( str ) ( rtl::OUStringToOString(str,RTL_TEXTENCODING_ASCII_US) .getStr() ) -// --------------------------------------------------------------------------- -#if 0 -static void testComplete() -{ - uno::Reference< uno::XInterface > test = * new ComponentContext(uno::Reference< uno::XComponentContext >,uno::Sequence < beans::NamedValue >(),true); -} -#endif -// --------------------------------------------------------------------------- - -ComponentContext::ComponentContext(uno::Reference< uno::XComponentContext > const & _xContext) -: cppu::WeakComponentImplHelper3 < uno::XComponentContext, uno::XCurrentContext, lang::XServiceInfo >(UnoApiLock::getLock()) -, m_xContext(_xContext) -, m_hBootstrapData(NULL) -, m_xServiceManager() -{ -} -// --------------------------------------------------------------------------- - -ComponentContext::~ComponentContext() -{ - if (m_hBootstrapData) rtl_bootstrap_args_close(m_hBootstrapData); -} -// --------------------------------------------------------------------------- - -void ComponentContext::initialize( const rtl::OUString& _aURL ) -{ - UnoApiLock aLock; - - OSL_ASSERT(!m_hBootstrapData); - m_hBootstrapData = rtl_bootstrap_args_open(_aURL.pData); - - uno::Reference< lang::XComponent > xOwner(m_xContext, uno::UNO_QUERY); - - if (xOwner.is()) DisposingForwarder::forward(xOwner,this); - - if (!m_xContext.is()) - { - OSL_ENSURE(rBHelper.bDisposed,"ComponentContext::initialize - Context unexpectedly missing"); - throw lang::DisposedException(OUSTR("Parent context has been disposed early"),*this); - } -} -// --------------------------------------------------------------------------- - -// ComponentHelper -void SAL_CALL ComponentContext::disposing() -{ - UnoApiLock aLock; - - m_xContext.clear(); - - if (m_hBootstrapData) - { - rtl_bootstrap_args_close(m_hBootstrapData); - m_hBootstrapData = NULL; - } -} -// --------------------------------------------------------------------------- - -rtl::OUString ComponentContext::getBootstrapURL() const -{ - rtl::OUString aResult; - - UnoApiLock aLock; - - if (m_hBootstrapData) - { - rtl_bootstrap_get_iniName_from_handle(m_hBootstrapData,&aResult.pData); - } - else - { - OSL_TRACE( "configmgr: No bootstrap data URL set"); - } - - return aResult; -} -// --------------------------------------------------------------------------- - -uno::Reference< lang::XMultiComponentFactory > SAL_CALL - ComponentContext::getServiceManager( ) - throw (uno::RuntimeException) -{ - UnoApiLock aLock; - - if (!m_xServiceManager.is()) - { - uno::Reference< uno::XComponentContext > xBase = basecontext(); - if (!xBase.is()) - throw lang::DisposedException(OUSTR("Parent context has been disposed"),*this); - - uno::Reference< lang::XMultiComponentFactory > xBaseServiceManager = xBase->getServiceManager(); - OSL_ENSURE( xBaseServiceManager.is(), "Base context has no service manager"); - - if (xBaseServiceManager.is()) - { - // create new smgr based on delegate's one - m_xServiceManager.set( - xBaseServiceManager->createInstanceWithContext( OUSTR("com.sun.star.comp.stoc.OServiceManagerWrapper"), xBase ), - uno::UNO_QUERY ); - // patch DefaultContext property of new one - uno::Reference< beans::XPropertySet > xProps( m_xServiceManager, uno::UNO_QUERY ); - OSL_ASSERT( xProps.is() ); - if (xProps.is()) - { - uno::Reference< XComponentContext > xThis( this ); - xProps->setPropertyValue( OUSTR("DefaultContext"), uno::makeAny( xThis ) ); - } - else - OSL_ENSURE(!m_xServiceManager.is(), "Cannot set Default Context of Service Manager Wrapper: no property set"); - } - } - return m_xServiceManager; -} -// --------------------------------------------------------------------------- - - -// --------------------------------------------------------------------------- - -sal_Bool ComponentContext::isPassthrough(uno::Reference< uno::XComponentContext > const & _xContext) -{ - OSL_ENSURE(_xContext.is(),"Unexpected NULL context"); - if (!_xContext.is()) return false; - - sal_Bool bValue = false; - _xContext->getValueByName(OUSTR(IMPL_ITEM_PASSTHRU)) >>= bValue; - return bValue; -} -// --------------------------------------------------------------------------- - -beans::NamedValue ComponentContext::makePassthroughMarker(sal_Bool bPassthrough) -{ - return beans::NamedValue(OUSTR(IMPL_ITEM_PASSTHRU),uno::makeAny(bPassthrough)); -} -// --------------------------------------------------------------------------- - -bool ComponentContext::lookupInContext( uno::Any & _rValue, const rtl::OUString& _aName ) const -{ - uno::Reference< uno::XComponentContext > xBase = basecontext(); - if (!xBase.is()) - throw lang::DisposedException(OUSTR("Parent context has been disposed"),const_cast<ComponentContext&>(*this)); - - if (_aName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( IMPL_ITEM_BASECONTEXT ))) - { - _rValue = uno::makeAny(xBase); - return true; - } - - uno::Any aCtxValue = xBase->getValueByName( _aName ); - - if (aCtxValue.hasValue()) - { - _rValue = aCtxValue; - return true; - } - else - return false; -} -// --------------------------------------------------------------------------- - -bool ComponentContext::lookupInBootstrap( uno::Any & _rValue, const rtl::OUString& _aName ) const -{ - UnoApiLock aLock; - rtl::OUString sResult; - if ( rtl_bootstrap_get_from_handle( m_hBootstrapData, _aName.pData, &sResult.pData, 0) ) - { - _rValue <<= sResult; - return true; - } - else - return false; -} -// --------------------------------------------------------------------------- -// --------------------------------------------------------------------------- - -static const char k_TunneledContext[] = "/services/com.sun.star.configuration.bootstrap.Context"; - -class UnoContextTunnel::Tunnel -: public ::cppu::WeakImplHelper2< uno::XCurrentContext, lang::XUnoTunnel > -{ - uno::Reference< uno::XComponentContext > m_xTunneledContext; - uno::Reference< uno::XCurrentContext > m_xOldContext; - uno::Any m_aFailure; -public: - Tunnel(uno::Reference< uno::XComponentContext > const & xTunneledContext, uno::Reference< uno::XCurrentContext > const & xOldContext) - : m_xTunneledContext(xTunneledContext) - , m_xOldContext(xOldContext) - , m_aFailure() - {} - - virtual uno::Any SAL_CALL - getValueByName( const rtl::OUString& name ) - throw (uno::RuntimeException) - { - if (name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(k_TunneledContext) ) ) - { - return uno::makeAny(m_xTunneledContext); - } - else if (m_xOldContext.is()) - { - return m_xOldContext->getValueByName(name); - } - else - { - return uno::Any(); - } - } - - virtual sal_Int64 SAL_CALL - getSomething( const uno::Sequence< sal_Int8 >& aIdentifier ) - throw (uno::RuntimeException) - { - if (getTunnelId() == aIdentifier) - return reinterpret_cast<sal_Int64>(&m_aFailure); - else - return 0; - } - - static uno::Any * getFailure(uno::Reference< lang::XUnoTunnel > const & xTunnel); - - static uno::Sequence< sal_Int8 > getTunnelId(); -}; -// --------------------------------------------------------------------------- - -uno::Sequence< sal_Int8 > UnoContextTunnel::Tunnel::getTunnelId() -{ - static ::cppu::OImplementationId aTunnelId; - return aTunnelId.getImplementationId(); -} -// --------------------------------------------------------------------------- - -uno::Any * UnoContextTunnel::Tunnel::getFailure(uno::Reference< lang::XUnoTunnel > const & xTunnel) -{ - if (xTunnel.is()) - { - if (sal_Int64 nSomething = xTunnel->getSomething(getTunnelId())) - { - return reinterpret_cast<uno::Any *>(nSomething); - } - } - return NULL; -} -// --------------------------------------------------------------------------- - -UnoContextTunnel::UnoContextTunnel() -: m_xOldContext( uno::getCurrentContext() ) -, m_xActiveTunnel() -{ -} -// --------------------------------------------------------------------------- - -UnoContextTunnel::~UnoContextTunnel() -{ - uno::setCurrentContext( m_xOldContext ); -} -// --------------------------------------------------------------------------- - -void UnoContextTunnel::passthru(uno::Reference< uno::XComponentContext > const & xContext) -{ - OSL_ASSERT( xContext.is() ); - if ( ComponentContext::isPassthrough(xContext) ) - { - this ->tunnel(xContext); - } - else - { - this->tunnel(NULL); - } -} -// --------------------------------------------------------------------------- - -void UnoContextTunnel::tunnel(uno::Reference< uno::XComponentContext > const & xContext) -{ - Tunnel * pNewTunnel = new Tunnel(xContext,m_xOldContext); - m_xActiveTunnel = pNewTunnel; - uno::setCurrentContext( pNewTunnel ); -} -// --------------------------------------------------------------------------- - -uno::Reference< uno::XComponentContext > UnoContextTunnel::recoverContext(uno::Reference< uno::XComponentContext > const & xFallback ) -{ - try - { - uno::Reference< uno::XCurrentContext > const xCurrContext = uno::getCurrentContext(); - - if (xCurrContext.is()) - { - rtl::OUString aName(RTL_CONSTASCII_USTRINGPARAM(k_TunneledContext)); - uno::Reference< uno::XComponentContext > xResult; - if (xCurrContext->getValueByName(aName) >>= xResult) - { - if (xResult.is()) - return xResult; - } - else - { - OSL_ASSERT( !xResult.is() ); - OSL_ENSURE( !xCurrContext->getValueByName(aName).hasValue(), - "Value in context has wrong type"); - } - } - } - catch (uno::Exception &) - { - OSL_ENSURE(false, "Unexpected: Exception from accessing current context"); - } - - return xFallback; -} -// --------------------------------------------------------------------------- - -uno::Any UnoContextTunnel::recoverFailure(bool bRaise) -{ - if (uno::Any * pFail = UnoContextTunnel::Tunnel::getFailure(m_xActiveTunnel)) - { - if (bRaise) - { - if (pFail->hasValue()) - cppu::throwException(*pFail); - else - throw; - } - return *pFail; - } - - return uno::Any(); -} -// --------------------------------------------------------------------------- - -bool UnoContextTunnel::tunnelFailure(uno::Any const & aException, bool bRaise) -{ - OSL_ASSERT( !aException.hasValue() || aException.getValueTypeClass() == uno::TypeClass_EXCEPTION ); - - uno::Reference< lang::XUnoTunnel > xTunnel( uno::getCurrentContext(), uno::UNO_QUERY ); - - if (uno::Any * pFail = Tunnel::getFailure(xTunnel)) - { - *pFail = aException; - - if (bRaise && aException.hasValue()) - cppu::throwException(aException); - - if (bRaise) throw; - return true; - } - else - { - if (bRaise) throw; - return false; - } -} -// --------------------------------------------------------------------------- -// --------------------------------------------------------------------------- -void DisposingForwarder::disposing( lang::EventObject const & /*rSource*/ ) -throw (uno::RuntimeException) -{ - m_xTarget->dispose(); - m_xTarget.clear(); -} -// --------------------------------------------------------------------------- -// --------------------------------------------------------------------------- -} // namespace config - - diff --git a/configmgr/source/misc/bufferedfile.cxx b/configmgr/source/misc/bufferedfile.cxx deleted file mode 100644 index a3170bbde833..000000000000 --- a/configmgr/source/misc/bufferedfile.cxx +++ /dev/null @@ -1,133 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: bufferedfile.cxx,v $ - * $Revision: 1.7 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include <string.h> -#include "bufferedfile.hxx" - -#include "filehelper.hxx" - -#include <algorithm> - - -namespace configmgr -{ - -BufferedOutputFile::BufferedOutputFile( rtl::OUString const& aFileURL, sal_uInt32 nBufferSizeHint ) -: m_pFile(new osl::File(aFileURL)) -, m_buffer() -{ - m_buffer.reserve( nBufferSizeHint ? nBufferSizeHint : 512 ); -} - -BufferedOutputFile::~BufferedOutputFile () -{ - delete m_pFile; -} - - -BufferedOutputFile::RC BufferedOutputFile::open( sal_uInt32 uFlags ) -{ - if (!m_pFile) return E_BADF; - - return m_pFile->open(uFlags); -} - -BufferedOutputFile::RC BufferedOutputFile::close() -{ - if (!m_pFile) return E_BADF; - - RC rc = this->sync(); - RC rc2 = m_pFile->close(); - - delete m_pFile, m_pFile = 0; - if (rc == E_None) - rc = rc2; - return rc; -} - - -//BufferedOutputFile::RC BufferedOutputFile::getPos( sal_uInt64& uPos ) - -BufferedOutputFile::RC BufferedOutputFile::write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten) -{ - if (!m_pFile) return E_BADF; - - if (uBytesToWrite > m_buffer.max_size()-m_buffer.size()) - { - // write big chunks natively - RC rc = this->sync(); - if (rc == E_None) - { - OSL_ASSERT(m_buffer.empty()); - rc = m_pFile->write(pBuffer, uBytesToWrite, rBytesWritten); - } - return rc; - } - - // FIXME: handle out-out-memory here - const sal_uInt8 * data = static_cast<const sal_uInt8 *>(pBuffer); - m_buffer.insert(m_buffer.end(), data, data + uBytesToWrite); - rBytesWritten = uBytesToWrite; - - return E_None; -} - -BufferedOutputFile::RC BufferedOutputFile::sync() -{ - if (!m_pFile) return E_BADF; - - sal_uInt64 size = m_buffer.size(); - sal_uInt64 written = 0; - - RC rc = m_pFile->write(&m_buffer.front(),size,written); - - if (rc != E_None) - return rc; - - // we don't support special files where multiple write passes are needed - if (written < size) - { - // but we try our best to stay consistent - m_buffer.erase(m_buffer.begin(), - m_buffer.end() + sal::static_int_cast<sal_uInt32>( written )); - - return E_IO; - } - - m_buffer.clear(); - - return E_None; -} - -} // namespace configmgr - diff --git a/configmgr/source/misc/configinteractionhandler.cxx b/configmgr/source/misc/configinteractionhandler.cxx deleted file mode 100644 index 34ca0e505e9a..000000000000 --- a/configmgr/source/misc/configinteractionhandler.cxx +++ /dev/null @@ -1,115 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: configinteractionhandler.cxx,v $ - * $Revision: 1.6 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "sal/config.h" - -#include "configinteractionhandler.hxx" - -#include "com/sun/star/task/XInteractionHandler.hpp" -#include "com/sun/star/uno/Any.hxx" -#include "com/sun/star/uno/Reference.hxx" -#include "com/sun/star/uno/RuntimeException.hpp" -#include "com/sun/star/uno/XCurrentContext.hpp" -#include "cppuhelper/implbase1.hxx" -#include "rtl/string.h" -#include "rtl/ustring.h" -#include "rtl/ustring.hxx" -#include "uno/current_context.hxx" - -namespace { - -namespace css = com::sun::star; - -static char const INTERACTION_HANDLER[] = "configuration.interaction-handler"; - -} - -namespace configmgr { namespace apihelper { - -class ConfigurationInteractionHandler::Context: - public cppu::WeakImplHelper1< css::uno::XCurrentContext > -{ -public: - explicit Context(ConfigurationInteractionHandler * parent): - m_parent(parent) {} - - virtual css::uno::Any SAL_CALL getValueByName(rtl::OUString const & name) - throw (css::uno::RuntimeException) - { - return - name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(INTERACTION_HANDLER)) - ? m_handler : m_parent->getPreviousContextValue(name); - } - - void setInteractionHandler( - css::uno::Reference< css::task::XInteractionHandler > const & handler) - { m_handler <<= handler; } - -private: - Context(Context &); // not defined - void operator =(Context &); // not defined - - virtual ~Context() {} - - ConfigurationInteractionHandler * m_parent; - css::uno::Any m_handler; -}; - -ConfigurationInteractionHandler::ConfigurationInteractionHandler(): - m_context(new Context(this)), m_layer(m_context.get()) {} - -ConfigurationInteractionHandler::~ConfigurationInteractionHandler() {} - -css::uno::Reference< css::task::XInteractionHandler > -ConfigurationInteractionHandler::get() const { - return css::uno::Reference< css::task::XInteractionHandler >( - getPreviousContextValue( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(INTERACTION_HANDLER))), - css::uno::UNO_QUERY); -} - -void ConfigurationInteractionHandler::setRecursive( - css::uno::Reference< css::task::XInteractionHandler > const & handler) -{ - m_context->setInteractionHandler(handler); -} - -css::uno::Any ConfigurationInteractionHandler::getPreviousContextValue( - rtl::OUString const & name) const -{ - css::uno::Reference< css::uno::XCurrentContext > c( - m_layer.getPreviousContext()); - return c.is() ? c->getValueByName(name) : css::uno::Any(); -} - -} } diff --git a/configmgr/source/misc/configunoreg.cxx b/configmgr/source/misc/configunoreg.cxx deleted file mode 100644 index 203acca20479..000000000000 --- a/configmgr/source/misc/configunoreg.cxx +++ /dev/null @@ -1,389 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: configunoreg.cxx,v $ - * $Revision: 1.33 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" -#include <stdio.h> - -#include "confapifactory.hxx" -#include "serviceinfohelper.hxx" -#include <cppuhelper/factory.hxx> -#include <rtl/ustrbuf.hxx> - -// *************************************************************************************** -// -// Die vorgeschriebene C-Api muss erfuellt werden! -// Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen. -// - -//--------------------------------------------------------------------------------------- -void RegisterService( - const configmgr::ServiceRegistrationInfo* pInfo, - const com::sun::star::uno::Reference< com::sun::star::registry::XRegistryKey > & xKey) -{ - if (pInfo == 0 || pInfo->registeredServiceNames==0 || pInfo->implementationName==0) - return; - - rtl::OUStringBuffer aMainKeyName; - aMainKeyName.appendAscii("/"); - aMainKeyName.appendAscii(pInfo->implementationName); - aMainKeyName.appendAscii("/UNO/SERVICES"); - - com::sun::star::uno::Reference< com::sun::star::registry::XRegistryKey > xNewKey( xKey->createKey(aMainKeyName.makeStringAndClear()) ); - OSL_ENSURE(xNewKey.is(), "CONFMGR::component_writeInfo : could not create a registry key !"); - - for(sal_Char const * const* p = pInfo->registeredServiceNames ; *p; ++p) - { - xNewKey->createKey(rtl::OUString::createFromAscii(*p)); - } -} - -//--------------------------------------------------------------------------------------- - -void RegisterSingleton( - const configmgr::SingletonRegistrationInfo* pInfo, - const com::sun::star::uno::Reference< com::sun::star::registry::XRegistryKey > & xKey) -{ - if (pInfo == 0 || pInfo->singletonName ==0 || - pInfo->implementationName ==0 || - pInfo->instantiatedServiceName ==0 ) - return; - - rtl::OUStringBuffer aSingletonKeyName; - aSingletonKeyName.appendAscii("/"); - aSingletonKeyName.appendAscii(pInfo->implementationName); - aSingletonKeyName.appendAscii("/UNO/SINGLETONS/"); - aSingletonKeyName.appendAscii(pInfo->singletonName); - - com::sun::star::uno::Reference< com::sun::star::registry::XRegistryKey > xNewKey( xKey->createKey(aSingletonKeyName.makeStringAndClear()) ); - OSL_ENSURE(xNewKey.is(), "CONFMGR::component_writeInfo : could not create a registry key !"); - - xNewKey->setStringValue(rtl::OUString::createFromAscii(pInfo->instantiatedServiceName)); - - if (pInfo->mappedImplementation != 0) - RegisterService(pInfo->mappedImplementation,xKey); -} - - -//----------------------------------------------------------------------------- -struct ServiceImplementationRequest -{ - com::sun::star::uno::Reference< com::sun::star::uno::XInterface > xRet; - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > const m_xServiceManager; - rtl::OUString const sImplementationName; - - //------------------------------------------------------------------------- - ServiceImplementationRequest( - void* pServiceManager, - sal_Char const* pImplementationName - ) - : m_xServiceManager(reinterpret_cast<com::sun::star::lang::XMultiServiceFactory*>(pServiceManager)) - , sImplementationName(rtl::OUString::createFromAscii(pImplementationName)) - { - } - //------------------------------------------------------------------------- - inline - sal_Bool shouldCreate(const configmgr::ServiceRegistrationInfo* pInfo) const - { - OSL_ENSURE(!xRet.is(), "CreateProvider : invalid creation request: we already have a return value !"); - return !xRet.is() && - pInfo != 0 && - 0 == sImplementationName.compareToAscii(pInfo->implementationName); - } - - //------------------------------------------------------------------------- - - sal_Bool CreateProviderFactory( - const configmgr::ServiceRegistrationInfo* pInfo, - bool bAdmin - ) - { - if (this->shouldCreate(pInfo)) - try - { - configmgr::ServiceRegistrationHelper aInfo(pInfo); - - const com::sun::star::uno::Sequence< rtl::OUString > Services= aInfo.getRegisteredServiceNames(); - - xRet = configmgr::createProviderFactory( aInfo.getImplementationName(), bAdmin); - - OSL_ENSURE(xRet.is(), "CreateProvider : WHERE IS THE return value !"); - } - catch(com::sun::star::uno::Exception&) - { - } - return xRet.is(); - } - - //------------------------------------------------------------------------- - - sal_Bool CreateServiceFactory( - const configmgr::ServiceRegistrationInfo* pInfo, - ::cppu::ComponentFactoryFunc Factory - ) - { - if (this->shouldCreate(pInfo)) - try - { - configmgr::ServiceRegistrationHelper aInfo(pInfo); - - const com::sun::star::uno::Sequence< rtl::OUString > Services= aInfo.getRegisteredServiceNames(); - - xRet = cppu::createSingleComponentFactory( Factory, aInfo.getImplementationName(), Services, 0); - - OSL_ENSURE(xRet.is(), "CreateProvider : WHERE IS THE return value !"); - } - catch(com::sun::star::uno::Exception&) - { - } - return xRet.is(); - } - - //------------------------------------------------------------------------- - - sal_Bool CreateSingletonMapperFactory( - const configmgr::SingletonRegistrationInfo* pInfo, - ::cppu::ComponentFactoryFunc Mapper - ) - { - OSL_ENSURE(pInfo && pInfo->mappedImplementation, "CreateProvider : Cannot map unmapped singleton !"); - - return pInfo && pInfo->mappedImplementation && - CreateServiceFactory(pInfo->mappedImplementation,Mapper); - } - - //------------------------------------------------------------------------- - void* getService() const - { - // we want to transport the interface pointer as flat C void pointer, so this prevents deletion - if (xRet.is()) - xRet->acquire(); - - return xRet.get(); - } -}; - -//--------------------------------------------------------------------------------------- - -extern "C" SAL_DLLPUBLIC_EXPORT -void SAL_CALL component_getImplementationEnvironment( - const sal_Char **ppEnvTypeName, - uno_Environment ** /* ppEnv */ - ) -{ - *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; -} - -//--------------------------------------------------------------------------------------- -extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo( - void* /* pServiceManager */, - void* pRegistryKey - ) -{ - if (pRegistryKey) - try - { - com::sun::star::uno::Reference< com::sun::star::registry::XRegistryKey > xKey(reinterpret_cast<com::sun::star::registry::XRegistryKey*>(pRegistryKey)); - - // configuration access entry points: configuration provider - RegisterSingleton(configmgr::getDefaultProviderSingletonInfo(), xKey) ; - - RegisterService(configmgr::getConfigurationProviderServiceInfo(), xKey); - RegisterService(configmgr::getDefaultProviderServiceInfo(), xKey); - RegisterService(configmgr::getAdminProviderServiceInfo(), xKey); - - // registry wrapper (deprecated) - RegisterService(configmgr::getConfigurationRegistryServiceInfo(), xKey); - - // updating - RegisterService(configmgr::backend::getUpdateMergerServiceInfo(), xKey); - - // xml handling - RegisterService(configmgr::xml::getSchemaParserServiceInfo(), xKey); - RegisterService(configmgr::xml::getLayerParserServiceInfo(), xKey); - RegisterService(configmgr::xml::getLayerWriterServiceInfo(), xKey); - - // bootstrap handling - RegisterSingleton(configmgr::getBootstrapContextSingletonInfo(), xKey) ; - RegisterService(configmgr::getBootstrapContextServiceInfo(), xKey) ; - - // backend singletons - RegisterSingleton(configmgr::backend::getDefaultBackendSingletonInfo(), xKey) ; - - // backends - RegisterService(configmgr::backend::getDefaultBackendServiceInfo(), xKey) ; - RegisterService(configmgr::backend::getSingleBackendAdapterServiceInfo(), xKey) ; - RegisterService(configmgr::backend::getMultiStratumBackendServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalBackendServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalDataImportServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalHierarchyBrowserServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalSchemaSupplierServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalLegacyStratumServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalDataStratumServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalReadonlyStratumServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalResourceStratumServiceInfo(), xKey) ; - RegisterService(configmgr::localbe::getLocalMultiStratumServiceInfo(), xKey) ; - - // im/export - RegisterService(configmgr::backend::getMergeImportServiceInfo(), xKey); - RegisterService(configmgr::backend::getCopyImportServiceInfo(), xKey); - - return sal_True; - } - catch (::com::sun::star::registry::InvalidRegistryException& ) - { - OSL_ENSURE(sal_False, "configmgr: component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); - } - - return sal_False; -} - -//--------------------------------------------------------------------------------------- -extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( - const sal_Char* pImplementationName, - void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = 0; - if (pServiceManager) - { - ServiceImplementationRequest aReq(pServiceManager,pImplementationName); - - // configuration access entry points: configuration provider - aReq.CreateProviderFactory( - configmgr::getConfigurationProviderServiceInfo(), - false) - || - aReq.CreateProviderFactory( - configmgr::getAdminProviderServiceInfo(), - true) - || - aReq.CreateServiceFactory( - configmgr::getDefaultProviderServiceInfo(), - &configmgr::instantiateDefaultProvider) - || - // registry wrapper (deprecated) - aReq.CreateServiceFactory( - configmgr::getConfigurationRegistryServiceInfo(), - &configmgr::instantiateConfigRegistry) - || - // updating - aReq.CreateServiceFactory( - configmgr::backend::getUpdateMergerServiceInfo(), - &configmgr::backend::instantiateUpdateMerger) - || - // xml handling - aReq.CreateServiceFactory( - configmgr::xml::getSchemaParserServiceInfo(), - &configmgr::xml::instantiateSchemaParser) - || - aReq.CreateServiceFactory( - configmgr::xml::getLayerParserServiceInfo(), - &configmgr::xml::instantiateLayerParser) - || - aReq.CreateServiceFactory( - configmgr::xml::getLayerWriterServiceInfo(), - &configmgr::xml::instantiateLayerWriter) - || - // bootstrap handling - aReq.CreateServiceFactory( - configmgr::getBootstrapContextServiceInfo(), - &configmgr::instantiateBootstrapContext) - || - // backend singletons - aReq.CreateSingletonMapperFactory( - configmgr::backend::getDefaultBackendSingletonInfo(), - configmgr::backend::getDefaultBackendSingleton) - || - // backends - aReq.CreateServiceFactory( - configmgr::backend::getDefaultBackendServiceInfo(), - configmgr::backend::instantiateDefaultBackend) - || - aReq.CreateServiceFactory( - configmgr::backend::getSingleBackendAdapterServiceInfo(), - configmgr::backend::instantiateSingleBackendAdapter) - || - aReq.CreateServiceFactory( - configmgr::backend::getMultiStratumBackendServiceInfo(), - configmgr::backend::instantiateMultiStratumBackend) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalBackendServiceInfo(), - configmgr::localbe::instantiateLocalBackend) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalDataImportServiceInfo(), - configmgr::localbe::instantiateLocalDataImporter) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalHierarchyBrowserServiceInfo(), - configmgr::localbe::instantiateLocalHierarchyBrowser) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalSchemaSupplierServiceInfo(), - configmgr::localbe::instantiateLocalSchemaSupplier) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalLegacyStratumServiceInfo(), - configmgr::localbe::instantiateLocalLegacyStratum) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalDataStratumServiceInfo(), - configmgr::localbe::instantiateLocalDataStratum) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalReadonlyStratumServiceInfo(), - configmgr::localbe::instantiateLocalReadonlyStratum) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalResourceStratumServiceInfo(), - configmgr::localbe::instantiateLocalResourceStratum) - || - aReq.CreateServiceFactory( - configmgr::localbe::getLocalMultiStratumServiceInfo(), - configmgr::localbe::instantiateLocalMultiStratum) - || - // im/export - aReq.CreateServiceFactory( - configmgr::backend::getMergeImportServiceInfo(), - &configmgr::backend::instantiateMergeImporter) - || - aReq.CreateServiceFactory( - configmgr::backend::getCopyImportServiceInfo(), - &configmgr::backend::instantiateCopyImporter); - - pRet = aReq.getService(); - } - - return pRet; -} -//--------------------------------------------------------------------------------------- - diff --git a/configmgr/source/misc/filehelper.cxx b/configmgr/source/misc/filehelper.cxx deleted file mode 100644 index ffa1302c6cac..000000000000 --- a/configmgr/source/misc/filehelper.cxx +++ /dev/null @@ -1,390 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: filehelper.cxx,v $ - * $Revision: 1.19 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - - -#ifndef _RTL_USTRING_H_ -#include <rtl/ustring.hxx> -#endif -#include <osl/file.hxx> -#include "filehelper.hxx" -#include <rtl/ustrbuf.hxx> -#include <osl/diagnose.h> - -#define ASCII(x) rtl::OUString::createFromAscii(x) - -namespace configmgr -{ - //========================================================================== - //= FileHelper - //========================================================================== - - // ----------------------------------------------------------------------------- - bool FileHelper::tryToRemoveFile(const rtl::OUString& _aURL, bool tryBackupFirst) - { - if (tryBackupFirst) - { - rtl::OUString aBakURL = _aURL.concat( ASCII(".bak") ); - osl::File::RC eBakError = osl::File::move(_aURL,aBakURL); - if (eBakError == osl::File::E_None) - return true; - } - osl::File::RC eError = osl::File::remove(_aURL); - return eError == osl::File::E_None || eError == osl::File::E_NOENT; - } - // ----------------------------------------------------------------------------- - void FileHelper::replaceFile( - const rtl::OUString& _aToURL, const rtl::OUString &_aFromURL) SAL_THROW((io::IOException)) - { - osl::File::remove(_aToURL); - osl::File::RC eError = osl::File::move(_aFromURL, _aToURL); - if (eError != osl::File::E_None && - eError != osl::File::E_NOENT) - { - rtl::OUStringBuffer sErrorBuf; - sErrorBuf.appendAscii("Configmgr: replaceFile failed "); - sErrorBuf.appendAscii("for replacing file \"").append(_aFromURL).appendAscii("\". "); - sErrorBuf.appendAscii("by file \"").append(_aToURL).appendAscii("\". "); - sErrorBuf.appendAscii("Error = \"").append(FileHelper::createOSLErrorString(eError)).appendAscii("\" "); - sErrorBuf.appendAscii("[").append(sal_Int32(eError)).appendAscii("] "); - - rtl::OUString const sError = sErrorBuf.makeStringAndClear(); - OSL_ENSURE(0, rtl::OUStringToOString(sError,RTL_TEXTENCODING_ASCII_US).getStr()); - throw io::IOException(sError, NULL); - } - } - - // ----------------------------------------------------------------------------- - bool FileHelper::fileExists(rtl::OUString const& _sFileURL) - { - osl::DirectoryItem aItem; - return osl::DirectoryItem::get(_sFileURL, aItem) == osl::Directory::E_None; - } - - // ----------------------------------------------------------------------------- - bool FileHelper::dirExists(rtl::OUString const& _sDirURL) - { - return osl::Directory(_sDirURL).open() == osl::Directory::E_None; - } - - // ----------------------------------------------------------------------------- - sal_uInt64 FileHelper::getModifyStatus(rtl::OUString const& _sURL, TimeValue & rModifyTime) - { - static const TimeValue k_NullTime = {0,0}; - sal_uInt64 aSize = 0; - rModifyTime = k_NullTime; - - osl::DirectoryItem aItem; - if (osl::FileBase::E_None == osl::DirectoryItem::get(_sURL, aItem)) - { - osl::FileStatus aStatus(osl_FileStatus_Mask_ModifyTime|osl_FileStatus_Mask_Type|osl_FileStatus_Mask_FileSize); - if (osl::FileBase::E_None == aItem.getFileStatus(aStatus)) - { - if (aStatus.isValid(osl_FileStatus_Mask_ModifyTime)) - rModifyTime = aStatus.getModifyTime(); - - if (aStatus.isValid(osl_FileStatus_Mask_FileSize)) - aSize = aStatus.getFileSize(); - } - } - return aSize; - } - - // ----------------------------------------------------------------------------- - rtl::OUString FileHelper::createOSLErrorString(osl::FileBase::RC eError) - { - rtl::OUString aRet; - switch(eError) - { - case osl::FileBase::E_None: - break; - - case osl::FileBase::E_PERM: - aRet = ASCII("Operation not permitted"); - break; - - case osl::FileBase::E_NOENT: - aRet = ASCII("No such file or directory"); - break; - - case osl::FileBase::E_SRCH: - aRet = ASCII("unknown error: osl_File_E_SRCH"); - break; - - case osl::FileBase::E_INTR: - aRet = ASCII("function call was interrupted"); - break; - - case osl::FileBase::E_IO: - aRet = ASCII("I/O error"); - break; - - case osl::FileBase::E_NXIO: - aRet = ASCII("No such device or address"); - break; - - case osl::FileBase::E_2BIG: - aRet = ASCII("unknown error: osl_File_E_2BIG"); - break; - - case osl::FileBase::E_NOEXEC: - aRet = ASCII("unknown error: osl_File_E_NOEXEC"); - break; - - case osl::FileBase::E_BADF: - aRet = ASCII("Bad file"); - break; - - case osl::FileBase::E_CHILD: - aRet = ASCII("unknown error: osl_File_E_CHILD"); - break; - - case osl::FileBase::E_AGAIN: - aRet = ASCII("Operation would block"); - break; - - case osl::FileBase::E_NOMEM: - aRet = ASCII("not enough memory for allocating structures"); - break; - - case osl::FileBase::E_ACCES: - aRet = ASCII("Permission denied"); - break; - - case osl::FileBase::E_FAULT: - aRet = ASCII("Bad address"); - break; - - case osl::FileBase::E_BUSY: - aRet = ASCII("Text file busy"); - break; - - case osl::FileBase::E_EXIST: - aRet = ASCII("File exists"); - break; - - case osl::FileBase::E_XDEV: - aRet = ASCII("unknown error: osl_File_E_XDEV"); - break; - - case osl::FileBase::E_NODEV: - aRet = ASCII("No such device"); - break; - - case osl::FileBase::E_NOTDIR: - aRet = ASCII("Not a directory"); - break; - - case osl::FileBase::E_ISDIR: - aRet = ASCII("Is a director"); - break; - - case osl::FileBase::E_INVAL: - aRet = ASCII("the format of the parameters was not valid"); - break; - - case osl::FileBase::E_NFILE: - aRet = ASCII("too many open files in the system"); - break; - - case osl::FileBase::E_MFILE: - aRet = ASCII("too many open files used by the process"); - break; - - case osl::FileBase::E_NOTTY: - aRet = ASCII("unknown error: osl_File_E_NOTTY"); - break; - - case osl::FileBase::E_FBIG: - aRet = ASCII("File too large"); - break; - - case osl::FileBase::E_NOSPC: - aRet = ASCII("No space left on device"); - break; - - case osl::FileBase::E_SPIPE: - aRet = ASCII("unknown error: osl_File_E_SPIPE"); - break; - - case osl::FileBase::E_ROFS: - aRet = ASCII("Read-only file system"); - break; - - case osl::FileBase::E_MLINK: - aRet = ASCII("Too many links"); - break; - - case osl::FileBase::E_PIPE: - aRet = ASCII("unknown error: osl_File_E_PIPE"); - break; - - case osl::FileBase::E_DOM: - aRet = ASCII("unknown error: osl_File_E_DOM"); - break; - - case osl::FileBase::E_RANGE: - aRet = ASCII("unknown error: osl_File_E_RANGE"); - break; - - case osl::FileBase::E_DEADLK: - aRet = ASCII("unknown error: osl_File_E_DEADLK"); - break; - - case osl::FileBase::E_NAMETOOLONG: - aRet = ASCII("File name too long"); - break; - - case osl::FileBase::E_NOLCK: - aRet = ASCII("No record locks available"); - break; - - case osl::FileBase::E_NOSYS: - aRet = ASCII("Function not implemente"); - break; - - case osl::FileBase::E_NOTEMPTY: - aRet = ASCII("Directory not empt"); - break; - - case osl::FileBase::E_LOOP: - aRet = ASCII("Too many symbolic links encountered"); - break; - - case osl::FileBase::E_ILSEQ: - aRet = ASCII("unknown error: osl_File_E_ILSEQ"); - break; - - case osl::FileBase::E_NOLINK: - aRet = ASCII("Link has been severed"); - break; - - case osl::FileBase::E_MULTIHOP: - aRet = ASCII("Multihop attempted"); - break; - - case osl::FileBase::E_USERS: - aRet = ASCII("unknown error: osl_File_E_USERS"); - break; - - case osl::FileBase::E_OVERFLOW: - aRet = ASCII("Value too large for defined data type"); - break; - - /* unmapped error: always last entry in enum! */ - default: OSL_ENSURE(false, "Found unknown OSL File Error"); - case osl::FileBase::E_invalidError: - aRet = ASCII("unmapped Error"); - break; - } - return aRet; - } - - // ----------------------------------------------------------------------------- - rtl::OUString FileHelper::getParentDir(rtl::OUString const& _sURL) - { - rtl::OUString parentDirectory ; - rtl::OUString fileName ; - - splitFileUrl(_sURL, parentDirectory, fileName) ; - return parentDirectory ; - } - - // ----------------------------------------------------------------------------- - void FileHelper::splitFileUrl(const rtl::OUString& aFileUrl, - rtl::OUString& aParentDirectory, - rtl::OUString& aFileName) { - // goto last '/' and cut the rest. - sal_Int32 nIdx = aFileUrl.lastIndexOf(delimiter, aFileUrl.getLength()); - if (nIdx > 0) { - aParentDirectory = aFileUrl.copy(0, nIdx); - aFileName = aFileUrl.copy(nIdx + 1) ; - } - else { - aParentDirectory = rtl::OUString() ; - aFileName = aFileUrl ; - } - } - - // ----------------------------------------------------------------------------- - rtl::OUString FileHelper::getFileName(const rtl::OUString& aFileUrl) { - rtl::OUString parentDirectory ; - rtl::OUString fileName ; - - splitFileUrl(aFileUrl, parentDirectory, fileName) ; - return fileName ; - } - // ----------------------------------------------------------------------------- - osl::FileBase::RC FileHelper::mkdir(rtl::OUString const& _sDirURL) - { - // direct create a directory - osl::FileBase::RC eError = osl::Directory::create(_sDirURL); // try to create the directory - if (eError == osl::FileBase::E_EXIST || - eError == osl::FileBase::E_None || - FileHelper::dirExists(_sDirURL)) - { - eError = osl::FileBase::E_None; // Exists or created - } - return eError; - } - - // ----------------------------------------------------------------------------- - osl::FileBase::RC FileHelper::mkdirs(rtl::OUString const& _sDirURL) - { - osl::FileBase::RC eError = mkdir(_sDirURL); - switch (eError) - { - case osl::FileBase::E_EXIST: OSL_ASSERT(false); - case osl::FileBase::E_None: - break; - - case osl::FileBase::E_NOENT: - { - rtl::OUString sParentDir = FileHelper::getParentDir(_sDirURL); - if (sParentDir.getLength() == 0) - break; - - eError = mkdirs(sParentDir); - if (eError != osl::FileBase::E_None) - break; - - eError = mkdir(_sDirURL); - } - break; - - default: OSL_TRACE("configmgr: Could not create directory (%d).", int(eError)); - break; - } - return eError; - } - -} // namespace configmgr diff --git a/configmgr/source/misc/interactionrequest.cxx b/configmgr/source/misc/interactionrequest.cxx deleted file mode 100644 index b5f32ff9cf17..000000000000 --- a/configmgr/source/misc/interactionrequest.cxx +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: interactionrequest.cxx,v $ - * $Revision: 1.6 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "interactionrequest.hxx" - -namespace configmgr { -namespace apihelper { - namespace uno = com::sun::star::uno; - namespace task = com::sun::star::task; -//========================================================================= -//========================================================================= -// -// InteractionRequest Implementation. -// -//========================================================================= -//========================================================================= - -struct InteractionRequest::Impl -{ - uno::Reference< task::XInteractionContinuation > m_xSelection; - uno::Any m_aRequest; - uno::Sequence< uno::Reference< task::XInteractionContinuation > > m_aContinuations; - - Impl() {} - Impl( const uno::Any & rRequest ) - : m_aRequest( rRequest ) - {} -}; - -//========================================================================= -InteractionRequest::InteractionRequest( const uno::Any & rRequest ) -: m_pImpl( new Impl( rRequest ) ) -{ -} - -//========================================================================= -// virtual -InteractionRequest::~InteractionRequest() -{ - delete m_pImpl; -} - -//========================================================================= -void InteractionRequest::setContinuations( - const uno::Sequence< uno::Reference< - task::XInteractionContinuation > > & rContinuations ) -{ - m_pImpl->m_aContinuations = rContinuations; -} - -//========================================================================= -uno::Reference< task::XInteractionContinuation > InteractionRequest::getSelection() const -{ - return m_pImpl->m_xSelection; -} - -//========================================================================= -void InteractionRequest::setSelection( const uno::Reference< task::XInteractionContinuation > & rxSelection ) -{ - m_pImpl->m_xSelection = rxSelection; -} - -//========================================================================= -// -// XInteractionRequest methods. -// -//========================================================================= - -// virtual -uno::Any SAL_CALL InteractionRequest::getRequest() - throw( uno::RuntimeException ) -{ - return m_pImpl->m_aRequest; -} - -//========================================================================= -// virtual -uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL - InteractionRequest::getContinuations() - throw( uno::RuntimeException ) -{ - return m_pImpl->m_aContinuations; -} - -//========================================================================= - -} // namespace apihelper -} // namespace configmgr diff --git a/configmgr/source/misc/logger.cxx b/configmgr/source/misc/logger.cxx deleted file mode 100644 index 40a282265c97..000000000000 --- a/configmgr/source/misc/logger.cxx +++ /dev/null @@ -1,96 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: logger.cxx,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "logger.hxx" - -#define CONFIG_LOGGER_SINGLETON "/singletons/com.sun.star.configuration.theLogger" -#define OUSTR( lit ) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( lit ) ) -#define OU2A( ustr ) rtl::OUStringToOString( ustr, RTL_TEXTENCODING_UTF8 ).getStr() -#define A2OU( astr ) rtl::OUString::createFromAscii( astr ) - -static const sal_Char k_unspecifiedClass[] = "configmgr"; -static const sal_Char k_unspecifiedMethod[] = "log-message"; - -namespace configmgr -{ - -//-------------------------------------------------------------------------- -void Logger::log(sal_Int32 nLevel, const char * msg, const char * sourceMethod, const char * sourceClass) const -{ - OSL_ASSERT(msg); - if (!msg) msg = ""; - - this->log(nLevel,A2OU(msg),sourceMethod,sourceClass); -} - -//-------------------------------------------------------------------------- -void Logger::log(sal_Int32 nLevel, const rtl::OUString & msg, const char * sourceMethod, const char * sourceClass) const -{ - if (!sourceClass) sourceClass = k_unspecifiedClass; - if (!sourceMethod) sourceMethod = k_unspecifiedMethod; - - // this place can be used to further enrich or instrument log output - if (m_xLogger.is()) - try - { - m_xLogger->logp(nLevel,A2OU(sourceClass),A2OU(sourceMethod),msg); - } - catch (uno::Exception & e) - { - OSL_TRACE("Configuration Log failure: %s\n" - "Log message was [Level=%04d] %s::%s : %s\n", - OU2A(e.Message),int(nLevel),sourceClass,sourceMethod,OU2A(msg)); - } - else if (nLevel >= (LogLevel::SEVERE - OSL_DEBUG_LEVEL*(LogLevel::SEVERE-LogLevel::WARNING))) - OSL_TRACE("Configuration Log [%04d] %s::%s : %s\n", int(nLevel),sourceClass,sourceMethod,OU2A(msg)); - -} - -//-------------------------------------------------------------------------- -uno::Reference< logging::XLogger > - Logger::getUnoLoggerFromContext(uno::Reference< uno::XComponentContext > const & xContext) -{ - uno::Reference< logging::XLogger > xLogger; - - if (xContext.is()) - try { xContext->getValueByName( OUSTR(CONFIG_LOGGER_SINGLETON) ) >>= xLogger; } - catch (uno::Exception & ) {} - - return xLogger; -} - -//-------------------------------------------------------------------------- - -} // namespace configmgr - - diff --git a/configmgr/source/misc/makefile.mk b/configmgr/source/misc/makefile.mk deleted file mode 100644 index 8fc6389dc9b5..000000000000 --- a/configmgr/source/misc/makefile.mk +++ /dev/null @@ -1,77 +0,0 @@ -#************************************************************************* -# -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# Copyright 2008 by Sun Microsystems, Inc. -# -# OpenOffice.org - a multi-platform office productivity suite -# -# $RCSfile: makefile.mk,v $ -# -# $Revision: 1.28 $ -# -# This file is part of OpenOffice.org. -# -# OpenOffice.org is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License version 3 -# only, as published by the Free Software Foundation. -# -# OpenOffice.org 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 version 3 for more details -# (a copy is included in the LICENSE file that accompanied this code). -# -# You should have received a copy of the GNU Lesser General Public License -# version 3 along with OpenOffice.org. If not, see -# <http://www.openoffice.org/license.html> -# for a copy of the LGPLv3 License. -# -#************************************************************************* - -PRJ=..$/.. -PRJINC=$(PRJ)$/source -PRJNAME=configmgr -TARGET=misc - -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ---------------------------------- - -.INCLUDE : settings.mk -.INCLUDE : $(PRJ)$/makefile.pmk -.INCLUDE : $(PRJ)$/version.mk - -# --- Files ------------------------------------- - -SLOFILES= \ - $(SLO)$/bootstrap.obj \ - $(SLO)$/providerfactory.obj \ - $(SLO)$/providerwrapper.obj \ - $(SLO)$/logger.obj \ - $(SLO)$/tracer.obj \ - $(SLO)$/configunoreg.obj \ - $(SLO)$/serviceinfohelper.obj \ - $(SLO)$/bootstrapcontext.obj \ - $(SLO)$/anypair.obj \ - $(SLO)$/strimpl.obj \ - $(SLO)$/mergechange.obj \ - $(SLO)$/oslstream.obj \ - $(SLO)$/filehelper.obj \ - $(SLO)$/bufferedfile.obj \ - $(SLO)$/requestoptions.obj \ - $(SLO)$/interactionrequest.obj \ - $(SLO)$/configinteractionhandler.obj \ - $(SLO)$/simpleinteractionrequest.obj \ - $(SLO)$/propertysethelper.obj \ - -OBJFILES= \ - $(OBJ)$/oslstream.obj \ - $(OBJ)$/filehelper.obj \ - $(OBJ)$/bufferedfile.obj \ - - -# --- Targets ---------------------------------- - -.INCLUDE : target.mk - diff --git a/configmgr/source/misc/mergechange.cxx b/configmgr/source/misc/mergechange.cxx deleted file mode 100644 index b4b3f0d431fd..000000000000 --- a/configmgr/source/misc/mergechange.cxx +++ /dev/null @@ -1,831 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: mergechange.cxx,v $ - * $Revision: 1.27 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "builddata.hxx" -#include "mergechange.hxx" -#include "updatehelper.hxx" -#include "treeactions.hxx" -#include "treefragment.hxx" -#include "change.hxx" -#include "treechangefactory.hxx" -#include "treechangelist.hxx" -#include "configexcept.hxx" -#include "tracer.hxx" - -#define ASCII(x) rtl::OUString::createFromAscii(x) - -namespace configmgr -{ - // ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - - // ----------------------------------------------------------------------------- - class OMergeChanges : private ChangeTreeAction, private OPathCreator<configuration::RelativePath> - { - SubtreeChange &m_rSubtreeChange; // ChangeList, which will be grown - SubtreeChange *m_pCurrentParent; // our current position - - // ------- Helper for Path stack ------- - SubtreeChange* pushTree(SubtreeChange& _rTree); - void popTree(SubtreeChange* _pSaveTree); - - public: - // CTor - OMergeChanges(SubtreeChange& _rTree); - - // start function, with the Change we want to do. - // WARNING this could be a big tree, because a change can contain subtreechanges! - void mergeChanges(const SubtreeChange &_rChange, const configuration::RelativePath& _aPathToChange); - void mergeChanges(const SubtreeChange &_rChange); - - private: - void initRoot(const SubtreeChange &_rRootChange, const configuration::RelativePath& _aPathToChange); - private: - virtual void handle(ValueChange const& _rValueNode); - virtual void handle(AddNode const& _rAddNode); - virtual void handle(RemoveNode const& _rRemoveNode); - virtual void handle(SubtreeChange const& _rSubtree); - - }; - // ----------------------------------------------------------------------------- - void combineUpdates(SubtreeChange const& _anUpdate, SubtreeChange& _aCombinedUpdate) - { - OMergeChanges aCombined(_aCombinedUpdate); - aCombined.mergeChanges(_anUpdate); - } - // ----------------------------------------------------------------------------- - - configuration::Path::Component ONameCreator::createName(Change const& _rChange, SubtreeChange const* _pParent) - { - OSL_ENSURE(_pParent, "ONameCreator: Cannot create proper name without a parent"); - if (_pParent && _pParent->isSetNodeChange()) - { - rtl::OUString sElementName = _rChange.getNodeName(); - rtl::OUString sTypeName = _pParent->getElementTemplateName(); - - return configuration::Path::makeCompositeName(sElementName, sTypeName); - } - else - { - rtl::OUString sElementName = _rChange.getNodeName(); - - // OSL_ENSURE(isSimpleName(sElementName),"Unexpected: Non-simple name in non-set node"); - - return configuration::Path::wrapSafeName(sElementName); - } - } - - - // ----------------------------------------------------------------------------- - class OMergeValueChange : private ChangeTreeModification - { - SubtreeChange& m_rTargetParent; - const ValueChange& m_aValueChange; - public: - OMergeValueChange(SubtreeChange& _rTargetParent, const ValueChange& _aValueChange) - :m_rTargetParent(_rTargetParent) - ,m_aValueChange(_aValueChange) - { - - } - void handleChange(Change &_rNode) - { - this->applyToChange(_rNode); - } - private: - virtual void handle(ValueChange& _rValueChange) - { - // POST: Handle ValueChange - _rValueChange.setNewValue(m_aValueChange.getNewValue(), m_aValueChange.getMode()); - } - virtual void handle(RemoveNode& /*_rRemoveNode*/) - { - OSL_ENSURE(false, "OMergeValueChange::handle(ValueChange): have a ValueChange for a removed node!"); - // should never happen. How did the user change a value for a node which is obviously flagged as removed? - } - virtual void handle(AddNode& _rAddNode); - virtual void handle(SubtreeChange& _rSubtree) - { - if ( isLocalizedValueSet(_rSubtree) ) - { - std::auto_ptr<ValueChange> pNewValueChange( new ValueChange(m_aValueChange) ); - OSL_ENSURE(pNewValueChange->isLocalizedValue(), "OMergeValueChange:handle(SubtreeChange): have a non-localized ValueChange a for a localized node!"); - - std::auto_ptr<Change> pNewChange( pNewValueChange.release() ); - - replaceExistingEntry(pNewChange); - } - else - OSL_ENSURE(false, "OMergeValueChange:handle(SubtreeChange): have a ValueChange for a sub tree!"); - } - - void replaceExistingEntry(std::auto_ptr<Change> pNewChange) - { - m_rTargetParent.removeChange(pNewChange->getNodeName()); - m_rTargetParent.addChange(pNewChange); - } - static std::auto_ptr<ValueNode> createNodeFromChange(ValueChange const& rChange) - { - std::auto_ptr<ValueNode> aRet; - - uno::Any aNewValue = rChange.getNewValue(); - - // currently not supporting change modes ! - if (aNewValue.hasValue()) - aRet.reset( new ValueNode(rChange.getNodeName(), aNewValue, rChange.getAttributes()) ); - - else // NULL - { - aRet.reset( new ValueNode(rChange.getNodeName(), rChange.getValueType(), rChange.getAttributes()) ); - - OSL_ENSURE(aRet->isValid(), "Cannot recover type for change to NULL"); - } - return aRet; - } - - }; - -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - // TODO: operate directly on new data structures - - void OMergeValueChange::handle(AddNode& _rAddNode) - { - if (m_aValueChange.isToDefault()) - { - std::auto_ptr<Change> aChangeToDefault(m_aValueChange.clone()); - m_rTargetParent.removeChange(_rAddNode.getNodeName()); - m_rTargetParent.addChange( aChangeToDefault ); - } - else - { - // POST: Handle ValueChange in AddNode - rtl::Reference< data::TreeSegment > seg(_rAddNode.getNewTree()); - std::auto_ptr<INode> pAddedNode = data::convertTree(seg.is() ? seg->fragment : 0, false); - - if (ValueNode *pValueNode = pAddedNode->asValueNode()) - { - m_aValueChange.applyChangeNoRecover(*pValueNode); - } - - else if (ISubtree* pValueSetNode = pAddedNode->asISubtree() ) - { - if ( isLocalizedValueSet(*pValueSetNode) ) - { - std::auto_ptr<ValueNode> pNewValueNode = createNodeFromChange(m_aValueChange); - if (pNewValueNode.get()) - { - OSL_ENSURE(pNewValueNode->isLocalized(), "OMergeValueChange:handle(AddNode): have a non-localized ValueChange a for a localized node!"); - pNewValueNode->setName(pAddedNode->getName()); - } - else - OSL_ENSURE(false, "OMergeValueChange:handle(SubtreeChange): Creating a NULL node to replace a localized value set not yet supported"); - - - pAddedNode.reset(pNewValueNode.release()); - } - else - { - OSL_ENSURE(sal_False, "OMergeValueChange:handle(AddNode): have a ValueChange a for non-value node!"); - pAddedNode.reset(); // leave unchanged - } - - } - else - { - OSL_ENSURE(sal_False, "OMergeValueChange:handle(AddNode): Found unknown node type!"); - pAddedNode.reset(); // leave unchanged - } - - if (pAddedNode.get() != NULL) - { - rtl::Reference< data::TreeSegment > aNewTree = data::TreeSegment::create(_rAddNode.getNodeName(),pAddedNode); - - std::auto_ptr<AddNode> pNewAdd( new AddNode(aNewTree,m_aValueChange.getNodeName(), m_aValueChange.isToDefault()) ); - if (_rAddNode.isReplacing()) - pNewAdd->setReplacing(); - - std::auto_ptr<Change> pNewChange( pNewAdd.release() ); - replaceExistingEntry(pNewChange); - } - } - } -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - // ----------------------------------------------------------------------------- - class OMergeRemoveNode : private ChangeTreeModification - { - public: - // actions to take with the remove node change - enum Action - { - RemoveCompletely, - FlagDeleted, - Undetermined - }; - - protected: - Action m_eAction; - - public: - OMergeRemoveNode() : m_eAction(Undetermined) { } - - Action getAction() const { return m_eAction; } - - void handleChange(Change* _pChange) - { - if (_pChange) - applyToChange(*_pChange); - else - // no change -> flag as deleted - m_eAction = FlagDeleted; - } - - private: - virtual void handle(ValueChange& aValueChange) - { - if (aValueChange.getAttributes().existsInDefault()) - m_eAction = FlagDeleted; - else - m_eAction = RemoveCompletely; - } - - virtual void handle(RemoveNode& /*_rRemoveNode*/) - { - OSL_ENSURE(false, "OMergeRemoveNode::handle(RemoveNode): should never happen!"); - // how can a RemoveNode change exist if in the file we're merging it into - // there already is such a RemoveNode change (_rRemoveNode)? - } - - virtual void handle(AddNode& _rAddNode) - { - if (_rAddNode.isReplacing()) - m_eAction = FlagDeleted; - else - m_eAction = RemoveCompletely; - } - - virtual void handle(SubtreeChange& _rSubtree) - { - if (_rSubtree.getAttributes().existsInDefault()) - m_eAction = FlagDeleted; - else - m_eAction = RemoveCompletely; - } - }; - // ----------------------------------------------------------------------------- - // ----------------------------------------------------------------------------- - - static - inline - Change* findExistingChange(SubtreeChange* pCurrentParent, configuration::Path::Component const & _aName) - { - OSL_ASSERT(pCurrentParent); - - Change *pChange = pCurrentParent->getChange(_aName.getName()); - - if (!pChange && !_aName.isSimpleName()) - { - pChange = pCurrentParent->getChange(_aName.toPathString()); - OSL_ENSURE(!pChange, "Update trouble: Existing node found only by composite name while merging"); - } - - return pChange; - } - - static - inline - Change* findExistingChange(SubtreeChange* pCurrentParent, rtl::OUString const & _aName) - { - OSL_ASSERT(pCurrentParent); - - Change *pChange = pCurrentParent->getChange(_aName); - - return pChange; - } - // ----------------------------------------------------------------------------- - - void adjustElementTemplate(SubtreeChange& _rChange, const rtl::OUString& _rName, const rtl::OUString& _rModule) - { - if (!_rChange.isSetNodeChange() || isGenericSetElementType(_rChange.getElementTemplateName())) - { - _rChange.setElementTemplate(_rName,_rModule); - } - else if ( isDummySetElementModule(_rChange.getElementTemplateModule()) && - !isGenericSetElementType(_rName) && !isDummySetElementModule(_rModule)) - { - OSL_ENSURE(_rChange.getElementTemplateName() == _rName, "Adjusting: Template modules do not match"); - - _rChange.setElementTemplate(_rName,_rModule); - } - OSL_POSTCOND(_rChange.getElementTemplateName() == _rName || isGenericSetElementType(_rName), - "Adjusting: Template modules do not match"); - OSL_POSTCOND(_rChange.getElementTemplateModule() == _rModule || isDummySetElementModule(_rModule), - "Adjusting: Template modules do not match"); - } - // ----------------------------------------------------------------------------- - - inline void adjustElementTemplate(SubtreeChange& _rChange, SubtreeChange const& _rSource) - { - if (_rSource.isSetNodeChange()) - adjustElementTemplate(_rChange, _rSource.getElementTemplateName(), _rSource.getElementTemplateModule()); - } - - // ----------------------------------------------------------------------------- - - // CTor - OMergeChanges::OMergeChanges(SubtreeChange& _rTree) - : m_rSubtreeChange(_rTree), m_pCurrentParent(NULL) - { - } - // ----------------------------------------------------------------------------- - - void OMergeChanges::initRoot(const SubtreeChange &_rRootChange, const configuration::RelativePath& _aPathToChange) - { - SubtreeChange* pCurrentParent = &m_rSubtreeChange; - - if (!_aPathToChange.isEmpty()) - { - OSL_PRECOND(_aPathToChange.getLocalName().getName() == _rRootChange.getNodeName(), - "Path to change root does not match change being merged" ); - - std::vector<configuration::Path::Component>::const_reverse_iterator const firstEnsure = _aPathToChange.begin(); - std::vector<configuration::Path::Component>::const_reverse_iterator lastEnsure = _aPathToChange.end(); - std::vector<configuration::Path::Component>::const_reverse_iterator it; - - OSL_ASSERT( firstEnsure != lastEnsure ); - --lastEnsure; // last to ensure is the actual root - - for( it = firstEnsure; it != lastEnsure; ++it) - { - OSL_ASSERT( it != _aPathToChange.end() ); - - Change *pChange = findExistingChange(pCurrentParent,*it); - - if (!pChange) - { - OSL_ASSERT( it+1 != _aPathToChange.end()); - rtl::OUString const aElementTypeName = (it+1)->getTypeName(); - - // create a correspondens for the name, we did not find. - std::auto_ptr<SubtreeChange> pNewChange = - OTreeChangeFactory::createDummyChange(it->getName(), aElementTypeName); - - pChange = pNewChange.get(); - - pCurrentParent->addChange(base_ptr(pNewChange)); - - OSL_ENSURE(pChange == findExistingChange(pCurrentParent,*it), - "ERROR: Newly added change cannot be found in parent change"); - } - - pCurrentParent = dynamic_cast<SubtreeChange*>( pChange); - if (pCurrentParent == 0) - { - OSL_ENSURE(false, "Change to merge does not point to a Subtree Change"); - throw configuration::InvalidName(_aPathToChange.toString(), "points to a non- subtree change in this changes list, but a subtree change is required as root."); - } - } - - Change *pRootChange = findExistingChange(pCurrentParent,*lastEnsure); - - if (!pRootChange) - { - // create a correspondens for the name, we did not find. - std::auto_ptr<SubtreeChange> pNewChange( - new SubtreeChange(_rRootChange, treeop::NoChildCopy()) ); - - pRootChange = pNewChange.get(); - - pCurrentParent->addChange(base_ptr(pNewChange)); - - OSL_ENSURE(pRootChange == findExistingChange(pCurrentParent,*it), - "ERROR: Newly added change cannot be found in parent change"); - } - - pCurrentParent = dynamic_cast<SubtreeChange*>( pRootChange); - if (pCurrentParent == 0) - { - OSL_ENSURE(false, "Change to merge does not point to a Subtree Change"); - throw configuration::InvalidName(_aPathToChange.toString(), "points to a non-subtree change in this changes list, but a subtree change is required as root."); - } - } - - OSL_ENSURE(pCurrentParent->getNodeName() == _rRootChange.getNodeName(), - "Change being merged has a different name"); - - adjustElementTemplate(*pCurrentParent,_rRootChange); - - this->init(_aPathToChange); - - m_pCurrentParent = pCurrentParent; - } - // ----------------------------------------------------------------------------- - - // ------- Helper for Path stack ------- - SubtreeChange* OMergeChanges::pushTree(SubtreeChange& _rTree) - { - pushName( ONameCreator::createName(_rTree,m_pCurrentParent) ); - - SubtreeChange* pSave = m_pCurrentParent; - m_pCurrentParent = &_rTree; - return pSave; - } - void OMergeChanges::popTree(SubtreeChange* _pSaveTree) - { - m_pCurrentParent = _pSaveTree; - - popName(); - } - // ----------------------------------------------------------------------------- - - // start function, with the Change we want to do. - // WARNING this could be a big tree, because a change can contain subtreechanges! - void OMergeChanges::mergeChanges(const SubtreeChange &_rChange) - { - mergeChanges(_rChange, configuration::RelativePath()); - } - // ----------------------------------------------------------------------------- - - // start function, with the Change we want to do. - // WARNING this could be a big tree, because a change can contain subtreechanges! - void OMergeChanges::mergeChanges(const SubtreeChange &_rChange, const configuration::RelativePath& _aPathToChange) - { - initRoot(_rChange, _aPathToChange); // path location being merged must exist - - this->applyToChildren(_rChange); //- semantics ? - } - // ----------------------------------------------------------------------------- - - // Algorithm: search the actual path in the out m_aSubtreeChange - // if we found something, we must merge/convert the Node with our Node - // if we found nothing, we must create a new Node with our change - // thats it. - - // the merge is contructed with helper classes because, it's possible that we - // are a ValueChange but in the TreeChangeList this change is an AddNode, so - // we have something to do. - - void OMergeChanges::handle(ValueChange const& _rValueNode) - { - // Handle a ValueChange, - rtl::OUString aNodeName = _rValueNode.getNodeName(); - - if (Change *pChange = findExistingChange(m_pCurrentParent,aNodeName)) - { - // Value found, merge content - OMergeValueChange aMergeValue(*m_pCurrentParent,_rValueNode); - aMergeValue.handleChange(*pChange); - } - else - { - // there is no ValueChange in the List, insert new one - std::auto_ptr<Change> pNewChange(new ValueChange(_rValueNode)); - m_pCurrentParent->addChange(pNewChange); - } - } - // ----------------------------------------------------------------------------- - - void OMergeChanges::handle(AddNode const& _rAddNode) - { - // Handle an AddNode - bool bReplacing = _rAddNode.isReplacing(); - - rtl::OUString aNodeName = _rAddNode.getNodeName(); - - if (Change *pChange = findExistingChange(m_pCurrentParent,aNodeName)) - { - OSL_ENSURE(dynamic_cast< RemoveNode * >(pChange) != 0 || bReplacing, "OMergeChanges::handle(AddNode): the changes tree given already contains a change for this!"); - - m_pCurrentParent->removeChange(pChange->getNodeName()); - - bReplacing = true; - } - - // insert manually - rtl::Reference< data::TreeSegment > aAddedTree = data::TreeSegment::create(_rAddNode.getNewTree()); - - std::auto_ptr<AddNode> pNewAdd(new AddNode(aAddedTree, _rAddNode.getNodeName(), _rAddNode.isToDefault())); - if (bReplacing) - pNewAdd->setReplacing(); - - std::auto_ptr<Change> pNewChange( pNewAdd.release() ); - m_pCurrentParent->addChange(pNewChange); - } - // ----------------------------------------------------------------------------- - - void OMergeChanges::handle(RemoveNode const& _rRemoveNode) - { - // Handle a RemoveNode - rtl::OUString aNodeName = _rRemoveNode.getNodeName(); - - Change *pChange = findExistingChange(m_pCurrentParent,aNodeName); - - // examine what to do with this change - OMergeRemoveNode aExaminer; - aExaminer.handleChange(pChange); - - // remove the change from it's parent (may it's re-inserted in another form below) - if (pChange) - m_pCurrentParent->removeChange(pChange->getNodeName()); - - // insert a new change if necessary - switch (aExaminer.getAction()) - { - case OMergeRemoveNode::RemoveCompletely: - // nothing to do, we already removed it - break; - default: - OSL_ENSURE(sal_False, "OMergeChanges::handle(RemoveNode): don't know what to do with this!"); - // NO BREAK. - // defaulting this so that the node will be marked as deleted - case OMergeRemoveNode::FlagDeleted: - { - std::auto_ptr<Change> pNewChange(new RemoveNode(_rRemoveNode.getNodeName(),_rRemoveNode.isToDefault())); - m_pCurrentParent->addChange(pNewChange); - } - break; - } - } - -// ----------------------------------------------------------------------------- - inline - void OStripDefaults::stripOne(Change& _rChange) - { - m_rParent.removeChange(_rChange.getNodeName()); - } - - void OStripDefaults::handle(ValueChange& _rValueNode) - { - if (_rValueNode.isToDefault()) - stripOne(_rValueNode); - } - void OStripDefaults::handle(AddNode& _rAddNode) - { - if (_rAddNode.isToDefault()) - { - sharable::TreeFragment const * pAdded = _rAddNode.getNewTreeData(); - OSL_ENSURE(pAdded,"No Data in AddNode"); - if (pAdded == NULL || pAdded->getAttributes().isDefault()) - stripOne(_rAddNode); - - // else we should strip the defaults from the added node - } - } - void OStripDefaults::handle(RemoveNode& _rRemoveNode) - { - if (_rRemoveNode.isToDefault()) - stripOne(_rRemoveNode); - } - void OStripDefaults::handle(SubtreeChange& _rSubtree) - { - if ( strip(_rSubtree) ) - if (_rSubtree.isToDefault() || !_rSubtree.isSetNodeChange()) - stripOne(_rSubtree); - } - - OStripDefaults& OStripDefaults::strip() - { - SubtreeChange::MutatingChildIterator it = m_rParent.begin_changes(), stop = m_rParent.end_changes(); - - while (it != stop) - { - this->applyToChange(*it++); - } - - return *this; - } - - -// ----------------------------------------------------------------------------- - class TreeUpdater : public ChangeTreeAction - { - ISubtree* m_pCurrentSubtree; -#if OSL_DEBUG_LEVEL > 1 - std::vector<rtl::OString> aLog; -#endif - - public: - TreeUpdater(ISubtree* pSubtree):m_pCurrentSubtree(pSubtree){} - - void handle(ValueChange const& aValueNode); - void handle(AddNode const& aAddNode); - void handle(RemoveNode const& aRemoveNode); - void handle(SubtreeChange const& aSubtree); - }; - -// ----------------------------------------------------------------------------- - - - void OMergeChanges::handle(SubtreeChange const& _rSubtree) - { - // Handle a SubtreeChange - // we must check if exact this SubtreeChange is in the TreeChangeList, if not, - // we must add this SubtreeChange to the TreeChangeList - // with the pointer m_pCurrentParent we remember our SubtreeChange in witch we - // add all other Changes. - - rtl::OUString aNodeName = _rSubtree.getNodeName(); - - Change *pChange = findExistingChange(m_pCurrentParent,aNodeName); - - // const sal_Char* pType = pChange ? pChange->getType() : NULL; - SubtreeChange* pSubtreeChange = NULL; - if (pChange == NULL || dynamic_cast< SubtreeChange * >(pChange) != 0) - { - // need to create a new Subtreechange - if (!pChange) - { - // create a new SubtreeChange - std::auto_ptr<SubtreeChange> pNewChange(new SubtreeChange(_rSubtree, treeop::NoChildCopy())); - pSubtreeChange = pNewChange.get(); - - // add the new SubtreeChange in m_aTreeChangeList - m_pCurrentParent->addChange(std::auto_ptr<Change>(pNewChange.release())); - // check list for this new SubtreeChange - OSL_ASSERT(pSubtreeChange == findExistingChange(m_pCurrentParent,aNodeName)); - } - else - { - pSubtreeChange = dynamic_cast<SubtreeChange*>(pChange); - OSL_ASSERT(pSubtreeChange != 0); - adjustElementTemplate(*pSubtreeChange,_rSubtree); - } - - // save this SubtreeChange so we allways have the last Subtree - SubtreeChange* pSaveParent = pushTree(*pSubtreeChange); - this->applyToChildren(_rSubtree); - popTree( pSaveParent ); - } - else if (AddNode* pAddNode = dynamic_cast<AddNode*>(pChange)) - { - rtl::Reference< data::TreeSegment > seg(pAddNode->getNewTree()); - std::auto_ptr<INode> pAddedNode = data::convertTree(seg.is() ? seg->fragment : 0, false); - ISubtree* pSubtree = pAddedNode.get() ? pAddedNode->asISubtree() : 0; - if (pSubtree) - { - pSubtree->markAsDefault( _rSubtree.isToDefault() ); - - // Now apply _rSubtree to the subtree - TreeUpdater aTreeUpdate(pSubtree); - aTreeUpdate.applyToChildren(_rSubtree); - - // make a new subtree with the changed data - rtl::Reference< data::TreeSegment > aNewTree = data::TreeSegment::create(pAddNode->getNodeName(), pAddedNode); - - std::auto_ptr<AddNode> pNewAdd( new AddNode(aNewTree, pAddNode->getNodeName(), pAddNode->isToDefault()) ); - if (pAddNode->isReplacing()) - pNewAdd->setReplacing(); - - std::auto_ptr<Change> pNewChange( pNewAdd.release() ); - - m_pCurrentParent->removeChange(pAddNode->getNodeName()); - m_pCurrentParent->addChange( pNewChange ); - } - else - { - OSL_ENSURE(false, "OMergeChanges: Unexpected node type found in an AddNode."); - /* wrong type of node found: böse ASSERTEN/WERFEN */; - } -// ----------------------------------------------------------------------------- -// ----------------------------------------------------------------------------- - } - else - { - OSL_ENSURE(false, "OMergeChanges: Unexpected change type found for a subtree."); - /* wrong type of node found: böse ASSERTEN/WERFEN */; - } - } - - // --------------------------------- updateTree --------------------------------- - void TreeUpdater::handle(ValueChange const& aValueNode) - { - // Change a Value - OSL_ENSURE(m_pCurrentSubtree,"Cannot apply ValueChange without subtree"); - - INode* pBaseNode = m_pCurrentSubtree ? m_pCurrentSubtree->getChild(aValueNode.getNodeName()) : 0; - OSL_ENSURE(pBaseNode,"Cannot apply Change: No node to change"); - - ValueNode* pValue = pBaseNode ? pBaseNode->asValueNode() : 0; - OSL_ENSURE(pValue,"Cannot apply ValueChange: Node is not a value"); - - if (pValue) - aValueNode.applyChangeNoRecover(*pValue); -#if OSL_DEBUG_LEVEL > 1 - else - { - ::rtl::OString aStr("TreeUpdater: Can't find value with name:="); - aStr += rtl::OUStringToOString(aValueNode.getNodeName(),RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(pValue, aStr.getStr()); - aLog.push_back(aStr); - } -#endif - } - - void TreeUpdater::handle(AddNode const& aAddNode) - { - // Add a new Value - if (m_pCurrentSubtree) - { - if (aAddNode.isReplacing()) - { - std::auto_ptr<INode> aOldNode = m_pCurrentSubtree->removeChild(aAddNode.getNodeName()); - -#if OSL_DEBUG_LEVEL > 1 - OSL_ENSURE(aOldNode.get(), "TreeUpdater:AddNode: can't recover node being replaced"); - if (aOldNode.get() == NULL) - aLog.push_back(rtl::OString("TreeUpdater: can't recover node being replaced (for AddNode)")); -#endif - } - - rtl::Reference< data::TreeSegment > seg(aAddNode.getNewTree()); - std::auto_ptr<INode> pNode(data::convertTree(seg.is() ? seg->fragment : 0, true)); - - m_pCurrentSubtree->addChild(pNode); - } -#if OSL_DEBUG_LEVEL > 1 - else - aLog.push_back(rtl::OString("TreeUpdater: no CurrentSubtree for AddNode")); -#endif - - } - - void TreeUpdater::handle(RemoveNode const& aRemoveNode) - { - // remove a Value - if (m_pCurrentSubtree) - { - std::auto_ptr<INode> aOldNode = m_pCurrentSubtree->removeChild(aRemoveNode.getNodeName()); - -#if OSL_DEBUG_LEVEL > 1 - if (NULL == aOldNode.get()) - { - ::rtl::OString aStr("TreeUpdater: Can't remove child with name:="); - aStr += rtl::OUStringToOString(aRemoveNode.getNodeName(),RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(false, aStr.getStr()); - aLog.push_back(aStr); - } -#endif - } - } - - void TreeUpdater::handle(SubtreeChange const& _aSubtree) - { - // handle traversion - ISubtree *pOldSubtree = m_pCurrentSubtree; - rtl::OUString aNodeName = _aSubtree.getNodeName(); - - INode* pChild = m_pCurrentSubtree->getChild(aNodeName); - OSL_ENSURE(pChild, "TreeUpdater::handle : invalid subtree change ... no child for change !"); - m_pCurrentSubtree = pChild ? pChild->asISubtree() : NULL; - -#if OSL_DEBUG_LEVEL > 1 - if (!m_pCurrentSubtree) - { - ::rtl::OString aStr("TreeUpdater: there is no Subtree for name:="); - aStr += rtl::OUStringToOString(_aSubtree.getNodeName(),RTL_TEXTENCODING_ASCII_US); - OSL_ENSURE(false, aStr.getStr()); - aLog.push_back(aStr); - } -#endif - // recurse - if (m_pCurrentSubtree) - { - m_pCurrentSubtree->markAsDefault( _aSubtree.isToDefault() ); - _aSubtree.forEachChange(*this); - } - - m_pCurrentSubtree = pOldSubtree; - } - -} // namespace configmgr diff --git a/configmgr/source/misc/oslstream.cxx b/configmgr/source/misc/oslstream.cxx deleted file mode 100644 index 3a52329e7c98..000000000000 --- a/configmgr/source/misc/oslstream.cxx +++ /dev/null @@ -1,264 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: oslstream.cxx,v $ - * $Revision: 1.10 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" -#include "oslstream.hxx" - -#include "filehelper.hxx" - -namespace configmgr -{ - static void raiseIOException(osl::File::RC error, staruno::Reference<staruno::XInterface> const & context) - { - const rtl::OUString message = FileHelper::createOSLErrorString(error); - switch (error) - { - case osl::File::E_NOMEM: - throw stario::BufferSizeExceededException(message, context); - - case osl::File::E_BADF: - throw stario::NotConnectedException(message, context); - - default: - throw stario::IOException(message, context); - } - } -//------------------------------------------------------------------ -OSLInputStreamWrapper::OSLInputStreamWrapper( osl::File& _rFile ) - :m_pFile(&_rFile) - ,m_bFileOwner(sal_False) -{ -} - -//------------------------------------------------------------------ -OSLInputStreamWrapper::OSLInputStreamWrapper( osl::File* pStream, sal_Bool bOwner ) - :m_pFile( pStream ) - ,m_bFileOwner( bOwner ) -{ -} - -//------------------------------------------------------------------ -OSLInputStreamWrapper::~OSLInputStreamWrapper() -{ - if( m_bFileOwner ) - delete m_pFile; -} - -//------------------------------------------------------------------------------ -sal_Int32 SAL_CALL OSLInputStreamWrapper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) - throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) -{ - if (!m_pFile) - throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); - - if (nBytesToRead < 0) - throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); - - osl::MutexGuard aGuard( m_aMutex ); - - aData.realloc(nBytesToRead); - - sal_uInt64 nRead = 0; - osl::File::RC eError = m_pFile->read(aData.getArray(), nBytesToRead, nRead); - if (eError != osl::File::E_None) - throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); - - // Wenn gelesene Zeichen < MaxLength, staruno::Sequence anpassen - if (nRead < (sal_uInt64)nBytesToRead) - aData.realloc( sal::static_int_cast<sal_Int32>( nRead )); - - return sal::static_int_cast<sal_Int32>( nRead ); -} - -//------------------------------------------------------------------------------ -sal_Int32 SAL_CALL OSLInputStreamWrapper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) -{ - if (!m_pFile) - throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); - - if (nMaxBytesToRead < 0) - throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); - - /* - if (m_pFile->IsEof()) - { - aData.realloc(0); - return 0; - } - else - */ - return readBytes(aData, nMaxBytesToRead); -} - -//------------------------------------------------------------------------------ -void SAL_CALL OSLInputStreamWrapper::skipBytes(sal_Int32 nBytesToSkip) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) -{ - osl::MutexGuard aGuard( m_aMutex ); - if (!m_pFile) - throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); - - sal_uInt64 nCurrentPos; - m_pFile->getPos(nCurrentPos); - - sal_uInt64 nNewPos = nCurrentPos + nBytesToSkip; - osl::File::RC eError = m_pFile->setPos(osl_Pos_Absolut, nNewPos); - if (eError != osl::File::E_None) - { - throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); - } -} - -//------------------------------------------------------------------------------ -sal_Int32 SAL_CALL OSLInputStreamWrapper::available() throw( stario::NotConnectedException, staruno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if (!m_pFile) - throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); - - sal_uInt64 nPos; - osl::File::RC eError = m_pFile->getPos(nPos); - if (eError != osl::File::E_None) - throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); - - sal_uInt64 nDummy = 0; - eError = m_pFile->setPos(Pos_End, nDummy); - if (eError != osl::File::E_None) - throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); - - sal_uInt64 nAvailable; - eError = m_pFile->getPos(nAvailable); - if (eError != osl::File::E_None) - throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); - - nAvailable = nAvailable - nPos; - eError = m_pFile->setPos(Pos_Absolut, nPos); - if (eError != osl::File::E_None) - throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); - return sal::static_int_cast<sal_Int32>( nAvailable ); -} - -//------------------------------------------------------------------------------ -void SAL_CALL OSLInputStreamWrapper::closeInput() throw( stario::NotConnectedException, staruno::RuntimeException ) -{ - if (!m_pFile) - throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); - - m_pFile->close(); - if (m_bFileOwner) - delete m_pFile; - - m_pFile = NULL; -} - -/*************************************************************************/ -// stario::XOutputStream -//------------------------------------------------------------------------------ -void SAL_CALL OSLOutputStreamWrapper::writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) -{ - sal_uInt32 const nLength = sal_uInt32(aData.getLength()); - if (nLength != 0) - { - sal_uInt64 nWritten; - osl::File::RC eError = rFile.write(aData.getConstArray(),nLength, nWritten); - if (eError != osl::File::E_None || nWritten != nLength) - { - throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); - } - } -} - - -//------------------------------------------------------------------ -void SAL_CALL OSLOutputStreamWrapper::flush() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) -{ -} - -//------------------------------------------------------------------ -void SAL_CALL OSLOutputStreamWrapper::closeOutput() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) -{ - rFile.close(); -} - -//------------------------------------------------------------------ -//------------------------------------------------------------------ -BufferedFileOutputStream::BufferedFileOutputStream( rtl::OUString const & aFileURL, bool bCreate, sal_uInt32 nBufferSizeHint) -: m_aFile( aFileURL, nBufferSizeHint ) -{ - sal_Int32 flags = bCreate ? OpenFlag_Write|OpenFlag_Create : OpenFlag_Write; - - osl::File::RC rc = m_aFile.open(flags); - if (rc != osl::File::E_None) - raiseIOException(rc,NULL); -} - -//------------------------------------------------------------------ -BufferedFileOutputStream::~BufferedFileOutputStream() -{ -} - -//------------------------------------------------------------------------------ -void SAL_CALL BufferedFileOutputStream::writeBytes(const staruno::Sequence< sal_Int8 >& aData) - throw( stario::NotConnectedException, stario::BufferSizeExceededException, - stario::IOException, staruno::RuntimeException ) -{ - const sal_uInt64 size = sal_uInt64(aData.getLength()); - sal_uInt64 written = 0; - - osl::File::RC rc = m_aFile.write(aData.getConstArray(), size, written); - if (rc != osl::File::E_None) - raiseIOException(rc,*this); - - // we don't support special files where multiple write passes are needed - if (written < size) - raiseIOException(osl::File::E_IO,*this); -} - -void SAL_CALL BufferedFileOutputStream::flush() - throw( stario::NotConnectedException, stario::BufferSizeExceededException, - stario::IOException, staruno::RuntimeException ) -{ - osl::File::RC rc = m_aFile.sync(); - if (rc != osl::File::E_None) - raiseIOException(rc,*this); -} - -void SAL_CALL BufferedFileOutputStream::closeOutput() - throw( stario::NotConnectedException, stario::BufferSizeExceededException, - stario::IOException, staruno::RuntimeException ) -{ - osl::File::RC rc = m_aFile.close(); - if (rc != osl::File::E_None) - raiseIOException(rc,*this); -} - -} // namespace configmgr - - diff --git a/configmgr/source/misc/propertysethelper.cxx b/configmgr/source/misc/propertysethelper.cxx deleted file mode 100644 index 7dd706190315..000000000000 --- a/configmgr/source/misc/propertysethelper.cxx +++ /dev/null @@ -1,134 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: propertysethelper.cxx,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "propertysethelper.hxx" -#include <com/sun/star/lang/XTypeProvider.hpp> - -#include <cppuhelper/typeprovider.hxx> - -//.......................................................................... -namespace configmgr { - namespace apihelper { -//.......................................................................... - namespace uno = com::sun::star::uno; - namespace lang = com::sun::star::lang; - namespace beans = com::sun::star::beans; -//.......................................................................... -PropertySetHelper::PropertySetHelper() -: BroadcasterBase() -, cppu::OWeakObject() -, cppu::OPropertySetHelper( BroadcasterBase::getBroadcastHelper() ) -, m_pHelper(0) -{ -} - -//.......................................................................... -PropertySetHelper::~PropertySetHelper() -{ - delete m_pHelper; -} - -//.......................................................................... -// XInterface -uno::Any SAL_CALL PropertySetHelper::queryInterface( uno::Type const & rType ) throw (uno::RuntimeException) -{ - uno::Any aResult = cppu::OPropertySetHelper::queryInterface(rType); - if (!aResult.hasValue()) - aResult = OWeakObject::queryInterface(rType); - return aResult; -} - -void SAL_CALL PropertySetHelper::acquire() throw () -{ - OWeakObject::acquire(); -} - -void SAL_CALL PropertySetHelper::release() throw () -{ - if (m_refCount == 1) - this->disposing(); - - OWeakObject::release(); -} - -//.......................................................................... -// XTypeProvider -uno::Sequence< uno::Type > SAL_CALL PropertySetHelper::getTypes() throw (uno::RuntimeException) -{ - // could be static instance - cppu::OTypeCollection aTypes( - ::getCppuType( static_cast< uno::Reference< beans::XPropertySet > const * >(0) ), - ::getCppuType( static_cast< uno::Reference< beans::XMultiPropertySet > const * >(0) ), - ::getCppuType( static_cast< uno::Reference< beans::XFastPropertySet > const * >(0) ), - ::getCppuType( static_cast< uno::Reference< lang::XTypeProvider > const * >(0) ) ); - - return aTypes.getTypes(); -} - -//.......................................................................... -// cppu::OPropertySetHelper -uno::Reference< beans::XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( ) - throw (uno::RuntimeException) -{ - return createPropertySetInfo(getInfoHelper()); -} - -//.......................................................................... -cppu::IPropertyArrayHelper & SAL_CALL PropertySetHelper::getInfoHelper() -{ - osl::MutexGuard aGuard( getBroadcastMutex() ); - if (!m_pHelper) - m_pHelper = newInfoHelper(); - - OSL_ENSURE(m_pHelper,"Derived class did not create new PropertyInfoHelper"); - if (!m_pHelper) - throw uno::RuntimeException(rtl::OUString::createFromAscii("No PropertyArrayHelper available"),*this); - - return *m_pHelper; -} - -//.......................................................................... -sal_Bool SAL_CALL PropertySetHelper::convertFastPropertyValue( - uno::Any & rConvertedValue, uno::Any & rOldValue, sal_Int32 nHandle, const uno::Any& rValue ) - throw (lang::IllegalArgumentException) -{ - this->getFastPropertyValue(rOldValue, nHandle); - rConvertedValue = rValue; - return rValue.isExtractableTo( rOldValue.getValueType() ); -} -//.......................................................................... - } // namespace apihelper -} // namespace configmgr -//.......................................................................... - - diff --git a/configmgr/source/misc/providerfactory.cxx b/configmgr/source/misc/providerfactory.cxx deleted file mode 100644 index 1cb726742185..000000000000 --- a/configmgr/source/misc/providerfactory.cxx +++ /dev/null @@ -1,244 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: providerfactory.cxx,v $ - * $Revision: 1.24 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" -#include <stdio.h> - -#include "providerfactory.hxx" - -#ifndef CONFIGMGR_API_FACTORY_HXX_ -#include "confapifactory.hxx" -#endif -#include "bootstrap.hxx" -#include "providerwrapper.hxx" -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/configuration/CannotLoadConfigurationException.hpp> -#include <cppuhelper/exc_hlp.hxx> -#include <rtl/ustrbuf.hxx> -#include <osl/diagnose.h> -#include <rtl/logfile.hxx> - -//--------------------------------------------------------------------------------------- -namespace configmgr -{ - //--------------------------------------------------------------------------------------- - //= OProviderFactory - //--------------------------------------------------------------------------------------- - - //--------------------------------------------------------------------------------------- - - ProviderFactory::ProviderFactory(rtl::OUString const & aImplementationName, bool bAdmin) - : m_aImplementationName(aImplementationName) - , m_bAdmin(bAdmin) - { - } - //--------------------------------------------------------------------------------------- - - ProviderFactory::~ProviderFactory() - { - } - //--------------------------------------------------------------------------------------- - - uno::Reference< uno::XInterface > ProviderFactory::getProviderAlways(uno::Reference< uno::XComponentContext > const & xContext) - { - RTL_LOGFILE_CONTEXT_AUTHOR(aLog, "configmgr::ProviderFactory", "jb99855", "configmgr::ProviderFactory::getProviderAlways()"); - uno::Reference< uno::XInterface > xResult = getDefaultConfigProviderSingleton(xContext); - - // check for success - OSL_ENSURE(xResult.is(), "Context could not create provider, but returned NULL instead of throwing an exception"); - if (!xResult.is()) - { - static sal_Char const sCannotCreate[] = "Cannot create ConfigurationProvider. Unknown backend or factory error."; - - throw com::sun::star::configuration::CannotLoadConfigurationException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sCannotCreate)), *this ); - } - - return xResult; - } - //--------------------------------------------------------------------------------------- - uno::Reference< uno::XInterface > ProviderFactory::getProviderFromContext(uno::Reference< uno::XComponentContext > const & xContext) - { - OSL_ENSURE(ContextReader::testAdminService(xContext, this->m_bAdmin), - "Creation context admin flag does not match service being created"); - - try - { - return getProviderAlways(xContext); - } - catch(uno::Exception& e) - { - ContextReader aContext(xContext); - - uno::Any aError = aContext.getBootstrapError(); - if (aError.hasValue()) - { - OSL_ASSERT(aError.getValueTypeClass() == uno::TypeClass_EXCEPTION); - cppu::throwException(aError); - } - - OSL_ASSERT(aContext.isBootstrapValid()); - - static const sal_Char sErrContext[] = "Cannot open Configuration: "; - rtl::OUString const sContext(RTL_CONSTASCII_USTRINGPARAM(sErrContext)); - e.Message = sContext.concat(e.Message); - throw; - } - } - //--------------------------------------------------------------------------------------- - uno::Reference< uno::XInterface > ProviderFactory::createProviderWithArguments(uno::Reference< uno::XComponentContext > const & xContext, uno::Sequence < uno::Any > const & _aArguments) - { - RTL_LOGFILE_CONTEXT_AUTHOR(aLog, "configmgr::ProviderFactory", "jb99855", "configmgr::ProviderFactory::createProviderWithArguments()"); - - ContextReader aContext(xContext); - ArgumentHelper aParser(aContext.getBootstrapContext()); - - uno::Sequence < beans::NamedValue > aValues(_aArguments.getLength() + 2); - sal_Int32 nCount = parseArguments(aParser,aValues,_aArguments); - - bool bNeedNewBackend = aParser.hasBackendArguments(); - - if (!aContext.testAdminService(aContext.getBaseContext(),m_bAdmin)) - { - bNeedNewBackend = true; - OSL_ASSERT( nCount+2 <= aValues.getLength()); - aValues[nCount++] = ArgumentHelper::makeAdminServiceOverride(m_bAdmin); - aValues[nCount++] = BootstrapContext::makePassthroughMarker(sal_False); - } - - OSL_ASSERT(nCount <= aValues.getLength()); - aValues.realloc(nCount); - - if (bNeedNewBackend) - { - uno::Reference< uno::XComponentContext > xMergedContext = BootstrapContext::createWrapper(xContext,aValues); - uno::Reference< uno::XInterface > xResult = getProviderFromContext(xMergedContext); - - return xResult; - } - else - { - uno::Reference< uno::XInterface > xBaseProvider = getProviderFromContext(xContext); - uno::Reference< uno::XInterface > xResult = ProviderWrapper::create(xBaseProvider,aValues); - - return xResult; - } - } - //--------------------------------------------------------------------------------------- - uno::Reference< uno::XInterface > ProviderFactory::createProvider(uno::Reference< uno::XComponentContext > const & xContext, bool bAdmin) - { - RTL_LOGFILE_CONTEXT_AUTHOR(aLog, "configmgr::ProviderFactory", "jb99855", "configmgr::ProviderFactory::createProvider(bAdmin)"); - - uno::Sequence < beans::NamedValue > aValues(2); - aValues[0] = ArgumentHelper::makeAdminServiceOverride(bAdmin); - aValues[1] = BootstrapContext::makePassthroughMarker(sal_False); - - uno::Reference< uno::XComponentContext > xMergedContext = BootstrapContext::createWrapper(xContext,aValues); - uno::Reference< uno::XInterface > xResult = getProviderFromContext(xMergedContext); - - return xResult; - } - //--------------------------------------------------------------------------------------- - uno::Reference< uno::XInterface > ProviderFactory::createProvider(uno::Reference< uno::XComponentContext > const & xContext) - { - RTL_LOGFILE_CONTEXT_AUTHOR(aLog, "configmgr::ProviderFactory", "jb99855", "configmgr::ProviderFactory::createProvider()"); - - if (BootstrapContext::isPassthrough(xContext)) - { - // make sure this uses a new BootstrapContext ! - uno::Reference< uno::XComponentContext > xPatchedContext = BootstrapContext::createWrapper(xContext,uno::Sequence < beans::NamedValue >()); - return getProviderFromContext(xPatchedContext); - } - else - return getProviderFromContext(xContext); - } - //--------------------------------------------------------------------------------------- - - sal_Int32 ProviderFactory::parseArguments(ArgumentHelper & aParser, uno::Sequence < beans::NamedValue > & rValues, uno::Sequence < uno::Any > const & _aArguments) - { - OSL_ASSERT(rValues.getLength() >= _aArguments.getLength()); - - sal_Int32 nCount = 0; - for (sal_Int32 i = 0; i < _aArguments.getLength(); ++i) - { - if (!aParser.extractArgument(rValues[nCount],_aArguments[i])) - { - rtl::OUStringBuffer sMsg; - sMsg.appendAscii("ProviderFactory: Unexpected Argument Type. "); - sMsg.appendAscii("Expected NamedValue or PropertyValue, "); - sMsg.appendAscii("found ").append(_aArguments[i].getValueTypeName()).appendAscii(". "); - throw lang::IllegalArgumentException(sMsg.makeStringAndClear(),*this,static_cast<sal_Int16>(i)); - } - - if (aParser.filterAndAdjustArgument(rValues[nCount])) - { - aParser.checkBackendArgument(rValues[nCount]); - ++nCount; - } - } - return nCount; - } - //--------------------------------------------------------------------------------------- - - uno::Reference< uno::XInterface > - SAL_CALL ProviderFactory::createInstanceWithContext( const uno::Reference< uno::XComponentContext >& xContext ) - throw (uno::Exception, ::com::sun::star::uno::RuntimeException) - { - // default provider ? - if (ContextReader::testAdminService(xContext,m_bAdmin)) - return createProvider( xContext ); - - else - return createProvider(xContext,m_bAdmin); - } - //--------------------------------------------------------------------------------------- - - uno::Reference< uno::XInterface > SAL_CALL - ProviderFactory::createInstanceWithArgumentsAndContext( const uno::Sequence< uno::Any >& aArguments, const uno::Reference< uno::XComponentContext >& xContext ) - throw (uno::Exception, uno::RuntimeException) - { - // default request - return createProviderWithArguments(xContext, aArguments); - } - - //--------------------------------------------------------------------------------------- - //--------------------------------------------------------------------------------------- - - uno::Reference< lang::XSingleComponentFactory > SAL_CALL createProviderFactory( - rtl::OUString const & aImplementationName, - bool bAdmin - ) - { - return new ProviderFactory(aImplementationName, bAdmin); - } - //--------------------------------------------------------------------------------------- -} // namespace configmgr -//........................................................................ - diff --git a/configmgr/source/misc/providerfactory.hxx b/configmgr/source/misc/providerfactory.hxx deleted file mode 100644 index ef3e879b7059..000000000000 --- a/configmgr/source/misc/providerfactory.hxx +++ /dev/null @@ -1,91 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: providerfactory.hxx,v $ - * $Revision: 1.10 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#ifndef _CONFIGMGR_PROVIDER_FACTORY_HXX_ -#define _CONFIGMGR_PROVIDER_FACTORY_HXX_ - -#include <cppuhelper/implbase1.hxx> -#include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/lang/XSingleComponentFactory.hpp> -#include <com/sun/star/lang/XEventListener.hpp> -#include <com/sun/star/beans/NamedValue.hpp> -/* -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <comphelper/stl_types.hxx> -*/ -//------------------------------------------------------------------------ -namespace configmgr -{ - //------------------------------------------------------------------------ - namespace uno = ::com::sun::star::uno; - namespace lang = ::com::sun::star::lang; - namespace beans = ::com::sun::star::beans; - //------------------------------------------------------------------------ - class ContextReader; - class ArgumentHelper; - //------------------------------------------------------------------------ - //= OProviderFactory - //------------------------------------------------------------------------ - /** a special factory for the configuration provider, - which maps creation arguments into a context. - */ - class ProviderFactory : public cppu::WeakImplHelper1< lang::XSingleComponentFactory > - { - rtl::OUString const m_aImplementationName; - bool m_bAdmin; - - public: - explicit - ProviderFactory(rtl::OUString const & aImplementationName, bool bAdmin); - ~ProviderFactory(); - - virtual uno::Reference< uno::XInterface > - SAL_CALL createInstanceWithContext(uno::Reference< uno::XComponentContext > const & xContext ) - throw (uno::Exception, uno::RuntimeException); - - virtual uno::Reference< uno::XInterface > SAL_CALL - createInstanceWithArgumentsAndContext( uno::Sequence < uno::Any > const & aArguments, uno::Reference< uno::XComponentContext > const & xContext ) - throw (uno::Exception, uno::RuntimeException); - - private: - uno::Reference< uno::XInterface > getProviderFromContext(uno::Reference< uno::XComponentContext > const & aContext); - uno::Reference< uno::XInterface > getProviderAlways(uno::Reference< uno::XComponentContext > const & xContext); - uno::Reference< uno::XInterface > createProviderWithArguments(uno::Reference< uno::XComponentContext > const & xContext, uno::Sequence < uno::Any > const & _aArguments); - uno::Reference< uno::XInterface > createProvider(uno::Reference< uno::XComponentContext > const & xContext,bool bAdmin); - uno::Reference< uno::XInterface > createProvider(uno::Reference< uno::XComponentContext > const & xContext); - sal_Int32 parseArguments(ArgumentHelper & aParser, uno::Sequence < beans::NamedValue > & rValues, uno::Sequence < uno::Any > const & _aArguments); - }; -//------------------------------------------------------------------------ -} // namespace configmgr -//------------------------------------------------------------------------ - -#endif // _CONFIGMGR_PROVIDER_FACTORY_HXX_ - diff --git a/configmgr/source/misc/providerwrapper.cxx b/configmgr/source/misc/providerwrapper.cxx deleted file mode 100644 index b350c3ed5865..000000000000 --- a/configmgr/source/misc/providerwrapper.cxx +++ /dev/null @@ -1,196 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: providerwrapper.cxx,v $ - * $Revision: 1.7 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "providerwrapper.hxx" -#include "bootstrap.hxx" -#include "bootstrapcontext.hxx" - - -#include <com/sun/star/lang/NullPointerException.hpp> -#include <com/sun/star/lang/DisposedException.hpp> - -#include <algorithm> - - -namespace configmgr -{ - //========================================================================== - namespace uno = com::sun::star::uno; - namespace lang = com::sun::star::lang; - //========================================================================== - //= ProviderWrapper - //========================================================================== - - uno::Reference< uno::XInterface > ProviderWrapper::create( uno::Reference< uno::XInterface > xDelegate, uno::Sequence< com::sun::star::beans::NamedValue > const & aPresets) - { - uno::Reference< lang::XMultiServiceFactory > xProvDelegate(xDelegate, uno::UNO_QUERY); - if (!xProvDelegate.is()) - { - rtl::OUString sMsg(RTL_CONSTASCII_USTRINGPARAM("ProviderWrapper: Cannot wrap a NULL provider")); - throw lang::NullPointerException(sMsg,NULL); - } - //Strip prefixes - uno::Sequence< com::sun::star::beans::NamedValue > aStrippedPresets = aPresets; - - for (sal_Int32 i = 0; i < aPresets.getLength(); ++i) - { - if(aPresets[i].Name.matchAsciiL(RTL_CONSTASCII_STRINGPARAM(CONTEXT_ITEM_PREFIX_ ))) - { - aStrippedPresets[i].Name = aPresets[i].Name.copy(RTL_CONSTASCII_LENGTH(CONTEXT_ITEM_PREFIX_ )); - } - } - - uno::Reference< lang::XMultiServiceFactory > xResult( new ProviderWrapper(xProvDelegate,aStrippedPresets) ); - - DisposingForwarder::forward( uno::Reference< lang::XComponent >::query(xProvDelegate),uno::Reference< lang::XComponent >::query(xResult) ); - return uno::Reference< uno::XInterface >( xResult, uno::UNO_QUERY ); - } - - - ProviderWrapper::ProviderWrapper(uno::Reference< lang::XMultiServiceFactory > const & xDelegate, uno::Sequence< com::sun::star::beans::NamedValue > const & aPresets) - : cppu::WeakComponentImplHelper2< lang::XMultiServiceFactory, lang::XServiceInfo >( PWMutexHolder::mutex ) - , m_xDelegate(xDelegate) - , m_aDefaults(aPresets.getLength()) - { - OSL_ASSERT(m_xDelegate.is()); - - for (sal_Int32 i = 0; i<aPresets.getLength(); ++i) - { - m_aDefaults[i] <<= aPresets[i]; - } - } - - ProviderWrapper::~ProviderWrapper() {} - - void SAL_CALL ProviderWrapper::disposing() - { - osl::MutexGuard lock(mutex); - m_xDelegate.clear(); - } - - uno::Reference< lang::XMultiServiceFactory > ProviderWrapper::getDelegate() - { - osl::MutexGuard lock(mutex); - if (!m_xDelegate.is()) - { - rtl::OUString sMsg(RTL_CONSTASCII_USTRINGPARAM("ProviderWrapper: Delegate Provider has been disposed")); - throw lang::DisposedException(sMsg,*this); - } - return m_xDelegate; - } - - - uno::Reference<lang::XServiceInfo> ProviderWrapper::getDelegateInfo() - { - uno::Reference<lang::XServiceInfo> xDelegate( this->getDelegate(), uno::UNO_QUERY ); - if (!xDelegate.is()) - { - rtl::OUString sMsg(RTL_CONSTASCII_USTRINGPARAM("ProviderWrapper: Delegate Provider has no service info")); - throw uno::RuntimeException(sMsg,*this); - } - return xDelegate; - } - - /// XMultiServiceFactory - static inline uno::Any const * begin(uno::Sequence< uno::Any > const & aArgs) - { return aArgs.getConstArray(); } - static inline uno::Any const * end(uno::Sequence< uno::Any > const & aArgs) - { return aArgs.getConstArray() + aArgs.getLength(); } - static inline uno::Any * begin(uno::Sequence< uno::Any > & aArgs) - { return aArgs.getArray(); } - static inline uno::Any * end(uno::Sequence< uno::Any > & aArgs) - { return aArgs.getArray() + aArgs.getLength(); } - - uno::Sequence< uno::Any > ProviderWrapper::patchArguments(uno::Sequence< uno::Any > const & aArgs) const - { - // rely on evaluation order front to back - if (m_aDefaults.getLength() == 0) return aArgs; - - uno::Sequence< uno::Any > aResult(m_aDefaults.getLength() + aArgs.getLength()); - - uno::Any * pNext = std::copy(begin(m_aDefaults),end(m_aDefaults),begin(aResult)); - pNext = std::copy(begin(aArgs),end(aArgs),pNext); - - OSL_ASSERT(end(aResult) == pNext); - - return aResult; - } - - uno::Reference< uno::XInterface > SAL_CALL - ProviderWrapper::createInstance( const rtl::OUString& aServiceSpecifier ) - throw(uno::Exception, uno::RuntimeException) - { - return getDelegate()->createInstanceWithArguments(aServiceSpecifier,m_aDefaults); - } - - uno::Reference< uno::XInterface > SAL_CALL - ProviderWrapper::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const uno::Sequence< uno::Any >& rArguments ) - throw(uno::Exception, uno::RuntimeException) - { - return getDelegate()->createInstanceWithArguments(ServiceSpecifier,patchArguments(rArguments)); - } - - uno::Sequence< rtl::OUString > SAL_CALL - ProviderWrapper::getAvailableServiceNames( ) - throw(uno::RuntimeException) - { - return getDelegate()->getAvailableServiceNames( ); - } - - /// XServiceInfo - rtl::OUString SAL_CALL - ProviderWrapper::getImplementationName( ) - throw(uno::RuntimeException) - { - return rtl::OUString::createFromAscii("com.sun.star.comp.configuration.ConfigurationProviderWrapper"); - } - - sal_Bool SAL_CALL - ProviderWrapper::supportsService( const ::rtl::OUString& ServiceName ) - throw(uno::RuntimeException) - { - return getDelegateInfo()->supportsService( ServiceName ); - } - - uno::Sequence< rtl::OUString > SAL_CALL - ProviderWrapper::getSupportedServiceNames( ) - throw(uno::RuntimeException) - { - return getDelegateInfo()->getSupportedServiceNames( ); - } - - -} // namespace configmgr - - - diff --git a/configmgr/source/misc/providerwrapper.hxx b/configmgr/source/misc/providerwrapper.hxx deleted file mode 100644 index a8848d4cce7c..000000000000 --- a/configmgr/source/misc/providerwrapper.hxx +++ /dev/null @@ -1,101 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: providerwrapper.hxx,v $ - * $Revision: 1.4 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef CONFIGMGR_API_PROVIDERWRAPPER_HXX_ -#define CONFIGMGR_API_PROVIDERWRAPPER_HXX_ - -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/beans/NamedValue.hpp> -#include <com/sun/star/uno/Sequence.hxx> -#include <cppuhelper/compbase2.hxx> -#include <osl/mutex.hxx> - -namespace configmgr -{ - //========================================================================== - namespace uno = com::sun::star::uno; - namespace lang = com::sun::star::lang; - //========================================================================== - //= ProviderWrapper - //========================================================================== - struct PWMutexHolder { osl::Mutex mutex; }; // ad hoc ... - - class ProviderWrapper : private PWMutexHolder, public cppu::WeakComponentImplHelper2< lang::XMultiServiceFactory, lang::XServiceInfo > - { - private: - uno::Reference< lang::XMultiServiceFactory > m_xDelegate; - uno::Sequence< uno::Any > m_aDefaults; - private: - ProviderWrapper(uno::Reference< lang::XMultiServiceFactory > const & xDelegate, uno::Sequence< com::sun::star::beans::NamedValue > const & aPresets); - - public: - static uno::Reference< uno::XInterface > create( uno::Reference< uno::XInterface > xDelegate, uno::Sequence< com::sun::star::beans::NamedValue > const & aPresets); - ~ProviderWrapper(); - - /// XMultiServiceFactory - virtual uno::Reference< uno::XInterface > SAL_CALL - createInstance( const rtl::OUString& aServiceSpecifier ) - throw(uno::Exception, uno::RuntimeException); - - virtual uno::Reference< uno::XInterface > SAL_CALL - createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const uno::Sequence< uno::Any >& Arguments ) - throw(uno::Exception, uno::RuntimeException); - - virtual uno::Sequence< rtl::OUString > SAL_CALL - getAvailableServiceNames( ) - throw(uno::RuntimeException); - - /// XServiceInfo - virtual rtl::OUString SAL_CALL - getImplementationName( ) - throw(uno::RuntimeException); - - virtual sal_Bool SAL_CALL - supportsService( const ::rtl::OUString& ServiceName ) - throw(uno::RuntimeException); - - virtual uno::Sequence< rtl::OUString > SAL_CALL - getSupportedServiceNames( ) - throw(uno::RuntimeException); - - protected: - virtual void SAL_CALL disposing(); - private: - uno::Reference< lang::XMultiServiceFactory > getDelegate(); - uno::Reference<lang::XServiceInfo> getDelegateInfo(); - uno::Sequence< uno::Any > patchArguments(uno::Sequence< uno::Any > const & aArgs) const; - }; - - -} // namespace configmgr - -#endif // CONFIGMGR_API_CONFPROVIDER2_HXX_ - - diff --git a/configmgr/source/misc/requestoptions.cxx b/configmgr/source/misc/requestoptions.cxx deleted file mode 100644 index 75ed08511edb..000000000000 --- a/configmgr/source/misc/requestoptions.cxx +++ /dev/null @@ -1,107 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: requestoptions.cxx,v $ - * $Revision: 1.10 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "requestoptions.hxx" -#include "matchlocale.hxx" -#include "tracer.hxx" -#include <osl/diagnose.h> - -namespace configmgr -{ -// --------------------------------------------------------------------------- - - rtl::OUString RequestOptions::getIsoLocale() const - { - return localehelper::makeIsoLocale( m_sLocale ); - } -// --------------------------------------------------------------------------- - - bool RequestOptions::isForAllLocales() const - { - return localehelper::designatesAllLocales( m_sLocale ); - } -// --------------------------------------------------------------------------- - - void RequestOptions::setIsoLocale(rtl::OUString const & _sLocale) - { - setLocale( localehelper::makeLocale( _sLocale ) ); - } -// --------------------------------------------------------------------------- - - void RequestOptions::setAllLocales() - { - m_sLocale = localehelper::getAnyLocale(); - } -// --------------------------------------------------------------------------- - - void RequestOptions::ensureLocaleSet() - { - if (!hasLocale()) - m_sLocale = localehelper::getDefaultLocale(); - } -// --------------------------------------------------------------------------- - - static inline - sal_Int32 hashRequestLocale(com::sun::star::lang::Locale const & aLocale) - { - return aLocale.Language.hashCode() ^ aLocale.Country.hashCode(); - } -// --------------------------------------------------------------------------- - - static inline - sal_Int32 compareRequestLocale(com::sun::star::lang::Locale const& lhs, com::sun::star::lang::Locale const& rhs) - { - sal_Int32 nDiff = lhs.Language.compareTo(rhs.Language); - if (nDiff == 0) - { - nDiff = lhs.Country.compareTo(rhs.Country); - } - - return nDiff; - } -// --------------------------------------------------------------------------- - - sal_Int32 compareRequestOptions(RequestOptions const& lhs, RequestOptions const& rhs) - { - sal_Int32 nDiff = lhs.getEntity().compareTo(rhs.getEntity()); - if (nDiff == 0) - { - nDiff = compareRequestLocale(lhs.getUnoLocale(),rhs.getUnoLocale()); - } - - return nDiff; - } -// --------------------------------------------------------------------------- -} // namespace config - - diff --git a/configmgr/source/misc/serviceinfohelper.cxx b/configmgr/source/misc/serviceinfohelper.cxx deleted file mode 100644 index f96e3f548402..000000000000 --- a/configmgr/source/misc/serviceinfohelper.cxx +++ /dev/null @@ -1,192 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: serviceinfohelper.cxx,v $ - * $Revision: 1.5 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "serviceinfohelper.hxx" - -namespace configmgr -{ -// --------------------------------------------------------------------------- - - sal_Int32 ServiceInfoHelper::countServices( ) const - { - if (m_info == 0) - return 0; - - sal_Int32 nCount = 0; - if (sal_Char const * const* p= m_info->registeredServiceNames) - { - while (*p != 0) - { - ++nCount; - ++p; - } - } - if (sal_Char const * const* p= m_info->additionalServiceNames) - { - while (*p != 0) - { - ++nCount; - ++p; - } - } - - return nCount; - } -// --------------------------------------------------------------------------- - - rtl::OUString ServiceInfoHelper::getImplementationName( ) const - throw(uno::RuntimeException) - { - sal_Char const * p= m_info ? m_info->implementationName : 0; - - return p ? rtl::OUString::createFromAscii(p) : rtl::OUString(); - } -// --------------------------------------------------------------------------- - - sal_Bool ServiceInfoHelper::supportsService( rtl::OUString const & ServiceName ) const - throw(uno::RuntimeException) - { - if (m_info == 0) - return false; - - if (sal_Char const * const* p= m_info->registeredServiceNames) - { - while (*p != 0) - { - if (ServiceName.equalsAscii(*p)) - return true; - ++p; - } - } - if (sal_Char const * const* p= m_info->additionalServiceNames) - { - while (*p != 0) - { - if (ServiceName.equalsAscii(*p)) - return true; - ++p; - } - } - - return false; - } -// --------------------------------------------------------------------------- - - uno::Sequence< rtl::OUString > ServiceInfoHelper::getSupportedServiceNames( ) const - throw(uno::RuntimeException) - { - sal_Int32 const nCount = countServices(); - - uno::Sequence< rtl::OUString > aServices( nCount ); - - if (nCount) - { - OSL_ASSERT(m_info); - sal_Int32 i = 0; - if (sal_Char const * const* p= m_info->registeredServiceNames) - { - while (*p != 0) - { - aServices[i++] = rtl::OUString::createFromAscii(*p++); - } - } - if (sal_Char const * const* p= m_info->additionalServiceNames) - { - while (*p != 0) - { - aServices[i++] = rtl::OUString::createFromAscii(*p++); - } - } - OSL_ASSERT( i == nCount ); - } - - return aServices; - } -// --------------------------------------------------------------------------- -// --------------------------------------------------------------------------- - - sal_Int32 ServiceRegistrationHelper::countServices( ) const - { - if (m_info == 0) - return 0; - - sal_Int32 nCount = 0; - if (sal_Char const * const* p= m_info->registeredServiceNames) - { - while (*p != 0) - { - ++nCount; - ++p; - } - } - - return nCount; - } -// --------------------------------------------------------------------------- - - rtl::OUString ServiceRegistrationHelper::getImplementationName( ) const - throw(uno::RuntimeException) - { - sal_Char const * p= m_info ? m_info->implementationName : 0; - - return p ? rtl::OUString::createFromAscii(p) : rtl::OUString(); - } -// --------------------------------------------------------------------------- - - uno::Sequence< rtl::OUString > ServiceRegistrationHelper::getRegisteredServiceNames( ) const - throw(uno::RuntimeException) - { - sal_Int32 const nCount = countServices(); - - uno::Sequence< rtl::OUString > aServices( nCount ); - - if (nCount) - { - OSL_ASSERT(m_info); - sal_Int32 i = 0; - if (sal_Char const * const* p= m_info->registeredServiceNames) - { - while (*p != 0) - { - aServices[i++] = rtl::OUString::createFromAscii(*p++); - } - } - OSL_ASSERT( i == nCount ); - } - - return aServices; - } -// --------------------------------------------------------------------------- -} // namespace config - - diff --git a/configmgr/source/misc/simpleinteractionrequest.cxx b/configmgr/source/misc/simpleinteractionrequest.cxx deleted file mode 100644 index 254b4165ed2b..000000000000 --- a/configmgr/source/misc/simpleinteractionrequest.cxx +++ /dev/null @@ -1,100 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: simpleinteractionrequest.cxx,v $ - * $Revision: 1.5.18.1 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -#include "simpleinteractionrequest.hxx" - -namespace configmgr { namespace apihelper { - -namespace uno = com::sun::star::uno; -namespace task = com::sun::star::task; -//========================================================================= -SimpleInteractionRequest::SimpleInteractionRequest( - const uno::Any & rRequest, - const sal_uInt32 nContinuations ) -: InteractionRequest( rRequest ) -{ - // Set continuations. - OSL_ENSURE( nContinuations != CONTINUATION_UNKNOWN, - "SimpleInteractionRequest - No continuation!" ); - - sal_Int32 nLength = 0; - - const sal_uInt32 k_NumContinuationTypes = 4; - uno::Reference< task::XInteractionContinuation > xContinuations[ k_NumContinuationTypes ]; - - if ( nContinuations & CONTINUATION_ABORT ) - xContinuations[nLength++] = new InteractionContinuation< task::XInteractionAbort >( this ); - - if ( nContinuations & CONTINUATION_RETRY ) - xContinuations[nLength++] = new InteractionContinuation< task::XInteractionRetry >( this ); - - if ( nContinuations & CONTINUATION_APPROVE ) - xContinuations[nLength++] = new InteractionContinuation< task::XInteractionApprove >( this ); - - if ( nContinuations & CONTINUATION_DISAPPROVE ) - xContinuations[nLength++] = new InteractionContinuation< task::XInteractionDisapprove >( this ); - - OSL_ENSURE( nLength > 0, - "SimpleInteractionRequest - No continuation!" ); - - uno::Sequence< uno::Reference< task::XInteractionContinuation > > - aContinuations( xContinuations, nLength ); - - this->setContinuations( aContinuations ); -} - -//========================================================================= -sal_uInt32 SimpleInteractionRequest::getResponse() const -{ - uno::Reference< task::XInteractionContinuation > xSelection = this->getSelection(); - if ( xSelection.is() ) - { - if ( uno::Reference< task::XInteractionApprove >::query(xSelection).is() ) - return CONTINUATION_APPROVE; - - if ( uno::Reference< task::XInteractionDisapprove >::query(xSelection).is() ) - return CONTINUATION_DISAPPROVE; - - if ( uno::Reference< task::XInteractionRetry >::query(xSelection).is() ) - return CONTINUATION_RETRY; - - if ( uno::Reference< task::XInteractionAbort >::query(xSelection).is() ) - return CONTINUATION_ABORT; - - OSL_ENSURE( sal_False, - "SimpleInteractionRequest::getResponse - Unknown continuation!" ); - } - return CONTINUATION_UNKNOWN; -} - -} } diff --git a/configmgr/source/misc/strimpl.cxx b/configmgr/source/misc/strimpl.cxx deleted file mode 100644 index 3b82f40b850a..000000000000 --- a/configmgr/source/misc/strimpl.cxx +++ /dev/null @@ -1,63 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: strimpl.cxx,v $ - * $Revision: 1.17 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" -#include "strdecl.hxx" - -namespace configmgr -{ - // simple types names - IMPLEMENT_CONSTASCII_USTRING(TYPE_BOOLEAN, "boolean"); - IMPLEMENT_CONSTASCII_USTRING(TYPE_SHORT, "short"); - IMPLEMENT_CONSTASCII_USTRING(TYPE_INT, "int"); - IMPLEMENT_CONSTASCII_USTRING(TYPE_LONG, "long"); - IMPLEMENT_CONSTASCII_USTRING(TYPE_DOUBLE, "double"); - IMPLEMENT_CONSTASCII_USTRING(TYPE_STRING, "string"); - // Type: Sequence<bytes> - IMPLEMENT_CONSTASCII_USTRING(TYPE_BINARY, "binary"); - // Universal type: Any - IMPLEMENT_CONSTASCII_USTRING(TYPE_ANY, "any"); - - // special template names for native/localized value types - IMPLEMENT_CONSTASCII_USTRING(TEMPLATE_MODULE_NATIVE_PREFIX, "cfg:"); - IMPLEMENT_CONSTASCII_USTRING(TEMPLATE_MODULE_NATIVE_VALUE, "cfg:value"); - IMPLEMENT_CONSTASCII_USTRING(TEMPLATE_MODULE_LOCALIZED_VALUE, "cfg:localized"); - - IMPLEMENT_CONSTASCII_USTRING(TEMPLATE_LIST_SUFFIX, "-list"); - - - -// emacs: -// create the declare from the implement -// (fset 'create-declare-from-implement -// [home M-right ?\C- ?\C-s ?, left right left ?\M-w f12 return up tab ?D ?E ?C ?L ?A ?R ?E ?\C-y ?) ?; home down f12 home down]) - -} // namespace configmgr diff --git a/configmgr/source/misc/tracer.cxx b/configmgr/source/misc/tracer.cxx deleted file mode 100644 index bb2fe993fb34..000000000000 --- a/configmgr/source/misc/tracer.cxx +++ /dev/null @@ -1,474 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: tracer.cxx,v $ - * $Revision: 1.21 $ - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org 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 version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_configmgr.hxx" - -// SUNPRO5 does not like the following to be done after including stdio.h, that's why it's here at the very -// beginning of the file -#undef _TIME_T_DEFINED -#include <time.h> -#include <rtl/string.hxx> -#include <map> - -#include "tracer.hxx" - -#ifdef CFG_ENABLE_TRACING - -#include <cstdarg> -#include <stdlib.h> -#include <ctype.h> -#include <string.h> - -#include <osl/process.h> -#include <osl/thread.h> -#include <osl/diagnose.h> -#include <rtl/ustring.hxx> -#include <rtl/instance.hxx> - -namespace configmgr -{ - -extern "C" -{ - static void call_freeThreadData(void*); -} - -struct OTracerSetup -{ - enum { - INFO = 0x01, - WARNING = 0x02, - ERROR = 0x04, - LEVEL_MASK = 0x0f, - - TIME = 0x10, - THREAD = 0x20, - DATA_MASK = 0xf0 - }; - - sal_uInt32 m_nTraceMask; - FILE* m_pOutputMedium; - sal_Bool m_bInitialized; - oslThreadKey m_nThreadKey; - - ::std::map< ::rtl::OString, void*, ::std::less< ::rtl::OString > > m_aDevices; - - OTracerSetup() - :m_nTraceMask(WARNING | ERROR) - ,m_pOutputMedium(NULL) - ,m_bInitialized(sal_False) - { - m_nThreadKey = ::osl_createThreadKey(call_freeThreadData); - } - ~OTracerSetup() - { - ::osl_destroyThreadKey(m_nThreadKey); - } - - bool isTracing(sal_uInt32 nTraceValue) const - { return (nTraceValue & this->m_nTraceMask) == nTraceValue; } - - void setTracing(sal_uInt32 nTraceValue) - { this->m_nTraceMask |= nTraceValue; } - - void setTracing(sal_uInt32 nTraceValue, sal_uInt32 nMask) - { - OSL_ENSURE( (nTraceValue&nMask) == nTraceValue, "Flags being set must be part of mask"); - this->m_nTraceMask &= ~nMask; - this->m_nTraceMask |= nTraceValue; - } - - sal_Int32& indentDepth(); - - struct ThreadData - { - ThreadData() : m_nIndentDepth(0) {} - sal_Int32 m_nIndentDepth; - }; - - ThreadData& ensureThreadData(); - static void freeThreadData(void*p); -}; - -//========================================================================== -//= OConfigTracer -//========================================================================== -OTracerSetup* OConfigTracer::s_pImpl = NULL; -#ifdef WNT -timeb OConfigTracer::s_aStartTime; -#else -timeval OConfigTracer::s_aStartTime; -#endif - -::osl::Mutex & OConfigTracer::getMutex() -{ - return rtl::Static<osl::Mutex,OConfigTracer>::get(); -} -//-------------------------------------------------------------------------- -void OConfigTracer::startGlobalTimer() -{ -#ifdef WNT - ftime( &s_aStartTime ); -#else - gettimeofday( &s_aStartTime, NULL ); -#endif -} - -//-------------------------------------------------------------------------- -sal_uInt32 OConfigTracer::getGlobalTimer() -{ -#ifdef WNT - struct timeb currentTime; - sal_uInt32 nSeconds; - ftime( ¤tTime ); - nSeconds = (sal_uInt32)( currentTime.time - s_aStartTime.time ); - return ( nSeconds * 1000 ) + (long)( currentTime.millitm - s_aStartTime.millitm ); -#else - struct timeval currentTime; - sal_uInt32 nSeconds; - gettimeofday( ¤tTime, NULL ); - nSeconds = (sal_uInt32)( currentTime.tv_sec - s_aStartTime.tv_sec ); - return ( nSeconds * 1000 ) + (long)( currentTime.tv_usec - s_aStartTime.tv_usec )/1000; -#endif -} - -//-------------------------------------------------------------------------- -sal_Int32& OTracerSetup::indentDepth() -{ - return ensureThreadData().m_nIndentDepth; -} - -//-------------------------------------------------------------------------- -OTracerSetup::ThreadData& OTracerSetup::ensureThreadData() -{ - void * pThreadData = ::osl_getThreadKeyData(m_nThreadKey); - - OTracerSetup::ThreadData* pRet - = static_cast< OTracerSetup::ThreadData * >(pThreadData); - - if (pRet == NULL) - { - pThreadData = pRet = new ThreadData(); - - if (!::osl_setThreadKeyData(m_nThreadKey,pThreadData)) - { - OSL_ENSURE(false, "Cannot create per-thread data for tracing"); - freeThreadData(pThreadData); - - static ThreadData sharedThreadData; - pRet = &sharedThreadData; - } - else - OSL_ASSERT( pThreadData == ::osl_getThreadKeyData(m_nThreadKey) ); - - OSL_ASSERT( pRet != NULL ); - } - - return *pRet; -} - -static void call_freeThreadData( void* p ) -{ - OTracerSetup::freeThreadData( p ); -} - -//-------------------------------------------------------------------------- -void OTracerSetup::freeThreadData(void* p) -{ - delete static_cast< OTracerSetup::ThreadData * > (p); -} - -//-------------------------------------------------------------------------- -void OConfigTracer::ensureData() -{ - if (s_pImpl) - return; - s_pImpl = new OTracerSetup; -} - -//-------------------------------------------------------------------------- -void OConfigTracer::inc() -{ - ::osl::MutexGuard aGuard(getMutex()); - ensureData(); - ++s_pImpl->indentDepth(); -} - -//-------------------------------------------------------------------------- -void OConfigTracer::dec() -{ - ::osl::MutexGuard aGuard(getMutex()); - ensureData(); - --s_pImpl->indentDepth(); -} - -//-------------------------------------------------------------------------- -void OConfigTracer::traceInfo(const sal_Char* _pFormat, ...) -{ - ::osl::MutexGuard aGuard(getMutex()); - ensureData(); - ensureInitalized(); - if (s_pImpl->isTracing(OTracerSetup::INFO) ) - { - - - va_list args; - va_start(args, _pFormat); - implTrace("info", _pFormat, args); - va_end(args); - } -} -#if OSL_DEBUG_LEVEL > 0 -//-------------------------------------------------------------------------- -void OConfigTracer::traceWarning(const sal_Char* _pFormat, ...) -{ - ::osl::MutexGuard aGuard(getMutex()); - ensureData(); - ensureInitalized(); - if (s_pImpl->isTracing(OTracerSetup::WARNING)) - { - va_list args; - va_start(args, _pFormat); - implTrace("warning", _pFormat, args); - va_end(args); - } -} - -//-------------------------------------------------------------------------- -void OConfigTracer::traceError(const sal_Char* _pFormat, ...) -{ - ::osl::MutexGuard aGuard(getMutex()); - ensureData(); - ensureInitalized(); - if (s_pImpl->isTracing(OTracerSetup::ERROR)) - { - va_list args; - va_start(args, _pFormat); - implTrace("error", _pFormat, args); - va_end(args); - } -} -#endif -//-------------------------------------------------------------------------- -void OConfigTracer::indent() -{ - sal_Int32 nIndent = s_pImpl->indentDepth(); - for (sal_Int32 i=0; i<nIndent; ++i) - fprintf(s_pImpl->m_pOutputMedium, " "); -} - -//-------------------------------------------------------------------------- -FILE* disambiguate(const ::rtl::OString& _rFileName) -{ - FILE* pExistenceCheck = NULL; - sal_Int32 i = 1; - ::rtl::OString sLoop; - while (i <= 256) - { - sLoop = _rFileName; - sLoop += "."; - sLoop += ::rtl::OString::valueOf(i); - - pExistenceCheck = fopen(sLoop.getStr(), "r"); - if (!pExistenceCheck) - // does not exist - return fopen(sLoop.getStr(), "w+"); - - // already exists, try the next name - fclose(pExistenceCheck); - ++i; - } - - // could not open such a file - return NULL; -} - -//-------------------------------------------------------------------------- -void OConfigTracer::ensureInitalized() -{ - if (s_pImpl->m_bInitialized) - return; - - s_pImpl->m_bInitialized = sal_True; - - char* pSettings = getenv("ENVCFGFLAGS"); - if (!pSettings) - return; - - /* currently recognized structure : - + switches have to be separated by whitespaces - + valid switches are: - -m[e|o|f<file>] - output to stderr (e), stdout (o) or a file (f). In the latter case the whole rest - of the param ('til the next one, means 'til the next whitespace) is the filename - -t{i,w,e,p,d}* - type of output : i includes infos, w includes warnings, e includes errors - content : p includes timestamp, d includes thread-id - */ - - s_pImpl->m_pOutputMedium = stderr; - s_pImpl->setTracing(0, OTracerSetup::LEVEL_MASK); - s_pImpl->setTracing(0, OTracerSetup::DATA_MASK); - - char* pParamLoop = pSettings; - while (*pParamLoop) - { - while (!isspace(*pParamLoop) && *pParamLoop) - ++pParamLoop; - - sal_Int32 nLen = pParamLoop - pSettings; - if ((nLen > 1) && (*pSettings == '-')) - { - ++pSettings; - switch (*pSettings) - { - case 'm': - case 'w': - if (nLen > 2) - { - ++pSettings; - switch (*pSettings) - { - case 'e': - s_pImpl->m_pOutputMedium = stderr; - break; - case 'o': - s_pImpl->m_pOutputMedium = stdout; - break; - case 'f': - { - ++pSettings; - // copy the filename into an own buffer - ::rtl::OString sFileName(pSettings, pParamLoop - pSettings); - - // open the file - s_pImpl->m_pOutputMedium = disambiguate(sFileName); - - break; - } - } - } - break; - case 'd': - { // assign a virtual device - // copy the device assingment description - ::rtl::OString sDescription(pSettings + 1, pParamLoop - pSettings - 1); - sal_Int32 nSep = sDescription.indexOf(':'); - if (-1 == nSep) - break; // invalid format - - ::rtl::OString sVirtualDeviceName, sFileName; - sVirtualDeviceName = sDescription.copy(0, nSep); - sFileName = sDescription.copy(nSep + 1); - - FILE* pVirtualDevice = disambiguate(sFileName); - if (pVirtualDevice) - s_pImpl->m_aDevices[sVirtualDeviceName] = pVirtualDevice; - } - case 't': - { - ++pSettings; - while (pSettings != pParamLoop) - { - switch (*pSettings) - { - case 'i': s_pImpl->setTracing( OTracerSetup::INFO ); break; - case 'w': s_pImpl->setTracing( OTracerSetup::WARNING ); break; - case 'e': s_pImpl->setTracing( OTracerSetup::ERROR ); break; - case 'p': s_pImpl->setTracing( OTracerSetup::TIME ); - startGlobalTimer(); - break; - case 'd': s_pImpl->setTracing( OTracerSetup::THREAD ); break; - } - ++pSettings; - } - } - } - } - - if (!*pParamLoop) - break; - - ++pParamLoop; - pSettings = pParamLoop; - } - - // trace some initial information - CFG_TRACE_INFO_NI("initialization: process id: 0x%08X", osl_getProcess(0)); - ::rtl::OUString sExecutable; - osl_getExecutableFile(&sExecutable.pData); - CFG_TRACE_INFO_NI("initialization: executable file name: %s", OUSTRING2ASCII(sExecutable)); -} - -//-------------------------------------------------------------------------- -//----------------------------------------------------------- -// need raw unsigned int to safely printf a value -static inline -unsigned int getThreadID() -{ - oslThreadIdentifier nRealThreadID = ::osl_getThreadIdentifier(NULL); - - return nRealThreadID; // if this loses data, we can still hope that lsb is changing between thraeds -} - -//-------------------------------------------------------------------------- -void OConfigTracer::implTrace(const sal_Char* _pType, const sal_Char* _pFormat, va_list args) -{ - ensureInitalized(); - if (!s_pImpl->m_pOutputMedium) - // no tracing enabled - return; - - if (_pType && strlen(_pType)) - { - if (s_pImpl->isTracing(OTracerSetup::THREAD)) - { - fprintf(s_pImpl->m_pOutputMedium, "[%04x] ", getThreadID()); - } - - fprintf(s_pImpl->m_pOutputMedium, "%s ", _pType); - - if (s_pImpl->isTracing(OTracerSetup::TIME)) - { - fprintf(s_pImpl->m_pOutputMedium, "(%06" SAL_PRIuUINT32 ")", getGlobalTimer()); - } - } - fprintf(s_pImpl->m_pOutputMedium, ": "); - - indent(); - - vfprintf(s_pImpl->m_pOutputMedium, _pFormat, args); - fprintf(s_pImpl->m_pOutputMedium,"\n"); - fflush(s_pImpl->m_pOutputMedium); -} - -} // namespace configmgr - -#endif // CFG_ENABLE_TRACING - |