1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_comphelper.hxx" 30 #include <comphelper/ChainablePropertySetInfo.hxx> 31 #include <comphelper/TypeGeneration.hxx> 32 33 using ::rtl::OUString; 34 using ::comphelper::PropertyInfo; 35 using ::comphelper::GenerateCppuType; 36 using ::comphelper::ChainablePropertySetInfo; 37 using ::com::sun::star::uno::Any; 38 using ::com::sun::star::uno::Type; 39 using ::com::sun::star::uno::Sequence; 40 using ::com::sun::star::uno::Reference; 41 using ::com::sun::star::uno::XInterface; 42 using ::com::sun::star::uno::RuntimeException; 43 using ::com::sun::star::beans::Property; 44 using ::com::sun::star::beans::XPropertySetInfo; 45 using ::com::sun::star::beans::UnknownPropertyException; 46 47 ChainablePropertySetInfo::ChainablePropertySetInfo() 48 throw() 49 { 50 } 51 52 ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap ) 53 throw() 54 { 55 add ( pMap ); 56 } 57 58 ChainablePropertySetInfo::~ChainablePropertySetInfo() 59 throw() 60 { 61 } 62 63 void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount ) 64 throw() 65 { 66 // nCount < 0 => add all 67 // nCount == 0 => add nothing 68 // nCount > 0 => add at most nCount entries 69 if( maProperties.getLength() ) 70 maProperties.realloc( 0 ); 71 72 while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) ) 73 { 74 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 75 76 #ifdef DBG_UTIL 77 PropertyInfoHash::iterator aIter = maMap.find( aName ); 78 if( aIter != maMap.end() ) 79 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!"); 80 #endif 81 maMap[aName] = pMap++; 82 } 83 } 84 85 void ChainablePropertySetInfo::remove( const rtl::OUString& aName ) 86 throw() 87 { 88 maMap.erase ( aName ); 89 if ( maProperties.getLength() ) 90 maProperties.realloc( 0 ); 91 } 92 93 Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties() 94 throw(::com::sun::star::uno::RuntimeException) 95 { 96 sal_Int32 nSize = maMap.size(); 97 if( maProperties.getLength() != nSize ) 98 { 99 maProperties.realloc ( nSize ); 100 Property* pProperties = maProperties.getArray(); 101 102 PropertyInfoHash::iterator aIter = maMap.begin(); 103 const PropertyInfoHash::iterator aEnd = maMap.end(); 104 for ( ; aIter != aEnd; ++aIter, ++pProperties) 105 { 106 PropertyInfo* pInfo = (*aIter).second; 107 108 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 109 pProperties->Handle = pInfo->mnHandle; 110 const Type* pType; 111 GenerateCppuType ( pInfo->meCppuType, pType); 112 pProperties->Type = *pType; 113 pProperties->Attributes = pInfo->mnAttributes; 114 } 115 } 116 return maProperties; 117 } 118 119 Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const ::rtl::OUString& rName ) 120 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 121 { 122 PropertyInfoHash::iterator aIter = maMap.find( rName ); 123 124 if ( maMap.end() == aIter ) 125 throw UnknownPropertyException( rName, *this ); 126 127 PropertyInfo *pInfo = (*aIter).second; 128 Property aProperty; 129 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 130 aProperty.Handle = pInfo->mnHandle; 131 const Type* pType = &aProperty.Type; 132 GenerateCppuType ( pInfo->meCppuType, pType ); 133 aProperty.Type = *pType; 134 aProperty.Attributes = pInfo->mnAttributes; 135 return aProperty; 136 } 137 138 sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName ) 139 throw(::com::sun::star::uno::RuntimeException) 140 { 141 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() ); 142 } 143