1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
29 #define EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
31 /** === begin UNO includes === **/
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 /** === end UNO includes === **/
36 //........................................................................
39 //........................................................................
41 //====================================================================
43 //====================================================================
44 /** a helper class for working with a component context
46 class ComponentContext
49 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
50 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiComponentFactory
> m_xORB
;
53 /** constructs an instance
55 the component context to manage
56 @throws ::com::sun::star::lang::NullPointerException
57 if the given context, or its component factory, are <NULL/>
59 ComponentContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
61 /** returns the ->XComponentContext interface
63 inline ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
64 getUNOContext() const { return m_xContext
; }
66 /** determines whether the context is not <NULL/>
68 inline sal_Bool
is() const
70 return m_xContext
.is();
73 /** creates a component using our component factory/context
74 @throws ::com::sun::star::uno::Exception
76 <TRUE/> if and only if the component could be successfully created
78 template < class INTERFACE
>
79 bool createComponent( const ::rtl::OUString
& _rServiceName
, ::com::sun::star::uno::Reference
< INTERFACE
>& _out_rxComponent
) const
81 _out_rxComponent
.clear();
82 _out_rxComponent
= _out_rxComponent
.query(
83 m_xORB
->createInstanceWithContext( _rServiceName
, m_xContext
)
85 return _out_rxComponent
.is();
88 /** creates a component using our component factory/context
89 @throws ::com::sun::star::uno::Exception
91 <TRUE/> if and only if the component could be successfully created
93 template < class INTERFACE
>
94 bool createComponent( const sal_Char
* _pAsciiServiceName
, ::com::sun::star::uno::Reference
< INTERFACE
>& _out_rxComponent
) const
96 return createComponent( ::rtl::OUString::createFromAscii( _pAsciiServiceName
), _out_rxComponent
);
99 /** creates a component using our component factory/context
101 @throws ::com::sun::star::lang::ServiceNotRegisteredException
102 if the given service is not registered
104 if an exception occured during creating the component
106 the newly created component. Is never <NULL/>.
108 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> createComponent( const ::rtl::OUString
& _rServiceName
) const;
110 /** creates a component using our component factory/context
112 @throws ::com::sun::star::lang::ServiceNotRegisteredException
113 if the given service is not registered
115 if an exception occured during creating the component
117 the newly created component. Is never <NULL/>.
119 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> createComponent( const sal_Char
* _pAsciiServiceName
) const
121 return createComponent( ::rtl::OUString::createFromAscii( _pAsciiServiceName
) );
124 /** returns the ->XMultiServiceFactory interface of ->m_xORB, for passing to
125 older code which does not yet support ->XMultiComponentFactory
126 @throws ::com::sun::star::uno::RuntimeException
127 if our our component factory does not support this interface
129 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>
130 getLegacyServiceFactory() const;
132 /** retrieves a value from our component context
134 the name of the value to retrieve
136 the context value with the given name
137 @seealso XComponentContext::getValueByName
138 @seealso getContextValueByAsciiName
140 ::com::sun::star::uno::Any
141 getContextValueByName( const ::rtl::OUString
& _rName
) const;
143 /** retrieves a value from our component context, specified by 8-bit ASCII string
145 the name of the value to retrieve, as ASCII character string
147 the context value with the given name
148 @seealso XComponentContext::getValueByName
149 @seealso getContextValueByName
151 inline ::com::sun::star::uno::Any
152 getContextValueByAsciiName( const sal_Char
* _pAsciiName
) const
154 return getContextValueByName( ::rtl::OUString::createFromAscii( _pAsciiName
) );
157 /** retrieve context to create interfaces by the ctors
159 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> getContext() const { return m_xContext
;}
163 //........................................................................
165 //........................................................................
167 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX