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 31 #include "comphelper/propertysetinfo.hxx" 32 33 using namespace ::rtl; 34 using namespace ::comphelper; 35 using namespace ::com::sun::star; 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::beans; 38 using namespace ::com::sun::star::lang; 39 40 namespace comphelper 41 { 42 class PropertyMapImpl 43 { 44 public: 45 PropertyMapImpl() throw(); 46 virtual ~PropertyMapImpl() throw(); 47 48 void add( PropertyMapEntry* pMap, sal_Int32 nCount = -1 ) throw(); 49 void remove( const OUString& aName ) throw(); 50 51 Sequence< Property > getProperties() throw(); 52 53 const PropertyMap* getPropertyMap() const throw(); 54 55 Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException ); 56 sal_Bool hasPropertyByName( const OUString& aName ) throw(); 57 58 private: 59 PropertyMap maPropertyMap; 60 Sequence< Property > maProperties; 61 }; 62 } 63 64 PropertyMapImpl::PropertyMapImpl() throw() 65 { 66 } 67 68 PropertyMapImpl::~PropertyMapImpl() throw() 69 { 70 } 71 72 void PropertyMapImpl::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw() 73 { 74 // nCount < 0 => add all 75 // nCount == 0 => add nothing 76 // nCount > 0 => add at most nCount entries 77 78 while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) ) 79 { 80 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 81 82 #ifdef DBG_UTIL 83 PropertyMap::iterator aIter = maPropertyMap.find( aName ); 84 if( aIter != maPropertyMap.end() ) 85 { 86 OSL_ENSURE( sal_False, "Warning: PropertyMapEntry added twice, possible error!"); 87 } 88 #endif 89 if( NULL == pMap->mpType ) 90 { 91 OSL_ENSURE( sal_False, "No type in PropertyMapEntry!"); 92 pMap->mpType = &::getCppuType((const sal_Int32*)0); 93 } 94 95 maPropertyMap[aName] = pMap; 96 97 if( maProperties.getLength() ) 98 maProperties.realloc( 0 ); 99 100 pMap = &pMap[1]; 101 } 102 } 103 104 void PropertyMapImpl::remove( const OUString& aName ) throw() 105 { 106 maPropertyMap.erase( aName ); 107 108 if( maProperties.getLength() ) 109 maProperties.realloc( 0 ); 110 } 111 112 Sequence< Property > PropertyMapImpl::getProperties() throw() 113 { 114 // maybe we have to generate the properties after 115 // a change in the property map or at first call 116 // to getProperties 117 if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() ) 118 { 119 maProperties = Sequence< Property >( maPropertyMap.size() ); 120 Property* pProperties = maProperties.getArray(); 121 122 PropertyMap::iterator aIter = maPropertyMap.begin(); 123 const PropertyMap::iterator aEnd = maPropertyMap.end(); 124 while( aIter != aEnd ) 125 { 126 PropertyMapEntry* pEntry = (*aIter).second; 127 128 pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 129 pProperties->Handle = pEntry->mnHandle; 130 pProperties->Type = *pEntry->mpType; 131 pProperties->Attributes = pEntry->mnAttributes; 132 133 pProperties++; 134 aIter++; 135 } 136 } 137 138 return maProperties; 139 } 140 141 const PropertyMap* PropertyMapImpl::getPropertyMap() const throw() 142 { 143 return &maPropertyMap; 144 } 145 146 Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException ) 147 { 148 PropertyMap::iterator aIter = maPropertyMap.find( aName ); 149 150 if( maPropertyMap.end() == aIter ) 151 throw UnknownPropertyException( aName, NULL ); 152 153 PropertyMapEntry* pEntry = (*aIter).second; 154 155 return Property( aName, pEntry->mnHandle, *pEntry->mpType, pEntry->mnAttributes ); 156 } 157 158 sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw() 159 { 160 return maPropertyMap.find( aName ) != maPropertyMap.end(); 161 } 162 163 /////////////////////////////////////////////////////////////////////// 164 165 PropertySetInfo::PropertySetInfo() throw() 166 { 167 mpMap = new PropertyMapImpl(); 168 } 169 170 PropertySetInfo::PropertySetInfo( PropertyMapEntry* pMap ) throw() 171 { 172 mpMap = new PropertyMapImpl(); 173 mpMap->add( pMap ); 174 } 175 176 PropertySetInfo::~PropertySetInfo() throw() 177 { 178 delete mpMap; 179 } 180 181 void PropertySetInfo::add( PropertyMapEntry* pMap ) throw() 182 { 183 mpMap->add( pMap ); 184 } 185 186 void PropertySetInfo::add( PropertyMapEntry* pMap, sal_Int32 nCount ) throw() 187 { 188 mpMap->add( pMap, nCount ); 189 } 190 191 void PropertySetInfo::remove( const rtl::OUString& aName ) throw() 192 { 193 mpMap->remove( aName ); 194 } 195 196 Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException) 197 { 198 return mpMap->getProperties(); 199 } 200 201 Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 202 { 203 return mpMap->getPropertyByName( aName ); 204 } 205 206 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException) 207 { 208 return mpMap->hasPropertyByName( Name ); 209 } 210 211 const PropertyMap* PropertySetInfo::getPropertyMap() const throw() 212 { 213 return mpMap->getPropertyMap(); 214 } 215