1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include "pcrcomponentcontext.hxx"
22 #include <com/sun/star/lang/NullPointerException.hpp>
23 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
26 //........................................................................
29 //........................................................................
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::XComponentContext
;
33 using ::com::sun::star::lang::NullPointerException
;
34 using ::com::sun::star::lang::ServiceNotRegisteredException
;
35 using ::com::sun::star::uno::Exception
;
36 using ::com::sun::star::uno::Any
;
37 using ::com::sun::star::uno::XInterface
;
38 using ::com::sun::star::uno::UNO_QUERY_THROW
;
39 using ::com::sun::star::lang::XMultiServiceFactory
;
40 using ::com::sun::star::beans::XPropertySet
;
41 using ::com::sun::star::uno::UNO_QUERY
;
42 using ::com::sun::star::uno::RuntimeException
;
44 //====================================================================
46 //====================================================================
47 //--------------------------------------------------------------------
48 ComponentContext::ComponentContext( const Reference
< XComponentContext
>& _rxContext
)
49 :m_xContext( _rxContext
)
51 if ( m_xContext
.is() )
52 m_xORB
= m_xContext
->getServiceManager();
54 throw NullPointerException();
57 //------------------------------------------------------------------------
58 Any
ComponentContext::getContextValueByName( const OUString
& _rName
) const
63 aReturn
= m_xContext
->getValueByName( _rName
);
65 catch( const Exception
& )
67 OSL_FAIL( "PropertyHandler::getContextValueByName: caught an exception!" );
72 //------------------------------------------------------------------------
73 Reference
< XInterface
> ComponentContext::createComponent( const OUString
& _rServiceName
) const
75 Reference
< XInterface
> xComponent(
76 m_xORB
->createInstanceWithContext( _rServiceName
, m_xContext
)
78 if ( !xComponent
.is() )
79 throw ServiceNotRegisteredException( _rServiceName
, NULL
);
83 //------------------------------------------------------------------------
84 Reference
< XMultiServiceFactory
> ComponentContext::getLegacyServiceFactory() const
86 return Reference
< XMultiServiceFactory
>( m_xORB
, UNO_QUERY_THROW
);
89 //........................................................................
91 //........................................................................
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */