1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "precompiled_configmgr.hxx" 29*cdf0e10cSrcweir #include "sal/config.h" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertiesChangeListener.hpp" 32*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertyChangeListener.hpp" 33*cdf0e10cSrcweir #include "com/sun/star/container/XContainerListener.hpp" 34*cdf0e10cSrcweir #include "com/sun/star/lang/DisposedException.hpp" 35*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" 36*cdf0e10cSrcweir #include "com/sun/star/lang/XEventListener.hpp" 37*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx" 38*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp" 39*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx" 40*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp" 41*cdf0e10cSrcweir #include "com/sun/star/util/XChangesListener.hpp" 42*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx" 43*cdf0e10cSrcweir #include "osl/diagnose.hxx" 44*cdf0e10cSrcweir #include "rtl/string.h" 45*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 46*cdf0e10cSrcweir #include "rtl/ustring.h" 47*cdf0e10cSrcweir #include "rtl/ustring.hxx" 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include "broadcaster.hxx" 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir namespace configmgr { 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir namespace { 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir namespace css = com::sun::star; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir void appendMessage( 58*cdf0e10cSrcweir rtl::OUStringBuffer & buffer, css::uno::Exception const & exception) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir buffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("; ")); 61*cdf0e10cSrcweir buffer.append(exception.Message); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir void Broadcaster::addDisposeNotification( 67*cdf0e10cSrcweir css::uno::Reference< css::lang::XEventListener > const & listener, 68*cdf0e10cSrcweir css::lang::EventObject const & event) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir disposeNotifications_.push_back(DisposeNotification(listener, event)); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir void Broadcaster::addContainerElementReplacedNotification( 74*cdf0e10cSrcweir css::uno::Reference< css::container::XContainerListener > const & listener, 75*cdf0e10cSrcweir css::container::ContainerEvent const & event) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir containerElementReplacedNotifications_.push_back( 78*cdf0e10cSrcweir ContainerNotification(listener, event)); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void Broadcaster::addContainerElementInsertedNotification( 82*cdf0e10cSrcweir css::uno::Reference< css::container::XContainerListener > const & listener, 83*cdf0e10cSrcweir css::container::ContainerEvent const & event) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir containerElementInsertedNotifications_.push_back( 86*cdf0e10cSrcweir ContainerNotification(listener, event)); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir void Broadcaster::addContainerElementRemovedNotification( 90*cdf0e10cSrcweir css::uno::Reference< css::container::XContainerListener > const & listener, 91*cdf0e10cSrcweir css::container::ContainerEvent const & event) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir containerElementRemovedNotifications_.push_back( 94*cdf0e10cSrcweir ContainerNotification(listener, event)); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir void Broadcaster::addPropertyChangeNotification( 98*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertyChangeListener > const & listener, 99*cdf0e10cSrcweir css::beans::PropertyChangeEvent const & event) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir propertyChangeNotifications_.push_back( 102*cdf0e10cSrcweir PropertyChangeNotification(listener, event)); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir void Broadcaster::addPropertiesChangeNotification( 106*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertiesChangeListener > const & 107*cdf0e10cSrcweir listener, 108*cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyChangeEvent > const & event) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir propertiesChangeNotifications_.push_back( 111*cdf0e10cSrcweir PropertiesChangeNotification(listener, event)); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir void Broadcaster::addChangesNotification( 115*cdf0e10cSrcweir css::uno::Reference< css::util::XChangesListener > const & listener, 116*cdf0e10cSrcweir css::util::ChangesEvent const & event) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir changesNotifications_.push_back(ChangesNotification(listener, event)); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir void Broadcaster::send() { 122*cdf0e10cSrcweir css::uno::Any exception; 123*cdf0e10cSrcweir rtl::OUStringBuffer messages; 124*cdf0e10cSrcweir for (DisposeNotifications::iterator i(disposeNotifications_.begin()); 125*cdf0e10cSrcweir i != disposeNotifications_.end(); ++i) { 126*cdf0e10cSrcweir try { 127*cdf0e10cSrcweir i->listener->disposing(i->event); 128*cdf0e10cSrcweir } catch (css::lang::DisposedException &) { 129*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 130*cdf0e10cSrcweir exception = cppu::getCaughtException(); 131*cdf0e10cSrcweir appendMessage(messages, e); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir for (ContainerNotifications::iterator i( 135*cdf0e10cSrcweir containerElementInsertedNotifications_.begin()); 136*cdf0e10cSrcweir i != containerElementInsertedNotifications_.end(); ++i) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir try { 139*cdf0e10cSrcweir i->listener->elementInserted(i->event); 140*cdf0e10cSrcweir } catch (css::lang::DisposedException &) { 141*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 142*cdf0e10cSrcweir exception = cppu::getCaughtException(); 143*cdf0e10cSrcweir appendMessage(messages, e); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir for (ContainerNotifications::iterator i( 147*cdf0e10cSrcweir containerElementRemovedNotifications_.begin()); 148*cdf0e10cSrcweir i != containerElementRemovedNotifications_.end(); ++i) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir try { 151*cdf0e10cSrcweir i->listener->elementRemoved(i->event); 152*cdf0e10cSrcweir } catch (css::lang::DisposedException &) { 153*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 154*cdf0e10cSrcweir exception = cppu::getCaughtException(); 155*cdf0e10cSrcweir appendMessage(messages, e); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir for (ContainerNotifications::iterator i( 159*cdf0e10cSrcweir containerElementReplacedNotifications_.begin()); 160*cdf0e10cSrcweir i != containerElementReplacedNotifications_.end(); ++i) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir try { 163*cdf0e10cSrcweir i->listener->elementReplaced(i->event); 164*cdf0e10cSrcweir } catch (css::lang::DisposedException &) { 165*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 166*cdf0e10cSrcweir exception = cppu::getCaughtException(); 167*cdf0e10cSrcweir appendMessage(messages, e); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir for (PropertyChangeNotifications::iterator i( 171*cdf0e10cSrcweir propertyChangeNotifications_.begin()); 172*cdf0e10cSrcweir i != propertyChangeNotifications_.end(); ++i) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir try { 175*cdf0e10cSrcweir i->listener->propertyChange(i->event); 176*cdf0e10cSrcweir } catch (css::lang::DisposedException &) { 177*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 178*cdf0e10cSrcweir exception = cppu::getCaughtException(); 179*cdf0e10cSrcweir appendMessage(messages, e); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir for (PropertiesChangeNotifications::iterator i( 183*cdf0e10cSrcweir propertiesChangeNotifications_.begin()); 184*cdf0e10cSrcweir i != propertiesChangeNotifications_.end(); ++i) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir try { 187*cdf0e10cSrcweir i->listener->propertiesChange(i->event); 188*cdf0e10cSrcweir } catch (css::lang::DisposedException &) { 189*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 190*cdf0e10cSrcweir exception = cppu::getCaughtException(); 191*cdf0e10cSrcweir appendMessage(messages, e); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir for (ChangesNotifications::iterator i(changesNotifications_.begin()); 195*cdf0e10cSrcweir i != changesNotifications_.end(); ++i) { 196*cdf0e10cSrcweir try { 197*cdf0e10cSrcweir i->listener->changesOccurred(i->event); 198*cdf0e10cSrcweir } catch (css::lang::DisposedException &) { 199*cdf0e10cSrcweir } catch (css::uno::Exception & e) { 200*cdf0e10cSrcweir exception = cppu::getCaughtException(); 201*cdf0e10cSrcweir appendMessage(messages, e); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir if (exception.hasValue()) { 205*cdf0e10cSrcweir throw css::lang::WrappedTargetRuntimeException( 206*cdf0e10cSrcweir (rtl::OUString( 207*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 208*cdf0e10cSrcweir "configmgr exceptions during listener notification")) + 209*cdf0e10cSrcweir messages.makeStringAndClear()), 210*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >(), 211*cdf0e10cSrcweir exception); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir Broadcaster::DisposeNotification::DisposeNotification( 216*cdf0e10cSrcweir css::uno::Reference< css::lang::XEventListener > const & theListener, 217*cdf0e10cSrcweir css::lang::EventObject const & theEvent): 218*cdf0e10cSrcweir listener(theListener), event(theEvent) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir OSL_ASSERT(theListener.is()); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir Broadcaster::ContainerNotification::ContainerNotification( 224*cdf0e10cSrcweir css::uno::Reference< css::container::XContainerListener > const & 225*cdf0e10cSrcweir theListener, 226*cdf0e10cSrcweir css::container::ContainerEvent const & theEvent): 227*cdf0e10cSrcweir listener(theListener), event(theEvent) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir OSL_ASSERT(theListener.is()); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir Broadcaster::PropertyChangeNotification::PropertyChangeNotification( 233*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertyChangeListener > const & 234*cdf0e10cSrcweir theListener, 235*cdf0e10cSrcweir css::beans::PropertyChangeEvent const & theEvent): 236*cdf0e10cSrcweir listener(theListener), event(theEvent) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir OSL_ASSERT(theListener.is()); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification( 242*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertiesChangeListener > const & 243*cdf0e10cSrcweir theListener, 244*cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyChangeEvent > const & theEvent): 245*cdf0e10cSrcweir listener(theListener), event(theEvent) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir OSL_ASSERT(theListener.is()); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir Broadcaster::ChangesNotification::ChangesNotification( 251*cdf0e10cSrcweir css::uno::Reference< css::util::XChangesListener > const & theListener, 252*cdf0e10cSrcweir css::util::ChangesEvent const & theEvent): 253*cdf0e10cSrcweir listener(theListener), event(theEvent) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir OSL_ASSERT(theListener.is()); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir } 259