xref: /AOO41X/main/dbaccess/source/core/misc/PropertyForward.cxx (revision 96de54900b79e13b861fbc62cbf36018b54e21b7)
1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "PropertyForward.hxx"
28cdf0e10cSrcweir #include "dbastrings.hrc"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <comphelper/property.hxx>
35cdf0e10cSrcweir #include <tools/debug.hxx>
36cdf0e10cSrcweir #include <tools/diagnose_ex.h>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //........................................................................
40cdf0e10cSrcweir namespace dbaccess
41cdf0e10cSrcweir {
42cdf0e10cSrcweir //........................................................................
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
46cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
47cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
48cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
49cdf0e10cSrcweir 
DBG_NAME(OPropertyForward)50cdf0e10cSrcweir     DBG_NAME(OPropertyForward)
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     //------------------------------------------------------------------------
53cdf0e10cSrcweir     OPropertyForward::OPropertyForward( const Reference< XPropertySet>& _xSource, const Reference< XNameAccess>& _xDestContainer,
54cdf0e10cSrcweir             const ::rtl::OUString& _sName, const ::std::vector< ::rtl::OUString>& _aPropertyList )
55cdf0e10cSrcweir         :m_xSource( _xSource, UNO_SET_THROW )
56cdf0e10cSrcweir         ,m_xDestContainer( _xDestContainer, UNO_SET_THROW )
57cdf0e10cSrcweir         ,m_sName( _sName )
58cdf0e10cSrcweir         ,m_bInInsert( sal_False )
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir 	    DBG_CTOR(OPropertyForward,NULL);
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         osl_incrementInterlockedCount(&m_refCount);
63cdf0e10cSrcweir 	    try
64cdf0e10cSrcweir 	    {
65cdf0e10cSrcweir 		    if ( _aPropertyList.empty() )
66cdf0e10cSrcweir 			    _xSource->addPropertyChangeListener( ::rtl::OUString(), this );
67cdf0e10cSrcweir 		    else
68cdf0e10cSrcweir 		    {
69cdf0e10cSrcweir 			    ::std::vector< ::rtl::OUString >::const_iterator aIter = _aPropertyList.begin();
70cdf0e10cSrcweir 			    ::std::vector< ::rtl::OUString >::const_iterator aEnd = _aPropertyList.end();
71cdf0e10cSrcweir 			    for (; aIter != aEnd ; ++aIter )
72cdf0e10cSrcweir 				    _xSource->addPropertyChangeListener( *aIter, this );
73cdf0e10cSrcweir 		    }
74cdf0e10cSrcweir 	    }
75cdf0e10cSrcweir 	    catch( const Exception& )
76cdf0e10cSrcweir 	    {
77cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
78cdf0e10cSrcweir 	    }
79cdf0e10cSrcweir 	    osl_decrementInterlockedCount( &m_refCount );
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     // -----------------------------------------------------------------------------
~OPropertyForward()83cdf0e10cSrcweir     OPropertyForward::~OPropertyForward()
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir 	    DBG_DTOR(OPropertyForward,NULL);
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     // -----------------------------------------------------------------------------
propertyChange(const PropertyChangeEvent & evt)89cdf0e10cSrcweir     void SAL_CALL OPropertyForward::propertyChange( const PropertyChangeEvent& evt ) throw(RuntimeException)
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir 	    ::osl::MutexGuard aGuard( m_aMutex );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         if ( !m_xDestContainer.is() )
94cdf0e10cSrcweir             throw DisposedException( ::rtl::OUString(), *this );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         try
97cdf0e10cSrcweir         {
98cdf0e10cSrcweir             if ( !m_xDest.is() )
99cdf0e10cSrcweir             {
100cdf0e10cSrcweir 	            if ( m_xDestContainer->hasByName( m_sName ) )
101cdf0e10cSrcweir 	            {
102cdf0e10cSrcweir 		            m_xDest.set( m_xDestContainer->getByName( m_sName ), UNO_QUERY_THROW );
103cdf0e10cSrcweir 	            }
104cdf0e10cSrcweir 	            else
105cdf0e10cSrcweir 	            {
106cdf0e10cSrcweir 		            Reference< XDataDescriptorFactory > xFactory( m_xDestContainer, UNO_QUERY_THROW );
107cdf0e10cSrcweir 		            m_xDest.set( xFactory->createDataDescriptor(), UNO_SET_THROW );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir                     ::comphelper::copyProperties( m_xSource, m_xDest );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir                     m_bInInsert = sal_True;
112cdf0e10cSrcweir 	                Reference< XAppend > xAppend( m_xDestContainer, UNO_QUERY_THROW );
113cdf0e10cSrcweir 	                xAppend->appendByDescriptor( m_xDest );
114cdf0e10cSrcweir 	                m_bInInsert = sal_False;
115cdf0e10cSrcweir 	            }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	            m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
118cdf0e10cSrcweir             }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir             if ( m_xDestInfo->hasPropertyByName( evt.PropertyName ) )
121cdf0e10cSrcweir 	        {
122cdf0e10cSrcweir 		        m_xDest->setPropertyValue( evt.PropertyName, evt.NewValue );
123cdf0e10cSrcweir 	        }
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir         catch( const Exception& )
126cdf0e10cSrcweir         {
127cdf0e10cSrcweir 	        DBG_UNHANDLED_EXCEPTION();
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     // -----------------------------------------------------------------------------
disposing(const::com::sun::star::lang::EventObject &)132cdf0e10cSrcweir     void SAL_CALL OPropertyForward::disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ ) throw (RuntimeException)
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir 	    ::osl::MutexGuard aGuard(m_aMutex);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         if ( !m_xSource.is() )
137cdf0e10cSrcweir             throw DisposedException( ::rtl::OUString(), *this );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	    m_xSource->removePropertyChangeListener( ::rtl::OUString(), this );
140cdf0e10cSrcweir 	    m_xSource = NULL;
141cdf0e10cSrcweir 	    m_xDestContainer = NULL;
142cdf0e10cSrcweir 	    m_xDestInfo = NULL;
143cdf0e10cSrcweir 	    m_xDest = NULL;
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // -----------------------------------------------------------------------------
setDefinition(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & _xDest)147cdf0e10cSrcweir     void OPropertyForward::setDefinition( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest )
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir 	    ::osl::MutexGuard aGuard( m_aMutex );
150cdf0e10cSrcweir 	    if ( m_bInInsert )
151cdf0e10cSrcweir             return;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         OSL_ENSURE( !m_xDest.is(), "OPropertyForward::setDefinition: definition object is already set!" );
154cdf0e10cSrcweir         try
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir 	        m_xDest.set( _xDest, UNO_SET_THROW );
157cdf0e10cSrcweir 	        m_xDestInfo.set( m_xDest->getPropertySetInfo(), UNO_SET_THROW );
158cdf0e10cSrcweir 	        ::comphelper::copyProperties( m_xDest, m_xSource );
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir         catch( const Exception& )
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir     	    DBG_UNHANDLED_EXCEPTION();
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir //........................................................................
167cdf0e10cSrcweir }	// namespace dbaccess
168cdf0e10cSrcweir //........................................................................
169cdf0e10cSrcweir 
170