1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "PropertyForward.hxx"
21 #include "dbastrings.hrc"
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
25 #include <com/sun/star/sdbcx/XAppend.hpp>
27 #include <comphelper/property.hxx>
28 #include <tools/debug.hxx>
29 #include <tools/diagnose_ex.h>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::container
;
37 using namespace ::com::sun::star::sdbcx
;
38 using namespace ::com::sun::star::lang
;
41 OPropertyForward::OPropertyForward( const Reference
< XPropertySet
>& _xSource
, const Reference
< XNameAccess
>& _xDestContainer
,
42 const OUString
& _sName
, const ::std::vector
< OUString
>& _aPropertyList
)
43 :m_xSource( _xSource
, UNO_SET_THROW
)
44 ,m_xDestContainer( _xDestContainer
, UNO_SET_THROW
)
49 osl_atomic_increment(&m_refCount
);
52 if ( _aPropertyList
.empty() )
53 _xSource
->addPropertyChangeListener( OUString(), this );
56 ::std::vector
< OUString
>::const_iterator aIter
= _aPropertyList
.begin();
57 ::std::vector
< OUString
>::const_iterator aEnd
= _aPropertyList
.end();
58 for (; aIter
!= aEnd
; ++aIter
)
59 _xSource
->addPropertyChangeListener( *aIter
, this );
62 catch( const Exception
& )
64 DBG_UNHANDLED_EXCEPTION();
66 osl_atomic_decrement( &m_refCount
);
69 OPropertyForward::~OPropertyForward()
73 void SAL_CALL
OPropertyForward::propertyChange( const PropertyChangeEvent
& evt
) throw(RuntimeException
, std::exception
)
75 ::osl::MutexGuard
aGuard( m_aMutex
);
77 if ( !m_xDestContainer
.is() )
78 throw DisposedException( OUString(), *this );
84 if ( m_xDestContainer
->hasByName( m_sName
) )
86 m_xDest
.set( m_xDestContainer
->getByName( m_sName
), UNO_QUERY_THROW
);
90 Reference
< XDataDescriptorFactory
> xFactory( m_xDestContainer
, UNO_QUERY_THROW
);
91 m_xDest
.set( xFactory
->createDataDescriptor(), UNO_SET_THROW
);
93 ::comphelper::copyProperties( m_xSource
, m_xDest
);
96 Reference
< XAppend
> xAppend( m_xDestContainer
, UNO_QUERY_THROW
);
97 xAppend
->appendByDescriptor( m_xDest
);
101 m_xDestInfo
.set( m_xDest
->getPropertySetInfo(), UNO_SET_THROW
);
104 if ( m_xDestInfo
->hasPropertyByName( evt
.PropertyName
) )
106 m_xDest
->setPropertyValue( evt
.PropertyName
, evt
.NewValue
);
109 catch( const Exception
& )
111 DBG_UNHANDLED_EXCEPTION();
115 void SAL_CALL
OPropertyForward::disposing( const ::com::sun::star::lang::EventObject
& /*_rSource*/ ) throw (RuntimeException
, std::exception
)
117 ::osl::MutexGuard
aGuard(m_aMutex
);
119 if ( !m_xSource
.is() )
120 throw DisposedException( OUString(), *this );
122 m_xSource
->removePropertyChangeListener( OUString(), this );
124 m_xDestContainer
= NULL
;
129 void OPropertyForward::setDefinition( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xDest
)
131 ::osl::MutexGuard
aGuard( m_aMutex
);
135 OSL_ENSURE( !m_xDest
.is(), "OPropertyForward::setDefinition: definition object is already set!" );
138 m_xDest
.set( _xDest
, UNO_SET_THROW
);
139 m_xDestInfo
.set( m_xDest
->getPropertySetInfo(), UNO_SET_THROW
);
140 ::comphelper::copyProperties( m_xDest
, m_xSource
);
142 catch( const Exception
& )
144 DBG_UNHANDLED_EXCEPTION();
148 } // namespace dbaccess
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */