1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PropertyForward.cxx,v $
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"
36 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
37 #include <com/sun/star/beans/PropertyValue.hpp>
39 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
40 #include "dbastrings.hrc"
42 #ifndef _COMPHELPER_PROPERTY_HXX_
43 #include <comphelper/property.hxx>
45 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
46 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
48 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
49 #include <com/sun/star/sdbcx/XAppend.hpp>
51 #ifndef _TOOLS_DEBUG_HXX
52 #include <tools/debug.hxx>
56 //........................................................................
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
)
71 , m_xDestContainer(_xDestContainer
)
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
);
81 if ( _aPropertyList
.empty() )
82 _xSource
->addPropertyChangeListener(::rtl::OUString(), this);
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);
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
);
114 Reference
<XDataDescriptorFactory
> xFactory(m_xDestContainer
,UNO_QUERY
);
117 m_xDest
= xFactory
->createDataDescriptor();
120 ::comphelper::copyProperties(m_xSource
,m_xDest
);
121 m_bInInsert
= sal_True
;
122 Reference
<XAppend
> xAppend(m_xDestContainer
,UNO_QUERY
);
124 xAppend
->appendByDescriptor(m_xDest
);
125 m_bInInsert
= sal_False
;
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);
147 m_xDestContainer
= NULL
;
151 // -----------------------------------------------------------------------------
152 void OPropertyForward::setDefinition(const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xDest
)
154 ::osl::MutexGuard
aGuard(m_aMutex
);
157 OSL_ENSURE( !m_xDest
.is(),"Definition object is already set!");
162 m_xDestInfo
= m_xDest
->getPropertySetInfo();
163 ::comphelper::copyProperties(m_xDest
,m_xSource
);
167 //........................................................................
168 } // namespace dbaccess
169 //........................................................................