fs34c: #i117625# when assigning events, only throw if there is an invalid type given, *not* if the type is correct, but the sequence is merely empty

* found as LGPLv3-only fix at svn rev 1172123 (http://svn.apache.org/viewvc?view=revision&revision=1172123)
This commit is contained in:
mst 2011-09-17 22:41:28 +00:00 committed by Thorsten Behrens
parent c9e1a120ff
commit 1b056c65f6
3 changed files with 23 additions and 2 deletions

View file

@ -118,6 +118,14 @@ namespace comphelper
impl_assign( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() );
}
/** determines whether or not named values can be extracted from the given value
@return
<TRUE/> if and only if the given <code>Any</code> contains a <code>NamedValue</code>, a
<code>PropertyValue</code>, or a sequence thereof.
*/
static bool canExtractFrom( ::com::sun::star::uno::Any const & i_value );
/// returns the number of elements in the collection
size_t size() const;

View file

@ -126,6 +126,19 @@ namespace comphelper
{
}
//--------------------------------------------------------------------
bool NamedValueCollection::canExtractFrom( ::com::sun::star::uno::Any const & i_value )
{
Type const & aValueType = i_value.getValueType();
if ( aValueType.equals( ::cppu::UnoType< PropertyValue >::get() )
|| aValueType.equals( ::cppu::UnoType< NamedValue >::get() )
|| aValueType.equals( ::cppu::UnoType< Sequence< PropertyValue > >::get() )
|| aValueType.equals( ::cppu::UnoType< Sequence< NamedValue > >::get() )
)
return true;
return false;
}
//--------------------------------------------------------------------
NamedValueCollection& NamedValueCollection::merge( const NamedValueCollection& _rAdditionalValues, bool _bOverwriteExisting )
{

View file

@ -84,10 +84,10 @@ void SAL_CALL SfxEvents_Impl::replaceByName( const OUSTRING & aName, const ANY &
{
if ( maEventNames[i] == aName )
{
const ::comphelper::NamedValueCollection aEventDescriptor( rElement );
// check for correct type of the element
if ( rElement.hasValue() && aEventDescriptor.empty() )
if ( !::comphelper::NamedValueCollection::canExtractFrom( rElement ) )
throw ILLEGALARGUMENTEXCEPTION();
::comphelper::NamedValueCollection const aEventDescriptor( rElement );
// create Configuration at first, creation might call this method also and that would overwrite everything
// we might have stored before!