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: PropertySet.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "tools/PropertySet.hxx"
35 #include <boost/bind.hpp>
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using ::rtl::OUString
;
43 namespace sd
{ namespace tools
{
45 PropertySet::PropertySet (void)
46 : PropertySetInterfaceBase(m_aMutex
),
47 mpChangeListeners(new ChangeListenerContainer())
54 PropertySet::~PropertySet (void)
61 void SAL_CALL
PropertySet::disposing (void)
68 beans::UnknownPropertyException
PropertySet::CreateUnknownPropertyException (
69 const rtl::OUString
& rsPropertyName
)
71 return beans::UnknownPropertyException(
72 OUString::createFromAscii("property ")
74 + OUString::createFromAscii(" is not known"),
75 static_cast<XWeak
*>(this));
81 //----- XPropertySet ----------------------------------------------------------
83 Reference
<beans::XPropertySetInfo
> SAL_CALL
PropertySet::getPropertySetInfo (void)
84 throw(RuntimeException
)
92 void SAL_CALL
PropertySet::setPropertyValue (
93 const rtl::OUString
& rsPropertyName
,
94 const css::uno::Any
& rsPropertyValue
)
95 throw(css::beans::UnknownPropertyException
,
96 css::beans::PropertyVetoException
,
97 css::lang::IllegalArgumentException
,
98 css::lang::WrappedTargetException
,
99 css::uno::RuntimeException
)
103 Any
aOldValue (SetPropertyValue(rsPropertyName
,rsPropertyValue
));
104 if (aOldValue
!= rsPropertyValue
)
106 // Inform listeners that are registered specifically for the
107 // property and those registered for any property.
108 beans::PropertyChangeEvent
aEvent(
109 static_cast<XWeak
*>(this),
115 CallListeners(rsPropertyName
, aEvent
);
116 CallListeners(OUString(), aEvent
);
123 Any SAL_CALL
PropertySet::getPropertyValue (const OUString
& rsPropertyName
)
124 throw(css::beans::UnknownPropertyException
,
125 css::lang::WrappedTargetException
,
126 css::uno::RuntimeException
)
130 return GetPropertyValue(rsPropertyName
);
136 void SAL_CALL
PropertySet::addPropertyChangeListener (
137 const rtl::OUString
& rsPropertyName
,
138 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& rxListener
)
139 throw(css::beans::UnknownPropertyException
,
140 css::lang::WrappedTargetException
,
141 css::uno::RuntimeException
)
143 if ( ! rxListener
.is())
144 throw lang::IllegalArgumentException();
146 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
149 mpChangeListeners
->insert(
150 ChangeListenerContainer::value_type(
158 void SAL_CALL
PropertySet::removePropertyChangeListener (
159 const rtl::OUString
& rsPropertyName
,
160 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& rxListener
)
161 throw(beans::UnknownPropertyException
,
162 css::lang::WrappedTargetException
,
163 css::uno::RuntimeException
)
165 ::std::pair
<ChangeListenerContainer::iterator
,ChangeListenerContainer::iterator
>
166 aRange (mpChangeListeners
->equal_range(rsPropertyName
));
168 ChangeListenerContainer::iterator
iListener (
173 std::bind1st(std::equal_to
<Reference
<beans::XPropertyChangeListener
> >(),
175 std::select2nd
<ChangeListenerContainer::value_type
>())));
176 if (iListener
!= mpChangeListeners
->end())
178 mpChangeListeners
->erase(iListener
);
182 throw lang::IllegalArgumentException();
189 void SAL_CALL
PropertySet::addVetoableChangeListener (
190 const rtl::OUString
& rsPropertyName
,
191 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& rxListener
)
192 throw(css::beans::UnknownPropertyException
,
193 css::lang::WrappedTargetException
,
194 css::uno::RuntimeException
)
196 // Constraint properties are not supported and thus no vetoable
198 (void)rsPropertyName
;
205 void SAL_CALL
PropertySet::removeVetoableChangeListener (
206 const rtl::OUString
& rsPropertyName
,
207 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& rxListener
)
208 throw(css::beans::UnknownPropertyException
,
209 css::lang::WrappedTargetException
,
210 css::uno::RuntimeException
)
212 // Constraint properties are not supported and thus no vetoable
214 (void)rsPropertyName
;
221 //-----------------------------------------------------------------------------
223 void PropertySet::CallListeners (
224 const rtl::OUString
& rsPropertyName
,
225 const beans::PropertyChangeEvent
& rEvent
)
227 ::std::pair
<ChangeListenerContainer::iterator
,ChangeListenerContainer::iterator
>
228 aRange (mpChangeListeners
->equal_range(rsPropertyName
));
229 ChangeListenerContainer::const_iterator iListener
;
230 for (iListener
=aRange
.first
; iListener
!=aRange
.second
; ++iListener
)
232 if (iListener
->second
.is())
233 iListener
->second
->propertyChange(rEvent
);
240 void PropertySet::ThrowIfDisposed (void)
241 throw (::com::sun::star::lang::DisposedException
)
243 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
245 throw lang::DisposedException (
246 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
247 "PropertySet object has already been disposed")),
248 static_cast<uno::XWeak
*>(this));
252 } } // end of namespace ::sd::tools