diff options
Diffstat (limited to 'stoc/source/registry_tdprovider')
21 files changed, 4878 insertions, 0 deletions
diff --git a/stoc/source/registry_tdprovider/base.hxx b/stoc/source/registry_tdprovider/base.hxx new file mode 100644 index 000000000000..532b81dd8468 --- /dev/null +++ b/stoc/source/registry_tdprovider/base.hxx @@ -0,0 +1,649 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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 _STOC_RDBTDP_BASE_HXX +#define _STOC_RDBTDP_BASE_HXX + +#include <osl/diagnose.h> +#include <osl/mutex.hxx> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implementationentry.hxx> + +#include "registry/refltype.hxx" + +#include <list> +#include <memory> +#include <vector> + +#include <com/sun/star/reflection/XTypeDescription.hpp> +#include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp> +#include <com/sun/star/reflection/XInterfaceTypeDescription.hpp> +#include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp> +#include <com/sun/star/reflection/XCompoundTypeDescription.hpp> +#include <com/sun/star/reflection/XConstantTypeDescription.hpp> +#include <com/sun/star/reflection/XConstantsTypeDescription.hpp> +#include <com/sun/star/reflection/XEnumTypeDescription.hpp> +#include <com/sun/star/reflection/XIndirectTypeDescription.hpp> +#include <com/sun/star/reflection/XServiceConstructorDescription.hpp> +#include <com/sun/star/reflection/XServiceTypeDescription.hpp> +#include <com/sun/star/reflection/XServiceTypeDescription2.hpp> +#include <com/sun/star/reflection/XSingletonTypeDescription2.hpp> +#include <com/sun/star/reflection/XModuleTypeDescription.hpp> +#include <com/sun/star/reflection/XPublished.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> + +using namespace std; +using namespace osl; +using namespace cppu; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::container; +using namespace com::sun::star::reflection; + +using ::rtl::OUString; + +//-------------------------------------------------------------------------------------------------- + +extern rtl_StandardModuleCount g_moduleCount; + +namespace stoc_rdbtdp +{ + +com::sun::star::uno::Reference< XTypeDescription > resolveTypedefs( + com::sun::star::uno::Reference< XTypeDescription > const & type); + + +::osl::Mutex & getMutex(); + +//-------------------------------------------------------------------------------------------------- + +typedef ::std::list< ::com::sun::star::uno::Reference< + ::com::sun::star::registry::XRegistryKey > > RegistryKeyList; + +//-------------------------------------------------------------------------------------------------- + +class RegistryKeyCloser +{ +public: + RegistryKeyCloser( const ::com::sun::star::uno::Reference< + ::com::sun::star::registry::XRegistryKey > & xKey ) + : m_xKey( xKey ) {} + ~RegistryKeyCloser() + { if ( m_xKey.is() ) { try { if ( m_xKey->isValid() ) m_xKey->closeKey(); } catch (...) {} } } + + void reset() { m_xKey.clear(); } +private: + ::com::sun::star::uno::Reference< + ::com::sun::star::registry::XRegistryKey > m_xKey; +}; + +//-------------------------------------------------------------------------------------------------- + +// helper to create XTypeDescription instances using typereg::Reader +// (used from Type Provider and Type Description Enumeration implementation) +::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XTypeDescription > +createTypeDescription( + const ::com::sun::star::uno::Sequence< sal_Int8 > & rData, + const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XHierarchicalNameAccess > & xNameAccess, + bool bReturnEmptyRefForUnknownType ); + + +//-------------------------------------------------------------------------------------------------- +inline sal_Int32 getRTValueAsInt32( const RTConstValue & rVal ) +{ + switch (rVal.m_type) + { + case RT_TYPE_BYTE: + return rVal.m_value.aByte; + case RT_TYPE_INT16: + return rVal.m_value.aShort; + case RT_TYPE_UINT16: + return rVal.m_value.aUShort; + case RT_TYPE_INT32: + return rVal.m_value.aLong; + case RT_TYPE_UINT32: + return rVal.m_value.aULong; + default: + OSL_FAIL( "### unexpected value type!" ); + return 0; + } +} +//-------------------------------------------------------------------------------------------------- +inline Any getRTValue( const RTConstValue & rVal ) +{ + switch (rVal.m_type) + { + case RT_TYPE_BOOL: + return Any( &rVal.m_value.aBool, ::getCppuBooleanType() ); + case RT_TYPE_BYTE: + return Any( &rVal.m_value.aByte, ::getCppuType( (const sal_Int8 *)0 ) ); + case RT_TYPE_INT16: + return Any( &rVal.m_value.aShort, ::getCppuType( (const sal_Int16 *)0 ) ); + case RT_TYPE_UINT16: + return Any( &rVal.m_value.aUShort, ::getCppuType( (const sal_uInt16 *)0 ) ); + case RT_TYPE_INT32: + return Any( &rVal.m_value.aLong, ::getCppuType( (const sal_Int32 *)0 ) ); + case RT_TYPE_UINT32: + return Any( &rVal.m_value.aULong, ::getCppuType( (const sal_uInt32 *)0 ) ); + case RT_TYPE_INT64: + return Any( &rVal.m_value.aHyper, ::getCppuType( (const sal_Int64 *)0 ) ); + case RT_TYPE_UINT64: + return Any( &rVal.m_value.aUHyper, ::getCppuType( (const sal_uInt64 *)0 ) ); + case RT_TYPE_FLOAT: + return Any( &rVal.m_value.aFloat, ::getCppuType( (const float *)0 ) ); + case RT_TYPE_DOUBLE: + return Any( &rVal.m_value.aDouble, ::getCppuType( (const double *)0 ) ); + case RT_TYPE_STRING: + { + OUString aStr( rVal.m_value.aString ); + return Any( &aStr, ::getCppuType( (const OUString *)0 ) ); + } + default: + OSL_FAIL( "### unexpected RTValue!" ); + return Any(); + } +} + +//================================================================================================== +class TypeDescriptionImpl : public WeakImplHelper1< XTypeDescription > +{ + TypeClass _eTypeClass; + OUString _aName; + +public: + TypeDescriptionImpl( TypeClass eTypeClass, const OUString & rName ) + : _eTypeClass( eTypeClass ) + , _aName( rName ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~TypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); +}; + +//================================================================================================== +class InterfaceTypeDescriptionImpl: + public WeakImplHelper2< XInterfaceTypeDescription2, XPublished > +{ + com::sun::star::uno::Reference< XHierarchicalNameAccess > _xTDMgr; + Sequence< sal_Int8 > _aBytes; + + OUString _aName; + + Sequence< OUString > _aBaseTypes; + Sequence< com::sun::star::uno::Reference< XTypeDescription > > _xBaseTDs; + Sequence< OUString > _aOptionalBaseTypes; + Sequence< com::sun::star::uno::Reference< XTypeDescription > > + _xOptionalBaseTDs; + + sal_Int32 _nBaseOffset; + Sequence< + com::sun::star::uno::Reference< XInterfaceMemberTypeDescription > > + _members; + bool _membersInit; + + bool _published; + + void checkInterfaceType( + com::sun::star::uno::Reference< XTypeDescription > const & type); + +public: + InterfaceTypeDescriptionImpl( + const com::sun::star::uno::Reference< XHierarchicalNameAccess > & + xTDMgr, + const OUString & rName, const Sequence< OUString > & rBaseTypes, + const Sequence< OUString > & rOptionalBaseTypes, + const Sequence< sal_Int8 > & rBytes, bool published ); + virtual ~InterfaceTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); + + // XInterfaceTypeDescription2 + virtual Uik SAL_CALL getUik() throw(::com::sun::star::uno::RuntimeException); + virtual com::sun::star::uno::Reference< XTypeDescription > SAL_CALL + getBaseType() throw(::com::sun::star::uno::RuntimeException); + virtual + Sequence< + com::sun::star::uno::Reference< XInterfaceMemberTypeDescription > > + SAL_CALL getMembers() throw(::com::sun::star::uno::RuntimeException); + + virtual Sequence< com::sun::star::uno::Reference< XTypeDescription > > + SAL_CALL getBaseTypes() throw (RuntimeException); + + virtual Sequence< com::sun::star::uno::Reference< XTypeDescription > > + SAL_CALL getOptionalBaseTypes() throw (RuntimeException); + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return _published; } +}; + +//================================================================================================== +class CompoundTypeDescriptionImpl: + public WeakImplHelper2< XCompoundTypeDescription, XPublished > +{ + com::sun::star::uno::Reference< XHierarchicalNameAccess > _xTDMgr; + TypeClass _eTypeClass; + Sequence< sal_Int8 > _aBytes; + OUString _aName; + + OUString _aBaseType; + com::sun::star::uno::Reference< XTypeDescription > _xBaseTD; + + Sequence< com::sun::star::uno::Reference< XTypeDescription > > * _pMembers; + Sequence< OUString > * _pMemberNames; + + bool _published; + +public: + CompoundTypeDescriptionImpl( + const com::sun::star::uno::Reference< XHierarchicalNameAccess > & + xTDMgr, + TypeClass eTypeClass, + const OUString & rName, const OUString & rBaseName, + const Sequence< sal_Int8 > & rBytes, + bool published ) + : _xTDMgr( xTDMgr ) + , _eTypeClass( eTypeClass ) + , _aBytes( rBytes ) + , _aName( rName ) + , _aBaseType( rBaseName ) + , _pMembers( 0 ) + , _pMemberNames( 0 ) + , _published( published ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~CompoundTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); + + // XCompoundTypeDescription + virtual com::sun::star::uno::Reference< XTypeDescription > SAL_CALL + getBaseType() throw(::com::sun::star::uno::RuntimeException); + virtual Sequence< com::sun::star::uno::Reference< XTypeDescription > > + SAL_CALL getMemberTypes() throw(::com::sun::star::uno::RuntimeException); + virtual Sequence< OUString > SAL_CALL getMemberNames() throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return _published; } +}; + +//================================================================================================== +class EnumTypeDescriptionImpl: + public WeakImplHelper2< XEnumTypeDescription, XPublished > +{ + com::sun::star::uno::Reference< XHierarchicalNameAccess > _xTDMgr; + Sequence< sal_Int8 > _aBytes; + + OUString _aName; + sal_Int32 _nDefaultValue; + + Sequence< OUString > * _pEnumNames; + Sequence< sal_Int32 > * _pEnumValues; + + bool _published; + +public: + EnumTypeDescriptionImpl( + const com::sun::star::uno::Reference< XHierarchicalNameAccess > & + xTDMgr, + const OUString & rName, sal_Int32 nDefaultValue, + const Sequence< sal_Int8 > & rBytes, bool published ) + : _xTDMgr( xTDMgr ) + , _aBytes( rBytes ) + , _aName( rName ) + , _nDefaultValue( nDefaultValue ) + , _pEnumNames( 0 ) + , _pEnumValues( 0 ) + , _published( published ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~EnumTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); + + // XEnumTypeDescription + virtual sal_Int32 SAL_CALL getDefaultEnumValue() throw(::com::sun::star::uno::RuntimeException); + virtual Sequence< OUString > SAL_CALL getEnumNames() throw(::com::sun::star::uno::RuntimeException); + virtual Sequence< sal_Int32 > SAL_CALL getEnumValues() throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return _published; } +}; + +//================================================================================================== +class TypedefTypeDescriptionImpl: + public WeakImplHelper2< XIndirectTypeDescription, XPublished > +{ + com::sun::star::uno::Reference< XHierarchicalNameAccess > _xTDMgr; + OUString _aName; + + OUString _aRefName; + com::sun::star::uno::Reference< XTypeDescription > _xRefTD; + + bool _published; + +public: + TypedefTypeDescriptionImpl( + const com::sun::star::uno::Reference< XHierarchicalNameAccess > & + xTDMgr, + const OUString & rName, const OUString & rRefName, bool published ) + : _xTDMgr( xTDMgr ) + , _aName( rName ) + , _aRefName( rRefName ) + , _published( published ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~TypedefTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); + + // XIndirectTypeDescription + virtual com::sun::star::uno::Reference< XTypeDescription > SAL_CALL + getReferencedType() throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return _published; } +}; + +//================================================================================================== +class ServiceTypeDescriptionImpl: + public WeakImplHelper2< XServiceTypeDescription2, XPublished > +{ + OUString _aName; + Sequence< sal_Int8 > _aBytes; + com::sun::star::uno::Reference< XHierarchicalNameAccess > _xTDMgr; + bool _bInitReferences; + + com::sun::star::uno::Reference< XTypeDescription > _xInterfaceTD; + std::auto_ptr< + Sequence< + com::sun::star::uno::Reference< XServiceConstructorDescription > > > + _pCtors; + Sequence< com::sun::star::uno::Reference< XServiceTypeDescription > > + _aMandatoryServices; + Sequence< com::sun::star::uno::Reference< XServiceTypeDescription > > + _aOptionalServices; + Sequence< com::sun::star::uno::Reference< XInterfaceTypeDescription > > + _aMandatoryInterfaces; + Sequence< com::sun::star::uno::Reference< XInterfaceTypeDescription > > + _aOptionalInterfaces; + std::auto_ptr< + Sequence< com::sun::star::uno::Reference< XPropertyTypeDescription > > > + _pProps; + + bool _published; + +public: + ServiceTypeDescriptionImpl( + const com::sun::star::uno::Reference< XHierarchicalNameAccess > & + xTDMgr, + const OUString & rName, const Sequence< sal_Int8 > & rBytes, + bool published) + : _aName( rName ), _aBytes( rBytes ), _xTDMgr( xTDMgr ), + _bInitReferences( false ), _published( published ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~ServiceTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL + getTypeClass() + throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL + getName() + throw(::com::sun::star::uno::RuntimeException); + + // XServiceTypeDescription + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XServiceTypeDescription > > SAL_CALL + getMandatoryServices() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XServiceTypeDescription > > SAL_CALL + getOptionalServices() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XInterfaceTypeDescription > > SAL_CALL + getMandatoryInterfaces() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XInterfaceTypeDescription > > SAL_CALL + getOptionalInterfaces() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XPropertyTypeDescription > > SAL_CALL + getProperties() + throw (::com::sun::star::uno::RuntimeException); + + // XServiceTypeDescription2 + virtual sal_Bool SAL_CALL isSingleInterfaceBased() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< XTypeDescription > SAL_CALL + getInterface() throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XServiceConstructorDescription > > + SAL_CALL getConstructors() + throw (::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return _published; } + +private: + void getReferences() + throw (::com::sun::star::uno::RuntimeException); +}; + +//================================================================================================== +class ModuleTypeDescriptionImpl : public WeakImplHelper1< XModuleTypeDescription > +{ + OUString _aName; + com::sun::star::uno::Reference< XTypeDescriptionEnumerationAccess > _xTDMgr; + + Sequence< com::sun::star::uno::Reference< XTypeDescription > > * _pMembers; + +public: + ModuleTypeDescriptionImpl( + const com::sun::star::uno::Reference< + XTypeDescriptionEnumerationAccess > & xTDMgr, + const OUString & rName ) + : _aName( rName ), _xTDMgr( xTDMgr ), _pMembers( 0 ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~ModuleTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL + getTypeClass() + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL + getName() + throw( ::com::sun::star::uno::RuntimeException ); + + // XModuleTypeDescription + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XTypeDescription > > SAL_CALL + getMembers() + throw ( ::com::sun::star::uno::RuntimeException ); +}; + +//================================================================================================== +class ConstantTypeDescriptionImpl : public WeakImplHelper1< XConstantTypeDescription > +{ + OUString _aName; + Any _aValue; + +public: + ConstantTypeDescriptionImpl( const OUString & rName, + const Any & rValue ) + : _aName( rName ), _aValue( rValue ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~ConstantTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL + getTypeClass() + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL + getName() + throw( ::com::sun::star::uno::RuntimeException ); + + // XConstantTypeDescription + virtual ::com::sun::star::uno::Any SAL_CALL + getConstantValue() + throw ( ::com::sun::star::uno::RuntimeException ); +}; + +//================================================================================================== +class ConstantsTypeDescriptionImpl: + public WeakImplHelper2< XConstantsTypeDescription, XPublished > +{ + OUString _aName; + Sequence< sal_Int8 > _aBytes; + Sequence< com::sun::star::uno::Reference< XConstantTypeDescription > > * + _pMembers; + + bool _published; + +public: + ConstantsTypeDescriptionImpl( const OUString & rName, + const Sequence< sal_Int8 > & rBytes, + bool published ) + : _aName( rName ), _aBytes( rBytes), _pMembers( 0 ), _published( published ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~ConstantsTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL + getTypeClass() + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL + getName() + throw( ::com::sun::star::uno::RuntimeException ); + + // XConstantsTypeDescription + virtual + Sequence< com::sun::star::uno::Reference< XConstantTypeDescription > > + SAL_CALL getConstants() throw ( RuntimeException ); + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return _published; } +}; + +//================================================================================================== +class SingletonTypeDescriptionImpl: + public WeakImplHelper2< XSingletonTypeDescription2, XPublished > +{ + OUString _aName; + OUString _aBaseName; + com::sun::star::uno::Reference< XHierarchicalNameAccess > _xTDMgr; + com::sun::star::uno::Reference< XTypeDescription > _xInterfaceTD; + com::sun::star::uno::Reference< XServiceTypeDescription > _xServiceTD; + + bool _published; + + void init(); + +public: + SingletonTypeDescriptionImpl( + const com::sun::star::uno::Reference< XHierarchicalNameAccess > & + xTDMgr, + const OUString & rName, const OUString & rBaseName, bool published ) + : _aName( rName ), _aBaseName( rBaseName), _xTDMgr( xTDMgr ), + _published( published ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~SingletonTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL + getTypeClass() + throw( ::com::sun::star::uno::RuntimeException ); + virtual OUString SAL_CALL + getName() + throw( ::com::sun::star::uno::RuntimeException ); + + // XSingletonTypeDescription + virtual com::sun::star::uno::Reference< XServiceTypeDescription > SAL_CALL + getService() throw ( ::com::sun::star::uno::RuntimeException ); + + // XSingletonTypeDescription2 + virtual sal_Bool SAL_CALL isInterfaceBased() + throw (::com::sun::star::uno::RuntimeException); + virtual com::sun::star::uno::Reference< XTypeDescription > SAL_CALL + getInterface() throw (::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return _published; } +}; + +} + +#endif /* _STOC_RDBTDP_BASE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/functiondescription.cxx b/stoc/source/registry_tdprovider/functiondescription.cxx new file mode 100644 index 000000000000..01af60d9b988 --- /dev/null +++ b/stoc/source/registry_tdprovider/functiondescription.cxx @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" + +#include "functiondescription.hxx" + +#include "com/sun/star/container/NoSuchElementException.hpp" +#include "com/sun/star/container/XHierarchicalNameAccess.hpp" +#include "com/sun/star/reflection/XCompoundTypeDescription.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/Sequence.hxx" +#include "com/sun/star/uno/TypeClass.hpp" +#include "com/sun/star/uno/XInterface.hpp" +#include "cppuhelper/implbase1.hxx" +#include "osl/diagnose.h" +#include "osl/mutex.hxx" +#include "registry/reader.hxx" +#include "registry/version.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +namespace css = com::sun::star; + +using stoc::registry_tdprovider::FunctionDescription; + +FunctionDescription::FunctionDescription( + css::uno::Reference< css::container::XHierarchicalNameAccess > const & + manager, + com::sun::star::uno::Sequence< sal_Int8 > const & bytes, + sal_uInt16 index): + m_manager(manager), m_bytes(bytes), m_index(index), m_exceptionsInit(false) +{} + +FunctionDescription::~FunctionDescription() {} + +css::uno::Sequence< + css::uno::Reference< css::reflection::XCompoundTypeDescription > > +FunctionDescription::getExceptions() const { + { + osl::MutexGuard guard(m_mutex); + if (m_exceptionsInit) { + return m_exceptions; + } + } + typereg::Reader reader(getReader()); + sal_uInt16 n = reader.getMethodExceptionCount(m_index); + css::uno::Sequence< + css::uno::Reference< css::reflection::XCompoundTypeDescription > > + exceptions(n); + for (sal_uInt16 i = 0; i < n; ++i) { + rtl::OUString name( + reader.getMethodExceptionTypeName(m_index, i).replace('/', '.')); + css::uno::Any any; + try { + any = m_manager->getByHierarchicalName(name); + } catch (css::container::NoSuchElementException & e) { + throw new css::uno::RuntimeException( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container.NoSuchElementException: ")) + + e.Message), + css::uno::Reference< css::uno::XInterface >()); //TODO + } + if (!(any >>= exceptions[i]) + || exceptions[i]->getTypeClass() != css::uno::TypeClass_EXCEPTION) + { + throw new css::uno::RuntimeException( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("not an exception type: ")) + + name), + css::uno::Reference< css::uno::XInterface >()); //TODO + } + OSL_ASSERT(exceptions[i].is()); + } + osl::MutexGuard guard(m_mutex); + if (!m_exceptionsInit) { + m_exceptions = exceptions; + m_exceptionsInit = true; + } + return m_exceptions; +} + +typereg::Reader FunctionDescription::getReader() const { + return typereg::Reader( + m_bytes.getConstArray(), m_bytes.getLength(), false, TYPEREG_VERSION_1); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/functiondescription.hxx b/stoc/source/registry_tdprovider/functiondescription.hxx new file mode 100644 index 000000000000..1ecb88b945c0 --- /dev/null +++ b/stoc/source/registry_tdprovider/functiondescription.hxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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 INCLUDED_stoc_source_registry_tdprovider_functiondescription_hxx +#define INCLUDED_stoc_source_registry_tdprovider_functiondescription_hxx + +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/Sequence.hxx" +#include "osl/mutex.hxx" +#include "sal/types.h" + +namespace com { namespace sun { namespace star { + namespace container { + class XHierarchicalNameAccess; + } + namespace reflection { + class XCompoundTypeDescription; + } +} } } +namespace typereg { class Reader; } + +namespace stoc { namespace registry_tdprovider { + +class FunctionDescription { +public: + FunctionDescription( + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > const & + manager, + com::sun::star::uno::Sequence< sal_Int8 > const & bytes, + sal_uInt16 index); + + ~FunctionDescription(); + + com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< + com::sun::star::reflection::XCompoundTypeDescription > > + getExceptions() const; + +protected: + typereg::Reader getReader() const; + + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > m_manager; + com::sun::star::uno::Sequence< sal_Int8 > m_bytes; + sal_uInt16 m_index; + + mutable osl::Mutex m_mutex; + mutable com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< + com::sun::star::reflection::XCompoundTypeDescription > > + m_exceptions; + mutable bool m_exceptionsInit; + +private: + FunctionDescription(FunctionDescription &); // not implemented + void operator =(FunctionDescription); // not implemented +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/makefile.mk b/stoc/source/registry_tdprovider/makefile.mk new file mode 100644 index 000000000000..6b59701541bb --- /dev/null +++ b/stoc/source/registry_tdprovider/makefile.mk @@ -0,0 +1,61 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# 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=..$/.. + +PRJNAME= stoc +TARGET = regtypeprov +ENABLE_EXCEPTIONS=TRUE +BOOTSTRAP_SERVICE=TRUE +UNOUCROUT= $(OUT)$/inc$/bootstrap + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# ------------------------------------------------------------------ + +SLOFILES= \ + $(SLO)$/tdprovider.obj \ + $(SLO)$/td.obj \ + $(SLO)$/tdef.obj \ + $(SLO)$/tdenum.obj \ + $(SLO)$/tdcomp.obj \ + $(SLO)$/tdconsts.obj \ + $(SLO)$/tdiface.obj \ + $(SLO)$/tdmodule.obj \ + $(SLO)$/tdprop.obj \ + $(SLO)$/tdservice.obj \ + $(SLO)$/tdsingleton.obj \ + $(SLO)$/rdbtdp_tdenumeration.obj \ + $(SLO)$/functiondescription.obj \ + $(SLO)$/methoddescription.obj \ + $(SLO)$/structtypedescription.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/stoc/source/registry_tdprovider/methoddescription.cxx b/stoc/source/registry_tdprovider/methoddescription.cxx new file mode 100644 index 000000000000..7914a82a6781 --- /dev/null +++ b/stoc/source/registry_tdprovider/methoddescription.cxx @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" + +#include "methoddescription.hxx" + +#include "com/sun/star/container/NoSuchElementException.hpp" +#include "com/sun/star/container/XHierarchicalNameAccess.hpp" +#include "com/sun/star/reflection/XParameter.hpp" +#include "com/sun/star/reflection/XTypeDescription.hpp" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/Sequence.hxx" +#include "cppuhelper/implbase1.hxx" +#include "cppuhelper/weak.hxx" +#include "osl/mutex.hxx" +#include "registry/reader.hxx" +#include "registry/types.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +namespace css = com::sun::star; + +using stoc::registry_tdprovider::MethodDescription; + +namespace { + +class Parameter: public cppu::WeakImplHelper1< css::reflection::XParameter > { +public: + Parameter( + css::uno::Reference< css::container::XHierarchicalNameAccess > const & + manager, + rtl::OUString const & name, rtl::OUString const & typeName, + RTParamMode mode, sal_Int32 position): + m_manager(manager), m_name(name), + m_typeName(typeName.replace('/', '.')), m_mode(mode), + m_position(position) {} + + virtual ~Parameter() {} + + virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException) + { return m_name; } + + virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL + getType() throw (css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isIn() throw (css::uno::RuntimeException) + { return (m_mode & RT_PARAM_IN) != 0; } + + virtual sal_Bool SAL_CALL isOut() throw (css::uno::RuntimeException) + { return (m_mode & RT_PARAM_OUT) != 0; } + + virtual sal_Int32 SAL_CALL getPosition() throw (css::uno::RuntimeException) + { return m_position; } + + virtual sal_Bool SAL_CALL isRestParameter() + throw (css::uno::RuntimeException) + { return (m_mode & RT_PARAM_REST) != 0; } + +private: + Parameter(Parameter &); // not implemented + void operator =(Parameter); // not implemented + + css::uno::Reference< css::container::XHierarchicalNameAccess > m_manager; + rtl::OUString m_name; + rtl::OUString m_typeName; + RTParamMode m_mode; + sal_Int32 m_position; +}; + +css::uno::Reference< css::reflection::XTypeDescription > Parameter::getType() + throw (css::uno::RuntimeException) +{ + try { + return css::uno::Reference< css::reflection::XTypeDescription >( + m_manager->getByHierarchicalName(m_typeName), + css::uno::UNO_QUERY_THROW); + } catch (css::container::NoSuchElementException & e) { + throw new css::uno::RuntimeException( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container.NoSuchElementException: ")) + + e.Message), + static_cast< cppu::OWeakObject * >(this)); + } +} + +} + +MethodDescription::MethodDescription( + css::uno::Reference< css::container::XHierarchicalNameAccess > const & + manager, + rtl::OUString const & name, + com::sun::star::uno::Sequence< sal_Int8 > const & bytes, + sal_uInt16 index): + FunctionDescription(manager, bytes, index), m_name(name), + m_parametersInit(false) +{} + +MethodDescription::~MethodDescription() {} + +css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > +MethodDescription::getParameters() const { + osl::MutexGuard guard(m_mutex); + if (!m_parametersInit) { + typereg::Reader reader(getReader()); + sal_uInt16 n = reader.getMethodParameterCount(m_index); + m_parameters.realloc(n); + for (sal_uInt16 i = 0; i < n; ++i) { + m_parameters[i] = new Parameter( + m_manager, reader.getMethodParameterName(m_index, i), + reader.getMethodParameterTypeName(m_index, i), + reader.getMethodParameterFlags(m_index, i), i); + } + m_parametersInit = true; + } + return m_parameters; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/methoddescription.hxx b/stoc/source/registry_tdprovider/methoddescription.hxx new file mode 100644 index 000000000000..c2f5b452901d --- /dev/null +++ b/stoc/source/registry_tdprovider/methoddescription.hxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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 INCLUDED_stoc_source_registry_tdprovider_methoddescription_hxx +#define INCLUDED_stoc_source_registry_tdprovider_methoddescription_hxx + +#include "functiondescription.hxx" + +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/Sequence.hxx" +#include "rtl/ustring.hxx" +#include "sal/types.h" + +namespace com { namespace sun { namespace star { + namespace container { + class XHierarchicalNameAccess; + } + namespace reflection { + class XParameter; + } +} } } +namespace typereg { class Reader; } + +namespace stoc { namespace registry_tdprovider { + +class MethodDescription: public FunctionDescription { +public: + MethodDescription( + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > const & + manager, + rtl::OUString const & name, + com::sun::star::uno::Sequence< sal_Int8 > const & bytes, + sal_uInt16 index); + + ~MethodDescription(); + + rtl::OUString getName() const { return m_name; } + + com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< + com::sun::star::reflection::XParameter > > + getParameters() const; + +private: + MethodDescription(MethodDescription &); // not implemented + void operator =(MethodDescription); // not implemented + + rtl::OUString m_name; + mutable com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< + com::sun::star::reflection::XParameter > > m_parameters; + mutable bool m_parametersInit; +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/rdbtdp_tdenumeration.cxx b/stoc/source/registry_tdprovider/rdbtdp_tdenumeration.cxx new file mode 100644 index 000000000000..3aea56231ad9 --- /dev/null +++ b/stoc/source/registry_tdprovider/rdbtdp_tdenumeration.cxx @@ -0,0 +1,634 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" + +//========================================================================= +// Todo: +// +// - closeKey() calls (according to JSC not really needed because XRegistry +// implementation closes key in it's dtor. +// +//========================================================================= +#include <osl/diagnose.h> +#include <rtl/ustrbuf.hxx> +#include "com/sun/star/reflection/XPublished.hpp" +#include "cppuhelper/implbase1.hxx" +#include "registry/reader.hxx" +#include "registry/version.h" +#include "base.hxx" +#include "rdbtdp_tdenumeration.hxx" + +using namespace com::sun::star; + +namespace { + +class IndividualConstantTypeDescriptionImpl: + public cppu::ImplInheritanceHelper1< + stoc_rdbtdp::ConstantTypeDescriptionImpl, + com::sun::star::reflection::XPublished > +{ +public: + IndividualConstantTypeDescriptionImpl( + rtl::OUString const & name, com::sun::star::uno::Any const & value, + bool published): + cppu::ImplInheritanceHelper1< + stoc_rdbtdp::ConstantTypeDescriptionImpl, + com::sun::star::reflection::XPublished >(name, value), + m_published(published) {} + + virtual sal_Bool SAL_CALL isPublished() + throw (::com::sun::star::uno::RuntimeException) + { return m_published; } + +private: + bool m_published; +}; + +} + +namespace stoc_rdbtdp +{ + +//========================================================================= +//========================================================================= +// +// TypeDescriptionEnumerationImpl Implementation. +// +//========================================================================= +//========================================================================= + +// static +rtl::Reference< TypeDescriptionEnumerationImpl > +TypeDescriptionEnumerationImpl::createInstance( + const uno::Reference< container::XHierarchicalNameAccess > & xTDMgr, + const rtl::OUString & rModuleName, + const uno::Sequence< uno::TypeClass > & rTypes, + reflection::TypeDescriptionSearchDepth eDepth, + const RegistryKeyList & rBaseKeys ) + throw ( reflection::NoSuchTypeNameException, + reflection::InvalidTypeNameException, + uno::RuntimeException ) +{ + if ( rModuleName.getLength() == 0 ) + { + // Enumeration for root requested. + return rtl::Reference< TypeDescriptionEnumerationImpl >( + new TypeDescriptionEnumerationImpl( + xTDMgr, rBaseKeys, rTypes, eDepth ) ); + } + + RegistryKeyList aModuleKeys; + + rtl::OUString aKey( rModuleName.replace( '.', '/' ) ); + + bool bOpenKeySucceeded = false; + + const RegistryKeyList::const_iterator end = rBaseKeys.end(); + RegistryKeyList::const_iterator it = rBaseKeys.begin(); + + while ( it != end ) + { + uno::Reference< registry::XRegistryKey > xKey; + try + { + xKey = (*it)->openKey( aKey ); + if ( xKey.is() ) + { + // closes key in it's dtor (which is + // called even in case of exceptions). + RegistryKeyCloser aCloser( xKey ); + + if ( xKey->isValid() ) + { + bOpenKeySucceeded = true; + + if ( xKey->getValueType() + == registry::RegistryValueType_BINARY ) + { + uno::Sequence< sal_Int8 > aBytes( + xKey->getBinaryValue() ); + + typereg::Reader aReader( + aBytes.getConstArray(), aBytes.getLength(), false, + TYPEREG_VERSION_1); + + rtl::OUString aName( + aReader.getTypeName().replace( '/', '.' ) ); + + if ( aReader.getTypeClass() == RT_TYPE_MODULE ) + { + // Do not close xKey! + aCloser.reset(); + + aModuleKeys.push_back( xKey ); + } + } + } + else + { + OSL_FAIL( + "TypeDescriptionEnumerationImpl::createInstance " + "- Invalid registry key!" ); + } + } + } + catch ( registry::InvalidRegistryException const & ) + { + // openKey, getValueType, getBinaryValue + + OSL_FAIL( "TypeDescriptionEnumerationImpl::createInstance " + "- Caught InvalidRegistryException!" ); + } + + ++it; + } + + if ( !bOpenKeySucceeded ) + throw reflection::NoSuchTypeNameException(); + + if ( aModuleKeys.size() == 0 ) + throw reflection::InvalidTypeNameException(); + + return rtl::Reference< TypeDescriptionEnumerationImpl >( + new TypeDescriptionEnumerationImpl( + xTDMgr, aModuleKeys, rTypes, eDepth ) ); +} + +//========================================================================= +TypeDescriptionEnumerationImpl::TypeDescriptionEnumerationImpl( + const uno::Reference< container::XHierarchicalNameAccess > & xTDMgr, + const RegistryKeyList & rModuleKeys, + const uno::Sequence< uno::TypeClass > & rTypes, + reflection::TypeDescriptionSearchDepth eDepth ) +: m_aModuleKeys( rModuleKeys ), + m_aTypes( rTypes ), + m_eDepth( eDepth ), + m_xTDMgr( xTDMgr ) +{ + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); +} + +//========================================================================= +// virtual +TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl() +{ + RegistryKeyList::const_iterator it = m_aModuleKeys.begin(); + RegistryKeyList::const_iterator end = m_aModuleKeys.end(); +/* + @@@ in case we enumerate root and queryMore was never called, then + m_aModuleKeys contains open root keys which where passed from + tdprov and must not be closed by us. + + while ( it != end ) + { + try + { + if ( (*it)->isValid() ) + (*it)->closeKey(); + } + catch (...) + { + // No exceptions from dtors, please! + OSL_FAIL( "TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl " + "- Caught exception!" ); + } + + it++; + } +*/ + it = m_aCurrentModuleSubKeys.begin(); + end = m_aCurrentModuleSubKeys.end(); + while ( it != end ) + { + try + { + if ( (*it)->isValid() ) + (*it)->closeKey(); + } + catch (Exception &) + { + // No exceptions from dtors, please! + OSL_FAIL( "TypeDescriptionEnumerationImpl::~TypeDescriptionEnumerationImpl " + "- Caught exception!" ); + } + + ++it; + } + + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +//========================================================================= +// +// XEnumeration (base of XTypeDescriptionEnumeration) methods +// +//========================================================================= + +// virtual +sal_Bool SAL_CALL TypeDescriptionEnumerationImpl::hasMoreElements() + throw ( uno::RuntimeException ) +{ + return queryMore(); +} + +//========================================================================= +// virtual +uno::Any SAL_CALL TypeDescriptionEnumerationImpl::nextElement() + throw ( container::NoSuchElementException, + lang::WrappedTargetException, + uno::RuntimeException ) +{ + return uno::Any( uno::makeAny( nextTypeDescription() ) ); +} + +//========================================================================= +// +// XTypeDescriptionEnumeration methods +// +//========================================================================= + +// virtual +uno::Reference< reflection::XTypeDescription > SAL_CALL +TypeDescriptionEnumerationImpl::nextTypeDescription() + throw ( container::NoSuchElementException, + uno::RuntimeException ) +{ + uno::Reference< reflection::XTypeDescription > xTD( queryNext() ); + + if ( xTD.is() ) + return xTD; + + throw container::NoSuchElementException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("No further elements in enumeration!") ), + static_cast< cppu::OWeakObject * >( this ) ); +} + +//========================================================================= +bool TypeDescriptionEnumerationImpl::match( + RTTypeClass eType1, uno::TypeClass eType2 ) +{ + switch ( eType1 ) + { + case RT_TYPE_INTERFACE: + return eType2 == uno::TypeClass_INTERFACE; + + case RT_TYPE_MODULE: + return eType2 == uno::TypeClass_MODULE; + + case RT_TYPE_STRUCT: + return eType2 == uno::TypeClass_STRUCT; + + case RT_TYPE_ENUM: + return eType2 == uno::TypeClass_ENUM; + + case RT_TYPE_EXCEPTION: + return eType2 == uno::TypeClass_EXCEPTION; + + case RT_TYPE_TYPEDEF: + return eType2 == uno::TypeClass_TYPEDEF; + + case RT_TYPE_SERVICE: + return eType2 == uno::TypeClass_SERVICE; + + case RT_TYPE_SINGLETON: + return eType2 == uno::TypeClass_SINGLETON; + + case RT_TYPE_CONSTANTS: + return eType2 == uno::TypeClass_CONSTANTS; + + case RT_TYPE_UNION: + return eType2 == uno::TypeClass_UNION; + + default: + return false; + } +} + +//========================================================================= +bool TypeDescriptionEnumerationImpl::queryMore() +{ + osl::MutexGuard aGuard( m_aMutex ); + + for (;;) + { + if ( !m_aCurrentModuleSubKeys.empty() || !m_aTypeDescs.empty() ) + { + // Okay, there is at least one more element. + return true; + } + + if ( m_aModuleKeys.empty() ) + { + // No module keys (therefore no elements) left. + return false; + } + + // Note: m_aCurrentModuleSubKeys is always empty AND m_aModuleKeys is + // never empty when ariving here. + // ==> select new module key, fill m_aCurrentModuleSubKeys + + uno::Sequence< uno::Reference< registry::XRegistryKey > > aKeys; + try + { + aKeys = m_aModuleKeys.front()->openKeys(); + for ( sal_Int32 n = 0; n < aKeys.getLength(); ++n ) + { + uno::Reference< registry::XRegistryKey > xKey = aKeys[ n ]; + + // closes key in it's dtor (which is + // called even in case of exceptions). + RegistryKeyCloser aCloser( xKey ); + + try + { + if ( xKey->isValid() ) + { + if ( xKey->getValueType() + == registry::RegistryValueType_BINARY ) + { + bool bIncludeIt = (m_aTypes.getLength() == 0); + bool bNeedTypeClass = + ((m_aTypes.getLength() > 0) || + (m_eDepth + == reflection::TypeDescriptionSearchDepth_INFINITE)); + if ( bNeedTypeClass ) + { + uno::Sequence< sal_Int8 > aBytes( + xKey->getBinaryValue() ); + + typereg::Reader aReader( + aBytes.getConstArray(), aBytes.getLength(), + false, TYPEREG_VERSION_1); + + RTTypeClass eTypeClass = aReader.getTypeClass(); + + // Does key match requested types? Empty + // sequence means include all. + if ( m_aTypes.getLength() > 0 ) + { + for ( sal_Int32 m = 0; + m < m_aTypes.getLength(); + ++m ) + { + if ( match(eTypeClass, m_aTypes[ m ]) ) + { + bIncludeIt = true; + break; + } + } + } + + if ( m_eDepth == + reflection::TypeDescriptionSearchDepth_INFINITE ) + { + if ( eTypeClass == RT_TYPE_MODULE ) + { + // Do not close xKey! + aCloser.reset(); + + // Remember new module key. + m_aModuleKeys.push_back( xKey ); + } + } + } + + if ( bIncludeIt ) + { + // Do not close xKey! + aCloser.reset(); + + m_aCurrentModuleSubKeys.push_back( xKey ); + } + } + } + else + { + OSL_FAIL( "TypeDescriptionEnumerationImpl::queryMore " + "- Invalid registry key!" ); + } + + } + catch ( registry::InvalidRegistryException const & ) + { + // getValueType, getBinaryValue + + OSL_FAIL( "TypeDescriptionEnumerationImpl::queryMore " + "- Caught InvalidRegistryException!" ); + + // Don't stop iterating! + } + } + } + catch ( registry::InvalidRegistryException const & ) + { + // openKeys + + for ( sal_Int32 n = 0; n < aKeys.getLength(); ++n ) + { + try + { + aKeys[ n ]->closeKey(); + } + catch ( registry::InvalidRegistryException const & ) + { + OSL_FAIL( "TypeDescriptionEnumerationImpl::queryMore " + "- Caught InvalidRegistryException!" ); + } + } + } + + ///////////////////////////////////////////////////////////////////// + // Special handling for constants contained directly in module. + ///////////////////////////////////////////////////////////////////// + + // Constants requested? + bool bIncludeConstants = ( m_aTypes.getLength() == 0 ); + if ( !bIncludeConstants ) + { + for ( sal_Int32 m = 0; m < m_aTypes.getLength(); ++m ) + { + if ( m_aTypes[ m ] == uno::TypeClass_CONSTANT ) + { + bIncludeConstants = true; + break; + } + } + + } + + if ( bIncludeConstants ) + { + if ( m_aModuleKeys.front()->getValueType() + == registry::RegistryValueType_BINARY ) + { + try + { + uno::Sequence< sal_Int8 > aBytes( + m_aModuleKeys.front()->getBinaryValue() ); + + typereg::Reader aReader( + aBytes.getConstArray(), aBytes.getLength(), false, + TYPEREG_VERSION_1); + + if ( aReader.getTypeClass() == RT_TYPE_MODULE ) + { + sal_uInt16 nFields = aReader.getFieldCount(); + while ( nFields-- ) + { + rtl::OUStringBuffer aName( + aReader.getTypeName().replace( '/', '.' ) ); + aName.appendAscii( "." ); + aName.append( aReader.getFieldName( nFields ) ); + + uno::Any aValue( + getRTValue( + aReader.getFieldValue( nFields ) ) ); + + m_aTypeDescs.push_back( + new IndividualConstantTypeDescriptionImpl( + aName.makeStringAndClear(), aValue, + ( ( aReader.getFieldFlags( nFields ) + & RT_ACCESS_PUBLISHED ) + != 0 ) ) ); + } + } + } + catch ( registry::InvalidRegistryException const & ) + { + // getBinaryValue + + OSL_FAIL( "TypeDescriptionEnumerationImpl::queryMore " + "- Caught InvalidRegistryException!" ); + } + } + } + + ///////////////////////////////////////////////////////////////////// + +/* + @@@ m_aModuleKeys.front() may have open sub keys (may be contained in + both m_aModuleKeys and m_aCurrentModuleSubKeys)! + + try + { + m_aModuleKeys.front()->closeKey(); + } + catch ( registry::InvalidRegistryException const & ) + { + OSL_FAIL( "TypeDescriptionEnumerationImpl::queryMore " + "- Caught InvalidRegistryException!" ); + } +*/ + // We're done with this module key, even if there were errors. + m_aModuleKeys.pop_front(); + } + + // unreachable +} + +//========================================================================= +uno::Reference< reflection::XTypeDescription > +TypeDescriptionEnumerationImpl::queryNext() +{ + osl::MutexGuard aGuard( m_aMutex ); + + for (;;) + { + if ( !queryMore() ) + return uno::Reference< reflection::XTypeDescription >(); + + uno::Reference< reflection::XTypeDescription > xTD; + + if ( !m_aTypeDescs.empty() ) + { + xTD = m_aTypeDescs.front(); + m_aTypeDescs.pop_front(); + return xTD; + } + + // Note: xKey is already opened. + uno::Reference< registry::XRegistryKey > + xKey( m_aCurrentModuleSubKeys.front() ); +/* + @@@ xKey may still be contained in m_aModuleKeys, too + + // closes key in it's dtor (which is + // called even in case of exceptions). + RegistryKeyCloser aCloser( xKey ); +*/ + try + { + { + if ( xKey->isValid() ) + { + if ( xKey->getValueType() + == registry::RegistryValueType_BINARY ) + { + uno::Sequence< sal_Int8 > aBytes( + xKey->getBinaryValue() ); + + xTD = createTypeDescription( aBytes, + m_xTDMgr, + false ); + OSL_ENSURE( xTD.is(), + "TypeDescriptionEnumerationImpl::queryNext " + "- No XTypeDescription created!" ); + } + } + else + { + OSL_FAIL( "TypeDescriptionEnumerationImpl::queryNext " + "- Invalid registry key!" ); + } + } + } + catch ( registry::InvalidRegistryException const & ) + { + // getValueType, getBinaryValue + + OSL_FAIL( "TypeDescriptionEnumerationImpl::queryNext " + "- Caught InvalidRegistryException!" ); + } + + // We're done with this key, even if there were errors. + m_aCurrentModuleSubKeys.pop_front(); + + if ( xTD.is() ) + return xTD; + + // next try... + + } // for (;;) +} + +} // namespace stoc_rdbtdp + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/rdbtdp_tdenumeration.hxx b/stoc/source/registry_tdprovider/rdbtdp_tdenumeration.hxx new file mode 100644 index 000000000000..b255e5ef06d7 --- /dev/null +++ b/stoc/source/registry_tdprovider/rdbtdp_tdenumeration.hxx @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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 _STOC_RDBTDP_TDENUMERATION_HXX +#define _STOC_RDBTDP_TDENUMERATION_HXX + +#include <list> +#include <osl/mutex.hxx> +#include <rtl/ref.hxx> +#include <registry/refltype.hxx> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/reflection/InvalidTypeNameException.hpp> +#include <com/sun/star/reflection/NoSuchTypeNameException.hpp> +#include <com/sun/star/reflection/TypeDescriptionSearchDepth.hpp> +#include <com/sun/star/reflection/XTypeDescriptionEnumeration.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/TypeClass.hpp> +#include <cppuhelper/implbase1.hxx> +#include "base.hxx" + +namespace stoc_rdbtdp +{ + +typedef ::std::list< ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XTypeDescription > > TypeDescriptionList; + +class TypeDescriptionEnumerationImpl + : public cppu::WeakImplHelper1< + com::sun::star::reflection::XTypeDescriptionEnumeration > +{ +public: + static rtl::Reference< TypeDescriptionEnumerationImpl > createInstance( + const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XHierarchicalNameAccess > & xTDMgr, + const rtl::OUString & rModuleName, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::TypeClass > & rTypes, + ::com::sun::star::reflection::TypeDescriptionSearchDepth eDepth, + const RegistryKeyList & rBaseKeys ) + throw ( ::com::sun::star::reflection::NoSuchTypeNameException, + ::com::sun::star::reflection::InvalidTypeNameException, + ::com::sun::star::uno::RuntimeException ); + + virtual ~TypeDescriptionEnumerationImpl(); + + // XEnumeration (base of XTypeDescriptionEnumeration) + virtual sal_Bool SAL_CALL hasMoreElements() + throw ( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Any SAL_CALL nextElement() + throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException ); + + // XTypeDescriptionEnumeration + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XTypeDescription > SAL_CALL + nextTypeDescription() + throw ( ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException ); + +private: + // Note: keys must be open (XRegistryKey->openKey(...)). + TypeDescriptionEnumerationImpl( + const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XHierarchicalNameAccess > & xTDMgr, + const RegistryKeyList & rModuleKeys, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::TypeClass > & rTypes, + ::com::sun::star::reflection::TypeDescriptionSearchDepth eDepth ); + + static bool match( ::RTTypeClass eType1, + ::com::sun::star::uno::TypeClass eType2 ); + bool queryMore(); + ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XTypeDescription > queryNext(); + + // members + osl::Mutex m_aMutex; + RegistryKeyList m_aModuleKeys; + RegistryKeyList m_aCurrentModuleSubKeys; + TypeDescriptionList m_aTypeDescs; + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::TypeClass > m_aTypes; + ::com::sun::star::reflection::TypeDescriptionSearchDepth m_eDepth; + ::com::sun::star::uno::Reference< + ::com::sun::star::container::XHierarchicalNameAccess > m_xTDMgr; +}; + +} // namespace stoc_rdbtdp + +#endif /* _STOC_RDBTDP_TDENUMERATION_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/structtypedescription.cxx b/stoc/source/registry_tdprovider/structtypedescription.cxx new file mode 100644 index 000000000000..1da060386245 --- /dev/null +++ b/stoc/source/registry_tdprovider/structtypedescription.cxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" + +#include "structtypedescription.hxx" + +#include "base.hxx" + +#include "com/sun/star/reflection/XTypeDescription.hpp" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/Sequence.hxx" +#include "com/sun/star/uno/TypeClass.hpp" +#include "cppuhelper/weak.hxx" +#include "osl/diagnose.h" +#include "registry/reader.hxx" +#include "registry/types.h" +#include "registry/version.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" + +#include <new> + +namespace css = com::sun::star; +using stoc::registry_tdprovider::StructTypeDescription; + +StructTypeDescription::StructTypeDescription( + css::uno::Reference< css::container::XHierarchicalNameAccess > const & + manager, + rtl::OUString const & name, rtl::OUString const & baseTypeName, + css::uno::Sequence< sal_Int8 > const & data, bool published): + m_data(data), + m_base( + new stoc_rdbtdp::CompoundTypeDescriptionImpl( + manager, css::uno::TypeClass_STRUCT, name, baseTypeName, data, + published)) +{} + +StructTypeDescription::~StructTypeDescription() +{} + +css::uno::TypeClass StructTypeDescription::getTypeClass() + throw (css::uno::RuntimeException) +{ + return m_base->getTypeClass(); +} + +rtl::OUString StructTypeDescription::getName() + throw (css::uno::RuntimeException) +{ + return m_base->getName(); +} + +css::uno::Reference< css::reflection::XTypeDescription > +StructTypeDescription::getBaseType() throw (css::uno::RuntimeException) +{ + return m_base->getBaseType(); +} + +css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > > +StructTypeDescription::getMemberTypes() throw (css::uno::RuntimeException) +{ + return m_base->getMemberTypes(); +} + +css::uno::Sequence< rtl::OUString > StructTypeDescription::getMemberNames() + throw (css::uno::RuntimeException) +{ + return m_base->getMemberNames(); +} + +css::uno::Sequence< rtl::OUString > StructTypeDescription::getTypeParameters() + throw (css::uno::RuntimeException) +{ + try { + typereg::Reader reader( + m_data.getConstArray(), m_data.getLength(), false, + TYPEREG_VERSION_1); + OSL_ASSERT(reader.isValid()); + sal_uInt16 n = reader.getReferenceCount(); + css::uno::Sequence< rtl::OUString > parameters(n); + for (sal_uInt16 i = 0; i < n; ++i) { + if (reader.getReferenceFlags(i) != RT_ACCESS_INVALID + || reader.getReferenceSort(i) != RT_REF_TYPE_PARAMETER) + { + throw css::uno::RuntimeException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "type parameter of polymorphic struct type template" + " not RT_ACCESS_INVALID/RT_REF_TYPE_PARAMETER")), + static_cast< cppu::OWeakObject * >(this)); + } + parameters[i] = reader.getReferenceTypeName(i); + } + return parameters; + } catch (std::bad_alloc &) { + throw css::uno::RuntimeException( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")), + static_cast< cppu::OWeakObject * >(this)); + } +} + +css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > > +StructTypeDescription::getTypeArguments() throw (css::uno::RuntimeException) +{ + return css::uno::Sequence< + css::uno::Reference< css::reflection::XTypeDescription > >(); +} + +sal_Bool StructTypeDescription::isPublished() throw (css::uno::RuntimeException) +{ + return m_base->isPublished(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/structtypedescription.hxx b/stoc/source/registry_tdprovider/structtypedescription.hxx new file mode 100644 index 000000000000..268f67a8fdb1 --- /dev/null +++ b/stoc/source/registry_tdprovider/structtypedescription.hxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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 INCLUDED_stoc_source_registry_tdprovider_structtypedescription_hxx +#define INCLUDED_stoc_source_registry_tdprovider_structtypedescription_hxx + +#include "com/sun/star/reflection/XPublished.hpp" +#include "com/sun/star/reflection/XStructTypeDescription.hpp" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/Sequence.hxx" +#include "cppuhelper/implbase2.hxx" +#include "rtl/ref.hxx" +#include "sal/types.h" + +namespace com { namespace sun { namespace star { + namespace container { class XHierarchicalNameAccess; } + namespace reflection { class XCompoundTypeDescription; } +} } } +namespace rtl { class OUString; } +namespace stoc_rdbtdp { class CompoundTypeDescriptionImpl; } + +namespace stoc { namespace registry_tdprovider { + +class StructTypeDescription: + public cppu::WeakImplHelper2< + com::sun::star::reflection::XStructTypeDescription, + com::sun::star::reflection::XPublished > +{ +public: + StructTypeDescription( + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > const & + manager, + rtl::OUString const & name, rtl::OUString const & baseTypeName, + com::sun::star::uno::Sequence< sal_Int8 > const & data, bool published); + + virtual ~StructTypeDescription(); + + virtual com::sun::star::uno::TypeClass SAL_CALL getTypeClass() + throw (com::sun::star::uno::RuntimeException); + + virtual rtl::OUString SAL_CALL getName() + throw (com::sun::star::uno::RuntimeException); + + virtual + com::sun::star::uno::Reference< + com::sun::star::reflection::XTypeDescription > + SAL_CALL getBaseType() throw (com::sun::star::uno::RuntimeException); + + virtual + com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< + com::sun::star::reflection::XTypeDescription > > + SAL_CALL getMemberTypes() throw (com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL + getMemberNames() throw (com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL + getTypeParameters() throw (com::sun::star::uno::RuntimeException); + + virtual + com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< + com::sun::star::reflection::XTypeDescription > > + SAL_CALL getTypeArguments() throw (com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isPublished() + throw (com::sun::star::uno::RuntimeException); + +private: + StructTypeDescription(StructTypeDescription &); // not implemented + void operator =(StructTypeDescription); // not implemented + + com::sun::star::uno::Sequence< sal_Int8 > m_data; + rtl::Reference< stoc_rdbtdp::CompoundTypeDescriptionImpl > m_base; +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/td.cxx b/stoc/source/registry_tdprovider/td.cxx new file mode 100644 index 000000000000..b532cbeb1282 --- /dev/null +++ b/stoc/source/registry_tdprovider/td.cxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" + +#include "osl/doublecheckedlocking.h" +#include "base.hxx" + +namespace stoc_rdbtdp +{ + +//------------------------------------------------------------------------------ +::osl::Mutex & getMutex() +{ + static ::osl::Mutex * s_pmutex = 0; + if (s_pmutex == 0) + { + ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); + if (s_pmutex == 0) + { + static ::osl::Mutex s_mutex; + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + s_pmutex = &s_mutex; + } + } + else + { + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + } + return *s_pmutex; +} + + +TypeDescriptionImpl::~TypeDescriptionImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +TypeClass TypeDescriptionImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return _eTypeClass; +} +//__________________________________________________________________________________________________ +OUString TypeDescriptionImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aName; +} + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdcomp.cxx b/stoc/source/registry_tdprovider/tdcomp.cxx new file mode 100644 index 000000000000..1ab3dda91334 --- /dev/null +++ b/stoc/source/registry_tdprovider/tdcomp.cxx @@ -0,0 +1,189 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include "base.hxx" + +#include "registry/reader.hxx" +#include "registry/version.h" + +namespace stoc_rdbtdp +{ + +//__________________________________________________________________________________________________ +CompoundTypeDescriptionImpl::~CompoundTypeDescriptionImpl() +{ + delete _pMembers; + delete _pMemberNames; + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +TypeClass CompoundTypeDescriptionImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return _eTypeClass; +} +//__________________________________________________________________________________________________ +OUString CompoundTypeDescriptionImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aName; +} + +// XCompoundTypeDescription +//__________________________________________________________________________________________________ +Reference< XTypeDescription > CompoundTypeDescriptionImpl::getBaseType() + throw(::com::sun::star::uno::RuntimeException) +{ + if (!_xBaseTD.is() && _aBaseType.getLength()) + { + try + { + Reference< XTypeDescription > xBaseTD; + if (_xTDMgr->getByHierarchicalName( _aBaseType ) >>= xBaseTD) + { + MutexGuard aGuard( getMutex() ); + if (! _xBaseTD.is()) + _xBaseTD = xBaseTD; + return _xBaseTD; + } + } + catch (NoSuchElementException &) + { + } + // never try again, if no base td was found + _aBaseType = OUString(); + } + return _xBaseTD; +} +//__________________________________________________________________________________________________ + +namespace { + +class TypeParameter: public WeakImplHelper1< XTypeDescription > { +public: + explicit TypeParameter(OUString const & name): m_name(name) {} + + virtual TypeClass SAL_CALL getTypeClass() throw (RuntimeException) + { return TypeClass_UNKNOWN; } + + virtual OUString SAL_CALL getName() throw (RuntimeException) + { return m_name; } + +private: + OUString m_name; +}; + +} + +Sequence< Reference< XTypeDescription > > CompoundTypeDescriptionImpl::getMemberTypes() + throw(::com::sun::star::uno::RuntimeException) +{ + if (! _pMembers) + { + typereg::Reader aReader( + _aBytes.getConstArray(), _aBytes.getLength(), false, + TYPEREG_VERSION_1); + + sal_uInt16 nFields = aReader.getFieldCount(); + Sequence< Reference< XTypeDescription > > * pTempMembers = + new Sequence< Reference< XTypeDescription > >( nFields ); + Reference< XTypeDescription > * pMembers = pTempMembers->getArray(); + + while (nFields--) + { + if ((aReader.getFieldFlags(nFields) & RT_ACCESS_PARAMETERIZED_TYPE) + != 0) + { + pMembers[nFields] = new TypeParameter( + aReader.getFieldTypeName(nFields)); + } else { + try { + _xTDMgr->getByHierarchicalName( + aReader.getFieldTypeName(nFields).replace('/', '.')) + >>= pMembers[nFields]; + } catch (NoSuchElementException &) {} + OSL_ENSURE( + pMembers[nFields].is(), "### compound member unknown!"); + } + } + + ClearableMutexGuard aGuard( getMutex() ); + if (_pMembers) + { + aGuard.clear(); + delete pTempMembers; + } + else + { + _pMembers = pTempMembers; + } + } + + return *_pMembers; +} +//__________________________________________________________________________________________________ +Sequence< OUString > CompoundTypeDescriptionImpl::getMemberNames() + throw(::com::sun::star::uno::RuntimeException) +{ + if (! _pMemberNames) + { + typereg::Reader aReader( + _aBytes.getConstArray(), _aBytes.getLength(), false, + TYPEREG_VERSION_1); + + sal_uInt16 nFields = aReader.getFieldCount(); + Sequence< OUString > * pTempMemberNames = new Sequence< OUString >( nFields ); + OUString * pMemberNames = pTempMemberNames->getArray(); + + while (nFields--) + { + pMemberNames[nFields] = aReader.getFieldName( nFields ); + } + + ClearableMutexGuard aGuard( getMutex() ); + if (_pMemberNames) + { + aGuard.clear(); + delete pTempMemberNames; + } + else + { + _pMemberNames = pTempMemberNames; + } + } + return *_pMemberNames; +} + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdconsts.cxx b/stoc/source/registry_tdprovider/tdconsts.cxx new file mode 100644 index 000000000000..aef656417ead --- /dev/null +++ b/stoc/source/registry_tdprovider/tdconsts.cxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include <osl/diagnose.h> +#include <rtl/ustrbuf.hxx> +#include "registry/reader.hxx" +#include "registry/version.h" +#include "base.hxx" + +namespace stoc_rdbtdp +{ + +//__________________________________________________________________________________________________ +// virtual +ConstantsTypeDescriptionImpl::~ConstantsTypeDescriptionImpl() +{ + delete _pMembers; + + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +// virtual +TypeClass ConstantsTypeDescriptionImpl::getTypeClass() + throw( RuntimeException ) +{ + return TypeClass_CONSTANTS; +} +//__________________________________________________________________________________________________ +// virtual +OUString ConstantsTypeDescriptionImpl::getName() + throw( RuntimeException ) +{ + return _aName; +} + +// XConstantsTypeDescription +//__________________________________________________________________________________________________ +// virtual +Sequence< Reference< XConstantTypeDescription > > SAL_CALL +ConstantsTypeDescriptionImpl::getConstants() + throw ( RuntimeException ) +{ + if ( !_pMembers ) + { + typereg::Reader aReader( + _aBytes.getConstArray(), _aBytes.getLength(), false, + TYPEREG_VERSION_1); + + sal_uInt16 nFields = aReader.getFieldCount(); + Sequence< Reference< XConstantTypeDescription > > * pTempConsts + = new Sequence< Reference< XConstantTypeDescription > >( nFields ); + Reference< XConstantTypeDescription > * pConsts + = pTempConsts->getArray(); + + while ( nFields-- ) + { + rtl::OUStringBuffer aName( _aName ); + aName.appendAscii( "." ); + aName.append( aReader.getFieldName( nFields ) ); + + Any aValue( getRTValue( aReader.getFieldValue( nFields ) ) ); + + pConsts[ nFields ] + = new ConstantTypeDescriptionImpl( aName.makeStringAndClear(), + aValue ); + } + + ClearableMutexGuard aGuard( getMutex() ); + if ( _pMembers ) + { + aGuard.clear(); + delete pTempConsts; + } + else + { + _pMembers = pTempConsts; + } + } + return *_pMembers; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdef.cxx b/stoc/source/registry_tdprovider/tdef.cxx new file mode 100644 index 000000000000..c4f7f865de31 --- /dev/null +++ b/stoc/source/registry_tdprovider/tdef.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include "base.hxx" + +namespace stoc_rdbtdp +{ +TypedefTypeDescriptionImpl::~TypedefTypeDescriptionImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +TypeClass TypedefTypeDescriptionImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return TypeClass_TYPEDEF; +} +//__________________________________________________________________________________________________ +OUString TypedefTypeDescriptionImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aName; +} + +// XIndirectTypeDescription +//__________________________________________________________________________________________________ +Reference< XTypeDescription > TypedefTypeDescriptionImpl::getReferencedType() + throw(::com::sun::star::uno::RuntimeException) +{ + if (!_xRefTD.is() && _aRefName.getLength()) + { + try + { + Reference< XTypeDescription > xRefTD; + if (_xTDMgr->getByHierarchicalName( _aRefName ) >>= xRefTD) + { + MutexGuard aGuard( getMutex() ); + if (! _xRefTD.is()) + _xRefTD = xRefTD; + return _xRefTD; + } + } + catch (NoSuchElementException &) + { + } + // never try again, if no base td was found + _aRefName = OUString(); + } + return _xRefTD; +} + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdenum.cxx b/stoc/source/registry_tdprovider/tdenum.cxx new file mode 100644 index 000000000000..22ad592f5d8c --- /dev/null +++ b/stoc/source/registry_tdprovider/tdenum.cxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include "base.hxx" + +#include "registry/reader.hxx" +#include "registry/version.h" + +namespace stoc_rdbtdp +{ + +//__________________________________________________________________________________________________ +EnumTypeDescriptionImpl::~EnumTypeDescriptionImpl() +{ + delete _pEnumNames; + delete _pEnumValues; + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +TypeClass EnumTypeDescriptionImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return TypeClass_ENUM; +} +//__________________________________________________________________________________________________ +OUString EnumTypeDescriptionImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aName; +} + +// XEnumTypeDescription +//__________________________________________________________________________________________________ +sal_Int32 EnumTypeDescriptionImpl::getDefaultEnumValue() + throw(::com::sun::star::uno::RuntimeException) +{ + return _nDefaultValue; +} +//__________________________________________________________________________________________________ +Sequence< OUString > EnumTypeDescriptionImpl::getEnumNames() + throw(::com::sun::star::uno::RuntimeException) +{ + if (! _pEnumNames) + { + typereg::Reader aReader( + _aBytes.getConstArray(), _aBytes.getLength(), false, + TYPEREG_VERSION_1); + + sal_uInt16 nFields = aReader.getFieldCount(); + Sequence< OUString > * pTempEnumNames = new Sequence< OUString >( nFields ); + OUString * pEnumNames = pTempEnumNames->getArray(); + + while (nFields--) + { + pEnumNames[nFields] = aReader.getFieldName( nFields ); + } + + ClearableMutexGuard aGuard( getMutex() ); + if (_pEnumNames) + { + aGuard.clear(); + delete pTempEnumNames; + } + else + { + _pEnumNames = pTempEnumNames; + } + } + return *_pEnumNames; +} +//__________________________________________________________________________________________________ +Sequence< sal_Int32 > EnumTypeDescriptionImpl::getEnumValues() + throw(::com::sun::star::uno::RuntimeException) +{ + if (! _pEnumValues) + { + typereg::Reader aReader( + _aBytes.getConstArray(), _aBytes.getLength(), false, + TYPEREG_VERSION_1); + + sal_uInt16 nFields = aReader.getFieldCount(); + Sequence< sal_Int32 > * pTempEnumValues = new Sequence< sal_Int32 >( nFields ); + sal_Int32 * pEnumValues = pTempEnumValues->getArray(); + + while (nFields--) + { + pEnumValues[nFields] = getRTValueAsInt32( + aReader.getFieldValue( nFields ) ); + } + + ClearableMutexGuard aGuard( getMutex() ); + if (_pEnumValues) + { + aGuard.clear(); + delete pTempEnumValues; + } + else + { + _pEnumValues = pTempEnumValues; + } + } + return *_pEnumValues; +} + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdiface.cxx b/stoc/source/registry_tdprovider/tdiface.cxx new file mode 100644 index 000000000000..9018867b281a --- /dev/null +++ b/stoc/source/registry_tdprovider/tdiface.cxx @@ -0,0 +1,588 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include <osl/diagnose.h> +#include <rtl/ustrbuf.hxx> +#include "registry/reader.hxx" +#include "registry/version.h" + +#include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp> +#include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp> +#include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp> +#include <com/sun/star/reflection/XMethodParameter.hpp> +#include <com/sun/star/reflection/XParameter.hpp> +#include "com/sun/star/uno/RuntimeException.hpp" +#include "base.hxx" +#include "functiondescription.hxx" +#include "methoddescription.hxx" + +#include <memory> +#include <set> + +namespace stoc_rdbtdp +{ + +//================================================================================================== +class InterfaceMethodImpl : public WeakImplHelper1< XInterfaceMethodTypeDescription > +{ + stoc::registry_tdprovider::MethodDescription _desc; + + Reference< XHierarchicalNameAccess > _xTDMgr; + + OUString _aTypeName; + + OUString _aReturnType; + Reference< XTypeDescription > _xReturnTD; + + sal_Bool _bIsOneWay; + sal_Int32 _nPosition; + +public: + InterfaceMethodImpl( const Reference< XHierarchicalNameAccess > & xTDMgr, + const OUString & rTypeName, + const OUString & rMemberName, + const OUString & rReturnType, + const Sequence< sal_Int8 > & rBytes, + sal_uInt16 nMethodIndex, + sal_Bool bIsOneWay, + sal_Int32 nPosition ) + : _desc(xTDMgr, rMemberName, rBytes, nMethodIndex) + , _xTDMgr( xTDMgr ) + , _aTypeName( rTypeName ) + , _aReturnType( rReturnType ) + , _bIsOneWay( bIsOneWay ) + , _nPosition( nPosition ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~InterfaceMethodImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); + + // XInterfaceMemberTypeDescription + virtual OUString SAL_CALL getMemberName() throw(::com::sun::star::uno::RuntimeException) + { return _desc.getName(); } + virtual sal_Int32 SAL_CALL getPosition() throw(::com::sun::star::uno::RuntimeException); + + // XInterfaceMethodTypeDescription + virtual Reference< XTypeDescription > SAL_CALL getReturnType() throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isOneway() throw(::com::sun::star::uno::RuntimeException); + virtual Sequence< Reference< XMethodParameter > > SAL_CALL getParameters() throw(::com::sun::star::uno::RuntimeException); + virtual Sequence< Reference< XTypeDescription > > SAL_CALL getExceptions() throw(::com::sun::star::uno::RuntimeException); +}; +//__________________________________________________________________________________________________ +InterfaceMethodImpl::~InterfaceMethodImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +TypeClass InterfaceMethodImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return TypeClass_INTERFACE_METHOD; +} +//__________________________________________________________________________________________________ +OUString InterfaceMethodImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aTypeName; +} + +// XInterfaceMemberTypeDescription +//__________________________________________________________________________________________________ +sal_Int32 InterfaceMethodImpl::getPosition() + throw(::com::sun::star::uno::RuntimeException) +{ + return _nPosition; +} + +// XInterfaceMethodTypeDescription +//__________________________________________________________________________________________________ +Reference<XTypeDescription > InterfaceMethodImpl::getReturnType() + throw(::com::sun::star::uno::RuntimeException) +{ + if (!_xReturnTD.is() && _aReturnType.getLength()) + { + try + { + Reference< XTypeDescription > xReturnTD; + if (_xTDMgr->getByHierarchicalName( _aReturnType ) >>= xReturnTD) + { + MutexGuard aGuard( getMutex() ); + if (! _xReturnTD.is()) + _xReturnTD = xReturnTD; + return _xReturnTD; + } + } + catch (NoSuchElementException &) + { + } + // never try again, if no td was found + _aReturnType = OUString(); + } + return _xReturnTD; +} +//__________________________________________________________________________________________________ +sal_Bool InterfaceMethodImpl::isOneway() + throw(::com::sun::star::uno::RuntimeException) +{ + return _bIsOneWay; +} +//__________________________________________________________________________________________________ +Sequence<Reference<XMethodParameter > > InterfaceMethodImpl::getParameters() + throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< Reference< XParameter > > s1(_desc.getParameters()); + Sequence< Reference< XMethodParameter > > s2(s1.getLength()); + for (sal_Int32 i = 0; i < s1.getLength(); ++i) { + s2[i] = s1[i].get(); + } + return s2; +} +//__________________________________________________________________________________________________ +Sequence<Reference<XTypeDescription > > InterfaceMethodImpl::getExceptions() + throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< Reference< XCompoundTypeDescription > > s1( + _desc.getExceptions()); + Sequence< Reference< XTypeDescription > > s2(s1.getLength()); + for (sal_Int32 i = 0; i < s1.getLength(); ++i) { + s2[i] = s1[i].get(); + } + return s2; +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + + +//================================================================================================== +class InterfaceAttributeImpl : public WeakImplHelper1< XInterfaceAttributeTypeDescription2 > +{ + Reference< XHierarchicalNameAccess > _xTDMgr; + + OUString _aTypeName; + OUString _aMemberName; + + OUString _aMemberTypeName; + Reference< XTypeDescription > _xMemberTD; + + sal_Bool _bReadOnly; + sal_Bool _bBound; + sal_Int32 _nPosition; + + std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > _getter; + std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > _setter; + +public: + InterfaceAttributeImpl( + const Reference< XHierarchicalNameAccess > & xTDMgr, + const OUString & rTypeName, + const OUString & rMemberName, + const OUString & rMemberTypeName, + sal_Bool bReadOnly, + sal_Bool bBound, + std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > & + getter, + std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > & + setter, + sal_Int32 nPosition ) + : _xTDMgr( xTDMgr ) + , _aTypeName( rTypeName ) + , _aMemberName( rMemberName ) + , _aMemberTypeName( rMemberTypeName ) + , _bReadOnly( bReadOnly ) + , _bBound( bBound ) + , _nPosition( nPosition ) + , _getter( getter ) + , _setter( setter ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~InterfaceAttributeImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException); + virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException); + + // XInterfaceMemberTypeDescription + virtual OUString SAL_CALL getMemberName() throw(::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getPosition() throw(::com::sun::star::uno::RuntimeException); + + // XInterfaceAttributeTypeDescription2 + virtual sal_Bool SAL_CALL isReadOnly() throw(::com::sun::star::uno::RuntimeException); + virtual Reference< XTypeDescription > SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL isBound() throw (RuntimeException) + { return _bBound; } + + virtual Sequence< Reference< XCompoundTypeDescription > > SAL_CALL + getGetExceptions() throw (RuntimeException) + { + if (_getter.get() != 0) { + return _getter->getExceptions(); + } else { + return Sequence< Reference< XCompoundTypeDescription > >(); + } + } + + virtual Sequence< Reference< XCompoundTypeDescription > > SAL_CALL + getSetExceptions() throw (RuntimeException) + { + if (_setter.get() != 0) { + return _setter->getExceptions(); + } else { + return Sequence< Reference< XCompoundTypeDescription > >(); + } + } +}; + +InterfaceAttributeImpl::~InterfaceAttributeImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} +// XTypeDescription +//__________________________________________________________________________________________________ +TypeClass InterfaceAttributeImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return TypeClass_INTERFACE_ATTRIBUTE; +} +//__________________________________________________________________________________________________ +OUString InterfaceAttributeImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aTypeName; +} + +// XInterfaceMemberTypeDescription +//__________________________________________________________________________________________________ +OUString InterfaceAttributeImpl::getMemberName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aMemberName; +} +//__________________________________________________________________________________________________ +sal_Int32 InterfaceAttributeImpl::getPosition() + throw(::com::sun::star::uno::RuntimeException) +{ + return _nPosition; +} + +// XInterfaceAttributeTypeDescription2 +//__________________________________________________________________________________________________ +sal_Bool InterfaceAttributeImpl::isReadOnly() + throw(::com::sun::star::uno::RuntimeException) +{ + return _bReadOnly; +} +//__________________________________________________________________________________________________ +Reference<XTypeDescription > InterfaceAttributeImpl::getType() + throw(::com::sun::star::uno::RuntimeException) +{ + if (!_xMemberTD.is() && _aMemberTypeName.getLength()) + { + try + { + Reference< XTypeDescription > xMemberTD; + if (_xTDMgr->getByHierarchicalName( _aMemberTypeName ) >>= xMemberTD) + { + MutexGuard aGuard( getMutex() ); + if (! _xMemberTD.is()) + _xMemberTD = xMemberTD; + return _xMemberTD; + } + } + catch (NoSuchElementException &) + { + } + // never try again, if no td was found + _aMemberTypeName = OUString(); + } + return _xMemberTD; +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + +void InterfaceTypeDescriptionImpl::checkInterfaceType( + Reference< XTypeDescription > const & type) +{ + if (resolveTypedefs(type)->getTypeClass() != TypeClass_INTERFACE) { + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Interface base is not an interface type")), + static_cast< OWeakObject * >(this)); + } +} + +namespace { + +class BaseOffset { +public: + BaseOffset(Reference< XInterfaceTypeDescription2 > const & desc); + + sal_Int32 get() const { return offset; } + +private: + void calculateBases(Reference< XInterfaceTypeDescription2 > const & desc); + + void calculate(Reference< XInterfaceTypeDescription2 > const & desc); + + std::set< rtl::OUString > set; + sal_Int32 offset; +}; + +BaseOffset::BaseOffset(Reference< XInterfaceTypeDescription2 > const & desc) { + offset = 0; + calculateBases(desc); +} + +void BaseOffset::calculateBases( + Reference< XInterfaceTypeDescription2 > const & desc) +{ + Sequence< Reference < XTypeDescription > > bases(desc->getBaseTypes()); + for (sal_Int32 i = 0; i < bases.getLength(); ++i) { + calculate( + Reference< XInterfaceTypeDescription2 >( + resolveTypedefs(bases[i]), UNO_QUERY_THROW)); + } +} + +void BaseOffset::calculate(Reference< XInterfaceTypeDescription2 > const & desc) +{ + if (set.insert(desc->getName()).second) { + calculateBases(desc); + offset += desc->getMembers().getLength(); + } +} + +} + +//__________________________________________________________________________________________________ +InterfaceTypeDescriptionImpl::InterfaceTypeDescriptionImpl( + const Reference< XHierarchicalNameAccess > & xTDMgr, + const OUString & rName, const Sequence< OUString > & rBaseTypes, + const Sequence< OUString > & rOptionalBaseTypes, + const Sequence< sal_Int8 > & rBytes, bool published ) + : _xTDMgr( xTDMgr ) + , _aBytes( rBytes ) + , _aName( rName ) + , _aBaseTypes( rBaseTypes ) + , _aOptionalBaseTypes( rOptionalBaseTypes ) + , _membersInit( false ) + , _published( published ) +{ + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); +} +//__________________________________________________________________________________________________ +InterfaceTypeDescriptionImpl::~InterfaceTypeDescriptionImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +TypeClass InterfaceTypeDescriptionImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return TypeClass_INTERFACE; +} +//__________________________________________________________________________________________________ +OUString InterfaceTypeDescriptionImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aName; +} + +// XInterfaceTypeDescription2 +//__________________________________________________________________________________________________ +Reference< XTypeDescription > InterfaceTypeDescriptionImpl::getBaseType() + throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< Reference< XTypeDescription > > aBaseTypes(getBaseTypes()); + return aBaseTypes.getLength() >= 1 ? aBaseTypes[0] : 0; +} +//__________________________________________________________________________________________________ +Uik SAL_CALL InterfaceTypeDescriptionImpl::getUik() + throw(::com::sun::star::uno::RuntimeException) +{ + return Uik(); +} +//__________________________________________________________________________________________________ +Sequence< Reference< XInterfaceMemberTypeDescription > > InterfaceTypeDescriptionImpl::getMembers() + throw(::com::sun::star::uno::RuntimeException) +{ + osl::MutexGuard guard(getMutex()); + if (!_membersInit) { + _nBaseOffset = BaseOffset(this).get(); + typereg::Reader reader( + _aBytes.getConstArray(), _aBytes.getLength(), false, + TYPEREG_VERSION_1); + sal_Int32 count = 0; + sal_uInt16 methodCount = reader.getMethodCount(); + {for (sal_uInt16 i = 0; i < methodCount; ++i) { + RTMethodMode flags = reader.getMethodFlags(i); + if (flags != RT_MODE_ATTRIBUTE_GET + && flags != RT_MODE_ATTRIBUTE_SET) + { + ++count; + } + }} + sal_uInt16 fieldCount = reader.getFieldCount(); + count += fieldCount; + _members.realloc(count); + sal_Int32 index = 0; + {for (sal_uInt16 i = 0; i < fieldCount; ++i) { + rtl::OUString name(reader.getFieldName(i)); + rtl::OUStringBuffer typeName(getName()); + typeName.appendAscii(RTL_CONSTASCII_STRINGPARAM("::")); + typeName.append(name); + RTFieldAccess flags = reader.getFieldFlags(i); + std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > + getter; + std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > + setter; + for (sal_uInt16 j = 0; j < methodCount; ++j) { + if (reader.getMethodName(j) == name) { + switch (reader.getMethodFlags(j)) { + case RT_MODE_ATTRIBUTE_GET: + OSL_ASSERT(getter.get() == 0); + getter.reset( + new stoc::registry_tdprovider::FunctionDescription( + _xTDMgr, _aBytes, j)); + break; + + case RT_MODE_ATTRIBUTE_SET: + OSL_ASSERT(setter.get() == 0); + setter.reset( + new stoc::registry_tdprovider::FunctionDescription( + _xTDMgr, _aBytes, j)); + break; + + default: + OSL_ASSERT(false); + break; + } + } + } + _members[index] = new InterfaceAttributeImpl( + _xTDMgr, typeName.makeStringAndClear(), name, + reader.getFieldTypeName(i).replace('/', '.'), + (flags & RT_ACCESS_READONLY) != 0, + (flags & RT_ACCESS_BOUND) != 0, getter, setter, + _nBaseOffset + index); + ++index; + }} + {for (sal_uInt16 i = 0; i < methodCount; ++i) { + RTMethodMode flags = reader.getMethodFlags(i); + if (flags != RT_MODE_ATTRIBUTE_GET + && flags != RT_MODE_ATTRIBUTE_SET) + { + rtl::OUString name(reader.getMethodName(i)); + rtl::OUStringBuffer typeName(getName()); + typeName.appendAscii(RTL_CONSTASCII_STRINGPARAM("::")); + typeName.append(name); + _members[index] = new InterfaceMethodImpl( + _xTDMgr, typeName.makeStringAndClear(), name, + reader.getMethodReturnTypeName(i).replace('/', '.'), + _aBytes, i, flags == RT_MODE_ONEWAY, _nBaseOffset + index); + ++index; + } + }} + _membersInit = true; + } + return _members; +} + +Sequence< Reference< XTypeDescription > > +InterfaceTypeDescriptionImpl::getBaseTypes() throw (RuntimeException) { + MutexGuard guard(getMutex()); + if (_xBaseTDs.getLength() == 0 && _aBaseTypes.getLength() != 0) { + Sequence< Reference< XTypeDescription > > tds(_aBaseTypes.getLength()); + for (sal_Int32 i = 0; i < _aBaseTypes.getLength(); ++i) { + try { + _xTDMgr->getByHierarchicalName(_aBaseTypes[i]) >>= tds[i]; + } catch (NoSuchElementException & e) { + throw RuntimeException( + (OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container.NoSuchElementException: ")) + + e.Message), + static_cast< OWeakObject * >(this)); + } + OSL_ASSERT(tds[i].is()); + checkInterfaceType(tds[i]); + } + _xBaseTDs = tds; + } + return _xBaseTDs; +} + +Sequence< Reference< XTypeDescription > > +InterfaceTypeDescriptionImpl::getOptionalBaseTypes() throw (RuntimeException) { + MutexGuard guard(getMutex()); + if (_xOptionalBaseTDs.getLength() == 0 + && _aOptionalBaseTypes.getLength() != 0) + { + Sequence< Reference< XTypeDescription > > tds( + _aOptionalBaseTypes.getLength()); + for (sal_Int32 i = 0; i < _aOptionalBaseTypes.getLength(); ++i) { + try { + _xTDMgr->getByHierarchicalName(_aOptionalBaseTypes[i]) + >>= tds[i]; + } catch (NoSuchElementException & e) { + throw RuntimeException( + (OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container.NoSuchElementException: ")) + + e.Message), + static_cast< OWeakObject * >(this)); + } + OSL_ASSERT(tds[i].is()); + checkInterfaceType(tds[i]); + } + _xOptionalBaseTDs = tds; + } + return _xOptionalBaseTDs; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdmodule.cxx b/stoc/source/registry_tdprovider/tdmodule.cxx new file mode 100644 index 000000000000..82464efb9442 --- /dev/null +++ b/stoc/source/registry_tdprovider/tdmodule.cxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" + +#include <vector> +#include <osl/diagnose.h> +#include "base.hxx" + +namespace stoc_rdbtdp +{ + +//__________________________________________________________________________________________________ +// virtual +ModuleTypeDescriptionImpl::~ModuleTypeDescriptionImpl() +{ + delete _pMembers; + + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +// virtual +TypeClass ModuleTypeDescriptionImpl::getTypeClass() + throw( RuntimeException ) +{ + return TypeClass_MODULE; +} +//__________________________________________________________________________________________________ +// virtual +OUString ModuleTypeDescriptionImpl::getName() + throw( RuntimeException ) +{ + return _aName; +} + +// XModuleTypeDescription +//__________________________________________________________________________________________________ +// virtual +Sequence< Reference< XTypeDescription > > SAL_CALL +ModuleTypeDescriptionImpl::getMembers() + throw ( RuntimeException ) +{ + if ( !_pMembers ) + { + Reference< XTypeDescriptionEnumeration > xEnum; + try + { + xEnum = _xTDMgr->createTypeDescriptionEnumeration( + _aName, + Sequence< TypeClass >(), + TypeDescriptionSearchDepth_ONE ); + } + catch ( NoSuchTypeNameException const & ) + { + } + catch ( InvalidTypeNameException const & ) + { + } + + OSL_ENSURE( xEnum.is(), + "ModuleTypeDescriptionImpl::getMembers - No enumeration!" ); + + std::vector< Reference< XTypeDescription > > aTDs; + while ( xEnum->hasMoreElements() ) + { + try + { + Reference< XTypeDescription > xTD( + xEnum->nextTypeDescription() ); + aTDs.push_back( xTD ); + } + catch ( NoSuchElementException const & ) + { + OSL_FAIL( "ModuleTypeDescriptionImpl::getMembers - " + " Caught NoSuchElementException!" ); + } + } + + Sequence< Reference< XTypeDescription > > * pMembers + = new Sequence< Reference< XTypeDescription > >( aTDs.size() ); + for ( sal_Int32 n = 0; n < pMembers->getLength(); n++ ) + (*pMembers)[ n ] = aTDs[ n ]; + + ClearableMutexGuard aGuard( getMutex() ); + if ( _pMembers ) + { + aGuard.clear(); + delete pMembers; + } + else + { + _pMembers = pMembers; + } + } + return *_pMembers; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdprop.cxx b/stoc/source/registry_tdprovider/tdprop.cxx new file mode 100644 index 000000000000..c022b88fe804 --- /dev/null +++ b/stoc/source/registry_tdprovider/tdprop.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include <osl/diagnose.h> +#include "base.hxx" + +namespace stoc_rdbtdp +{ + +//__________________________________________________________________________________________________ +// virtual +ConstantTypeDescriptionImpl::~ConstantTypeDescriptionImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +// virtual +TypeClass ConstantTypeDescriptionImpl::getTypeClass() + throw( RuntimeException ) +{ + return TypeClass_CONSTANT; +} +//__________________________________________________________________________________________________ +// virtual +OUString ConstantTypeDescriptionImpl::getName() + throw( RuntimeException ) +{ + return _aName; +} + +// XConstantTypeDescription +//__________________________________________________________________________________________________ +// virtual +Any SAL_CALL ConstantTypeDescriptionImpl::getConstantValue() + throw( RuntimeException ) +{ + return _aValue; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdprovider.cxx b/stoc/source/registry_tdprovider/tdprovider.cxx new file mode 100644 index 000000000000..bcebd85ffd44 --- /dev/null +++ b/stoc/source/registry_tdprovider/tdprovider.cxx @@ -0,0 +1,631 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include <osl/diagnose.h> +#include <osl/mutex.hxx> +#include <uno/dispatcher.h> +#include <uno/mapping.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/compbase4.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <cppuhelper/weakref.hxx> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp> +#include "com/sun/star/uno/RuntimeException.hpp" + +#include "registry/reader.hxx" +#include "registry/version.h" +#include "base.hxx" +#include "rdbtdp_tdenumeration.hxx" +#include "structtypedescription.hxx" + +#define SERVICENAME "com.sun.star.reflection.TypeDescriptionProvider" +#define IMPLNAME "com.sun.star.comp.stoc.RegistryTypeDescriptionProvider" + +using namespace com::sun::star; +using namespace com::sun::star::beans; +using namespace com::sun::star::registry; + +extern rtl_StandardModuleCount g_moduleCount; + +namespace stoc_bootstrap +{ +uno::Sequence< OUString > rdbtdp_getSupportedServiceNames() +{ + static Sequence < OUString > *pNames = 0; + if( ! pNames ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( !pNames ) + { + static Sequence< OUString > seqNames(1); + seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME)); + pNames = &seqNames; + } + } + return *pNames; +} + +OUString rdbtdp_getImplementationName() +{ + static OUString *pImplName = 0; + if( ! pImplName ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pImplName ) + { + static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) ); + pImplName = &implName; + } + } + return *pImplName; +} +} + +namespace stoc_rdbtdp +{ +struct MutexHolder +{ + Mutex _aComponentMutex; +}; +//================================================================================================== +class ProviderImpl + : public MutexHolder + , public WeakComponentImplHelper4< XServiceInfo, + XHierarchicalNameAccess, + XTypeDescriptionEnumerationAccess, + XInitialization > +{ + // XHierarchicalNameAccess + XTypeDescriptionEnumerationAccess wrapper + // first asking the tdmgr instance, then looking up locally + class TypeDescriptionManagerWrapper + : public ::cppu::WeakImplHelper2< + container::XHierarchicalNameAccess, + reflection::XTypeDescriptionEnumerationAccess> + { + com::sun::star::uno::Reference<container::XHierarchicalNameAccess> + m_xTDMgr; + com::sun::star::uno::Reference<container::XHierarchicalNameAccess> + m_xThisProvider; + public: + TypeDescriptionManagerWrapper( ProviderImpl * pProvider ) + : m_xTDMgr( pProvider->_xContext->getValueByName( + OUString( RTL_CONSTASCII_USTRINGPARAM( + "/singletons/com.sun.star.reflection." + "theTypeDescriptionManager") ) ), + UNO_QUERY_THROW ), + m_xThisProvider( pProvider ) + {} + // XHierarchicalNameAccess + virtual Any SAL_CALL getByHierarchicalName( OUString const & name ) + throw (container::NoSuchElementException, RuntimeException); + virtual sal_Bool SAL_CALL hasByHierarchicalName( OUString const & name ) + throw (RuntimeException); + + // XTypeDescriptionEnumerationAccess + virtual uno::Reference< + reflection::XTypeDescriptionEnumeration > SAL_CALL + createTypeDescriptionEnumeration( + const ::rtl::OUString& moduleName, + const uno::Sequence< uno::TypeClass >& types, + reflection::TypeDescriptionSearchDepth depth ) + throw ( reflection::NoSuchTypeNameException, + reflection::InvalidTypeNameException, + uno::RuntimeException ); + }; + friend class TypeDescriptionManagerWrapper; + + com::sun::star::uno::Reference< XComponentContext > _xContext; + com::sun::star::uno::WeakReference<XHierarchicalNameAccess> _xTDMgr; + com::sun::star::uno::Reference< XHierarchicalNameAccess > getTDMgr() SAL_THROW( () ); + + RegistryKeyList _aBaseKeys; + +protected: + virtual void SAL_CALL disposing(); + +public: + ProviderImpl( const com::sun::star::uno::Reference< XComponentContext > & xContext ); + virtual ~ProviderImpl(); + + // XInitialization + virtual void SAL_CALL initialize( const Sequence< Any > & args ) throw (Exception, RuntimeException); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw(::com::sun::star::uno::RuntimeException); + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); + + // XHierarchicalNameAccess + Any getByHierarchicalNameImpl( const OUString & rName ); + + virtual Any SAL_CALL getByHierarchicalName( const OUString & rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException); + + // XTypeDescriptionEnumerationAccess + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::reflection::XTypeDescriptionEnumeration > SAL_CALL + createTypeDescriptionEnumeration( + const ::rtl::OUString& moduleName, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::TypeClass >& types, + ::com::sun::star::reflection::TypeDescriptionSearchDepth depth ) + throw ( ::com::sun::star::reflection::NoSuchTypeNameException, + ::com::sun::star::reflection::InvalidTypeNameException, + ::com::sun::star::uno::RuntimeException ); +}; +//__________________________________________________________________________________________________ +ProviderImpl::ProviderImpl( const com::sun::star::uno::Reference< XComponentContext > & xContext ) + : WeakComponentImplHelper4< + XServiceInfo, XHierarchicalNameAccess, + XTypeDescriptionEnumerationAccess, XInitialization >( _aComponentMutex ) + , _xContext( xContext ) +{ + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); +} +//__________________________________________________________________________________________________ +ProviderImpl::~ProviderImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +//______________________________________________________________________________ +Any ProviderImpl::TypeDescriptionManagerWrapper::getByHierarchicalName( + OUString const & name ) throw (container::NoSuchElementException, + RuntimeException) +{ + try + { + // first try tdmgr: + return m_xTDMgr->getByHierarchicalName( name ); + } + catch (container::NoSuchElementException &) + { + // then lookup locally: + return m_xThisProvider->getByHierarchicalName( name ); + } +} + +//______________________________________________________________________________ +sal_Bool ProviderImpl::TypeDescriptionManagerWrapper::hasByHierarchicalName( + OUString const & name ) throw (RuntimeException) +{ + return m_xTDMgr->hasByHierarchicalName( name ) || m_xThisProvider->hasByHierarchicalName( name ); +} + +//______________________________________________________________________________ +uno::Reference< reflection::XTypeDescriptionEnumeration > SAL_CALL +ProviderImpl::TypeDescriptionManagerWrapper::createTypeDescriptionEnumeration( + const ::rtl::OUString& moduleName, + const uno::Sequence< uno::TypeClass >& types, + reflection::TypeDescriptionSearchDepth depth ) + throw ( reflection::NoSuchTypeNameException, + reflection::InvalidTypeNameException, + uno::RuntimeException ) +{ + try + { + // first try tdmgr: + uno::Reference< reflection::XTypeDescriptionEnumerationAccess > xTDEA( + m_xTDMgr, uno::UNO_QUERY_THROW ); + return + xTDEA->createTypeDescriptionEnumeration( moduleName, types, depth ); + } + catch (reflection::NoSuchTypeNameException &) + { + // then lookup locally: + uno::Reference< reflection::XTypeDescriptionEnumerationAccess > xTDEA( + m_xThisProvider, uno::UNO_QUERY_THROW ); + return + xTDEA->createTypeDescriptionEnumeration( moduleName, types, depth ); + } +} + +//__________________________________________________________________________________________________ +com::sun::star::uno::Reference< XHierarchicalNameAccess > ProviderImpl::getTDMgr() + SAL_THROW( () ) +{ + // harden weak reference: + com::sun::star::uno::Reference<container::XHierarchicalNameAccess> xTDMgr( + _xTDMgr ); + if (! xTDMgr.is()) + { + xTDMgr.set( new TypeDescriptionManagerWrapper(this) ); + { + MutexGuard guard( _aComponentMutex ); + _xTDMgr = xTDMgr; + } + } + return xTDMgr; +} + +//__________________________________________________________________________________________________ +void ProviderImpl::disposing() +{ + _xContext.clear(); + + for ( RegistryKeyList::const_iterator iPos( _aBaseKeys.begin() ); + iPos != _aBaseKeys.end(); ++iPos ) + { + (*iPos)->closeKey(); + } + _aBaseKeys.clear(); +} + +// XInitialization +//__________________________________________________________________________________________________ +void ProviderImpl::initialize( + const Sequence< Any > & args ) + throw (Exception, RuntimeException) +{ + // registries to read from + Any const * pRegistries = args.getConstArray(); + for ( sal_Int32 nPos = 0; nPos < args.getLength(); ++nPos ) + { + com::sun::star::uno::Reference< XSimpleRegistry > xRegistry( pRegistries[ nPos ], UNO_QUERY ); + if (xRegistry.is() && xRegistry->isValid()) + { + com::sun::star::uno::Reference< XRegistryKey > xKey( xRegistry->getRootKey()->openKey( + OUString( RTL_CONSTASCII_USTRINGPARAM("/UCR") ) ) ); + if (xKey.is() && xKey->isValid()) + { + _aBaseKeys.push_back( xKey ); + } + } + } +} + +// XServiceInfo +//__________________________________________________________________________________________________ +OUString ProviderImpl::getImplementationName() + throw(::com::sun::star::uno::RuntimeException) +{ + return stoc_bootstrap::rdbtdp_getImplementationName(); +} +//__________________________________________________________________________________________________ +sal_Bool ProviderImpl::supportsService( const OUString & rServiceName ) + throw(::com::sun::star::uno::RuntimeException) +{ + const Sequence< OUString > & rSNL = getSupportedServiceNames(); + const OUString * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + { + if (pArray[nPos] == rServiceName) + return sal_True; + } + return sal_False; +} +//__________________________________________________________________________________________________ +Sequence< OUString > ProviderImpl::getSupportedServiceNames() + throw(::com::sun::star::uno::RuntimeException) +{ + return stoc_bootstrap::rdbtdp_getSupportedServiceNames(); +} + +// XHierarchicalNameAccess +//__________________________________________________________________________________________________ +Any ProviderImpl::getByHierarchicalNameImpl( const OUString & rName ) +{ + Any aRet; + + // read from registry + OUString aKey( rName.replace( '.', '/' ) ); + for ( RegistryKeyList::const_iterator iPos( _aBaseKeys.begin() ); + !aRet.hasValue() && iPos != _aBaseKeys.end(); ++iPos ) + { + try + { + com::sun::star::uno::Reference< XRegistryKey > xBaseKey( *iPos ); + com::sun::star::uno::Reference< XRegistryKey > xKey( xBaseKey->openKey( aKey ) ); + if (xKey.is()) + { + // closes key in it's dtor (which is + // called even in case of exceptions). + RegistryKeyCloser aCloser( xKey ); + + if ( xKey->isValid() ) + { + if (xKey->getValueType() == RegistryValueType_BINARY) + { + Sequence< sal_Int8 > aBytes( xKey->getBinaryValue() ); + com::sun::star::uno::Reference< XTypeDescription > xTD( + createTypeDescription( aBytes, + getTDMgr(), + true ) ); + if ( xTD.is() ) + aRet <<= xTD; + } + } + } + else // might be a constant + { + sal_Int32 nIndex = aKey.lastIndexOf( '/' ); + if (nIndex > 0) + { + // open module + com::sun::star::uno::Reference< XRegistryKey > xKey2( xBaseKey->openKey( aKey.copy( 0, nIndex ) ) ); + if (xKey2.is()) + { + // closes key in it's dtor (which is + // called even in case of exceptions). + RegistryKeyCloser aCloser( xKey2 ); + + if ( xKey2->isValid() ) + { + if (xKey2->getValueType() == RegistryValueType_BINARY) + { + Sequence< sal_Int8 > aBytes( xKey2->getBinaryValue() ); + typereg::Reader aReader( + aBytes.getConstArray(), aBytes.getLength(), + false, TYPEREG_VERSION_1); + + if (aReader.getTypeClass() == RT_TYPE_MODULE || + aReader.getTypeClass() == RT_TYPE_CONSTANTS || + aReader.getTypeClass() == RT_TYPE_ENUM) + { + OUString aFieldName( aKey.copy( nIndex+1, aKey.getLength() - nIndex -1 ) ); + sal_Int16 nPos = aReader.getFieldCount(); + while (nPos--) + { + if (aFieldName.equals( + aReader.getFieldName(nPos))) + break; + } + if (nPos >= 0) + aRet = getRTValue( + aReader.getFieldValue(nPos)); + } + } + } + } + } + } + } + catch ( InvalidRegistryException const & ) + { + OSL_FAIL( "ProviderImpl::getByHierarchicalName " + "- Caught InvalidRegistryException!" ); + + // openKey, closeKey, getValueType, getBinaryValue, isValid + + // Don't stop iteration in this case. + } + catch ( NoSuchElementException const & ) + { + } + } + return aRet; +} + +Any SAL_CALL ProviderImpl::getByHierarchicalName( const OUString & rName ) + throw(::com::sun::star::uno::RuntimeException, com::sun::star::container::NoSuchElementException) +{ + Any aRet( getByHierarchicalNameImpl( rName ) ); + + if ( !aRet.hasValue() ) + throw NoSuchElementException( + rName, static_cast< cppu::OWeakObject * >( this ) ); + + return aRet; +} + +//__________________________________________________________________________________________________ +sal_Bool ProviderImpl::hasByHierarchicalName( const OUString & rName ) + throw(::com::sun::star::uno::RuntimeException) +{ + return getByHierarchicalNameImpl( rName ).hasValue(); +} + +// XTypeDescriptionEnumerationAccess +//__________________________________________________________________________________________________ +// virtual +com::sun::star::uno::Reference< XTypeDescriptionEnumeration > SAL_CALL +ProviderImpl::createTypeDescriptionEnumeration( + const OUString & moduleName, + const Sequence< TypeClass > & types, + TypeDescriptionSearchDepth depth ) + throw ( NoSuchTypeNameException, + InvalidTypeNameException, + RuntimeException ) +{ + return com::sun::star::uno::Reference< XTypeDescriptionEnumeration >( + TypeDescriptionEnumerationImpl::createInstance( getTDMgr(), + moduleName, + types, + depth, + _aBaseKeys ).get() ); +} + +//__________________________________________________________________________________________________ +// global helper function + +com::sun::star::uno::Reference< XTypeDescription > resolveTypedefs( + com::sun::star::uno::Reference< XTypeDescription > const & type) +{ + com::sun::star::uno::Reference< XTypeDescription > resolved(type); + while (resolved->getTypeClass() == TypeClass_TYPEDEF) { + resolved = com::sun::star::uno::Reference< XIndirectTypeDescription >( + resolved, UNO_QUERY_THROW)->getReferencedType(); + } + return resolved; +} + +com::sun::star::uno::Reference< XTypeDescription > createTypeDescription( + const Sequence< sal_Int8 > & rData, + const com::sun::star::uno::Reference< XHierarchicalNameAccess > & xNameAccess, + bool bReturnEmptyRefForUnknownType ) +{ + typereg::Reader aReader( + rData.getConstArray(), rData.getLength(), false, TYPEREG_VERSION_1); + + OUString aName( aReader.getTypeName().replace( '/', '.' ) ); + + switch (aReader.getTypeClass()) + { + case RT_TYPE_INTERFACE: + { + sal_uInt16 n = aReader.getSuperTypeCount(); + com::sun::star::uno::Sequence< rtl::OUString > aBaseTypeNames(n); + {for (sal_uInt16 i = 0; i < n; ++i) { + aBaseTypeNames[i] = aReader.getSuperTypeName(i).replace( + '/', '.'); + }} + sal_uInt16 n2 = aReader.getReferenceCount(); + com::sun::star::uno::Sequence< rtl::OUString > + aOptionalBaseTypeNames(n2); + {for (sal_uInt16 i = 0; i < n2; ++i) { + OSL_ASSERT( + aReader.getReferenceSort(i) == RT_REF_SUPPORTS + && aReader.getReferenceFlags(i) == RT_ACCESS_OPTIONAL); + aOptionalBaseTypeNames[i] = aReader.getReferenceTypeName(i); + }} + return com::sun::star::uno::Reference< XTypeDescription >( + new InterfaceTypeDescriptionImpl( xNameAccess, + aName, + aBaseTypeNames, + aOptionalBaseTypeNames, + rData, + aReader.isPublished() ) ); + } + + case RT_TYPE_MODULE: + { + com::sun::star::uno::Reference< + XTypeDescriptionEnumerationAccess > xTDEA( + xNameAccess, UNO_QUERY ); + + OSL_ENSURE( xTDEA.is(), + "No XTypeDescriptionEnumerationAccess!" ); + + return com::sun::star::uno::Reference< XTypeDescription >( + new ModuleTypeDescriptionImpl( xTDEA, aName ) ); + } + + case RT_TYPE_STRUCT: + { + rtl::OUString superTypeName; + if (aReader.getSuperTypeCount() == 1) { + superTypeName = aReader.getSuperTypeName(0).replace( + '/', '.'); + } + return com::sun::star::uno::Reference< XTypeDescription >( + new stoc::registry_tdprovider::StructTypeDescription( + xNameAccess, aName, superTypeName, rData, + aReader.isPublished())); + } + + case RT_TYPE_ENUM: + return com::sun::star::uno::Reference< XTypeDescription >( + new EnumTypeDescriptionImpl( xNameAccess, + aName, + getRTValueAsInt32( + aReader.getFieldValue( 0 ) ), + rData, aReader.isPublished() ) ); + + case RT_TYPE_EXCEPTION: + { + rtl::OUString superTypeName; + if (aReader.getSuperTypeCount() == 1) { + superTypeName = aReader.getSuperTypeName(0).replace( + '/', '.'); + } + return com::sun::star::uno::Reference< XTypeDescription >( + new CompoundTypeDescriptionImpl( + xNameAccess, TypeClass_EXCEPTION, aName, superTypeName, + rData, aReader.isPublished())); + } + + case RT_TYPE_TYPEDEF: + return com::sun::star::uno::Reference< XTypeDescription >( + new TypedefTypeDescriptionImpl( xNameAccess, + aName, + aReader.getSuperTypeName(0) + .replace( '/', '.' ), + aReader.isPublished() ) ); + case RT_TYPE_SERVICE: + return com::sun::star::uno::Reference< XTypeDescription >( + new ServiceTypeDescriptionImpl( + xNameAccess, aName, rData, aReader.isPublished() ) ); + + case RT_TYPE_CONSTANTS: + return com::sun::star::uno::Reference< XTypeDescription >( + new ConstantsTypeDescriptionImpl( + aName, rData, aReader.isPublished() ) ); + + case RT_TYPE_SINGLETON: + return com::sun::star::uno::Reference< XTypeDescription >( + new SingletonTypeDescriptionImpl( xNameAccess, + aName, + aReader.getSuperTypeName(0) + .replace( '/', '.' ), + aReader.isPublished() ) ); + case RT_TYPE_INVALID: + case RT_TYPE_OBJECT: // deprecated and not used + case RT_TYPE_UNION: // deprecated and not used + OSL_FAIL( "createTypeDescription - Unsupported Type!" ); + break; + + default: + OSL_FAIL( "createTypeDescription - Unknown Type!" ); + break; + } + + // Unknown type. + + if ( bReturnEmptyRefForUnknownType ) + return com::sun::star::uno::Reference< XTypeDescription >(); + + return com::sun::star::uno::Reference< XTypeDescription >( + new TypeDescriptionImpl( TypeClass_UNKNOWN, aName ) ); +} + +} + +namespace stoc_bootstrap +{ +//================================================================================================== +com::sun::star::uno::Reference< XInterface > SAL_CALL ProviderImpl_create( + com::sun::star::uno::Reference< XComponentContext > const & xContext ) + throw(::com::sun::star::uno::Exception) +{ + return com::sun::star::uno::Reference< XInterface >( *new stoc_rdbtdp::ProviderImpl( xContext ) ); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdservice.cxx b/stoc/source/registry_tdprovider/tdservice.cxx new file mode 100644 index 000000000000..76c50932f22b --- /dev/null +++ b/stoc/source/registry_tdprovider/tdservice.cxx @@ -0,0 +1,569 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include <osl/diagnose.h> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include "com/sun/star/uno/RuntimeException.hpp" + +#include "registry/reader.hxx" +#include "registry/version.h" +#include "base.hxx" +#include "methoddescription.hxx" + +#include <memory> + +using namespace com::sun::star; +using ::rtl::OUStringBuffer; + +namespace { + +class Constructor: + public cppu::WeakImplHelper1< XServiceConstructorDescription > +{ +public: + Constructor( + Reference< XHierarchicalNameAccess > const & manager, + rtl::OUString const & name, Sequence< sal_Int8 > const & bytes, + sal_uInt16 index): + m_desc(manager, name, bytes, index) {} + + virtual ~Constructor() {} + + virtual sal_Bool SAL_CALL isDefaultConstructor() throw (RuntimeException) + { return m_desc.getName().getLength() == 0; } + + virtual rtl::OUString SAL_CALL getName() throw (RuntimeException) + { return m_desc.getName(); } + + virtual Sequence< Reference< XParameter > > SAL_CALL getParameters() + throw (RuntimeException) + { return m_desc.getParameters(); } + + virtual Sequence< Reference<XCompoundTypeDescription > > SAL_CALL + getExceptions() throw (RuntimeException) + { return m_desc.getExceptions(); } + +private: + Constructor(Constructor &); // not implemented + void operator =(Constructor); // not implemented + + stoc::registry_tdprovider::MethodDescription m_desc; +}; + +} + +namespace stoc_rdbtdp +{ + +//================================================================================================== +// +// class PropertyTypeDescriptionImpl +// +//================================================================================================== +class PropertyTypeDescriptionImpl : public WeakImplHelper1< XPropertyTypeDescription > +{ + OUString _aName; + Reference< XTypeDescription > _xTD; + sal_Int16 _nFlags; + +public: + PropertyTypeDescriptionImpl( const OUString & rName, + const Reference< XTypeDescription > & xTD, + sal_Int16 nFlags ) + : _aName( rName ), _xTD( xTD ), _nFlags( nFlags ) + { + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + } + virtual ~PropertyTypeDescriptionImpl(); + + // XTypeDescription + virtual TypeClass SAL_CALL getTypeClass() + throw( RuntimeException ); + virtual OUString SAL_CALL getName() + throw( RuntimeException ); + + // XPropertyTypeDescription + virtual sal_Int16 SAL_CALL getPropertyFlags() + throw ( RuntimeException ); + virtual Reference< XTypeDescription > SAL_CALL getPropertyTypeDescription() + throw ( RuntimeException ); +}; + +//__________________________________________________________________________________________________ +// virtual +PropertyTypeDescriptionImpl::~PropertyTypeDescriptionImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +// virtual +TypeClass PropertyTypeDescriptionImpl::getTypeClass() + throw ( RuntimeException ) +{ + return TypeClass_PROPERTY; +} +//__________________________________________________________________________________________________ +// virtual +OUString PropertyTypeDescriptionImpl::getName() + throw ( RuntimeException ) +{ + return _aName; +} + +// XPropertyTypeDescription +//__________________________________________________________________________________________________ +// virtual +sal_Int16 SAL_CALL PropertyTypeDescriptionImpl::getPropertyFlags() + throw ( RuntimeException ) +{ + return _nFlags; +} + +//__________________________________________________________________________________________________ +// virtual +Reference< XTypeDescription > SAL_CALL +PropertyTypeDescriptionImpl::getPropertyTypeDescription() + throw ( RuntimeException ) +{ + return _xTD; +} + +//================================================================================================== +// +// ServiceTypeDescriptionImpl implementation +// +//================================================================================================== + +//__________________________________________________________________________________________________ +// virtual +ServiceTypeDescriptionImpl::~ServiceTypeDescriptionImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +// virtual +TypeClass ServiceTypeDescriptionImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return TypeClass_SERVICE; +} +//__________________________________________________________________________________________________ +// virtual +OUString ServiceTypeDescriptionImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aName; +} + +// XServiceTypeDescription +//__________________________________________________________________________________________________ +// virtual +Sequence< Reference< XServiceTypeDescription > > SAL_CALL +ServiceTypeDescriptionImpl::getMandatoryServices() + throw ( RuntimeException ) +{ + getReferences(); + return _aMandatoryServices; +} + +//__________________________________________________________________________________________________ +// virtual +Sequence< Reference< XServiceTypeDescription > > SAL_CALL +ServiceTypeDescriptionImpl::getOptionalServices() + throw ( RuntimeException ) +{ + getReferences(); + return _aOptionalServices; +} + +//__________________________________________________________________________________________________ +// virtual +Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL +ServiceTypeDescriptionImpl::getMandatoryInterfaces() + throw ( RuntimeException ) +{ + getReferences(); + return _aMandatoryInterfaces; +} + +//__________________________________________________________________________________________________ +// virtual +Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL +ServiceTypeDescriptionImpl::getOptionalInterfaces() + throw ( RuntimeException ) +{ + getReferences(); + return _aOptionalInterfaces; +} + +//__________________________________________________________________________________________________ +// virtual +Sequence< Reference< XPropertyTypeDescription > > SAL_CALL +ServiceTypeDescriptionImpl::getProperties() + throw ( RuntimeException ) +{ + { + MutexGuard guard(getMutex()); + if (_pProps.get() != 0) { + return *_pProps; + } + } + + typereg::Reader aReader( + _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1); + + sal_uInt16 nFields = (sal_uInt16)aReader.getFieldCount(); + std::auto_ptr< Sequence< Reference< XPropertyTypeDescription > > > + pTempProps( + new Sequence< Reference< XPropertyTypeDescription > >(nFields)); + Reference< XPropertyTypeDescription > * pProps = pTempProps->getArray(); + + while ( nFields-- ) + { + // name + OUStringBuffer aName( _aName ); + aName.appendAscii( "." ); + aName.append( aReader.getFieldName( nFields ) ); + + // type description + Reference< XTypeDescription > xTD; + try + { + _xTDMgr->getByHierarchicalName( + aReader.getFieldTypeName( nFields ).replace( '/', '.' ) ) + >>= xTD; + } + catch ( NoSuchElementException const & ) + { + } + OSL_ENSURE( xTD.is(), "### no type description for property!" ); + + // flags + RTFieldAccess nFlags = aReader.getFieldFlags( nFields ); + + sal_Int16 nAttribs = 0; + if ( nFlags & RT_ACCESS_READONLY ) + nAttribs |= beans::PropertyAttribute::READONLY; + if ( nFlags & RT_ACCESS_OPTIONAL ) + nAttribs |= beans::PropertyAttribute::OPTIONAL; + if ( nFlags & RT_ACCESS_MAYBEVOID ) + nAttribs |= beans::PropertyAttribute::MAYBEVOID; + if ( nFlags & RT_ACCESS_BOUND ) + nAttribs |= beans::PropertyAttribute::BOUND; + if ( nFlags & RT_ACCESS_CONSTRAINED ) + nAttribs |= beans::PropertyAttribute::CONSTRAINED; + if ( nFlags & RT_ACCESS_TRANSIENT ) + nAttribs |= beans::PropertyAttribute::TRANSIENT; + if ( nFlags & RT_ACCESS_MAYBEAMBIGUOUS ) + nAttribs |= beans::PropertyAttribute::MAYBEAMBIGUOUS; + if ( nFlags & RT_ACCESS_MAYBEDEFAULT ) + nAttribs |= beans::PropertyAttribute::MAYBEDEFAULT; + if ( nFlags & RT_ACCESS_REMOVEABLE ) + nAttribs |= beans::PropertyAttribute::REMOVEABLE; + + OSL_ENSURE( !(nFlags & RT_ACCESS_PROPERTY), + "### RT_ACCESS_PROPERTY is unexpected here!" ); + OSL_ENSURE( !(nFlags & RT_ACCESS_ATTRIBUTE), + "### RT_ACCESS_ATTRIBUTE is unexpected here!" ); + OSL_ENSURE( !(nFlags & RT_ACCESS_CONST), + "### RT_ACCESS_CONST is unexpected here!" ); + // always set, unless RT_ACCESS_READONLY is set. + //OSL_ENSURE( !(nFlags & RT_ACCESS_READWRITE), + // "### RT_ACCESS_READWRITE is unexpected here" ); + OSL_ENSURE( !(nFlags & RT_ACCESS_DEFAULT), + "### RT_ACCESS_DEAFAULT is unexpected here" ); + + pProps[ nFields ] + = new PropertyTypeDescriptionImpl( aName.makeStringAndClear(), + xTD, + nAttribs ); + } + + MutexGuard guard(getMutex()); + if (_pProps.get() == 0) { + _pProps = pTempProps; + } + return *_pProps; +} + +sal_Bool ServiceTypeDescriptionImpl::isSingleInterfaceBased() + throw (RuntimeException) +{ + getReferences(); + return _xInterfaceTD.is(); +} + +Reference< XTypeDescription > ServiceTypeDescriptionImpl::getInterface() + throw (RuntimeException) +{ + getReferences(); + return _xInterfaceTD; +} + +Sequence< Reference< XServiceConstructorDescription > > +ServiceTypeDescriptionImpl::getConstructors() throw (RuntimeException) { + MutexGuard guard(getMutex()); + if (_pCtors.get() == 0) { + typereg::Reader reader( + _aBytes.getConstArray(), _aBytes.getLength(), false, + TYPEREG_VERSION_1); + sal_uInt16 ctorCount = reader.getMethodCount(); + std::auto_ptr< Sequence< Reference< XServiceConstructorDescription > > > + ctors( + new Sequence< Reference< XServiceConstructorDescription > >( + ctorCount)); + for (sal_uInt16 i = 0; i < ctorCount; ++i) { + rtl::OUString name(reader.getMethodName(i)); + if (reader.getMethodFlags(i) != RT_MODE_TWOWAY + || (!reader.getMethodReturnTypeName(i).equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("void"))) + || (name.getLength() == 0 + && (ctorCount != 1 || reader.getMethodParameterCount(i) != 0 + || reader.getMethodExceptionCount(i) != 0))) + { + throw RuntimeException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Service has bad constructors")), + static_cast< OWeakObject * >(this)); + } + (*ctors)[i] = new Constructor( + _xTDMgr, reader.getMethodName(i), _aBytes, i); + } + _pCtors = ctors; + } + return *_pCtors; +} + +//__________________________________________________________________________________________________ +void ServiceTypeDescriptionImpl::getReferences() + throw ( RuntimeException ) +{ + { + MutexGuard guard(getMutex()); + if (_bInitReferences) { + return; + } + } + typereg::Reader aReader( + _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1); + sal_uInt16 superTypes = aReader.getSuperTypeCount(); + if (superTypes > 1) { + throw RuntimeException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Service has more than one supertype")), + static_cast< OWeakObject * >(this)); + } + if (superTypes == 1) { + OUString aBaseName( aReader.getSuperTypeName(0).replace( '/', '.' ) ); + if ( aReader.getReferenceCount() != 0 + || aReader.getFieldCount() != 0 ) + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Service is single-interface--based but also has" + " references and/or properties" ) ), + static_cast< OWeakObject * >( this ) ); + Reference< XTypeDescription > ifc; + try + { + _xTDMgr->getByHierarchicalName( aBaseName ) >>= ifc; + } + catch ( NoSuchElementException const & e ) + { + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container.NoSuchElementException: " ) ) + + e.Message, + static_cast< OWeakObject * >( this ) ); + } + OSL_ASSERT(ifc.is()); + if (resolveTypedefs(ifc)->getTypeClass() != TypeClass_INTERFACE) { + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Single-interface--based service is not based on" + " interface type" ) ), + static_cast< OWeakObject * >( this ) ); + } + MutexGuard guard(getMutex()); + if (!_bInitReferences) { + _xInterfaceTD = ifc; + _bInitReferences = true; + } + } + else + { + sal_uInt16 nRefs = aReader.getReferenceCount(); + Sequence< Reference< XServiceTypeDescription > > aMandatoryServices( + nRefs); + Sequence< Reference< XServiceTypeDescription > > aOptionalServices( + nRefs); + Sequence< Reference< XInterfaceTypeDescription > > aMandatoryInterfaces( + nRefs); + Sequence< Reference< XInterfaceTypeDescription > > aOptionalInterfaces( + nRefs); + sal_uInt32 nMS = 0; + sal_uInt32 nOS = 0; + sal_uInt32 nMI = 0; + sal_uInt32 nOI = 0; + + for ( sal_uInt16 nPos = 0; nPos < nRefs; ++nPos ) + { + RTReferenceType eType = aReader.getReferenceSort( nPos ); + switch ( eType ) + { + case RT_REF_EXPORTS: // service + { + uno::Any aTypeDesc; + try + { + aTypeDesc = _xTDMgr->getByHierarchicalName( + aReader.getReferenceTypeName( nPos ).replace( + '/', '.' ) ); + } + catch ( NoSuchElementException const & e ) + { + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container." + "NoSuchElementException: " ) ) + + e.Message, + static_cast< OWeakObject * >( this ) ); + } + + RTFieldAccess nAccess = aReader.getReferenceFlags( nPos ); + if ( nAccess & RT_ACCESS_OPTIONAL ) + { + // optional service + if ( !( aTypeDesc >>= aOptionalServices[ nOS ] ) ) + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Service 'export' is not a service" ) ), + static_cast< OWeakObject * >( this ) ); + nOS++; + } + else + { + // mandatory service + if ( !( aTypeDesc >>= aMandatoryServices[ nMS ] ) ) + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Service 'export' is not a service" ) ), + static_cast< OWeakObject * >( this ) ); + nMS++; + } + break; + } + case RT_REF_SUPPORTS: // interface + { + uno::Any aTypeDesc; + try + { + aTypeDesc = _xTDMgr->getByHierarchicalName( + aReader.getReferenceTypeName( nPos ).replace( + '/', '.' ) ); + } + catch ( NoSuchElementException const & e ) + { + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container." + "NoSuchElementException: " ) ) + + e.Message, + static_cast< OWeakObject * >( this ) ); + } + + RTFieldAccess nAccess = aReader.getReferenceFlags( nPos ); + if ( nAccess & RT_ACCESS_OPTIONAL ) + { + // optional interface + if ( !( aTypeDesc >>= aOptionalInterfaces[ nOI ] ) ) + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Service 'supports' is not an" + " interface" ) ), + static_cast< OWeakObject * >( this ) ); + nOI++; + } + else + { + // mandatory interface + if ( !( aTypeDesc >>= aMandatoryInterfaces[ nMI ] ) ) + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Service 'supports' is not an" + " interface" ) ), + static_cast< OWeakObject * >( this ) ); + nMI++; + } + break; + } + case RT_REF_OBSERVES: + case RT_REF_NEEDS: + break; + default: + OSL_FAIL( "### unsupported reference type!" ); + break; + } + } + aMandatoryServices.realloc( nMS ); + aOptionalServices.realloc( nOS ); + aMandatoryInterfaces.realloc( nMI ); + aOptionalInterfaces.realloc( nOI ); + + MutexGuard guard(getMutex()); + if (!_bInitReferences) { + _aMandatoryServices = aMandatoryServices; + _aOptionalServices = aOptionalServices; + _aMandatoryInterfaces = aMandatoryInterfaces; + _aOptionalInterfaces = aOptionalInterfaces; + _bInitReferences = true; + } + } +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/stoc/source/registry_tdprovider/tdsingleton.cxx b/stoc/source/registry_tdprovider/tdsingleton.cxx new file mode 100644 index 000000000000..cda20dd67232 --- /dev/null +++ b/stoc/source/registry_tdprovider/tdsingleton.cxx @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * 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_stoc.hxx" +#include <osl/diagnose.h> +#include "base.hxx" + +#include "com/sun/star/uno/RuntimeException.hpp" + +using namespace com::sun::star; + +namespace stoc_rdbtdp +{ + +void SingletonTypeDescriptionImpl::init() { + { + MutexGuard guard(getMutex()); + if (_xInterfaceTD.is() || _xServiceTD.is()) { + return; + } + } + Reference< XTypeDescription > base; + try { + base = Reference< XTypeDescription >( + _xTDMgr->getByHierarchicalName(_aBaseName), UNO_QUERY_THROW); + } catch (NoSuchElementException const & e) { + throw RuntimeException( + (OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.container.NoSuchElementException: ")) + + e.Message), + static_cast< OWeakObject * >(this)); + } + MutexGuard guard(getMutex()); + if (!_xInterfaceTD.is() && !_xServiceTD.is()) { + if (resolveTypedefs(base)->getTypeClass() == TypeClass_INTERFACE) { + _xInterfaceTD = base; + } else if (base->getTypeClass() == TypeClass_SERVICE) { + _xServiceTD = Reference< XServiceTypeDescription >( + base, UNO_QUERY_THROW); + } else { + throw RuntimeException( + OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Singleton is based on neither interface nor service")), + static_cast< OWeakObject * >(this)); + } + } + OSL_ASSERT(_xInterfaceTD.is() ^ _xServiceTD.is()); +} + +//__________________________________________________________________________________________________ +// virtual +SingletonTypeDescriptionImpl::~SingletonTypeDescriptionImpl() +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} + +// XTypeDescription +//__________________________________________________________________________________________________ +// virtual +TypeClass SingletonTypeDescriptionImpl::getTypeClass() + throw(::com::sun::star::uno::RuntimeException) +{ + return TypeClass_SINGLETON; +} +//__________________________________________________________________________________________________ +// virtual +OUString SingletonTypeDescriptionImpl::getName() + throw(::com::sun::star::uno::RuntimeException) +{ + return _aName; +} + +// XSingletonTypeDescription +//__________________________________________________________________________________________________ +// virtual +Reference< XServiceTypeDescription > SAL_CALL +SingletonTypeDescriptionImpl::getService() + throw(::com::sun::star::uno::RuntimeException) +{ + init(); + return _xServiceTD; +} + +// XSingletonTypeDescription2 +//______________________________________________________________________________ +// virtual +sal_Bool SAL_CALL +SingletonTypeDescriptionImpl::isInterfaceBased() + throw(::com::sun::star::uno::RuntimeException) +{ + init(); + return _xInterfaceTD.is(); +} + +//______________________________________________________________________________ +// virtual +Reference< XTypeDescription > SAL_CALL +SingletonTypeDescriptionImpl::getInterface() + throw(::com::sun::star::uno::RuntimeException) +{ + init(); + return _xInterfaceTD; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |