merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / propctrlr / pcrcomponentcontext.hxx
blob9d1edae7adb500c60010413aec80e235f8ddb05b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pcrcomponentcontext.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
32 #define EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX
34 /** === begin UNO includes === **/
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 /** === end UNO includes === **/
39 //........................................................................
40 namespace pcr
42 //........................................................................
44 //====================================================================
45 //= ComponentContext
46 //====================================================================
47 /** a helper class for working with a component context
49 class ComponentContext
51 private:
52 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
53 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiComponentFactory > m_xORB;
55 public:
56 /** constructs an instance
57 @param _rxContext
58 the component context to manage
59 @throws ::com::sun::star::lang::NullPointerException
60 if the given context, or its component factory, are <NULL/>
62 ComponentContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
64 /** returns the ->XComponentContext interface
66 inline ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
67 getUNOContext() const { return m_xContext; }
69 /** determines whether the context is not <NULL/>
71 inline sal_Bool is() const
73 return m_xContext.is();
76 /** creates a component using our component factory/context
77 @throws ::com::sun::star::uno::Exception
78 @return
79 <TRUE/> if and only if the component could be successfully created
81 template < class INTERFACE >
82 bool createComponent( const ::rtl::OUString& _rServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const
84 _out_rxComponent.clear();
85 _out_rxComponent = _out_rxComponent.query(
86 m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
88 return _out_rxComponent.is();
91 /** creates a component using our component factory/context
92 @throws ::com::sun::star::uno::Exception
93 @return
94 <TRUE/> if and only if the component could be successfully created
96 template < class INTERFACE >
97 bool createComponent( const sal_Char* _pAsciiServiceName, ::com::sun::star::uno::Reference< INTERFACE >& _out_rxComponent ) const
99 return createComponent( ::rtl::OUString::createFromAscii( _pAsciiServiceName ), _out_rxComponent );
102 /** creates a component using our component factory/context
104 @throws ::com::sun::star::lang::ServiceNotRegisteredException
105 if the given service is not registered
106 @throws Exception
107 if an exception occured during creating the component
108 @return
109 the newly created component. Is never <NULL/>.
111 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const ::rtl::OUString& _rServiceName ) const;
113 /** creates a component using our component factory/context
115 @throws ::com::sun::star::lang::ServiceNotRegisteredException
116 if the given service is not registered
117 @throws Exception
118 if an exception occured during creating the component
119 @return
120 the newly created component. Is never <NULL/>.
122 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createComponent( const sal_Char* _pAsciiServiceName ) const
124 return createComponent( ::rtl::OUString::createFromAscii( _pAsciiServiceName ) );
127 /** returns the ->XMultiServiceFactory interface of ->m_xORB, for passing to
128 older code which does not yet support ->XMultiComponentFactory
129 @throws ::com::sun::star::uno::RuntimeException
130 if our our component factory does not support this interface
132 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
133 getLegacyServiceFactory() const;
135 /** retrieves a value from our component context
136 @param _rName
137 the name of the value to retrieve
138 @return
139 the context value with the given name
140 @seealso XComponentContext::getValueByName
141 @seealso getContextValueByAsciiName
143 ::com::sun::star::uno::Any
144 getContextValueByName( const ::rtl::OUString& _rName ) const;
146 /** retrieves a value from our component context, specified by 8-bit ASCII string
147 @param _rName
148 the name of the value to retrieve, as ASCII character string
149 @return
150 the context value with the given name
151 @seealso XComponentContext::getValueByName
152 @seealso getContextValueByName
154 inline ::com::sun::star::uno::Any
155 getContextValueByAsciiName( const sal_Char* _pAsciiName ) const
157 return getContextValueByName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
160 /** retrieve context to create interfaces by the ctors
162 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > getContext() const { return m_xContext;}
166 //........................................................................
167 } // namespace pcr
168 //........................................................................
170 #endif // EXTENSIONS_SOURCE_PROPCTRLR_PCROMPONENTCONTEXT_HXX