fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / core / misc / ContainerMediator.cxx
blobef69529f51640f9eae24d89295bb4ba8ee5db98f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "ContainerMediator.hxx"
21 #include "dbastrings.hrc"
22 #include "PropertyForward.hxx"
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
26 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
27 #include <com/sun/star/sdbcx/XRename.hpp>
28 #include <connectivity/dbtools.hxx>
29 #include <comphelper/property.hxx>
30 #include <tools/debug.hxx>
31 #include <tools/diagnose_ex.h>
33 namespace dbaccess
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::sdbc;
38 using namespace ::com::sun::star::sdbcx;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::container;
42 OContainerMediator::OContainerMediator( const Reference< XContainer >& _xContainer, const Reference< XNameAccess >& _xSettings,
43 const Reference< XConnection >& _rxConnection )
44 : m_xSettings( _xSettings )
45 , m_xContainer( _xContainer )
46 , m_aConnection( _rxConnection )
49 if ( _xSettings.is() && _xContainer.is() )
51 osl_atomic_increment(&m_refCount);
52 try
54 m_xContainer->addContainerListener(this);
55 Reference< XContainer > xContainer(_xSettings, UNO_QUERY);
56 if ( xContainer.is() )
57 xContainer->addContainerListener(this);
59 catch(Exception&)
61 OSL_FAIL("OContainerMediator::OContainerMediator: caught an exception!");
63 osl_atomic_decrement( &m_refCount );
65 else
67 m_xSettings.clear();
68 m_xContainer.clear();
72 OContainerMediator::~OContainerMediator()
74 acquire();
75 impl_cleanup_nothrow();
78 void OContainerMediator::impl_cleanup_nothrow()
80 try
82 Reference< XContainer > xContainer( m_xSettings, UNO_QUERY );
83 if ( xContainer.is() )
84 xContainer->removeContainerListener( this );
85 m_xSettings.clear();
87 xContainer = m_xContainer;
88 if ( xContainer.is() )
89 xContainer->removeContainerListener( this );
90 m_xContainer.clear();
92 m_aForwardList.clear();
94 catch( const Exception& )
96 DBG_UNHANDLED_EXCEPTION();
100 void SAL_CALL OContainerMediator::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
102 ::osl::MutexGuard aGuard(m_aMutex);
103 if ( _rEvent.Source == m_xSettings && m_xSettings.is() )
105 OUString sElementName;
106 _rEvent.Accessor >>= sElementName;
107 PropertyForwardList::iterator aFind = m_aForwardList.find(sElementName);
108 if ( aFind != m_aForwardList.end() )
110 Reference< XPropertySet> xDest(_rEvent.Element,UNO_QUERY);
111 aFind->second->setDefinition( xDest );
116 void SAL_CALL OContainerMediator::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
118 ::osl::MutexGuard aGuard(m_aMutex);
119 Reference< XContainer > xContainer = m_xContainer;
120 if ( _rEvent.Source == xContainer && xContainer.is() )
122 OUString sElementName;
123 _rEvent.Accessor >>= sElementName;
124 m_aForwardList.erase(sElementName);
127 Reference<XNameContainer> xNameContainer( m_xSettings, UNO_QUERY );
128 if ( xNameContainer.is() && m_xSettings->hasByName( sElementName ) )
129 xNameContainer->removeByName( sElementName );
131 catch( const Exception& )
133 DBG_UNHANDLED_EXCEPTION();
138 void SAL_CALL OContainerMediator::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
140 Reference< XContainer > xContainer = m_xContainer;
141 if ( _rEvent.Source == xContainer && xContainer.is() )
143 OUString sElementName;
144 _rEvent.ReplacedElement >>= sElementName;
146 PropertyForwardList::iterator aFind = m_aForwardList.find(sElementName);
147 if ( aFind != m_aForwardList.end() )
149 OUString sNewName;
150 _rEvent.Accessor >>= sNewName;
153 Reference<XNameContainer> xNameContainer( m_xSettings, UNO_QUERY_THROW );
154 if ( xNameContainer.is() && m_xSettings->hasByName( sElementName ) )
156 Reference<XRename> xSource(m_xSettings->getByName(sElementName),UNO_QUERY_THROW);
157 xSource->rename(sNewName);
160 catch( const Exception& )
162 DBG_UNHANDLED_EXCEPTION();
165 aFind->second->setName(sNewName);
170 void SAL_CALL OContainerMediator::disposing( const EventObject& /*Source*/ ) throw(RuntimeException, std::exception)
172 ::osl::MutexGuard aGuard(m_aMutex);
174 impl_cleanup_nothrow();
177 void OContainerMediator::impl_initSettings_nothrow( const OUString& _rName, const Reference< XPropertySet >& _rxDestination )
181 if ( m_xSettings.is() && m_xSettings->hasByName( _rName ) )
183 Reference< XPropertySet > xSettings( m_xSettings->getByName( _rName ), UNO_QUERY_THROW );
184 ::comphelper::copyProperties( xSettings, _rxDestination );
187 catch( const Exception& )
189 DBG_UNHANDLED_EXCEPTION();
193 void OContainerMediator::notifyElementCreated( const OUString& _sName, const Reference< XPropertySet >& _xDest )
195 if ( !m_xSettings.is() )
196 return;
198 PropertyForwardList::iterator aFind = m_aForwardList.find( _sName );
199 if ( aFind != m_aForwardList.end()
200 && aFind->second->getDefinition().is()
203 OSL_FAIL( "OContainerMediator::notifyElementCreated: is this really a valid case?" );
204 return;
207 ::std::vector< OUString > aPropertyList;
210 // initially copy from the settings object (if existent) to the newly created object
211 impl_initSettings_nothrow( _sName, _xDest );
213 // collect the to-be-monitored properties
214 Reference< XPropertySetInfo > xPSI( _xDest->getPropertySetInfo(), UNO_QUERY_THROW );
215 Sequence< Property > aProperties( xPSI->getProperties() );
216 const Property* property = aProperties.getConstArray();
217 const Property* propertyEnd = aProperties.getConstArray() + aProperties.getLength();
218 for ( ; property != propertyEnd; ++property )
220 if ( ( property->Attributes & PropertyAttribute::READONLY ) != 0 )
221 continue;
222 if ( ( property->Attributes & PropertyAttribute::BOUND ) == 0 )
223 continue;
225 aPropertyList.push_back( property->Name );
228 catch( const Exception& )
230 DBG_UNHANDLED_EXCEPTION();
233 ::rtl::Reference< OPropertyForward > pForward( new OPropertyForward( _xDest, m_xSettings, _sName, aPropertyList ) );
234 m_aForwardList[ _sName ] = pForward;
237 } // namespace dbaccess
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */