1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertystorage.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "propertystorage.hxx"
36 /** === begin UNO includes === **/
37 /** === end UNO includes === **/
39 #include <svtools/itemset.hxx>
40 #include <svtools/stritem.hxx>
41 #include <svtools/eitem.hxx>
45 //........................................................................
48 //........................................................................
50 /** === begin UNO using === **/
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::uno::XInterface
;
53 using ::com::sun::star::uno::UNO_QUERY
;
54 using ::com::sun::star::uno::Exception
;
55 using ::com::sun::star::uno::RuntimeException
;
56 using ::com::sun::star::uno::Any
;
57 using ::com::sun::star::uno::makeAny
;
58 /** === end UNO using === **/
60 //====================================================================
62 //====================================================================
63 //--------------------------------------------------------------------
64 PropertyStorage::~PropertyStorage()
68 //====================================================================
70 //====================================================================
73 //----------------------------------------------------------------
74 template < class ITEMTYPE
, class UNOTYPE
>
78 static bool trySet( SfxItemSet
& _rSet
, ItemId _nItemId
, const Any
& _rValue
)
80 const SfxPoolItem
& rItem( _rSet
.Get( _nItemId
) );
81 const ITEMTYPE
* pTypedItem
= dynamic_cast< const ITEMTYPE
* >( &rItem
);
85 UNOTYPE
aValue( pTypedItem
->GetValue() );
86 OSL_VERIFY( _rValue
>>= aValue
);
87 // TODO: one could throw an IllegalArgumentException here - finally, this method
88 // is (to be) used from within an XPropertySet::setPropertyValue implementation,
89 // where this would be the appropriate reaction on wrong value types
90 ::std::auto_ptr
< ITEMTYPE
> pClone( dynamic_cast< ITEMTYPE
* >( pTypedItem
->Clone() ) );
91 pClone
->SetValue( aValue
);
96 static bool tryGet( const SfxPoolItem
& _rItem
, Any
& _out_rValue
)
98 const ITEMTYPE
* pTypedItem
= dynamic_cast< const ITEMTYPE
* >( &_rItem
);
102 _out_rValue
<<= UNOTYPE( pTypedItem
->GetValue() );
108 //====================================================================
109 //= SetItemPropertyStorage
110 //====================================================================
111 //--------------------------------------------------------------------
112 void SetItemPropertyStorage::getPropertyValue( Any
& _out_rValue
) const
114 const SfxPoolItem
& rItem( m_rItemSet
.Get( m_nItemID
) );
116 // try some known item types
117 if ( ItemAdapter
< SfxBoolItem
, sal_Bool
>::tryGet( rItem
, _out_rValue
)
118 || ItemAdapter
< SfxStringItem
, ::rtl::OUString
>::tryGet( rItem
, _out_rValue
)
122 OSL_ENSURE( false, "SetItemPropertyStorage::getPropertyValue: unsupported item type!" );
125 //--------------------------------------------------------------------
126 void SetItemPropertyStorage::setPropertyValue( const Any
& _rValue
)
128 // try some known item types
129 if ( ItemAdapter
< SfxBoolItem
, sal_Bool
>::trySet( m_rItemSet
, m_nItemID
, _rValue
)
130 || ItemAdapter
< SfxStringItem
, ::rtl::OUString
>::trySet( m_rItemSet
, m_nItemID
, _rValue
)
134 OSL_ENSURE( false, "SetItemPropertyStorage::setPropertyValue: unsupported item type!" );
137 //........................................................................
139 //........................................................................