Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "pcrcomponentcontext.hxx"
30 : :
31 : : #include <com/sun/star/lang/NullPointerException.hpp>
32 : : #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
33 : : #include <com/sun/star/beans/XPropertySet.hpp>
34 : :
35 : : //........................................................................
36 : : namespace pcr
37 : : {
38 : : //........................................................................
39 : :
40 : : /** === begin UNO using === **/
41 : : using ::com::sun::star::uno::Reference;
42 : : using ::com::sun::star::uno::XComponentContext;
43 : : using ::com::sun::star::lang::NullPointerException;
44 : : using ::com::sun::star::lang::ServiceNotRegisteredException;
45 : : using ::com::sun::star::uno::Exception;
46 : : using ::com::sun::star::uno::Any;
47 : : using ::com::sun::star::uno::XInterface;
48 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
49 : : using ::com::sun::star::lang::XMultiServiceFactory;
50 : : using ::com::sun::star::beans::XPropertySet;
51 : : using ::com::sun::star::uno::UNO_QUERY;
52 : : using ::com::sun::star::uno::RuntimeException;
53 : : /** === end UNO using === **/
54 : :
55 : : //====================================================================
56 : : //= ComponentContext
57 : : //====================================================================
58 : : //--------------------------------------------------------------------
59 : 0 : ComponentContext::ComponentContext( const Reference< XComponentContext >& _rxContext )
60 : 0 : :m_xContext( _rxContext )
61 : : {
62 : 0 : if ( m_xContext.is() )
63 : 0 : m_xORB = m_xContext->getServiceManager();
64 : 0 : if ( !m_xORB.is() )
65 : 0 : throw NullPointerException();
66 : 0 : }
67 : :
68 : : //------------------------------------------------------------------------
69 : 0 : Any ComponentContext::getContextValueByName( const ::rtl::OUString& _rName ) const
70 : : {
71 : 0 : Any aReturn;
72 : : try
73 : : {
74 : 0 : aReturn = m_xContext->getValueByName( _rName );
75 : : }
76 : 0 : catch( const Exception& )
77 : : {
78 : : OSL_FAIL( "PropertyHandler::getContextValueByName: caught an exception!" );
79 : : }
80 : 0 : return aReturn;
81 : : }
82 : :
83 : : //------------------------------------------------------------------------
84 : 0 : Reference< XInterface > ComponentContext::createComponent( const ::rtl::OUString& _rServiceName ) const
85 : : {
86 : : Reference< XInterface > xComponent(
87 : 0 : m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
88 : 0 : );
89 : 0 : if ( !xComponent.is() )
90 : 0 : throw ServiceNotRegisteredException( _rServiceName, NULL );
91 : 0 : return xComponent;
92 : : }
93 : :
94 : : //------------------------------------------------------------------------
95 : 0 : Reference< XMultiServiceFactory > ComponentContext::getLegacyServiceFactory() const
96 : : {
97 : 0 : return Reference< XMultiServiceFactory >( m_xORB, UNO_QUERY_THROW );
98 : : }
99 : :
100 : : //........................................................................
101 : : } // namespace pcr
102 : : //........................................................................
103 : :
104 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|