merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / extensions / source / propctrlr / pcrcomponentcontext.hxx
blob41ec8c4941968308d15d06c8966f055d9cd144f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
30 #define EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
32 /** === begin UNO includes === **/
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 /** === end UNO includes === **/
37 //........................................................................
38 namespace pcr
40 //........................................................................
42 //====================================================================
43 //= ComponentContext
44 //====================================================================
45 /** a helper class for working with a component context
47 class ComponentContext
49 private:
50 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
51 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiComponentFactory > m_xORB;
53 public:
54 /** constructs an instance
55 @param _rxContext
56 the component context to manage
57 @throws ::com::sun::star::lang::NullPointerException
58 if the given context, or its component factory, are <NULL/>
60 ComponentContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
62 /** returns the ->XComponentContext interface
64 inline ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
65 getUNOContext() const { return m_xContext; }
67 /** determines whether the context is not <NULL/>
69 inline sal_Bool is() const
71 return m_xContext.is();
74 /** creates a component using our component factory/context
75 @throws ::com::sun::star::uno::Exception
76 @return
77 <TRUE/> if and only if the component could be successfully created
79 template < class INTERFACE >
80 bool createComponent( const ::rtl::OUString& _rServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const
82 _out_rxComponent.clear();
83 _out_rxComponent = _out_rxComponent.query(
84 m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
86 return _out_rxComponent.is();
89 /** creates a component using our component factory/context
90 @throws ::com::sun::star::uno::Exception
91 @return
92 <TRUE/> if and only if the component could be successfully created
94 template < class INTERFACE >
95 bool createComponent( const sal_Char* _pAsciiServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const
97 return createComponent( ::rtl::OUString::createFromAscii( _pAsciiServiceName ), _out_rxComponent );
100 /** creates a component using our component factory/context
102 @throws ::com::sun::star::lang::ServiceNotRegisteredException
103 if the given service is not registered
104 @throws Exception
105 if an exception occured during creating the component
106 @return
107 the newly created component. Is never <NULL/>.
109 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const ::rtl::OUString& _rServiceName ) const;
111 /** creates a component using our component factory/context
113 @throws ::com::sun::star::lang::ServiceNotRegisteredException
114 if the given service is not registered
115 @throws Exception
116 if an exception occured during creating the component
117 @return
118 the newly created component. Is never <NULL/>.
120 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const sal_Char* _pAsciiServiceName ) const
122 return createComponent( ::rtl::OUString::createFromAscii( _pAsciiServiceName ) );
125 /** returns the ->XMultiServiceFactory interface of ->m_xORB, for passing to
126 older code which does not yet support ->XMultiComponentFactory
127 @throws ::com::sun::star::uno::RuntimeException
128 if our our component factory does not support this interface
130 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
131 getLegacyServiceFactory() const;
133 /** retrieves a value from our component context
134 @param _rName
135 the name of the value to retrieve
136 @return
137 the context value with the given name
138 @seealso XComponentContext::getValueByName
139 @seealso getContextValueByAsciiName
141 ::com::sun::star::uno::Any
142 getContextValueByName( const ::rtl::OUString& _rName ) const;
144 /** retrieves a value from our component context, specified by 8-bit ASCII string
145 @param _rName
146 the name of the value to retrieve, as ASCII character string
147 @return
148 the context value with the given name
149 @seealso XComponentContext::getValueByName
150 @seealso getContextValueByName
152 inline ::com::sun::star::uno::Any
153 getContextValueByAsciiName( const sal_Char* _pAsciiName ) const
155 return getContextValueByName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
158 /** retrieve context to create interfaces by the ctors
160 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > getContext() const { return m_xContext;}
164 //........................................................................
165 } // namespace pcr
166 //........................................................................
168 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */