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 #ifndef _COMPHELPER_CHAINABLEPROPERTYSETINFO_HXX_ 31 #include <comphelper/MasterPropertySetInfo.hxx> 32 #endif 33 #include <comphelper/TypeGeneration.hxx> 34 35 using ::rtl::OUString; 36 using ::comphelper::PropertyInfo; 37 using ::comphelper::GenerateCppuType; 38 using ::comphelper::MasterPropertySetInfo; 39 using ::com::sun::star::uno::Any; 40 using ::com::sun::star::uno::Type; 41 using ::com::sun::star::uno::Sequence; 42 using ::com::sun::star::uno::Reference; 43 using ::com::sun::star::uno::XInterface; 44 using ::com::sun::star::uno::RuntimeException; 45 using ::com::sun::star::beans::Property; 46 using ::com::sun::star::beans::XPropertySetInfo; 47 using ::com::sun::star::beans::UnknownPropertyException; 48 49 MasterPropertySetInfo::MasterPropertySetInfo() 50 throw() 51 { 52 } 53 54 MasterPropertySetInfo::MasterPropertySetInfo( PropertyInfo* pMap ) 55 throw() 56 { 57 add ( pMap ); 58 } 59 60 MasterPropertySetInfo::~MasterPropertySetInfo() 61 throw() 62 { 63 PropertyDataHash::iterator aEnd = maMap.end(), aIter = maMap.begin(); 64 while (aIter != aEnd ) 65 { 66 delete (*aIter).second; 67 aIter++; 68 } 69 } 70 71 void MasterPropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount, sal_uInt8 nMapId ) 72 throw() 73 { 74 // nCount < 0 => add all 75 // nCount == 0 => add nothing 76 // nCount > 0 => add at most nCount entries 77 if( maProperties.getLength() ) 78 maProperties.realloc( 0 ); 79 80 for ( ; pMap->mpName && ( ( nCount < 0 ) || ( nCount > 0 ) ); --nCount, ++pMap ) 81 { 82 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 83 84 #ifdef DBG_UTIL 85 PropertyDataHash::iterator aIter = maMap.find( aName ); 86 if( aIter != maMap.end() ) 87 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!"); 88 #endif 89 maMap[aName] = new PropertyData ( nMapId, pMap ); 90 } 91 } 92 93 void MasterPropertySetInfo::add( PropertyInfoHash &rHash, sal_uInt8 nMapId ) 94 throw() 95 { 96 if( maProperties.getLength() ) 97 maProperties.realloc( 0 ); 98 PropertyInfoHash::iterator aIter = rHash.begin(), aEnd = rHash.end(); 99 100 while ( aIter != aEnd ) 101 { 102 #ifdef DBG_UTIL 103 PropertyDataHash::iterator aDebugIter = maMap.find( (*aIter).first ); 104 if( aDebugIter != maMap.end() ) 105 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!"); 106 #endif 107 maMap[(*aIter).first] = new PropertyData ( nMapId, (*aIter).second ); 108 aIter++; 109 } 110 } 111 112 void MasterPropertySetInfo::remove( const rtl::OUString& aName ) 113 throw() 114 { 115 maMap.erase ( aName ); 116 if ( maProperties.getLength() ) 117 maProperties.realloc( 0 ); 118 } 119 120 Sequence< ::Property > SAL_CALL MasterPropertySetInfo::getProperties() 121 throw(::com::sun::star::uno::RuntimeException) 122 { 123 sal_Int32 nSize = maMap.size(); 124 if( maProperties.getLength() != nSize ) 125 { 126 maProperties.realloc ( nSize ); 127 Property* pProperties = maProperties.getArray(); 128 129 PropertyDataHash::iterator aIter = maMap.begin(); 130 const PropertyDataHash::iterator aEnd = maMap.end(); 131 for ( ; aIter != aEnd; ++aIter, ++pProperties) 132 { 133 PropertyInfo* pInfo = (*aIter).second->mpInfo; 134 135 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 136 pProperties->Handle = pInfo->mnHandle; 137 const Type* pType; 138 GenerateCppuType ( pInfo->meCppuType, pType); 139 pProperties->Type = *pType; 140 pProperties->Attributes = pInfo->mnAttributes; 141 } 142 } 143 return maProperties; 144 } 145 146 Property SAL_CALL MasterPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName ) 147 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 148 { 149 PropertyDataHash::iterator aIter = maMap.find( rName ); 150 151 if ( maMap.end() == aIter ) 152 throw UnknownPropertyException( rName, *this ); 153 154 PropertyInfo *pInfo = (*aIter).second->mpInfo; 155 Property aProperty; 156 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 157 aProperty.Handle = pInfo->mnHandle; 158 const Type* pType; 159 GenerateCppuType ( pInfo->meCppuType, pType ); 160 aProperty.Type = *pType; 161 162 aProperty.Attributes = pInfo->mnAttributes; 163 return aProperty; 164 } 165 166 sal_Bool SAL_CALL MasterPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName ) 167 throw(::com::sun::star::uno::RuntimeException) 168 { 169 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() ); 170 } 171