1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_unotools.hxx" 26 #include <tools/debug.hxx> 27 28 #include "unotools/propertysetinfo.hxx" 29 30 using namespace ::utl; 31 using namespace ::rtl; 32 using namespace ::com::sun::star; 33 using namespace ::com::sun::star::uno; 34 using namespace ::com::sun::star::beans; 35 using namespace ::com::sun::star::lang; 36 37 namespace utl 38 { 39 class PropertyMapImpl 40 { 41 public: 42 PropertyMapImpl() throw(); 43 virtual ~PropertyMapImpl() throw(); 44 45 void add( PropertyMapEntry* pMap ) throw(); 46 void remove( const OUString& aName ) throw(); 47 48 Sequence< Property > getProperties() throw(); 49 50 const PropertyMap* getPropertyMap() const throw(); 51 52 Property getPropertyByName( const OUString& aName ) throw( UnknownPropertyException ); 53 sal_Bool hasPropertyByName( const OUString& aName ) throw(); 54 55 private: 56 PropertyMap maPropertyMap; 57 Sequence< Property > maProperties; 58 }; 59 } 60 61 PropertyMapImpl::PropertyMapImpl() throw() 62 { 63 } 64 65 PropertyMapImpl::~PropertyMapImpl() throw() 66 { 67 } 68 69 void PropertyMapImpl::add( PropertyMapEntry* pMap ) throw() 70 { 71 while( pMap->mpName ) 72 { 73 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 74 75 #ifdef DBG_UTIL 76 PropertyMap::iterator aIter = maPropertyMap.find( aName ); 77 if( aIter != maPropertyMap.end() ) 78 { 79 DBG_ERROR( "Warning: PropertyMapEntry added twice, possible error!" ); 80 } 81 #endif 82 if( NULL == pMap->mpType ) 83 { 84 DBG_ERROR( "No type in PropertyMapEntry!" ); 85 pMap->mpType = &::getCppuType((const sal_Int32*)0); 86 } 87 88 maPropertyMap[aName] = pMap; 89 90 if( maProperties.getLength() ) 91 maProperties.realloc( 0 ); 92 93 pMap = &pMap[1]; 94 } 95 } 96 97 void PropertyMapImpl::remove( const OUString& aName ) throw() 98 { 99 maPropertyMap.erase( aName ); 100 101 if( maProperties.getLength() ) 102 maProperties.realloc( 0 ); 103 } 104 105 Sequence< Property > PropertyMapImpl::getProperties() throw() 106 { 107 // maybe we have to generate the properties after 108 // a change in the property map or at first call 109 // to getProperties 110 if( maProperties.getLength() != (sal_Int32)maPropertyMap.size() ) 111 { 112 maProperties = Sequence< Property >( maPropertyMap.size() ); 113 Property* pProperties = maProperties.getArray(); 114 115 PropertyMap::iterator aIter = maPropertyMap.begin(); 116 const PropertyMap::iterator aEnd = maPropertyMap.end(); 117 while( aIter != aEnd ) 118 { 119 PropertyMapEntry* pEntry = (*aIter).second; 120 121 pProperties->Name = OUString( pEntry->mpName, pEntry->mnNameLen, RTL_TEXTENCODING_ASCII_US ); 122 pProperties->Handle = pEntry->mnWhich; 123 pProperties->Type = *pEntry->mpType; 124 pProperties->Attributes = pEntry->mnFlags; 125 pProperties++; 126 aIter++; 127 } 128 } 129 130 return maProperties; 131 } 132 133 const PropertyMap* PropertyMapImpl::getPropertyMap() const throw() 134 { 135 return &maPropertyMap; 136 } 137 138 Property PropertyMapImpl::getPropertyByName( const OUString& aName ) throw( UnknownPropertyException ) 139 { 140 PropertyMap::iterator aIter = maPropertyMap.find( aName ); 141 142 if( maPropertyMap.end() == aIter ) 143 throw UnknownPropertyException(); 144 145 PropertyMapEntry* pEntry = (*aIter).second; 146 147 return Property( aName, pEntry->mnWhich, *pEntry->mpType, pEntry->mnFlags ); 148 } 149 150 sal_Bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) throw() 151 { 152 return maPropertyMap.find( aName ) != maPropertyMap.end(); 153 } 154 155 /////////////////////////////////////////////////////////////////////// 156 157 PropertySetInfo::PropertySetInfo() throw() 158 { 159 mpMap = new PropertyMapImpl(); 160 } 161 162 PropertySetInfo::~PropertySetInfo() throw() 163 { 164 delete mpMap; 165 } 166 167 void PropertySetInfo::add( PropertyMapEntry* pMap ) throw() 168 { 169 mpMap->add( pMap ); 170 } 171 172 void PropertySetInfo::remove( const rtl::OUString& aName ) throw() 173 { 174 mpMap->remove( aName ); 175 } 176 177 Sequence< ::com::sun::star::beans::Property > SAL_CALL PropertySetInfo::getProperties() throw(::com::sun::star::uno::RuntimeException) 178 { 179 return mpMap->getProperties(); 180 } 181 182 Property SAL_CALL PropertySetInfo::getPropertyByName( const ::rtl::OUString& aName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 183 { 184 return mpMap->getPropertyByName( aName ); 185 } 186 187 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const ::rtl::OUString& Name ) throw(::com::sun::star::uno::RuntimeException) 188 { 189 return mpMap->hasPropertyByName( Name ); 190 } 191 192 const PropertyMap* PropertySetInfo::getPropertyMap() const throw() 193 { 194 return mpMap->getPropertyMap(); 195 } 196