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: bootstrapcontext.hxx,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 #ifndef CONFIGMGR_BOOTSTRAPCONTEXT_HXX_
32 #define CONFIGMGR_BOOTSTRAPCONTEXT_HXX_
34 #include <cppuhelper/compbase3.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <rtl/bootstrap.h>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <com/sun/star/uno/XCurrentContext.hpp>
39 #include <com/sun/star/lang/XEventListener.hpp>
40 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <com/sun/star/beans/NamedValue.hpp>
42 #include <com/sun/star/uno/Sequence.hxx>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
45 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
46 class XComponentContext
;
49 // -----------------------------------------------------------------------------
50 #define SINGLETON_ "/singletons/"
51 #define SINGLETON( NAME ) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SINGLETON_ NAME ) )
52 // -----------------------------------------------------------------------------
55 // -----------------------------------------------------------------------------
56 namespace uno
= ::com::sun::star::uno
;
57 namespace lang
= ::com::sun::star::lang
;
58 namespace beans
= ::com::sun::star::beans
;
59 // -----------------------------------------------------------------------------
60 /** Base class for customized ComponentContext using bootstrap data and overrides
62 class ComponentContext
: public cppu::WeakComponentImplHelper3
< uno::XComponentContext
, uno::XCurrentContext
, lang::XServiceInfo
>
64 // creation and destruction
66 /** Constructs a ComponentContext based on the given overrides and context.
67 Initially no bootstrap data will be used.
70 The base context of this component context.
71 Values from here take precedence over values from bootstrap data.
74 The overrides used to create this component context.
75 These values take precedence over values from the base context or bootstrap data.
78 ComponentContext(uno::Reference
< uno::XComponentContext
> const & _xContext
);
80 /// Destroys this BootstrapContext
83 // gets the INI in use for getting bootstrap data
84 rtl::OUString
getBootstrapURL() const;
86 static sal_Bool
isPassthrough(uno::Reference
< uno::XComponentContext
> const & _xContext
);
88 static beans::NamedValue
makePassthroughMarker(sal_Bool bPassthrough
= true);
89 // interface implementations
92 // XComponentContext only
93 virtual uno::Reference
< lang::XMultiComponentFactory
> SAL_CALL
95 throw (uno::RuntimeException
);
99 virtual void SAL_CALL
disposing();
102 // two phase construct - also initialized the bootstrap data
103 void initialize(const rtl::OUString
& _aBootstrapURL
);
105 bool lookupInContext ( uno::Any
& _rValue
, const rtl::OUString
& _aName
) const;
106 bool lookupInBootstrap( uno::Any
& _rValue
, const rtl::OUString
& _aName
) const;
108 uno::Reference
< uno::XComponentContext
> const & basecontext() const { return m_xContext
; }
111 /// The context that most requests are delegated to
112 uno::Reference
< uno::XComponentContext
> m_xContext
;
113 /// The bootstrap data consulted as fallback
114 rtlBootstrapHandle m_hBootstrapData
;
115 /// The service manager associated with this context
116 uno::Reference
< lang::XMultiComponentFactory
> m_xServiceManager
;
118 // -----------------------------------------------------------------------------
120 class UnoContextTunnel
125 void tunnel(uno::Reference
< uno::XComponentContext
> const & xContext
);
126 void passthru(uno::Reference
< uno::XComponentContext
> const & xContext
);
127 uno::Any
recoverFailure(bool bRaise
); // true, if there is a failure
129 static uno::Reference
< uno::XComponentContext
> recoverContext(uno::Reference
< uno::XComponentContext
> const & xFallback
= uno::Reference
< uno::XComponentContext
>());
130 static bool tunnelFailure(uno::Any
const & aException
, bool bRaise
= false);
132 uno::Reference
< uno::XCurrentContext
> m_xOldContext
;
133 uno::Reference
< lang::XUnoTunnel
> m_xActiveTunnel
;
136 // -----------------------------------------------------------------------------
138 class DisposingForwarder
: public cppu::WeakImplHelper1
< lang::XEventListener
>
140 uno::Reference
< lang::XComponent
> m_xTarget
;
142 DisposingForwarder( uno::Reference
< lang::XComponent
> const & xTarget
) SAL_THROW( () )
143 : m_xTarget( xTarget
)
144 { OSL_ASSERT( m_xTarget
.is() ); }
146 virtual void SAL_CALL
disposing( lang::EventObject
const & rSource
)
147 throw (uno::RuntimeException
);
149 // listens at source for disposing, then disposes target
150 static inline void forward(
151 uno::Reference
< lang::XComponent
> const & xSource
,
152 uno::Reference
< lang::XComponent
> const & xTarget
)
153 SAL_THROW( (uno::RuntimeException
) );
155 //__________________________________________________________________________________________________
156 inline void DisposingForwarder::forward(
157 uno::Reference
< lang::XComponent
> const & xSource
,
158 uno::Reference
< lang::XComponent
> const & xTarget
)
159 SAL_THROW( (uno::RuntimeException
) )
163 xSource
->addEventListener( new DisposingForwarder( xTarget
) );
166 // -----------------------------------------------------------------------------
167 } // namespace configmgr