Kaydet (Commit) 04fe0cae authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Some clean-up

Change-Id: I8ab23a4b09f9d31ed49c98cdbbf1abc0e684358a
üst 615a69e3
...@@ -17,10 +17,14 @@ ...@@ -17,10 +17,14 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include "sal/config.h" #include "sal/config.h"
#include "cppuhelper/propertysetmixin.hxx" #include <algorithm>
#include <cassert>
#include <exception>
#include <map>
#include <set>
#include <vector>
#include "com/sun/star/beans/Property.hpp" #include "com/sun/star/beans/Property.hpp"
#include "com/sun/star/beans/PropertyChangeEvent.hpp" #include "com/sun/star/beans/PropertyChangeEvent.hpp"
...@@ -42,18 +46,16 @@ ...@@ -42,18 +46,16 @@
#include "com/sun/star/lang/IllegalArgumentException.hpp" #include "com/sun/star/lang/IllegalArgumentException.hpp"
#include "com/sun/star/lang/WrappedTargetException.hpp" #include "com/sun/star/lang/WrappedTargetException.hpp"
#include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
#include "com/sun/star/lang/XComponent.hpp"
#include "com/sun/star/lang/XMultiComponentFactory.hpp"
#include "com/sun/star/reflection/XCompoundTypeDescription.hpp" #include "com/sun/star/reflection/XCompoundTypeDescription.hpp"
#include "com/sun/star/reflection/XIdlClass.hpp" #include "com/sun/star/reflection/XIdlClass.hpp"
#include "com/sun/star/reflection/XIdlField2.hpp" #include "com/sun/star/reflection/XIdlField2.hpp"
#include "com/sun/star/reflection/XIdlReflection.hpp"
#include "com/sun/star/reflection/XIndirectTypeDescription.hpp" #include "com/sun/star/reflection/XIndirectTypeDescription.hpp"
#include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp" #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp"
#include "com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp" #include "com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp"
#include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp" #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp"
#include "com/sun/star/reflection/XStructTypeDescription.hpp" #include "com/sun/star/reflection/XStructTypeDescription.hpp"
#include "com/sun/star/reflection/XTypeDescription.hpp" #include "com/sun/star/reflection/XTypeDescription.hpp"
#include "com/sun/star/reflection/theCoreReflection.hpp"
#include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Any.hxx"
#include "com/sun/star/uno/DeploymentException.hpp" #include "com/sun/star/uno/DeploymentException.hpp"
#include "com/sun/star/uno/Exception.hpp" #include "com/sun/star/uno/Exception.hpp"
...@@ -65,51 +67,18 @@ ...@@ -65,51 +67,18 @@
#include "com/sun/star/uno/XComponentContext.hpp" #include "com/sun/star/uno/XComponentContext.hpp"
#include "com/sun/star/uno/XInterface.hpp" #include "com/sun/star/uno/XInterface.hpp"
#include "cppuhelper/implbase1.hxx" #include "cppuhelper/implbase1.hxx"
#include "cppuhelper/propertysetmixin.hxx"
#include "cppuhelper/weak.hxx" #include "cppuhelper/weak.hxx"
#include "osl/diagnose.h"
#include "osl/mutex.hxx" #include "osl/mutex.hxx"
#include "rtl/ref.hxx" #include "rtl/ref.hxx"
#include "rtl/string.h"
#include "rtl/ustring.h"
#include "rtl/ustring.hxx" #include "rtl/ustring.hxx"
#include "sal/types.h" #include "sal/types.h"
#include "salhelper/simplereferenceobject.hxx" #include "salhelper/simplereferenceobject.hxx"
#include <algorithm>
#include <exception>
#include <map>
#include <set>
#include <vector>
using cppu::PropertySetMixinImpl; using cppu::PropertySetMixinImpl;
namespace { namespace {
template< typename T > struct AutoDispose {
AutoDispose() {}
~AutoDispose() {
try {
dispose();
} catch (...) {}
}
void dispose() {
css::uno::Reference< css::lang::XComponent > comp(
ifc, css::uno::UNO_QUERY);
if (comp.is()) {
comp->dispose();
}
ifc.clear();
}
css::uno::Reference< T > ifc;
private:
AutoDispose(AutoDispose &); // not defined
void operator =(AutoDispose); // not defined
};
struct PropertyData { struct PropertyData {
explicit PropertyData( explicit PropertyData(
css::beans::Property const & theProperty, bool thePresent): css::beans::Property const & theProperty, bool thePresent):
...@@ -234,19 +203,16 @@ void Data::initProperties( ...@@ -234,19 +203,16 @@ void Data::initProperties(
{ {
t = resolveTypedefs(t); t = resolveTypedefs(t);
sal_Int16 n; sal_Int16 n;
if (t->getName().matchAsciiL( if (t->getName().startsWith(
RTL_CONSTASCII_STRINGPARAM( "com.sun.star.beans.Ambiguous<"))
"com.sun.star.beans.Ambiguous<")))
{ {
n = css::beans::PropertyAttribute::MAYBEAMBIGUOUS; n = css::beans::PropertyAttribute::MAYBEAMBIGUOUS;
} else if (t->getName().matchAsciiL( } else if (t->getName().startsWith(
RTL_CONSTASCII_STRINGPARAM( "com.sun.star.beans.Defaulted<"))
"com.sun.star.beans.Defaulted<")))
{ {
n = css::beans::PropertyAttribute::MAYBEDEFAULT; n = css::beans::PropertyAttribute::MAYBEDEFAULT;
} else if (t->getName().matchAsciiL( } else if (t->getName().startsWith(
RTL_CONSTASCII_STRINGPARAM( "com.sun.star.beans.Optional<"))
"com.sun.star.beans.Optional<")))
{ {
n = css::beans::PropertyAttribute::MAYBEVOID; n = css::beans::PropertyAttribute::MAYBEVOID;
} else { } else {
...@@ -261,12 +227,11 @@ void Data::initProperties( ...@@ -261,12 +227,11 @@ void Data::initProperties(
args( args(
css::uno::Reference< css::uno::Reference<
css::reflection::XStructTypeDescription >( css::reflection::XStructTypeDescription >(
t, t, css::uno::UNO_QUERY_THROW)->
css::uno::UNO_QUERY_THROW)->getTypeArguments()); getTypeArguments());
if (args.getLength() != 1) { if (args.getLength() != 1) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
rtl::OUString( "inconsistent UNO type registry",
"inconsistent UNO type registry"),
css::uno::Reference< css::uno::XInterface >()); css::uno::Reference< css::uno::XInterface >());
} }
t = args[0]; t = args[0];
...@@ -275,8 +240,7 @@ void Data::initProperties( ...@@ -275,8 +240,7 @@ void Data::initProperties(
= handleNames->size(); = handleNames->size();
if (handles > SAL_MAX_INT32) { if (handles > SAL_MAX_INT32) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
rtl::OUString( "interface type has too many attributes",
"interface type has too many attributes"),
css::uno::Reference< css::uno::XInterface >()); css::uno::Reference< css::uno::XInterface >());
} }
rtl::OUString name(members[i]->getMemberName()); rtl::OUString name(members[i]->getMemberName());
...@@ -294,8 +258,7 @@ void Data::initProperties( ...@@ -294,8 +258,7 @@ void Data::initProperties(
second) second)
{ {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
rtl::OUString( "inconsistent UNO type registry",
"inconsistent UNO type registry"),
css::uno::Reference< css::uno::XInterface >()); css::uno::Reference< css::uno::XInterface >());
} }
handleNames->push_back(name); handleNames->push_back(name);
...@@ -337,7 +300,7 @@ private: ...@@ -337,7 +300,7 @@ private:
css::uno::Sequence< css::beans::Property > Info::getProperties() css::uno::Sequence< css::beans::Property > Info::getProperties()
throw (css::uno::RuntimeException, std::exception) throw (css::uno::RuntimeException, std::exception)
{ {
OSL_ASSERT(m_data->properties.size() <= SAL_MAX_INT32); assert(m_data->properties.size() <= SAL_MAX_INT32);
css::uno::Sequence< css::beans::Property > s( css::uno::Sequence< css::beans::Property > s(
static_cast< sal_Int32 >(m_data->properties.size())); static_cast< sal_Int32 >(m_data->properties.size()));
sal_Int32 n = 0; sal_Int32 n = 0;
...@@ -466,36 +429,33 @@ PropertySetMixinImpl::Impl::Impl( ...@@ -466,36 +429,33 @@ PropertySetMixinImpl::Impl::Impl(
implements(theImplements), disposed(false), m_context(context), implements(theImplements), disposed(false), m_context(context),
m_absentOptional(absentOptional), m_type(type) m_absentOptional(absentOptional), m_type(type)
{ {
OSL_ASSERT( assert(context.is());
context.is() assert(
&& ((implements (implements
& ~(IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET & ~(IMPLEMENTS_PROPERTY_SET | IMPLEMENTS_FAST_PROPERTY_SET
| IMPLEMENTS_PROPERTY_ACCESS)) | IMPLEMENTS_PROPERTY_ACCESS))
== 0)); == 0);
m_idlClass = getReflection(m_type.getTypeName()); m_idlClass = getReflection(m_type.getTypeName());
css::uno::Reference< css::reflection::XTypeDescription > ifc; css::uno::Reference< css::reflection::XTypeDescription > ifc;
try { try {
ifc = css::uno::Reference< css::reflection::XTypeDescription >( ifc = css::uno::Reference< css::reflection::XTypeDescription >(
css::uno::Reference< css::container::XHierarchicalNameAccess >( css::uno::Reference< css::container::XHierarchicalNameAccess >(
m_context->getValueByName( m_context->getValueByName(
rtl::OUString( "/singletons/com.sun.star.reflection."
"/singletons/com.sun.star.reflection." "theTypeDescriptionManager"),
"theTypeDescriptionManager")),
css::uno::UNO_QUERY_THROW)->getByHierarchicalName( css::uno::UNO_QUERY_THROW)->getByHierarchicalName(
m_type.getTypeName()), m_type.getTypeName()),
css::uno::UNO_QUERY_THROW); css::uno::UNO_QUERY_THROW);
} catch (css::container::NoSuchElementException & e) { } catch (css::container::NoSuchElementException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.container.NoSuchElementException: "
"unexpected"
" com.sun.star.container.NoSuchElementException: ")
+ e.Message), + e.Message),
css::uno::Reference< css::uno::XInterface >()); css::uno::Reference< css::uno::XInterface >());
} }
std::vector< rtl::OUString > handleNames; std::vector< rtl::OUString > handleNames;
initProperties(ifc, m_absentOptional, &handleNames); initProperties(ifc, m_absentOptional, &handleNames);
std::vector< rtl::OUString >::size_type size = handleNames.size(); std::vector< rtl::OUString >::size_type size = handleNames.size();
OSL_ASSERT(size <= SAL_MAX_INT32); assert(size <= SAL_MAX_INT32);
handleMap.realloc(static_cast< sal_Int32 >(size)); handleMap.realloc(static_cast< sal_Int32 >(size));
std::copy(handleNames.begin(), handleNames.end(), handleMap.getArray()); std::copy(handleNames.begin(), handleNames.end(), handleMap.getArray());
} }
...@@ -506,9 +466,7 @@ rtl::OUString PropertySetMixinImpl::Impl::translateHandle( ...@@ -506,9 +466,7 @@ rtl::OUString PropertySetMixinImpl::Impl::translateHandle(
{ {
if (handle < 0 || handle >= handleMap.getLength()) { if (handle < 0 || handle >= handleMap.getLength()) {
throw css::beans::UnknownPropertyException( throw css::beans::UnknownPropertyException(
(rtl::OUString("bad handle ") "bad handle " + rtl::OUString::number(handle), object);
+ rtl::OUString::number(handle)),
object);
} }
return handleMap[handle]; return handleMap[handle];
} }
...@@ -532,9 +490,7 @@ void PropertySetMixinImpl::Impl::setProperty( ...@@ -532,9 +490,7 @@ void PropertySetMixinImpl::Impl::setProperty(
== 0))) == 0)))
{ {
throw css::lang::IllegalArgumentException( throw css::lang::IllegalArgumentException(
(rtl::OUString( ("flagging as ambiguous/defaulted non-ambiguous/defaulted property "
"flagging as ambiguous/defaulted non-ambiguous/defaulted"
" property ")
+ name), + name),
object, illegalArgumentPosition); object, illegalArgumentPosition);
} }
...@@ -566,9 +522,7 @@ void PropertySetMixinImpl::Impl::setProperty( ...@@ -566,9 +522,7 @@ void PropertySetMixinImpl::Impl::setProperty(
e.Message, object, illegalArgumentPosition); e.Message, object, illegalArgumentPosition);
} else { } else {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected"
" com.sun.star.lang.IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} }
...@@ -576,9 +530,7 @@ void PropertySetMixinImpl::Impl::setProperty( ...@@ -576,9 +530,7 @@ void PropertySetMixinImpl::Impl::setProperty(
//TODO Clarify whether PropertyVetoException is the correct exception //TODO Clarify whether PropertyVetoException is the correct exception
// to throw when trying to set a read-only property: // to throw when trying to set a read-only property:
throw css::beans::PropertyVetoException( throw css::beans::PropertyVetoException(
(rtl::OUString("cannot set read-only property ") "cannot set read-only property " + name, object);
+ name),
object);
} catch (css::lang::WrappedTargetRuntimeException & e) { } catch (css::lang::WrappedTargetRuntimeException & e) {
//FIXME A WrappedTargetRuntimeException from XIdlField2.get is not //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not
// guaranteed to originate directly within XIdlField2.get (and thus have // guaranteed to originate directly within XIdlField2.get (and thus have
...@@ -628,8 +580,7 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( ...@@ -628,8 +580,7 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
value = field->get(object->queryInterface(m_type)); value = field->get(object->queryInterface(m_type));
} catch (css::lang::IllegalArgumentException & e) { } catch (css::lang::IllegalArgumentException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected com.sun.star.lang.IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} catch (css::lang::WrappedTargetRuntimeException & e) { } catch (css::lang::WrappedTargetRuntimeException & e) {
...@@ -666,92 +617,76 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( ...@@ -666,92 +617,76 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
bool isDefaulted = false; bool isDefaulted = false;
while (undoAmbiguous || undoDefaulted || undoOptional) { while (undoAmbiguous || undoDefaulted || undoOptional) {
if (undoAmbiguous if (undoAmbiguous
&& value.getValueTypeName().matchAsciiL( && value.getValueTypeName().startsWith(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Ambiguous<"))) "com.sun.star.beans.Ambiguous<"))
{ {
css::uno::Reference< css::reflection::XIdlClass > ambiguous( css::uno::Reference< css::reflection::XIdlClass > ambiguous(
getReflection(value.getValueTypeName())); getReflection(value.getValueTypeName()));
try { try {
if (!(css::uno::Reference< css::reflection::XIdlField2 >( if (!(css::uno::Reference< css::reflection::XIdlField2 >(
ambiguous->getField( ambiguous->getField("IsAmbiguous"),
rtl::OUString("IsAmbiguous")),
css::uno::UNO_QUERY_THROW)->get(value) css::uno::UNO_QUERY_THROW)->get(value)
>>= isAmbiguous)) >>= isAmbiguous))
{ {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
rtl::OUString( ("unexpected type of com.sun.star.beans.Ambiguous"
"unexpected type of" " IsAmbiguous member"),
" com.sun.star.beans.Ambiguous IsAmbiguous"
" member"),
object); object);
} }
value = css::uno::Reference< css::reflection::XIdlField2 >( value = css::uno::Reference< css::reflection::XIdlField2 >(
ambiguous->getField( ambiguous->getField("Value"), css::uno::UNO_QUERY_THROW)->
rtl::OUString("Value")), get(value);
css::uno::UNO_QUERY_THROW)->get(value);
} catch (css::lang::IllegalArgumentException & e) { } catch (css::lang::IllegalArgumentException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected com.sun.star.lang."
"IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} }
undoAmbiguous = false; undoAmbiguous = false;
} else if (undoDefaulted } else if (undoDefaulted
&& value.getValueTypeName().matchAsciiL( && value.getValueTypeName().startsWith(
RTL_CONSTASCII_STRINGPARAM( "com.sun.star.beans.Defaulted<"))
"com.sun.star.beans.Defaulted<")))
{ {
css::uno::Reference< css::reflection::XIdlClass > defaulted( css::uno::Reference< css::reflection::XIdlClass > defaulted(
getReflection(value.getValueTypeName())); getReflection(value.getValueTypeName()));
try { try {
if (!(css::uno::Reference< css::reflection::XIdlField2 >( if (!(css::uno::Reference< css::reflection::XIdlField2 >(
defaulted->getField( defaulted->getField("IsDefaulted"),
rtl::OUString("IsDefaulted")),
css::uno::UNO_QUERY_THROW)->get(value) css::uno::UNO_QUERY_THROW)->get(value)
>>= isDefaulted)) >>= isDefaulted))
{ {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
rtl::OUString( ("unexpected type of com.sun.star.beans.Defaulted"
"unexpected type of" " IsDefaulted member"),
" com.sun.star.beans.Defaulted IsDefaulted"
" member"),
object); object);
} }
value = css::uno::Reference< css::reflection::XIdlField2 >( value = css::uno::Reference< css::reflection::XIdlField2 >(
defaulted->getField( defaulted->getField("Value"), css::uno::UNO_QUERY_THROW)->
rtl::OUString("Value")), get(value);
css::uno::UNO_QUERY_THROW)->get(value);
} catch (css::lang::IllegalArgumentException & e) { } catch (css::lang::IllegalArgumentException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected com.sun.star.lang."
"IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} }
undoDefaulted = false; undoDefaulted = false;
} else if (undoOptional } else if (undoOptional
&& value.getValueTypeName().matchAsciiL( && value.getValueTypeName().startsWith(
RTL_CONSTASCII_STRINGPARAM( "com.sun.star.beans.Optional<"))
"com.sun.star.beans.Optional<")))
{ {
css::uno::Reference< css::reflection::XIdlClass > optional( css::uno::Reference< css::reflection::XIdlClass > optional(
getReflection(value.getValueTypeName())); getReflection(value.getValueTypeName()));
try { try {
bool present = false; bool present = false;
if (!(css::uno::Reference< css::reflection::XIdlField2 >( if (!(css::uno::Reference< css::reflection::XIdlField2 >(
optional->getField( optional->getField("IsPresent"),
rtl::OUString("IsPresent")),
css::uno::UNO_QUERY_THROW)->get(value) css::uno::UNO_QUERY_THROW)->get(value)
>>= present)) >>= present))
{ {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
rtl::OUString( ("unexpected type of com.sun.star.beans.Optional"
"unexpected type of com.sun.star.beans.Optional" " IsPresent member"),
" IsPresent member"),
object); object);
} }
if (!present) { if (!present) {
...@@ -759,24 +694,18 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( ...@@ -759,24 +694,18 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
break; break;
} }
value = css::uno::Reference< css::reflection::XIdlField2 >( value = css::uno::Reference< css::reflection::XIdlField2 >(
optional->getField( optional->getField("Value"), css::uno::UNO_QUERY_THROW)->
rtl::OUString("Value")), get(value);
css::uno::UNO_QUERY_THROW)->get(value);
} catch (css::lang::IllegalArgumentException & e) { } catch (css::lang::IllegalArgumentException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected com.sun.star.lang."
"IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} }
undoOptional = false; undoOptional = false;
} else { } else {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( "unexpected type of attribute " + name, object);
"unexpected type of attribute ")
+ name),
object);
} }
} }
if (state != 0) { if (state != 0) {
...@@ -794,30 +723,9 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( ...@@ -794,30 +723,9 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
css::uno::Reference< css::reflection::XIdlClass > css::uno::Reference< css::reflection::XIdlClass >
PropertySetMixinImpl::Impl::getReflection(rtl::OUString const & typeName) const PropertySetMixinImpl::Impl::getReflection(rtl::OUString const & typeName) const
{ {
css::uno::Reference< css::lang::XMultiComponentFactory > factory( return css::uno::Reference< css::reflection::XIdlClass >(
m_context->getServiceManager(), css::uno::UNO_QUERY_THROW); css::reflection::theCoreReflection::get(m_context)->forName(typeName),
AutoDispose< css::reflection::XIdlReflection > refl; css::uno::UNO_SET_THROW);
try {
refl.ifc = css::uno::Reference< css::reflection::XIdlReflection >(
factory->createInstanceWithContext(
rtl::OUString(
"com.sun.star.reflection.CoreReflection"),
m_context),
css::uno::UNO_QUERY_THROW);
} catch (css::uno::RuntimeException &) {
throw;
} catch (css::uno::Exception & e) {
throw css::uno::DeploymentException(
(rtl::OUString(
"component context fails to supply service"
" com.sun.star.reflection.CoreReflection: ")
+ e.Message),
m_context);
}
css::uno::Reference< css::reflection::XIdlClass > idlClass(
refl.ifc->forName(typeName), css::uno::UNO_QUERY_THROW);
refl.dispose();
return idlClass;
} }
css::uno::Any PropertySetMixinImpl::Impl::wrapValue( css::uno::Any PropertySetMixinImpl::Impl::wrapValue(
...@@ -827,100 +735,77 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( ...@@ -827,100 +735,77 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue(
bool wrapAmbiguous, bool isAmbiguous, bool wrapDefaulted, bool isDefaulted, bool wrapAmbiguous, bool isAmbiguous, bool wrapDefaulted, bool isDefaulted,
bool wrapOptional) bool wrapOptional)
{ {
OSL_ASSERT( assert(wrapAmbiguous || !isAmbiguous);
(wrapAmbiguous || !isAmbiguous) && (wrapDefaulted || !isDefaulted)); assert(wrapDefaulted || !isDefaulted);
if (wrapAmbiguous if (wrapAmbiguous
&& type->getName().matchAsciiL( && type->getName().startsWith("com.sun.star.beans.Ambiguous<"))
RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Ambiguous<")))
{ {
css::uno::Any strct; css::uno::Any strct;
type->createObject(strct); type->createObject(strct);
try { try {
css::uno::Reference< css::reflection::XIdlField2 > field( css::uno::Reference< css::reflection::XIdlField2 > field(
type->getField( type->getField("Value"), css::uno::UNO_QUERY_THROW);
rtl::OUString("Value")),
css::uno::UNO_QUERY_THROW);
field->set( field->set(
strct, strct,
wrapValue( wrapValue(
object, value, field->getType(), false, false, object, value, field->getType(), false, false,
wrapDefaulted, isDefaulted, wrapOptional)); wrapDefaulted, isDefaulted, wrapOptional));
css::uno::Reference< css::reflection::XIdlField2 >( css::uno::Reference< css::reflection::XIdlField2 >(
type->getField( type->getField("IsAmbiguous"), css::uno::UNO_QUERY_THROW)->set(
rtl::OUString("IsAmbiguous")),
css::uno::UNO_QUERY_THROW)->set(
strct, css::uno::makeAny(isAmbiguous)); strct, css::uno::makeAny(isAmbiguous));
} catch (css::lang::IllegalArgumentException & e) { } catch (css::lang::IllegalArgumentException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected"
" com.sun.star.lang.IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} catch (css::lang::IllegalAccessException & e) { } catch (css::lang::IllegalAccessException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalAccessException: "
"unexpected"
" com.sun.star.lang.IllegalAccessException: ")
+ e.Message), + e.Message),
object); object);
} }
return strct; return strct;
} else if (wrapDefaulted } else if (wrapDefaulted
&& type->getName().matchAsciiL( && type->getName().startsWith("com.sun.star.beans.Defaulted<"))
RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Defaulted<")))
{ {
css::uno::Any strct; css::uno::Any strct;
type->createObject(strct); type->createObject(strct);
try { try {
css::uno::Reference< css::reflection::XIdlField2 > field( css::uno::Reference< css::reflection::XIdlField2 > field(
type->getField( type->getField("Value"), css::uno::UNO_QUERY_THROW);
rtl::OUString("Value")),
css::uno::UNO_QUERY_THROW);
field->set( field->set(
strct, strct,
wrapValue( wrapValue(
object, value, field->getType(), wrapAmbiguous, isAmbiguous, object, value, field->getType(), wrapAmbiguous, isAmbiguous,
false, false, wrapOptional)); false, false, wrapOptional));
css::uno::Reference< css::reflection::XIdlField2 >( css::uno::Reference< css::reflection::XIdlField2 >(
type->getField( type->getField("IsDefaulted"), css::uno::UNO_QUERY_THROW)->set(
rtl::OUString("IsDefaulted")),
css::uno::UNO_QUERY_THROW)->set(
strct, css::uno::makeAny(isDefaulted)); strct, css::uno::makeAny(isDefaulted));
} catch (css::lang::IllegalArgumentException & e) { } catch (css::lang::IllegalArgumentException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected"
" com.sun.star.lang.IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} catch (css::lang::IllegalAccessException & e) { } catch (css::lang::IllegalAccessException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalAccessException: "
"unexpected"
" com.sun.star.lang.IllegalAccessException: ")
+ e.Message), + e.Message),
object); object);
} }
return strct; return strct;
} else if (wrapOptional } else if (wrapOptional
&& type->getName().matchAsciiL( && type->getName().startsWith("com.sun.star.beans.Optional<"))
RTL_CONSTASCII_STRINGPARAM("com.sun.star.beans.Optional<")))
{ {
css::uno::Any strct; css::uno::Any strct;
type->createObject(strct); type->createObject(strct);
bool present = value.hasValue(); bool present = value.hasValue();
try { try {
css::uno::Reference< css::reflection::XIdlField2 >( css::uno::Reference< css::reflection::XIdlField2 >(
type->getField( type->getField("IsPresent"), css::uno::UNO_QUERY_THROW)->set(
rtl::OUString("IsPresent")),
css::uno::UNO_QUERY_THROW)->set(
strct, css::uno::makeAny(present)); strct, css::uno::makeAny(present));
if (present) { if (present) {
css::uno::Reference< css::reflection::XIdlField2 > field( css::uno::Reference< css::reflection::XIdlField2 > field(
type->getField( type->getField("Value"), css::uno::UNO_QUERY_THROW);
rtl::OUString("Value")),
css::uno::UNO_QUERY_THROW);
field->set( field->set(
strct, strct,
wrapValue( wrapValue(
...@@ -929,16 +814,12 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( ...@@ -929,16 +814,12 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue(
} }
} catch (css::lang::IllegalArgumentException & e) { } catch (css::lang::IllegalArgumentException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalArgumentException: "
"unexpected"
" com.sun.star.lang.IllegalArgumentException: ")
+ e.Message), + e.Message),
object); object);
} catch (css::lang::IllegalAccessException & e) { } catch (css::lang::IllegalAccessException & e) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
(rtl::OUString( ("unexpected com.sun.star.lang.IllegalAccessException: "
"unexpected"
" com.sun.star.lang.IllegalAccessException: ")
+ e.Message), + e.Message),
object); object);
} }
...@@ -946,9 +827,7 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( ...@@ -946,9 +827,7 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue(
} else { } else {
if (wrapAmbiguous || wrapDefaulted || wrapOptional) { if (wrapAmbiguous || wrapDefaulted || wrapOptional) {
throw css::uno::RuntimeException( throw css::uno::RuntimeException(
rtl::OUString( "unexpected type of attribute", object);
"unexpected type of attribute"),
object);
} }
return value; return value;
} }
...@@ -980,15 +859,14 @@ void PropertySetMixinImpl::prepareSet( ...@@ -980,15 +859,14 @@ void PropertySetMixinImpl::prepareSet(
css::uno::Any const & newValue, BoundListeners * boundListeners) css::uno::Any const & newValue, BoundListeners * boundListeners)
{ {
Impl::PropertyMap::const_iterator it(m_impl->properties.find(propertyName)); Impl::PropertyMap::const_iterator it(m_impl->properties.find(propertyName));
OSL_ASSERT(it != m_impl->properties.end()); assert(it != m_impl->properties.end());
Impl::VetoListenerBag specificVeto; Impl::VetoListenerBag specificVeto;
Impl::VetoListenerBag unspecificVeto; Impl::VetoListenerBag unspecificVeto;
{ {
osl::MutexGuard g(m_impl->mutex); osl::MutexGuard g(m_impl->mutex);
if (m_impl->disposed) { if (m_impl->disposed) {
throw css::lang::DisposedException( throw css::lang::DisposedException(
rtl::OUString("disposed"), "disposed", static_cast< css::beans::XPropertySet * >(this));
static_cast< css::beans::XPropertySet * >(this));
} }
if ((it->second.property.Attributes if ((it->second.property.Attributes
& css::beans::PropertyAttribute::CONSTRAINED) & css::beans::PropertyAttribute::CONSTRAINED)
...@@ -999,7 +877,7 @@ void PropertySetMixinImpl::prepareSet( ...@@ -999,7 +877,7 @@ void PropertySetMixinImpl::prepareSet(
if (i != m_impl->vetoListeners.end()) { if (i != m_impl->vetoListeners.end()) {
specificVeto = i->second; specificVeto = i->second;
} }
i = m_impl->vetoListeners.find(rtl::OUString()); i = m_impl->vetoListeners.find("");
if (i != m_impl->vetoListeners.end()) { if (i != m_impl->vetoListeners.end()) {
unspecificVeto = i->second; unspecificVeto = i->second;
} }
...@@ -1008,13 +886,13 @@ void PropertySetMixinImpl::prepareSet( ...@@ -1008,13 +886,13 @@ void PropertySetMixinImpl::prepareSet(
& css::beans::PropertyAttribute::BOUND) & css::beans::PropertyAttribute::BOUND)
!= 0) != 0)
{ {
OSL_ASSERT(boundListeners != 0); assert(boundListeners != 0);
Impl::BoundListenerMap::const_iterator i( Impl::BoundListenerMap::const_iterator i(
m_impl->boundListeners.find(propertyName)); m_impl->boundListeners.find(propertyName));
if (i != m_impl->boundListeners.end()) { if (i != m_impl->boundListeners.end()) {
boundListeners->m_impl->specificListeners = i->second; boundListeners->m_impl->specificListeners = i->second;
} }
i = m_impl->boundListeners.find(rtl::OUString()); i = m_impl->boundListeners.find("");
if (i != m_impl->boundListeners.end()) { if (i != m_impl->boundListeners.end()) {
boundListeners->m_impl->unspecificListeners = i->second; boundListeners->m_impl->unspecificListeners = i->second;
} }
...@@ -1045,7 +923,7 @@ void PropertySetMixinImpl::prepareSet( ...@@ -1045,7 +923,7 @@ void PropertySetMixinImpl::prepareSet(
if ((it->second.property.Attributes & css::beans::PropertyAttribute::BOUND) if ((it->second.property.Attributes & css::beans::PropertyAttribute::BOUND)
!= 0) != 0)
{ {
OSL_ASSERT(boundListeners != 0); assert(boundListeners != 0);
boundListeners->m_impl->event = css::beans::PropertyChangeEvent( boundListeners->m_impl->event = css::beans::PropertyChangeEvent(
static_cast< css::beans::XPropertySet * >(this), propertyName, static_cast< css::beans::XPropertySet * >(this), propertyName,
false, it->second.property.Handle, oldValue, newValue); false, it->second.property.Handle, oldValue, newValue);
...@@ -1146,7 +1024,7 @@ void PropertySetMixinImpl::addPropertyChangeListener( ...@@ -1146,7 +1024,7 @@ void PropertySetMixinImpl::addPropertyChangeListener(
css::uno::RuntimeException, std::exception) css::uno::RuntimeException, std::exception)
{ {
css::uno::Reference< css::beans::XPropertyChangeListener >( css::uno::Reference< css::beans::XPropertyChangeListener >(
listener, css::uno::UNO_QUERY_THROW); // reject NULL listener listener, css::uno::UNO_SET_THROW); // reject NULL listener
checkUnknown(propertyName); checkUnknown(propertyName);
bool disposed; bool disposed;
{ {
...@@ -1170,7 +1048,7 @@ void PropertySetMixinImpl::removePropertyChangeListener( ...@@ -1170,7 +1048,7 @@ void PropertySetMixinImpl::removePropertyChangeListener(
css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
css::uno::RuntimeException, std::exception) css::uno::RuntimeException, std::exception)
{ {
OSL_ASSERT(listener.is()); assert(listener.is());
checkUnknown(propertyName); checkUnknown(propertyName);
osl::MutexGuard g(m_impl->mutex); osl::MutexGuard g(m_impl->mutex);
Impl::BoundListenerMap::iterator i( Impl::BoundListenerMap::iterator i(
...@@ -1191,7 +1069,7 @@ void PropertySetMixinImpl::addVetoableChangeListener( ...@@ -1191,7 +1069,7 @@ void PropertySetMixinImpl::addVetoableChangeListener(
css::uno::RuntimeException, std::exception) css::uno::RuntimeException, std::exception)
{ {
css::uno::Reference< css::beans::XVetoableChangeListener >( css::uno::Reference< css::beans::XVetoableChangeListener >(
listener, css::uno::UNO_QUERY_THROW); // reject NULL listener listener, css::uno::UNO_SET_THROW); // reject NULL listener
checkUnknown(propertyName); checkUnknown(propertyName);
bool disposed; bool disposed;
{ {
...@@ -1215,7 +1093,7 @@ void PropertySetMixinImpl::removeVetoableChangeListener( ...@@ -1215,7 +1093,7 @@ void PropertySetMixinImpl::removeVetoableChangeListener(
css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
css::uno::RuntimeException, std::exception) css::uno::RuntimeException, std::exception)
{ {
OSL_ASSERT(listener.is()); assert(listener.is());
checkUnknown(propertyName); checkUnknown(propertyName);
osl::MutexGuard g(m_impl->mutex); osl::MutexGuard g(m_impl->mutex);
Impl::VetoListenerMap::iterator i(m_impl->vetoListeners.find(propertyName)); Impl::VetoListenerMap::iterator i(m_impl->vetoListeners.find(propertyName));
...@@ -1295,8 +1173,7 @@ void PropertySetMixinImpl::setPropertyValues( ...@@ -1295,8 +1173,7 @@ void PropertySetMixinImpl::setPropertyValues(
props[i].Handle))) props[i].Handle)))
{ {
throw css::beans::UnknownPropertyException( throw css::beans::UnknownPropertyException(
(rtl::OUString("name ") + props[i].Name ("name " + props[i].Name + " does not match handle "
+ rtl::OUString(" does not match handle ")
+ rtl::OUString::number(props[i].Handle)), + rtl::OUString::number(props[i].Handle)),
static_cast< css::beans::XPropertySet * >(this)); static_cast< css::beans::XPropertySet * >(this));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment