Branch data Line data Source code
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 : :
21 : : #include "PropertyForward.hxx"
22 : : #include "dbastrings.hrc"
23 : :
24 : : #include <com/sun/star/beans/PropertyValue.hpp>
25 : : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
26 : : #include <com/sun/star/sdbcx/XAppend.hpp>
27 : :
28 : : #include <comphelper/property.hxx>
29 : : #include <tools/debug.hxx>
30 : : #include <tools/diagnose_ex.h>
31 : :
32 : :
33 : : //........................................................................
34 : : namespace dbaccess
35 : : {
36 : : //........................................................................
37 : :
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;
43 : :
44 : : DBG_NAME(OPropertyForward)
45 : :
46 : : //------------------------------------------------------------------------
47 : 456 : 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 [ + - ][ + - ]: 456 : ,m_bInInsert( sal_False )
[ + - ]
53 : : {
54 : : DBG_CTOR(OPropertyForward,NULL);
55 : :
56 [ + - ]: 456 : osl_incrementInterlockedCount(&m_refCount);
57 : : try
58 : : {
59 [ - + ]: 456 : if ( _aPropertyList.empty() )
60 [ # # ][ # # ]: 0 : _xSource->addPropertyChangeListener( ::rtl::OUString(), this );
[ # # ]
61 : : else
62 : : {
63 : 456 : ::std::vector< ::rtl::OUString >::const_iterator aIter = _aPropertyList.begin();
64 : 456 : ::std::vector< ::rtl::OUString >::const_iterator aEnd = _aPropertyList.end();
65 [ + - ][ + + ]: 4580 : for (; aIter != aEnd ; ++aIter )
66 [ + - ][ + - ]: 4124 : _xSource->addPropertyChangeListener( *aIter, this );
[ + - ][ # # ]
67 : : }
68 : : }
69 [ # # ]: 0 : catch( const Exception& )
70 : : {
71 : : DBG_UNHANDLED_EXCEPTION();
72 : : }
73 [ + - ]: 456 : osl_decrementInterlockedCount( &m_refCount );
74 : 456 : }
75 : :
76 : : // -----------------------------------------------------------------------------
77 [ + - ]: 456 : OPropertyForward::~OPropertyForward()
78 : : {
79 : : DBG_DTOR(OPropertyForward,NULL);
80 [ - + ]: 912 : }
81 : :
82 : : // -----------------------------------------------------------------------------
83 : 0 : void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException)
84 : : {
85 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
86 : :
87 [ # # ]: 0 : if ( !m_xDestContainer.is() )
88 [ # # ][ # # ]: 0 : throw DisposedException( ::rtl::OUString(), *this );
89 : :
90 : : try
91 : : {
92 [ # # ]: 0 : if ( !m_xDest.is() )
93 : : {
94 [ # # ][ # # ]: 0 : if ( m_xDestContainer->hasByName( m_sName ) )
[ # # ]
95 : : {
96 [ # # ][ # # ]: 0 : m_xDest.set( m_xDestContainer->getByName( m_sName ), UNO_QUERY_THROW );
[ # # ]
97 : : }
98 : : else
99 : : {
100 [ # # ]: 0 : Reference< XDataDescriptorFactory > xFactory( m_xDestContainer, UNO_QUERY_THROW );
101 [ # # ][ # # ]: 0 : m_xDest.set( xFactory->createDataDescriptor(), UNO_SET_THROW );
[ # # ]
102 : :
103 [ # # ]: 0 : ::comphelper::copyProperties( m_xSource, m_xDest );
104 : :
105 : 0 : m_bInInsert = sal_True;
106 [ # # ]: 0 : Reference< XAppend > xAppend( m_xDestContainer, UNO_QUERY_THROW );
107 [ # # ][ # # ]: 0 : xAppend->appendByDescriptor( m_xDest );
108 : 0 : m_bInInsert = sal_False;
109 : : }
110 : :
111 [ # # ][ # # ]: 0 : m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
[ # # ][ # # ]
112 : : }
113 : :
114 [ # # ][ # # ]: 0 : if ( m_xDestInfo->hasPropertyByName( evt.PropertyName ) )
[ # # ]
115 : : {
116 [ # # ][ # # ]: 0 : m_xDest->setPropertyValue( evt.PropertyName, evt.NewValue );
117 : : }
118 : : }
119 [ # # ]: 0 : catch( const Exception& )
120 : : {
121 : : DBG_UNHANDLED_EXCEPTION();
122 [ # # ]: 0 : }
123 : 0 : }
124 : :
125 : : // -----------------------------------------------------------------------------
126 : 4124 : void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException)
127 : : {
128 [ + - ]: 4124 : ::osl::MutexGuard aGuard(m_aMutex);
129 : :
130 [ + + ]: 4124 : if ( !m_xSource.is() )
131 [ + - ][ + - ]: 3668 : throw DisposedException( ::rtl::OUString(), *this );
132 : :
133 [ + - ][ + - ]: 456 : m_xSource->removePropertyChangeListener( ::rtl::OUString(), this );
[ + - ]
134 [ + - ]: 456 : m_xSource = NULL;
135 [ + - ]: 456 : m_xDestContainer = NULL;
136 [ + - ]: 456 : m_xDestInfo = NULL;
137 [ + - ][ + - ]: 4124 : m_xDest = NULL;
138 : 456 : }
139 : :
140 : : // -----------------------------------------------------------------------------
141 : 0 : void OPropertyForward::setDefinition( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest )
142 : : {
143 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
144 [ # # ]: 0 : if ( m_bInInsert )
145 : 0 : return;
146 : :
147 : : OSL_ENSURE( !m_xDest.is(), "OPropertyForward::setDefinition: definition object is already set!" );
148 : : try
149 : : {
150 [ # # ]: 0 : m_xDest.set( _xDest, UNO_SET_THROW );
151 [ # # ][ # # ]: 0 : m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
[ # # ][ # # ]
152 [ # # ]: 0 : ::comphelper::copyProperties( m_xDest, m_xSource );
153 : : }
154 [ # # ]: 0 : catch( const Exception& )
155 : : {
156 : : DBG_UNHANDLED_EXCEPTION();
157 [ # # ][ # # ]: 0 : }
158 : : }
159 : :
160 : : //........................................................................
161 : : } // namespace dbaccess
162 : : //........................................................................
163 : :
164 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|