merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / api2 / apinotifierimpl.cxx
blob8dca2a44a00ed8839f2aa4c4b325f83e710e5958
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: apinotifierimpl.cxx,v $
10 * $Revision: 1.8.20.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "apinotifierimpl.hxx"
35 #include "apinodeaccess.hxx"
36 #include "noderef.hxx"
37 #include "valueref.hxx"
38 #include "confignotifier.hxx"
39 #include "configexcept.hxx"
40 #include <osl/diagnose.h>
42 namespace configmgr
44 namespace configapi
46 //-----------------------------------------------------------------------------------
47 namespace lang = css::lang;
48 namespace util = css::util;
49 namespace beans = css::beans;
51 // Generic Notifier Support Implementations
52 //-----------------------------------------------------------------------------------
54 /// add a Listener to the notifier of a NodeAccess
55 template <class Listener>
56 inline
57 void genericAddListener(NodeAccess& rNode, const uno::Reference< Listener >& xListener )
59 GuardedNotifier aGuardedNotifier( rNode ); // guard the notifier
60 aGuardedNotifier->add(rNode.getNodeRef(), xListener);
63 /// remove a Listener from the notifier of a NodeAccess
64 template <class Listener>
65 inline
66 void genericRemoveListener(NodeAccess& rNode, const uno::Reference< Listener >& xListener )
68 GuardedNotifier aGuardedNotifier( rNode ); // guard the notifier
69 aGuardedNotifier->remove(rNode.getNodeRef(), xListener);
73 /** add a Listener for all or some children of a NodeAccess to its notifier
74 <p> If the name given is empty, the listener will be added to all children of the node</p>
75 @returns
76 <TRUE/> if the node was found, or the name was empty
77 <FALSE/> if the named node wasn't found
79 template <class Listener>
80 inline
81 bool genericAddChildListener(NodeGroupInfoAccess& rNode, const uno::Reference< Listener >& xListener, const rtl::OUString& sName )
83 if (sName.getLength() != 0)
85 GuardedNodeData<NodeAccess> aGuardedNode( rNode ); // guard access to children
86 GuardedNotifier aGuardedNotifier( rNode ); // guard the notifier
88 rtl::Reference< configuration::Tree > aTree( aGuardedNode.getTree() );
89 configuration::NodeRef aNode( aGuardedNode.getNode() );
91 rtl::OUString aChildName = configuration::validateChildName(sName,aTree,aNode);
93 if (!aTree->hasChild(aNode,aChildName)) return false;
95 aGuardedNotifier->addForOne(aNode, xListener, aChildName);
97 else
99 GuardedNotifier aGuardedNotifier( rNode ); // guard the notifier
101 aGuardedNotifier->addForAll(rNode.getNodeRef(), xListener);
103 // always ok, as we addreess no specific NodeRef
105 return true;
108 /** remove a Listener from all or some children of a NodeAccess to its notifier
109 <p> If the name given is empty, the listener will be removed from any children of the node</p>
110 @returns
111 <TRUE/> if the node was found, or the name was empty
112 <FALSE/> if the named node wasn't found
114 template <class Listener>
115 inline
116 bool genericRemoveChildListener(NodeGroupInfoAccess& rNode, const uno::Reference< Listener >& xListener, const rtl::OUString& sName )
118 if (sName.getLength() != 0)
120 GuardedNodeData<NodeAccess> aGuardedNode( rNode ); // guard access to children
121 GuardedNotifier aGuardedNotifier( rNode ); // guard the notifier
123 rtl::Reference< configuration::Tree > aTree( aGuardedNode.getTree() );
124 configuration::NodeRef aNode( aGuardedNode.getNode() );
126 rtl::OUString aChildName = configuration::validateChildName(sName,aTree,aNode);
128 if (!aTree->hasChild(aNode,aChildName)) return false;
130 aGuardedNotifier->removeForOne(aNode, xListener, aChildName);
132 else
134 GuardedNotifier aGuardedNotifier( rNode ); // guard the notifier
136 aGuardedNotifier->removeForAll(rNode.getNodeRef(), xListener);
138 // always ok, as we addreess no specific NodeRef
140 return true;
145 // XComponent
146 //-----------------------------------------------------------------------------------
147 void implAddListener(NodeAccess& rNode, const uno::Reference< css::lang::XEventListener >& xListener )
148 throw(uno::RuntimeException)
150 genericAddListener(rNode,xListener);
153 void implRemoveListener(NodeAccess& rNode, const uno::Reference< css::lang::XEventListener >& xListener )
154 throw(uno::RuntimeException)
156 genericRemoveListener(rNode,xListener);
159 // XContainer
160 //-----------------------------------------------------------------------------------
161 void implAddListener(NodeAccess& rNode, const uno::Reference< css::container::XContainerListener >& xListener )
162 throw(uno::RuntimeException)
164 genericAddListener(rNode,xListener);
167 void implRemoveListener(NodeAccess& rNode, const uno::Reference< css::container::XContainerListener >& xListener )
168 throw(uno::RuntimeException)
170 genericRemoveListener(rNode,xListener);
173 // XChangesNotifier
174 //-----------------------------------------------------------------------------------
176 void implAddListener(NodeAccess& rNode, const uno::Reference< css::util::XChangesListener >& xListener )
177 throw(uno::RuntimeException)
179 genericAddListener(rNode,xListener);
182 void implRemoveListener(NodeAccess& rNode, const uno::Reference< css::util::XChangesListener >& xListener )
183 throw(uno::RuntimeException)
185 genericRemoveListener(rNode,xListener);
188 // XMultiPropertySet
189 //-----------------------------------------------------------------------------------
191 void implAddListener( NodeAccess& rNode, const uno::Reference< beans::XPropertiesChangeListener >& xListener, const uno::Sequence< rtl::OUString >& aPropertyNames )
192 throw(uno::RuntimeException)
195 GuardedNotifier impl( rNode );
197 // TODO: is an exception for unknown names allowed/needed ?
198 impl->add(rNode.getNodeRef(), xListener, aPropertyNames);
202 void implRemoveListener( NodeAccess& rNode, const uno::Reference< beans::XPropertiesChangeListener >& xListener )
203 throw(uno::RuntimeException)
205 genericRemoveListener(rNode,xListener);
208 // XPropertySet (manages listeners associated with named child node)
209 //-----------------------------------------------------------------------------------
211 // XPropertySet - VetoableChangeListeners
212 //-----------------------------------------------------------------------------------
214 void implAddListener( NodeGroupInfoAccess& rNode, const uno::Reference< beans::XVetoableChangeListener >& xListener, const rtl::OUString& sPropertyName )
215 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
219 if (!genericAddChildListener(rNode,xListener,sPropertyName))
221 throw css::beans::UnknownPropertyException(
222 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot add listener - node not found !")),
223 rNode.getUnoInstance() );
226 catch (configuration::InvalidName& ex)
228 ExceptionMapper e(ex);
229 throw css::beans::UnknownPropertyException(
230 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot add listener - node not found:")) += ex.message(),
231 rNode.getUnoInstance() );
233 catch (configuration::Exception& ex)
235 ExceptionMapper e(ex);
236 e.setContext( rNode.getUnoInstance() );
237 e.unhandled();
243 void implRemoveListener( NodeGroupInfoAccess& rNode, const uno::Reference< beans::XVetoableChangeListener >& xListener, const rtl::OUString& sPropertyName )
244 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
248 if (!genericRemoveChildListener(rNode,xListener,sPropertyName))
250 throw css::beans::UnknownPropertyException(
251 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot remove listener - node not found !")),
252 rNode.getUnoInstance() );
255 catch (configuration::InvalidName& ex)
257 ExceptionMapper e(ex);
258 throw css::beans::UnknownPropertyException(
259 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot remove listener - node not found:")) += ex.message(),
260 rNode.getUnoInstance() );
262 catch (configuration::Exception& ex)
264 ExceptionMapper e(ex);
265 e.setContext( rNode.getUnoInstance() );
266 e.unhandled();
270 // XPropertySet - PropertyChangeListeners
271 //-----------------------------------------------------------------------------------
273 void implAddListener( NodeGroupInfoAccess& rNode, const uno::Reference< beans::XPropertyChangeListener >& xListener, const rtl::OUString& sPropertyName )
274 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
278 if (!genericAddChildListener(rNode,xListener,sPropertyName))
280 throw css::beans::UnknownPropertyException(
281 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot add listener - node not found !")),
282 rNode.getUnoInstance() );
285 catch (configuration::InvalidName& ex)
287 ExceptionMapper e(ex);
288 throw css::beans::UnknownPropertyException(
289 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot add listener - node not found:")) += ex.message(),
290 rNode.getUnoInstance() );
292 catch (configuration::Exception& ex)
294 ExceptionMapper e(ex);
295 e.setContext( rNode.getUnoInstance() );
296 e.unhandled();
300 void implRemoveListener( NodeGroupInfoAccess& rNode, const uno::Reference< beans::XPropertyChangeListener >& xListener, const rtl::OUString& sPropertyName )
301 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
305 if (!genericRemoveChildListener(rNode,xListener,sPropertyName))
307 throw css::beans::UnknownPropertyException(
308 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot remove listener - node not found !")),
309 rNode.getUnoInstance() );
312 catch (configuration::InvalidName& ex)
314 ExceptionMapper e(ex);
315 throw css::beans::UnknownPropertyException(
316 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Configuration: cannot remove listener - node not found:")) += ex.message(),
317 rNode.getUnoInstance() );
319 catch (configuration::Exception& ex)
321 ExceptionMapper e(ex);
322 e.setContext( rNode.getUnoInstance() );
323 e.unhandled();
327 //-----------------------------------------------------------------------------------
328 } // namespace configapi
330 } // namespace configmgr