Update ooo320-m1
[ooovba.git] / dbaccess / source / core / misc / PropertyForward.cxx
blob697519295ed5c29e8d928c4e7717b1ab8bb7bb6b
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: PropertyForward.cxx,v $
10 * $Revision: 1.11 $
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_dbaccess.hxx"
33 #ifndef DBA_PROPERTYSETFORWARD_HXX
34 #include "PropertyForward.hxx"
35 #endif
36 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 #endif
39 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
40 #include "dbastrings.hrc"
41 #endif
42 #ifndef _COMPHELPER_PROPERTY_HXX_
43 #include <comphelper/property.hxx>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
46 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
49 #include <com/sun/star/sdbcx/XAppend.hpp>
50 #endif
51 #ifndef _TOOLS_DEBUG_HXX
52 #include <tools/debug.hxx>
53 #endif
56 //........................................................................
57 namespace dbaccess
59 //........................................................................
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::beans;
62 using namespace ::com::sun::star::container;
63 using namespace ::com::sun::star::sdbcx;
65 DBG_NAME(OPropertyForward)
66 OPropertyForward::OPropertyForward(const Reference< XPropertySet>& _xSource
67 ,const Reference< XNameAccess>& _xDestContainer
68 ,const ::rtl::OUString& _sName
69 ,const ::std::vector< ::rtl::OUString>& _aPropertyList)
70 : m_xSource(_xSource)
71 , m_xDestContainer(_xDestContainer)
72 , m_sName(_sName)
73 , m_bInInsert(sal_False)
75 DBG_CTOR(OPropertyForward,NULL);
76 OSL_ENSURE(_xDestContainer.is(),"OPropertyForward::OPropertyForward: destination should be valid!");
77 OSL_ENSURE(m_xSource.is(),"OPropertyForward::OPropertyForward: source must be valid!");
78 osl_incrementInterlockedCount(&m_refCount);
79 try
81 if ( _aPropertyList.empty() )
82 _xSource->addPropertyChangeListener(::rtl::OUString(), this);
83 else
85 ::std::vector< ::rtl::OUString>::const_iterator aIter = _aPropertyList.begin();
86 ::std::vector< ::rtl::OUString>::const_iterator aEnd = _aPropertyList.end();
87 for (; aIter != aEnd ; ++aIter )
88 _xSource->addPropertyChangeListener(*aIter, this);
91 catch(Exception&)
93 OSL_ENSURE(sal_False, "OPropertyForward::OPropertyForward: caught an exception!");
95 osl_decrementInterlockedCount(&m_refCount);
97 // -----------------------------------------------------------------------------
98 OPropertyForward::~OPropertyForward()
100 DBG_DTOR(OPropertyForward,NULL);
102 // -----------------------------------------------------------------------------
103 void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException)
105 ::osl::MutexGuard aGuard(m_aMutex);
106 if ( m_xDestContainer.is() )
108 if ( m_xDestContainer->hasByName(m_sName) )
110 m_xDest.set(m_xDestContainer->getByName(m_sName),UNO_QUERY);
112 else
114 Reference<XDataDescriptorFactory> xFactory(m_xDestContainer,UNO_QUERY);
115 if ( xFactory.is() )
117 m_xDest = xFactory->createDataDescriptor();
118 if ( m_xDest.is() )
120 ::comphelper::copyProperties(m_xSource,m_xDest);
121 m_bInInsert = sal_True;
122 Reference<XAppend> xAppend(m_xDestContainer,UNO_QUERY);
123 if ( xAppend.is() )
124 xAppend->appendByDescriptor(m_xDest);
125 m_bInInsert = sal_False;
129 if ( m_xDest.is() )
130 m_xDestInfo = m_xDest->getPropertySetInfo();
133 if ( m_xDestInfo.is() && m_xDestInfo->hasPropertyByName(evt.PropertyName) )
135 m_xDest->setPropertyValue(evt.PropertyName,evt.NewValue);
138 // -----------------------------------------------------------------------------
139 void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException)
141 ::osl::MutexGuard aGuard(m_aMutex);
142 if ( m_xSource.is() )
144 m_xSource->removePropertyChangeListener(::rtl::OUString(), this);
145 m_xSource = NULL;
147 m_xDestContainer = NULL;
148 m_xDestInfo = NULL;
149 m_xDest = NULL;
151 // -----------------------------------------------------------------------------
152 void OPropertyForward::setDefinition(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest)
154 ::osl::MutexGuard aGuard(m_aMutex);
155 if ( !m_bInInsert )
157 OSL_ENSURE( !m_xDest.is(),"Definition object is already set!");
159 m_xDest = _xDest;
160 if ( m_xDest.is() )
162 m_xDestInfo = m_xDest->getPropertySetInfo();
163 ::comphelper::copyProperties(m_xDest,m_xSource);
167 //........................................................................
168 } // namespace dbaccess
169 //........................................................................