1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10*96de5490SAndrew Rist * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*96de5490SAndrew Rist * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19*96de5490SAndrew Rist * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "propertystorage.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir /** === begin UNO includes === **/ 30cdf0e10cSrcweir /** === end UNO includes === **/ 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <svl/itemset.hxx> 33cdf0e10cSrcweir #include <svl/stritem.hxx> 34cdf0e10cSrcweir #include <svl/eitem.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <memory> 37cdf0e10cSrcweir 38cdf0e10cSrcweir //........................................................................ 39cdf0e10cSrcweir namespace dbaui 40cdf0e10cSrcweir { 41cdf0e10cSrcweir //........................................................................ 42cdf0e10cSrcweir 43cdf0e10cSrcweir /** === begin UNO using === **/ 44cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 45cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 46cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 47cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 48cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 49cdf0e10cSrcweir using ::com::sun::star::uno::Any; 50cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 51cdf0e10cSrcweir /** === end UNO using === **/ 52cdf0e10cSrcweir 53cdf0e10cSrcweir //==================================================================== 54cdf0e10cSrcweir //= PropertyStorage 55cdf0e10cSrcweir //==================================================================== 56cdf0e10cSrcweir //-------------------------------------------------------------------- ~PropertyStorage()57cdf0e10cSrcweir PropertyStorage::~PropertyStorage() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir //==================================================================== 62cdf0e10cSrcweir //= helper 63cdf0e10cSrcweir //==================================================================== 64cdf0e10cSrcweir namespace 65cdf0e10cSrcweir { 66cdf0e10cSrcweir //---------------------------------------------------------------- 67cdf0e10cSrcweir template < class ITEMTYPE, class UNOTYPE > 68cdf0e10cSrcweir class ItemAdapter 69cdf0e10cSrcweir { 70cdf0e10cSrcweir public: trySet(SfxItemSet & _rSet,ItemId _nItemId,const Any & _rValue)71cdf0e10cSrcweir static bool trySet( SfxItemSet& _rSet, ItemId _nItemId, const Any& _rValue ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir const SfxPoolItem& rItem( _rSet.Get( _nItemId ) ); 74cdf0e10cSrcweir const ITEMTYPE* pTypedItem = dynamic_cast< const ITEMTYPE* >( &rItem ); 75cdf0e10cSrcweir if ( !pTypedItem ) 76cdf0e10cSrcweir return false; 77cdf0e10cSrcweir 78cdf0e10cSrcweir UNOTYPE aValue( pTypedItem->GetValue() ); 79cdf0e10cSrcweir OSL_VERIFY( _rValue >>= aValue ); 80cdf0e10cSrcweir // TODO: one could throw an IllegalArgumentException here - finally, this method 81cdf0e10cSrcweir // is (to be) used from within an XPropertySet::setPropertyValue implementation, 82cdf0e10cSrcweir // where this would be the appropriate reaction on wrong value types 83cdf0e10cSrcweir ::std::auto_ptr< ITEMTYPE > pClone( dynamic_cast< ITEMTYPE* >( pTypedItem->Clone() ) ); 84cdf0e10cSrcweir pClone->SetValue( aValue ); 85cdf0e10cSrcweir _rSet.Put( *pClone ); 86cdf0e10cSrcweir return true; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir tryGet(const SfxPoolItem & _rItem,Any & _out_rValue)89cdf0e10cSrcweir static bool tryGet( const SfxPoolItem& _rItem, Any& _out_rValue ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir const ITEMTYPE* pTypedItem = dynamic_cast< const ITEMTYPE* >( &_rItem ); 92cdf0e10cSrcweir if ( !pTypedItem ) 93cdf0e10cSrcweir return false; 94cdf0e10cSrcweir 95cdf0e10cSrcweir _out_rValue <<= UNOTYPE( pTypedItem->GetValue() ); 96cdf0e10cSrcweir return true; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir }; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir //==================================================================== 102cdf0e10cSrcweir //= SetItemPropertyStorage 103cdf0e10cSrcweir //==================================================================== 104cdf0e10cSrcweir //-------------------------------------------------------------------- getPropertyValue(Any & _out_rValue) const105cdf0e10cSrcweir void SetItemPropertyStorage::getPropertyValue( Any& _out_rValue ) const 106cdf0e10cSrcweir { 107cdf0e10cSrcweir const SfxPoolItem& rItem( m_rItemSet.Get( m_nItemID ) ); 108cdf0e10cSrcweir 109cdf0e10cSrcweir // try some known item types 110cdf0e10cSrcweir if ( ItemAdapter< SfxBoolItem, sal_Bool >::tryGet( rItem, _out_rValue ) 111cdf0e10cSrcweir || ItemAdapter< SfxStringItem, ::rtl::OUString >::tryGet( rItem, _out_rValue ) 112cdf0e10cSrcweir ) 113cdf0e10cSrcweir return; 114cdf0e10cSrcweir 115cdf0e10cSrcweir OSL_ENSURE( false, "SetItemPropertyStorage::getPropertyValue: unsupported item type!" ); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir //-------------------------------------------------------------------- setPropertyValue(const Any & _rValue)119cdf0e10cSrcweir void SetItemPropertyStorage::setPropertyValue( const Any& _rValue ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir // try some known item types 122cdf0e10cSrcweir if ( ItemAdapter< SfxBoolItem, sal_Bool >::trySet( m_rItemSet, m_nItemID, _rValue ) 123cdf0e10cSrcweir || ItemAdapter< SfxStringItem, ::rtl::OUString >::trySet( m_rItemSet, m_nItemID, _rValue ) 124cdf0e10cSrcweir ) 125cdf0e10cSrcweir return; 126cdf0e10cSrcweir 127cdf0e10cSrcweir OSL_ENSURE( false, "SetItemPropertyStorage::setPropertyValue: unsupported item type!" ); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir //........................................................................ 131cdf0e10cSrcweir } // namespace dbaui 132cdf0e10cSrcweir //........................................................................ 133