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: apitools.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"
34 #ifndef _DBASHARED_APITOOLS_HXX_
35 #include "apitools.hxx"
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
40 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
41 #include <cppuhelper/typeprovider.hxx>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #ifndef _OSL_DIAGNOSE_H_
45 #include <osl/diagnose.h>
47 #ifndef _TOOLS_DEBUG_HXX
48 #include <tools/debug.hxx>
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::lang
;
55 using namespace dbaccess
;
57 //==================================================================================
58 //= various helper functions
59 //==================================================================================
60 //============================================================
62 //============================================================
63 DBG_NAME(OSubComponent
)
64 //--------------------------------------------------------------------------
65 OSubComponent::OSubComponent(Mutex
& _rMutex
, const Reference
< XInterface
> & xParent
)
66 :OComponentHelper(_rMutex
)
69 DBG_CTOR(OSubComponent
,NULL
);
72 // -----------------------------------------------------------------------------
73 OSubComponent::~OSubComponent()
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();
92 //--------------------------------------------------------------------------
93 void OSubComponent::acquire() throw ( )
95 OComponentHelper::acquire();
98 //--------------------------------------------------------------------------
99 void OSubComponent::release() throw ( )
101 Reference
< XInterface
> x( xDelegator
);
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
);
118 OSL_ENSURE( m_refCount
== 1, "OSubComponent::release: invalid ref count!" );
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 ~
129 MutexGuard
aGuard( rBHelper
.rMutex
);
133 // destroy the object if xHoldAlive decrement the refcount to 0
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
)
149 if (!rType
.equals(::getCppuType(static_cast< Reference
< XAggregation
>* >(NULL
))))
150 aReturn
= OComponentHelper::queryInterface(rType
);