1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
24 #include "com/sun/star/beans/XPropertiesChangeListener.hpp"
25 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
26 #include "com/sun/star/container/XContainerListener.hpp"
27 #include "com/sun/star/lang/DisposedException.hpp"
28 #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
29 #include "com/sun/star/lang/XEventListener.hpp"
30 #include "com/sun/star/uno/Any.hxx"
31 #include "com/sun/star/uno/Exception.hpp"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "com/sun/star/uno/XInterface.hpp"
34 #include "com/sun/star/util/XChangesListener.hpp"
35 #include "cppuhelper/exc_hlp.hxx"
36 #include "rtl/string.h"
37 #include "rtl/ustrbuf.hxx"
38 #include "rtl/ustring.h"
39 #include "rtl/ustring.hxx"
41 #include "broadcaster.hxx"
48 OUStringBuffer
& buffer
, css::uno::Exception
const & exception
)
50 buffer
.appendAscii("; ");
51 buffer
.append(exception
.Message
);
56 void Broadcaster::addDisposeNotification(
57 css::uno::Reference
< css::lang::XEventListener
> const & listener
,
58 css::lang::EventObject
const & event
)
60 disposeNotifications_
.push_back(DisposeNotification(listener
, event
));
63 void Broadcaster::addContainerElementReplacedNotification(
64 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
65 css::container::ContainerEvent
const & event
)
67 containerElementReplacedNotifications_
.push_back(
68 ContainerNotification(listener
, event
));
71 void Broadcaster::addContainerElementInsertedNotification(
72 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
73 css::container::ContainerEvent
const & event
)
75 containerElementInsertedNotifications_
.push_back(
76 ContainerNotification(listener
, event
));
79 void Broadcaster::addContainerElementRemovedNotification(
80 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
81 css::container::ContainerEvent
const & event
)
83 containerElementRemovedNotifications_
.push_back(
84 ContainerNotification(listener
, event
));
87 void Broadcaster::addPropertyChangeNotification(
88 css::uno::Reference
< css::beans::XPropertyChangeListener
> const & listener
,
89 css::beans::PropertyChangeEvent
const & event
)
91 propertyChangeNotifications_
.push_back(
92 PropertyChangeNotification(listener
, event
));
95 void Broadcaster::addPropertiesChangeNotification(
96 css::uno::Reference
< css::beans::XPropertiesChangeListener
> const &
98 css::uno::Sequence
< css::beans::PropertyChangeEvent
> const & event
)
100 propertiesChangeNotifications_
.push_back(
101 PropertiesChangeNotification(listener
, event
));
104 void Broadcaster::addChangesNotification(
105 css::uno::Reference
< css::util::XChangesListener
> const & listener
,
106 css::util::ChangesEvent
const & event
)
108 changesNotifications_
.push_back(ChangesNotification(listener
, event
));
111 void Broadcaster::send() {
112 css::uno::Any exception
;
113 OUStringBuffer messages
;
114 for (DisposeNotifications::iterator
i(disposeNotifications_
.begin());
115 i
!= disposeNotifications_
.end(); ++i
) {
117 i
->listener
->disposing(i
->event
);
118 } catch (css::lang::DisposedException
&) {
119 } catch (css::uno::Exception
& e
) {
120 exception
= cppu::getCaughtException();
121 appendMessage(messages
, e
);
124 for (ContainerNotifications::iterator
i(
125 containerElementInsertedNotifications_
.begin());
126 i
!= containerElementInsertedNotifications_
.end(); ++i
)
129 i
->listener
->elementInserted(i
->event
);
130 } catch (css::lang::DisposedException
&) {
131 } catch (css::uno::Exception
& e
) {
132 exception
= cppu::getCaughtException();
133 appendMessage(messages
, e
);
136 for (ContainerNotifications::iterator
i(
137 containerElementRemovedNotifications_
.begin());
138 i
!= containerElementRemovedNotifications_
.end(); ++i
)
141 i
->listener
->elementRemoved(i
->event
);
142 } catch (css::lang::DisposedException
&) {
143 } catch (css::uno::Exception
& e
) {
144 exception
= cppu::getCaughtException();
145 appendMessage(messages
, e
);
148 for (ContainerNotifications::iterator
i(
149 containerElementReplacedNotifications_
.begin());
150 i
!= containerElementReplacedNotifications_
.end(); ++i
)
153 i
->listener
->elementReplaced(i
->event
);
154 } catch (css::lang::DisposedException
&) {
155 } catch (css::uno::Exception
& e
) {
156 exception
= cppu::getCaughtException();
157 appendMessage(messages
, e
);
160 for (PropertyChangeNotifications::iterator
i(
161 propertyChangeNotifications_
.begin());
162 i
!= propertyChangeNotifications_
.end(); ++i
)
165 i
->listener
->propertyChange(i
->event
);
166 } catch (css::lang::DisposedException
&) {
167 } catch (css::uno::Exception
& e
) {
168 exception
= cppu::getCaughtException();
169 appendMessage(messages
, e
);
172 for (PropertiesChangeNotifications::iterator
i(
173 propertiesChangeNotifications_
.begin());
174 i
!= propertiesChangeNotifications_
.end(); ++i
)
177 i
->listener
->propertiesChange(i
->event
);
178 } catch (css::lang::DisposedException
&) {
179 } catch (css::uno::Exception
& e
) {
180 exception
= cppu::getCaughtException();
181 appendMessage(messages
, e
);
184 for (ChangesNotifications::iterator
i(changesNotifications_
.begin());
185 i
!= changesNotifications_
.end(); ++i
) {
187 i
->listener
->changesOccurred(i
->event
);
188 } catch (css::lang::DisposedException
&) {
189 } catch (css::uno::Exception
& e
) {
190 exception
= cppu::getCaughtException();
191 appendMessage(messages
, e
);
194 if (exception
.hasValue()) {
195 throw css::lang::WrappedTargetRuntimeException(
196 (OUString("configmgr exceptions during listener notification") +
197 messages
.makeStringAndClear()),
198 css::uno::Reference
< css::uno::XInterface
>(),
203 Broadcaster::DisposeNotification::DisposeNotification(
204 css::uno::Reference
< css::lang::XEventListener
> const & theListener
,
205 css::lang::EventObject
const & theEvent
):
206 listener(theListener
), event(theEvent
)
208 assert(theListener
.is());
211 Broadcaster::ContainerNotification::ContainerNotification(
212 css::uno::Reference
< css::container::XContainerListener
> const &
214 css::container::ContainerEvent
const & theEvent
):
215 listener(theListener
), event(theEvent
)
217 assert(theListener
.is());
220 Broadcaster::PropertyChangeNotification::PropertyChangeNotification(
221 css::uno::Reference
< css::beans::XPropertyChangeListener
> const &
223 css::beans::PropertyChangeEvent
const & theEvent
):
224 listener(theListener
), event(theEvent
)
226 assert(theListener
.is());
229 Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification(
230 css::uno::Reference
< css::beans::XPropertiesChangeListener
> const &
232 css::uno::Sequence
< css::beans::PropertyChangeEvent
> const & theEvent
):
233 listener(theListener
), event(theEvent
)
235 assert(theListener
.is());
238 Broadcaster::ChangesNotification::ChangesNotification(
239 css::uno::Reference
< css::util::XChangesListener
> const & theListener
,
240 css::util::ChangesEvent
const & theEvent
):
241 listener(theListener
), event(theEvent
)
243 assert(theListener
.is());
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */