Inserting a value into a XComponentContext
Stephan Bergmann
sbergman at redhat.com
Mon Dec 1 03:24:43 PST 2014
On 12/01/2014 12:29 AM, Chris Sherlock wrote:
> So what about the following approach:
>
> Reference< XComponentContext > xContext =
> ::comphelper::getProcessComponentContext();
> ::cppu::ContextEntry_Init aContextInfo[] =
> {
> ::cppu::ContextEntry_Init("testkey", uno::Any() ),
> }
> xNewContext = ::cppu::createComponentContext(aContextInfo,
> sizeof(aContextInfo) / sizeof (aHandlerContextInfo[0]), xContext);
>
> Then to get access to the container, I use something like this:
>
> Reference< container::XNameContainer > xNameContainer( xContext,
> UNO_QUERY );
>
> Is this the right approach? Will the delegate ComponentContext work?
The "philosophy" behind the UNO component context is that a component
(i.e., service or singleton) gets one passed in during creation (cf.
e.g. the context argument to the UNO service constructors, implicit in
UNOIDL but explicit in the C++ and Java language bindings at least) and
in turn uses it to obtain any other components. This is somewhat
blurred by the LO "convenience hack" of global
comphelper::get/setProcessComponentContext().
That said, the above provides you with a functional xNewContext that you
could "locally" use to instantiate some component with. See my other
reply for a way to instead modify the existing "global" component
context (what is what you actually want to do, for whatever reason, I
assume).
More information about the LibreOffice
mailing list