1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "pcrcomponentcontext.hxx"
31 
32 /** === begin UNO includes === **/
33 #include <com/sun/star/lang/NullPointerException.hpp>
34 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 /** === end UNO includes === **/
37 
38 //........................................................................
39 namespace pcr
40 {
41 //........................................................................
42 
43     /** === begin UNO using === **/
44     using ::com::sun::star::uno::Reference;
45     using ::com::sun::star::uno::XComponentContext;
46     using ::com::sun::star::lang::NullPointerException;
47     using ::com::sun::star::lang::ServiceNotRegisteredException;
48     using ::com::sun::star::uno::Exception;
49     using ::com::sun::star::uno::Any;
50     using ::com::sun::star::uno::XInterface;
51     using ::com::sun::star::uno::UNO_QUERY_THROW;
52     using ::com::sun::star::lang::XMultiServiceFactory;
53     using ::com::sun::star::beans::XPropertySet;
54     using ::com::sun::star::uno::UNO_QUERY;
55     using ::com::sun::star::uno::RuntimeException;
56     /** === end UNO using === **/
57 
58     //====================================================================
59 	//= ComponentContext
60 	//====================================================================
61 	//--------------------------------------------------------------------
62     ComponentContext::ComponentContext( const Reference< XComponentContext >& _rxContext )
63         :m_xContext( _rxContext )
64     {
65         if ( m_xContext.is() )
66             m_xORB = m_xContext->getServiceManager();
67         if ( !m_xORB.is() )
68             throw NullPointerException();
69     }
70 
71     //------------------------------------------------------------------------
72     Any ComponentContext::getContextValueByName( const ::rtl::OUString& _rName ) const
73     {
74         Any aReturn;
75         try
76         {
77             aReturn = m_xContext->getValueByName( _rName );
78         }
79         catch( const Exception& )
80         {
81             OSL_ENSURE( sal_False, "PropertyHandler::getContextValueByName: caught an exception!" );
82         }
83         return aReturn;
84     }
85 
86     //------------------------------------------------------------------------
87     Reference< XInterface > ComponentContext::createComponent( const ::rtl::OUString& _rServiceName ) const
88     {
89         Reference< XInterface > xComponent(
90             m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
91         );
92         if ( !xComponent.is() )
93             throw ServiceNotRegisteredException( _rServiceName, NULL );
94         return xComponent;
95     }
96 
97     //------------------------------------------------------------------------
98     Reference< XMultiServiceFactory > ComponentContext::getLegacyServiceFactory() const
99     {
100         return Reference< XMultiServiceFactory >( m_xORB, UNO_QUERY_THROW );
101     }
102 
103 //........................................................................
104 } // namespace pcr
105 //........................................................................
106 
107