update credits
[LibreOffice.git] / extensions / source / propctrlr / pcrcomponentcontext.hxx
blobe26a675e6d1bd16e246c859ffb01dbd3e8186075
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
21 #define EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 //........................................................................
27 namespace pcr
29 //........................................................................
31 //====================================================================
32 //= ComponentContext
33 //====================================================================
34 /** a helper class for working with a component context
36 class ComponentContext
38 private:
39 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
40 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiComponentFactory > m_xORB;
42 public:
43 /** constructs an instance
44 @param _rxContext
45 the component context to manage
46 @throws ::com::sun::star::lang::NullPointerException
47 if the given context, or its component factory, are <NULL/>
49 ComponentContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
51 /** returns the ->XComponentContext interface
53 inline ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
54 getUNOContext() const { return m_xContext; }
56 /** determines whether the context is not <NULL/>
58 inline sal_Bool is() const
60 return m_xContext.is();
63 /** creates a component using our component factory/context
64 @throws ::com::sun::star::uno::Exception
65 @return
66 <TRUE/> if and only if the component could be successfully created
68 template < class INTERFACE >
69 bool createComponent( const OUString& _rServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const
71 _out_rxComponent.clear();
72 _out_rxComponent = _out_rxComponent.query(
73 m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
75 return _out_rxComponent.is();
78 /** creates a component using our component factory/context
79 @throws ::com::sun::star::uno::Exception
80 @return
81 <TRUE/> if and only if the component could be successfully created
83 template < class INTERFACE >
84 bool createComponent( const sal_Char* _pAsciiServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const
86 return createComponent( OUString::createFromAscii( _pAsciiServiceName ), _out_rxComponent );
89 /** creates a component using our component factory/context
91 @throws ::com::sun::star::lang::ServiceNotRegisteredException
92 if the given service is not registered
93 @throws Exception
94 if an exception occurred during creating the component
95 @return
96 the newly created component. Is never <NULL/>.
98 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const OUString& _rServiceName ) const;
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 occurred 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 sal_Char* _pAsciiServiceName ) const
111 return createComponent( OUString::createFromAscii( _pAsciiServiceName ) );
114 /** returns the ->XMultiServiceFactory interface of ->m_xORB, for passing to
115 older code which does not yet support ->XMultiComponentFactory
116 @throws ::com::sun::star::uno::RuntimeException
117 if our our component factory does not support this interface
119 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
120 getLegacyServiceFactory() const;
122 /** retrieves a value from our component context
123 @param _rName
124 the name of the value to retrieve
125 @return
126 the context value with the given name
127 @seealso XComponentContext::getValueByName
128 @seealso getContextValueByAsciiName
130 ::com::sun::star::uno::Any
131 getContextValueByName( const OUString& _rName ) const;
133 /** retrieves a value from our component context, specified by 8-bit ASCII string
134 @param _rName
135 the name of the value to retrieve, as ASCII character string
136 @return
137 the context value with the given name
138 @seealso XComponentContext::getValueByName
139 @seealso getContextValueByName
141 inline ::com::sun::star::uno::Any
142 getContextValueByAsciiName( const sal_Char* _pAsciiName ) const
144 return getContextValueByName( OUString::createFromAscii( _pAsciiName ) );
147 /** retrieve context to create interfaces by the ctors
149 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > getContext() const { return m_xContext;}
153 //........................................................................
154 } // namespace pcr
155 //........................................................................
157 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */