merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / propctrlr / pcrcomponentcontext.hxx
blobddec5688613700ba4e7d57a51c83b10e39cbb040
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 //........................................................................
37 namespace pcr
39 //........................................................................
41 //====================================================================
42 //= ComponentContext
43 //====================================================================
44 /** a helper class for working with a component context
46 class ComponentContext
48 private:
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;
52 public:
53 /** constructs an instance
54 @param _rxContext
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
75 @return
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
90 @return
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
103 @throws Exception
104 if an exception occured during creating the component
105 @return
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
114 @throws Exception
115 if an exception occured during creating the component
116 @return
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
133 @param _rName
134 the name of the value to retrieve
135 @return
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
144 @param _rName
145 the name of the value to retrieve, as ASCII character string
146 @return
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 //........................................................................
164 } // namespace pcr
165 //........................................................................
167 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX