1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pcrcomponentcontext.cxx,v $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "pcrcomponentcontext.hxx"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/lang/NullPointerException.hpp>
37 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 /** === end UNO includes === **/
41 //........................................................................
44 //........................................................................
46 /** === begin UNO using === **/
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::XComponentContext
;
49 using ::com::sun::star::lang::NullPointerException
;
50 using ::com::sun::star::lang::ServiceNotRegisteredException
;
51 using ::com::sun::star::uno::Exception
;
52 using ::com::sun::star::uno::Any
;
53 using ::com::sun::star::uno::XInterface
;
54 using ::com::sun::star::uno::UNO_QUERY_THROW
;
55 using ::com::sun::star::lang::XMultiServiceFactory
;
56 using ::com::sun::star::beans::XPropertySet
;
57 using ::com::sun::star::uno::UNO_QUERY
;
58 using ::com::sun::star::uno::RuntimeException
;
59 /** === end UNO using === **/
61 //====================================================================
63 //====================================================================
64 //--------------------------------------------------------------------
65 ComponentContext::ComponentContext( const Reference
< XComponentContext
>& _rxContext
)
66 :m_xContext( _rxContext
)
68 if ( m_xContext
.is() )
69 m_xORB
= m_xContext
->getServiceManager();
71 throw NullPointerException();
74 //------------------------------------------------------------------------
75 Any
ComponentContext::getContextValueByName( const ::rtl::OUString
& _rName
) const
80 aReturn
= m_xContext
->getValueByName( _rName
);
82 catch( const Exception
& )
84 OSL_ENSURE( sal_False
, "PropertyHandler::getContextValueByName: caught an exception!" );
89 //------------------------------------------------------------------------
90 Reference
< XInterface
> ComponentContext::createComponent( const ::rtl::OUString
& _rServiceName
) const
92 Reference
< XInterface
> xComponent(
93 m_xORB
->createInstanceWithContext( _rServiceName
, m_xContext
)
95 if ( !xComponent
.is() )
96 throw ServiceNotRegisteredException( _rServiceName
, NULL
);
100 //------------------------------------------------------------------------
101 Reference
< XMultiServiceFactory
> ComponentContext::getLegacyServiceFactory() const
103 return Reference
< XMultiServiceFactory
>( m_xORB
, UNO_QUERY_THROW
);
106 //........................................................................
108 //........................................................................