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_dbaccess.hxx" 30 31 #include "propertystorage.hxx" 32 33 /** === begin UNO includes === **/ 34 /** === end UNO includes === **/ 35 36 #include <svl/itemset.hxx> 37 #include <svl/stritem.hxx> 38 #include <svl/eitem.hxx> 39 40 #include <memory> 41 42 //........................................................................ 43 namespace dbaui 44 { 45 //........................................................................ 46 47 /** === begin UNO using === **/ 48 using ::com::sun::star::uno::Reference; 49 using ::com::sun::star::uno::XInterface; 50 using ::com::sun::star::uno::UNO_QUERY; 51 using ::com::sun::star::uno::Exception; 52 using ::com::sun::star::uno::RuntimeException; 53 using ::com::sun::star::uno::Any; 54 using ::com::sun::star::uno::makeAny; 55 /** === end UNO using === **/ 56 57 //==================================================================== 58 //= PropertyStorage 59 //==================================================================== 60 //-------------------------------------------------------------------- 61 PropertyStorage::~PropertyStorage() 62 { 63 } 64 65 //==================================================================== 66 //= helper 67 //==================================================================== 68 namespace 69 { 70 //---------------------------------------------------------------- 71 template < class ITEMTYPE, class UNOTYPE > 72 class ItemAdapter 73 { 74 public: 75 static bool trySet( SfxItemSet& _rSet, ItemId _nItemId, const Any& _rValue ) 76 { 77 const SfxPoolItem& rItem( _rSet.Get( _nItemId ) ); 78 const ITEMTYPE* pTypedItem = dynamic_cast< const ITEMTYPE* >( &rItem ); 79 if ( !pTypedItem ) 80 return false; 81 82 UNOTYPE aValue( pTypedItem->GetValue() ); 83 OSL_VERIFY( _rValue >>= aValue ); 84 // TODO: one could throw an IllegalArgumentException here - finally, this method 85 // is (to be) used from within an XPropertySet::setPropertyValue implementation, 86 // where this would be the appropriate reaction on wrong value types 87 ::std::auto_ptr< ITEMTYPE > pClone( dynamic_cast< ITEMTYPE* >( pTypedItem->Clone() ) ); 88 pClone->SetValue( aValue ); 89 _rSet.Put( *pClone ); 90 return true; 91 } 92 93 static bool tryGet( const SfxPoolItem& _rItem, Any& _out_rValue ) 94 { 95 const ITEMTYPE* pTypedItem = dynamic_cast< const ITEMTYPE* >( &_rItem ); 96 if ( !pTypedItem ) 97 return false; 98 99 _out_rValue <<= UNOTYPE( pTypedItem->GetValue() ); 100 return true; 101 } 102 }; 103 } 104 105 //==================================================================== 106 //= SetItemPropertyStorage 107 //==================================================================== 108 //-------------------------------------------------------------------- 109 void SetItemPropertyStorage::getPropertyValue( Any& _out_rValue ) const 110 { 111 const SfxPoolItem& rItem( m_rItemSet.Get( m_nItemID ) ); 112 113 // try some known item types 114 if ( ItemAdapter< SfxBoolItem, sal_Bool >::tryGet( rItem, _out_rValue ) 115 || ItemAdapter< SfxStringItem, ::rtl::OUString >::tryGet( rItem, _out_rValue ) 116 ) 117 return; 118 119 OSL_ENSURE( false, "SetItemPropertyStorage::getPropertyValue: unsupported item type!" ); 120 } 121 122 //-------------------------------------------------------------------- 123 void SetItemPropertyStorage::setPropertyValue( const Any& _rValue ) 124 { 125 // try some known item types 126 if ( ItemAdapter< SfxBoolItem, sal_Bool >::trySet( m_rItemSet, m_nItemID, _rValue ) 127 || ItemAdapter< SfxStringItem, ::rtl::OUString >::trySet( m_rItemSet, m_nItemID, _rValue ) 128 ) 129 return; 130 131 OSL_ENSURE( false, "SetItemPropertyStorage::setPropertyValue: unsupported item type!" ); 132 } 133 134 //........................................................................ 135 } // namespace dbaui 136 //........................................................................ 137