Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / misc / PropertyForward.cxx
blob2894a7fe73e813b6eaba888a6cb0459852fd05f6
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 .
21 #include "PropertyForward.hxx"
22 #include "dbastrings.hrc"
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
26 #include <com/sun/star/sdbcx/XAppend.hpp>
28 #include <comphelper/property.hxx>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
33 //........................................................................
34 namespace dbaccess
36 //........................................................................
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::sdbcx;
42 using namespace ::com::sun::star::lang;
44 DBG_NAME(OPropertyForward)
46 //------------------------------------------------------------------------
47 OPropertyForward::OPropertyForward( const Reference< XPropertySet>& _xSource, const Reference< XNameAccess>& _xDestContainer,
48 const ::rtl::OUString& _sName, const ::std::vector< ::rtl::OUString>& _aPropertyList )
49 :m_xSource( _xSource, UNO_SET_THROW )
50 ,m_xDestContainer( _xDestContainer, UNO_SET_THROW )
51 ,m_sName( _sName )
52 ,m_bInInsert( sal_False )
54 DBG_CTOR(OPropertyForward,NULL);
56 osl_atomic_increment(&m_refCount);
57 try
59 if ( _aPropertyList.empty() )
60 _xSource->addPropertyChangeListener( ::rtl::OUString(), this );
61 else
63 ::std::vector< ::rtl::OUString >::const_iterator aIter = _aPropertyList.begin();
64 ::std::vector< ::rtl::OUString >::const_iterator aEnd = _aPropertyList.end();
65 for (; aIter != aEnd ; ++aIter )
66 _xSource->addPropertyChangeListener( *aIter, this );
69 catch( const Exception& )
71 DBG_UNHANDLED_EXCEPTION();
73 osl_atomic_decrement( &m_refCount );
76 // -----------------------------------------------------------------------------
77 OPropertyForward::~OPropertyForward()
79 DBG_DTOR(OPropertyForward,NULL);
82 // -----------------------------------------------------------------------------
83 void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException)
85 ::osl::MutexGuard aGuard( m_aMutex );
87 if ( !m_xDestContainer.is() )
88 throw DisposedException( ::rtl::OUString(), *this );
90 try
92 if ( !m_xDest.is() )
94 if ( m_xDestContainer->hasByName( m_sName ) )
96 m_xDest.set( m_xDestContainer->getByName( m_sName ), UNO_QUERY_THROW );
98 else
100 Reference< XDataDescriptorFactory > xFactory( m_xDestContainer, UNO_QUERY_THROW );
101 m_xDest.set( xFactory->createDataDescriptor(), UNO_SET_THROW );
103 ::comphelper::copyProperties( m_xSource, m_xDest );
105 m_bInInsert = sal_True;
106 Reference< XAppend > xAppend( m_xDestContainer, UNO_QUERY_THROW );
107 xAppend->appendByDescriptor( m_xDest );
108 m_bInInsert = sal_False;
111 m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
114 if ( m_xDestInfo->hasPropertyByName( evt.PropertyName ) )
116 m_xDest->setPropertyValue( evt.PropertyName, evt.NewValue );
119 catch( const Exception& )
121 DBG_UNHANDLED_EXCEPTION();
125 // -----------------------------------------------------------------------------
126 void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException)
128 ::osl::MutexGuard aGuard(m_aMutex);
130 if ( !m_xSource.is() )
131 throw DisposedException( ::rtl::OUString(), *this );
133 m_xSource->removePropertyChangeListener( ::rtl::OUString(), this );
134 m_xSource = NULL;
135 m_xDestContainer = NULL;
136 m_xDestInfo = NULL;
137 m_xDest = NULL;
140 // -----------------------------------------------------------------------------
141 void OPropertyForward::setDefinition( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest )
143 ::osl::MutexGuard aGuard( m_aMutex );
144 if ( m_bInInsert )
145 return;
147 OSL_ENSURE( !m_xDest.is(), "OPropertyForward::setDefinition: definition object is already set!" );
150 m_xDest.set( _xDest, UNO_SET_THROW );
151 m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
152 ::comphelper::copyProperties( m_xDest, m_xSource );
154 catch( const Exception& )
156 DBG_UNHANDLED_EXCEPTION();
160 //........................................................................
161 } // namespace dbaccess
162 //........................................................................
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */