LibreOffice Module dbaccess (master) 1
PropertyForward.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <PropertyForward.hxx>
21
22#include <com/sun/star/lang/DisposedException.hpp>
23#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
24#include <com/sun/star/sdbcx/XAppend.hpp>
25
27#include <utility>
29
30namespace dbaccess
31{
32
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
36 using namespace ::com::sun::star::sdbcx;
37 using namespace ::com::sun::star::lang;
38
39
40 OPropertyForward::OPropertyForward( const Reference< XPropertySet>& _xSource, const Reference< XNameAccess>& _xDestContainer,
41 OUString _sName, const std::vector< OUString>& _aPropertyList )
42 :m_xSource( _xSource, UNO_SET_THROW )
43 ,m_xDestContainer( _xDestContainer, UNO_SET_THROW )
44 ,m_sName(std::move( _sName ))
45 ,m_bInInsert( false )
46 {
47
48 osl_atomic_increment(&m_refCount);
49 try
50 {
51 if ( _aPropertyList.empty() )
52 _xSource->addPropertyChangeListener( OUString(), this );
53 else
54 {
55 for (auto const& property : _aPropertyList)
56 _xSource->addPropertyChangeListener(property, this);
57 }
58 }
59 catch( const Exception& )
60 {
61 DBG_UNHANDLED_EXCEPTION("dbaccess");
62 }
63 osl_atomic_decrement( &m_refCount );
64 }
65
67 {
68 }
69
70 void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt )
71 {
72 ::osl::MutexGuard aGuard( m_aMutex );
73
74 if ( !m_xDestContainer.is() )
75 throw DisposedException( OUString(), *this );
76
77 try
78 {
79 if ( !m_xDest.is() )
80 {
81 if ( m_xDestContainer->hasByName( m_sName ) )
82 {
83 m_xDest.set( m_xDestContainer->getByName( m_sName ), UNO_QUERY_THROW );
84 }
85 else
86 {
87 Reference< XDataDescriptorFactory > xFactory( m_xDestContainer, UNO_QUERY_THROW );
88 m_xDest.set( xFactory->createDataDescriptor(), UNO_SET_THROW );
89
90 ::comphelper::copyProperties( m_xSource, m_xDest );
91
92 m_bInInsert = true;
93 Reference< XAppend > xAppend( m_xDestContainer, UNO_QUERY_THROW );
94 xAppend->appendByDescriptor( m_xDest );
95 m_bInInsert = false;
96 }
97
98 m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
99 }
100
101 if ( m_xDestInfo->hasPropertyByName( evt.PropertyName ) )
102 {
103 m_xDest->setPropertyValue( evt.PropertyName, evt.NewValue );
104 }
105 }
106 catch( const Exception& )
107 {
108 DBG_UNHANDLED_EXCEPTION("dbaccess");
109 }
110 }
111
112 void SAL_CALL OPropertyForward::disposing( const css::lang::EventObject& /*_rSource*/ )
113 {
114 ::osl::MutexGuard aGuard(m_aMutex);
115
116 if ( !m_xSource.is() )
117 throw DisposedException( OUString(), *this );
118
119 m_xSource->removePropertyChangeListener( OUString(), this );
120 m_xSource = nullptr;
121 m_xDestContainer = nullptr;
122 m_xDestInfo = nullptr;
123 m_xDest = nullptr;
124 }
125
126 void OPropertyForward::setDefinition( const css::uno::Reference< css::beans::XPropertySet>& _xDest )
127 {
128 ::osl::MutexGuard aGuard( m_aMutex );
129 if ( m_bInInsert )
130 return;
131
132 OSL_ENSURE( !m_xDest.is(), "OPropertyForward::setDefinition: definition object is already set!" );
133 try
134 {
135 m_xDest.set( _xDest, UNO_SET_THROW );
136 m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
137 ::comphelper::copyProperties( m_xDest, m_xSource );
138 }
139 catch( const Exception& )
140 {
141 DBG_UNHANDLED_EXCEPTION("dbaccess");
142 }
143 }
144
145} // namespace dbaccess
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
mutable::osl::Mutex m_aMutex
css::uno::Reference< css::beans::XPropertySet > m_xDest
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &evt) override
void setDefinition(const css::uno::Reference< css::beans::XPropertySet > &_xDest)
virtual ~OPropertyForward() override
css::uno::Reference< css::beans::XPropertySetInfo > m_xDestInfo
css::uno::Reference< css::beans::XPropertySet > m_xSource
css::uno::Reference< css::container::XNameAccess > m_xDestContainer
OPropertyForward(const css::uno::Reference< css::beans::XPropertySet > &_xSource, const css::uno::Reference< css::container::XNameAccess > &_xDestContainer, OUString _sName, const std::vector< OUString > &_aPropertyList)
virtual void SAL_CALL disposing(const css::lang::EventObject &_rSource) override
const Reference< XRow > m_xSource
#define DBG_UNHANDLED_EXCEPTION(...)
ULONG m_refCount
OUString m_sName
Reference< XSingleServiceFactory > xFactory
@ Exception