Kaydet (Commit) 56842d2c authored tarafından Frank Schönheit's avatar Frank Schönheit

support XContainer - so that other instances may listen for insertions/removals of data sources

üst 79384e87
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: databasecontext.cxx,v $ * $RCSfile: databasecontext.cxx,v $
* *
* $Revision: 1.13 $ * $Revision: 1.14 $
* *
* last change: $Author: fs $ $Date: 2000-11-10 17:28:17 $ * last change: $Author: fs $ $Date: 2000-12-10 16:14:22 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -161,6 +161,7 @@ Reference< XInterface > ...@@ -161,6 +161,7 @@ Reference< XInterface >
ODatabaseContext::ODatabaseContext(const Reference< XMultiServiceFactory > & xServiceManager) ODatabaseContext::ODatabaseContext(const Reference< XMultiServiceFactory > & xServiceManager)
:DatabaseAccessContext_Base(m_aMutex) :DatabaseAccessContext_Base(m_aMutex)
,m_xServiceManager(xServiceManager) ,m_xServiceManager(xServiceManager)
,m_aContainerListeners(m_aMutex)
{ {
DBG_CTOR(ODatabaseContext,NULL); DBG_CTOR(ODatabaseContext,NULL);
...@@ -250,6 +251,11 @@ sal_Int64 SAL_CALL ODatabaseContext::getSomething(const Sequence<sal_Int8>& _rId ...@@ -250,6 +251,11 @@ sal_Int64 SAL_CALL ODatabaseContext::getSomething(const Sequence<sal_Int8>& _rId
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void ODatabaseContext::disposing() void ODatabaseContext::disposing()
{ {
// notify our listener
EventObject aDisposeEvent(static_cast< XContainer* >(this));
m_aContainerListeners.disposeAndClear(aDisposeEvent);
// dispose the data sources
for ( ObjectCache::iterator aIter = m_aDatabaseObjects.begin(); for ( ObjectCache::iterator aIter = m_aDatabaseObjects.begin();
aIter != m_aDatabaseObjects.end(); aIter != m_aDatabaseObjects.end();
++aIter ++aIter
...@@ -398,6 +404,11 @@ void ODatabaseContext::registerObject(const rtl::OUString& _rName, const Referen ...@@ -398,6 +404,11 @@ void ODatabaseContext::registerObject(const rtl::OUString& _rName, const Referen
else else
DBG_ERROR("ODatabaseContext::registerObject: missing the XComponent interface!"); DBG_ERROR("ODatabaseContext::registerObject: missing the XComponent interface!");
// notify our container listeners
ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rName), makeAny(_rxObject), Any());
OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
while (aListenerLoop.hasMoreElements())
static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -457,6 +468,18 @@ void SAL_CALL ODatabaseContext::disposing( const EventObject& _rSource ) throw(R ...@@ -457,6 +468,18 @@ void SAL_CALL ODatabaseContext::disposing( const EventObject& _rSource ) throw(R
} }
} }
//------------------------------------------------------------------------------
void SAL_CALL ODatabaseContext::addContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException)
{
m_aContainerListeners.addInterface(_rxListener);
}
//------------------------------------------------------------------------------
void SAL_CALL ODatabaseContext::removeContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException)
{
m_aContainerListeners.removeInterface(_rxListener);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exception, RuntimeException ) void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exception, RuntimeException )
{ {
...@@ -468,10 +491,12 @@ void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exceptio ...@@ -468,10 +491,12 @@ void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exceptio
if (!aObjectNode.isValid()) if (!aObjectNode.isValid())
throw NoSuchElementException(); throw NoSuchElementException();
Reference< XInterface > xExistent;
ObjectCacheIterator aExistent = m_aDatabaseObjects.find(_rName); ObjectCacheIterator aExistent = m_aDatabaseObjects.find(_rName);
if (aExistent != m_aDatabaseObjects.end()) if (aExistent != m_aDatabaseObjects.end())
{ {
Reference< XInterface > xExistent = aExistent->second.get(); xExistent = aExistent->second.get();
if (xExistent.is()) if (xExistent.is())
{ {
Reference< XComponent > xComponent(xExistent, UNO_QUERY); Reference< XComponent > xComponent(xExistent, UNO_QUERY);
...@@ -499,6 +524,13 @@ void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exceptio ...@@ -499,6 +524,13 @@ void ODatabaseContext::revokeObject(const rtl::OUString& _rName) throw( Exceptio
} }
else else
DBG_ERROR("ODatabaseContext::revokeObject: inconsistent state!"); DBG_ERROR("ODatabaseContext::revokeObject: inconsistent state!");
// notify our container listeners
ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rName), Any(), makeAny(xExistent));
// note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment
OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
while (aListenerLoop.hasMoreElements())
static_cast<XContainerListener*>(aListenerLoop.next())->elementRemoved(aEvent);
} }
// ::com::sun::star::container::XElementAccess // ::com::sun::star::container::XElementAccess
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: databasecontext.hxx,v $ * $RCSfile: databasecontext.hxx,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: fs $ $Date: 2000-11-08 16:02:50 $ * last change: $Author: fs $ $Date: 2000-12-10 16:14:22 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -80,15 +80,21 @@ ...@@ -80,15 +80,21 @@
#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
#include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
#include <com/sun/star/container/XContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp>
#endif #endif
#ifndef _CPPUHELPER_COMPBASE6_HXX_ #ifndef _CPPUHELPER_COMPBASE7_HXX_
#include <cppuhelper/compbase6.hxx> #include <cppuhelper/compbase7.hxx>
#endif #endif
#ifndef _COMPHELPER_STLTYPES_HXX_ #ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx> #include <comphelper/stl_types.hxx>
#endif #endif
#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_
#include <cppuhelper/interfacecontainer.hxx>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_ELEMENTEXISTEXCEPTION_HPP_ #ifndef _COM_SUN_STAR_CONTAINER_ELEMENTEXISTEXCEPTION_HPP_
#include <com/sun/star/container/ElementExistException.hpp> #include <com/sun/star/container/ElementExistException.hpp>
#endif #endif
...@@ -122,12 +128,14 @@ namespace dbaccess ...@@ -122,12 +128,14 @@ namespace dbaccess
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
ODatabaseContext_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); ODatabaseContext_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
typedef ::cppu::WeakComponentImplHelper6 < ::com::sun::star::lang::XServiceInfo typedef ::cppu::WeakComponentImplHelper7 < ::com::sun::star::lang::XServiceInfo
, ::com::sun::star::container::XEnumerationAccess , ::com::sun::star::container::XEnumerationAccess
, ::com::sun::star::container::XNameAccess , ::com::sun::star::container::XNameAccess
, ::com::sun::star::uno::XNamingService , ::com::sun::star::uno::XNamingService
, ::com::sun::star::lang::XEventListener , ::com::sun::star::lang::XEventListener
, ::com::sun::star::lang::XUnoTunnel > DatabaseAccessContext_Base; , ::com::sun::star::lang::XUnoTunnel
, ::com::sun::star::container::XContainer
> DatabaseAccessContext_Base;
class ODatabaseContext class ODatabaseContext
:public DatabaseAccessContext_Base :public DatabaseAccessContext_Base
...@@ -149,6 +157,8 @@ protected: ...@@ -149,6 +157,8 @@ protected:
// recreated afterwards. So it's our (the context's) responsibility to store the session-persistent // recreated afterwards. So it's our (the context's) responsibility to store the session-persistent
// properties. // properties.
::cppu::OInterfaceContainerHelper m_aContainerListeners;
public: public:
ODatabaseContext(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); ODatabaseContext(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
virtual ~ODatabaseContext(); virtual ~ODatabaseContext();
...@@ -192,6 +202,10 @@ public: ...@@ -192,6 +202,10 @@ public:
// ::com::sun::star::lang::XEventListener // ::com::sun::star::lang::XEventListener
virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
// ::com::sun::star::container::XContainer
virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
private: private:
/// get the node a data source is based on /// get the node a data source is based on
OConfigurationNode getObjectNode(const ::rtl::OUString& _rTitle, sal_Bool _bCreate) throw(); OConfigurationNode getObjectNode(const ::rtl::OUString& _rTitle, sal_Bool _bCreate) throw();
......
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