1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_dbaccess.hxx" 30 31 #include "PropertyForward.hxx" 32 #include "dbastrings.hrc" 33 34 #include <com/sun/star/beans/PropertyValue.hpp> 35 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> 36 #include <com/sun/star/sdbcx/XAppend.hpp> 37 38 #include <comphelper/property.hxx> 39 #include <tools/debug.hxx> 40 #include <tools/diagnose_ex.h> 41 42 43 //........................................................................ 44 namespace dbaccess 45 { 46 //........................................................................ 47 48 using namespace ::com::sun::star::uno; 49 using namespace ::com::sun::star::beans; 50 using namespace ::com::sun::star::container; 51 using namespace ::com::sun::star::sdbcx; 52 using namespace ::com::sun::star::lang; 53 54 DBG_NAME(OPropertyForward) 55 56 //------------------------------------------------------------------------ 57 OPropertyForward::OPropertyForward( const Reference< XPropertySet>& _xSource, const Reference< XNameAccess>& _xDestContainer, 58 const ::rtl::OUString& _sName, const ::std::vector< ::rtl::OUString>& _aPropertyList ) 59 :m_xSource( _xSource, UNO_SET_THROW ) 60 ,m_xDestContainer( _xDestContainer, UNO_SET_THROW ) 61 ,m_sName( _sName ) 62 ,m_bInInsert( sal_False ) 63 { 64 DBG_CTOR(OPropertyForward,NULL); 65 66 osl_incrementInterlockedCount(&m_refCount); 67 try 68 { 69 if ( _aPropertyList.empty() ) 70 _xSource->addPropertyChangeListener( ::rtl::OUString(), this ); 71 else 72 { 73 ::std::vector< ::rtl::OUString >::const_iterator aIter = _aPropertyList.begin(); 74 ::std::vector< ::rtl::OUString >::const_iterator aEnd = _aPropertyList.end(); 75 for (; aIter != aEnd ; ++aIter ) 76 _xSource->addPropertyChangeListener( *aIter, this ); 77 } 78 } 79 catch( const Exception& ) 80 { 81 DBG_UNHANDLED_EXCEPTION(); 82 } 83 osl_decrementInterlockedCount( &m_refCount ); 84 } 85 86 // ----------------------------------------------------------------------------- 87 OPropertyForward::~OPropertyForward() 88 { 89 DBG_DTOR(OPropertyForward,NULL); 90 } 91 92 // ----------------------------------------------------------------------------- 93 void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException) 94 { 95 ::osl::MutexGuard aGuard( m_aMutex ); 96 97 if ( !m_xDestContainer.is() ) 98 throw DisposedException( ::rtl::OUString(), *this ); 99 100 try 101 { 102 if ( !m_xDest.is() ) 103 { 104 if ( m_xDestContainer->hasByName( m_sName ) ) 105 { 106 m_xDest.set( m_xDestContainer->getByName( m_sName ), UNO_QUERY_THROW ); 107 } 108 else 109 { 110 Reference< XDataDescriptorFactory > xFactory( m_xDestContainer, UNO_QUERY_THROW ); 111 m_xDest.set( xFactory->createDataDescriptor(), UNO_SET_THROW ); 112 113 ::comphelper::copyProperties( m_xSource, m_xDest ); 114 115 m_bInInsert = sal_True; 116 Reference< XAppend > xAppend( m_xDestContainer, UNO_QUERY_THROW ); 117 xAppend->appendByDescriptor( m_xDest ); 118 m_bInInsert = sal_False; 119 } 120 121 m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW ); 122 } 123 124 if ( m_xDestInfo->hasPropertyByName( evt.PropertyName ) ) 125 { 126 m_xDest->setPropertyValue( evt.PropertyName, evt.NewValue ); 127 } 128 } 129 catch( const Exception& ) 130 { 131 DBG_UNHANDLED_EXCEPTION(); 132 } 133 } 134 135 // ----------------------------------------------------------------------------- 136 void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException) 137 { 138 ::osl::MutexGuard aGuard(m_aMutex); 139 140 if ( !m_xSource.is() ) 141 throw DisposedException( ::rtl::OUString(), *this ); 142 143 m_xSource->removePropertyChangeListener( ::rtl::OUString(), this ); 144 m_xSource = NULL; 145 m_xDestContainer = NULL; 146 m_xDestInfo = NULL; 147 m_xDest = NULL; 148 } 149 150 // ----------------------------------------------------------------------------- 151 void OPropertyForward::setDefinition( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest ) 152 { 153 ::osl::MutexGuard aGuard( m_aMutex ); 154 if ( m_bInInsert ) 155 return; 156 157 OSL_ENSURE( !m_xDest.is(), "OPropertyForward::setDefinition: definition object is already set!" ); 158 try 159 { 160 m_xDest.set( _xDest, UNO_SET_THROW ); 161 m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW ); 162 ::comphelper::copyProperties( m_xDest, m_xSource ); 163 } 164 catch( const Exception& ) 165 { 166 DBG_UNHANDLED_EXCEPTION(); 167 } 168 } 169 170 //........................................................................ 171 } // namespace dbaccess 172 //........................................................................ 173 174