update dev300-m58
[ooovba.git] / dbaccess / source / core / misc / apitools.cxx
blobbb4b4531563db78140ead0c5937fcdd0307f81e5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: apitools.cxx,v $
10 * $Revision: 1.11 $
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"
34 #ifndef _DBASHARED_APITOOLS_HXX_
35 #include "apitools.hxx"
36 #endif
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
39 #endif
40 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
41 #include <cppuhelper/typeprovider.hxx>
42 #endif
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #ifndef _OSL_DIAGNOSE_H_
45 #include <osl/diagnose.h>
46 #endif
47 #ifndef _TOOLS_DEBUG_HXX
48 #include <tools/debug.hxx>
49 #endif
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::lang;
53 using namespace cppu;
54 using namespace osl;
55 using namespace dbaccess;
57 //==================================================================================
58 //= various helper functions
59 //==================================================================================
60 //============================================================
61 //= OSubComponent
62 //============================================================
63 DBG_NAME(OSubComponent)
64 //--------------------------------------------------------------------------
65 OSubComponent::OSubComponent(Mutex& _rMutex, const Reference< XInterface > & xParent)
66 :OComponentHelper(_rMutex)
67 ,m_xParent(xParent)
69 DBG_CTOR(OSubComponent,NULL);
72 // -----------------------------------------------------------------------------
73 OSubComponent::~OSubComponent()
75 m_xParent = NULL;
77 DBG_DTOR(OSubComponent,NULL);
80 // com::sun::star::lang::XTypeProvider
81 //--------------------------------------------------------------------------
82 Sequence< Type > OSubComponent::getTypes() throw (RuntimeException)
84 OTypeCollection aTypes(::getCppuType( (const Reference< XComponent > *)0 ),
85 ::getCppuType( (const Reference< XTypeProvider > *)0 ),
86 ::getCppuType( (const Reference< XWeak > *)0 ));
88 return aTypes.getTypes();
91 // XInterface
92 //--------------------------------------------------------------------------
93 void OSubComponent::acquire() throw ( )
95 OComponentHelper::acquire();
98 //--------------------------------------------------------------------------
99 void OSubComponent::release() throw ( )
101 Reference< XInterface > x( xDelegator );
102 if (! x.is())
104 if (osl_decrementInterlockedCount( &m_refCount ) == 0 && m_refCount == 0 )
106 OSL_ENSURE( m_refCount == 0, "OSubComponent::release: why the hell is this false!" );
107 if (! rBHelper.bDisposed)
109 Reference< XInterface > xHoldAlive( *this );
110 // remember the parent
111 Reference< XInterface > xParent;
113 MutexGuard aGuard( rBHelper.rMutex );
114 xParent = m_xParent;
115 m_xParent = NULL;
118 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count!" );
120 // First dispose
121 dispose();
123 // only the alive ref holds the object
124 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count!" );
126 // release the parent in the ~
127 if (xParent.is())
129 MutexGuard aGuard( rBHelper.rMutex );
130 m_xParent = xParent;
133 // destroy the object if xHoldAlive decrement the refcount to 0
134 return;
137 // restore the reference count
138 osl_incrementInterlockedCount( &m_refCount );
141 // as we cover the job of the componenthelper we use the ...
142 OWeakAggObject::release();
145 //--------------------------------------------------------------------------
146 Any OSubComponent::queryInterface( const Type & rType ) throw(RuntimeException)
148 Any aReturn;
149 if (!rType.equals(::getCppuType(static_cast< Reference< XAggregation >* >(NULL))))
150 aReturn = OComponentHelper::queryInterface(rType);
152 return aReturn;