1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 #include "pcrcomponentcontext.hxx"
27 
28 /** === begin UNO includes === **/
29 #include <com/sun/star/lang/NullPointerException.hpp>
30 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 /** === end UNO includes === **/
33 
34 //........................................................................
35 namespace pcr
36 {
37 //........................................................................
38 
39     /** === begin UNO using === **/
40     using ::com::sun::star::uno::Reference;
41     using ::com::sun::star::uno::XComponentContext;
42     using ::com::sun::star::lang::NullPointerException;
43     using ::com::sun::star::lang::ServiceNotRegisteredException;
44     using ::com::sun::star::uno::Exception;
45     using ::com::sun::star::uno::Any;
46     using ::com::sun::star::uno::XInterface;
47     using ::com::sun::star::uno::UNO_QUERY_THROW;
48     using ::com::sun::star::lang::XMultiServiceFactory;
49     using ::com::sun::star::beans::XPropertySet;
50     using ::com::sun::star::uno::UNO_QUERY;
51     using ::com::sun::star::uno::RuntimeException;
52     /** === end UNO using === **/
53 
54     //====================================================================
55 	//= ComponentContext
56 	//====================================================================
57 	//--------------------------------------------------------------------
ComponentContext(const Reference<XComponentContext> & _rxContext)58     ComponentContext::ComponentContext( const Reference< XComponentContext >& _rxContext )
59         :m_xContext( _rxContext )
60     {
61         if ( m_xContext.is() )
62             m_xORB = m_xContext->getServiceManager();
63         if ( !m_xORB.is() )
64             throw NullPointerException();
65     }
66 
67     //------------------------------------------------------------------------
getContextValueByName(const::rtl::OUString & _rName) const68     Any ComponentContext::getContextValueByName( const ::rtl::OUString& _rName ) const
69     {
70         Any aReturn;
71         try
72         {
73             aReturn = m_xContext->getValueByName( _rName );
74         }
75         catch( const Exception& )
76         {
77             OSL_ENSURE( sal_False, "PropertyHandler::getContextValueByName: caught an exception!" );
78         }
79         return aReturn;
80     }
81 
82     //------------------------------------------------------------------------
createComponent(const::rtl::OUString & _rServiceName) const83     Reference< XInterface > ComponentContext::createComponent( const ::rtl::OUString& _rServiceName ) const
84     {
85         Reference< XInterface > xComponent(
86             m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
87         );
88         if ( !xComponent.is() )
89             throw ServiceNotRegisteredException( _rServiceName, NULL );
90         return xComponent;
91     }
92 
93     //------------------------------------------------------------------------
getLegacyServiceFactory() const94     Reference< XMultiServiceFactory > ComponentContext::getLegacyServiceFactory() const
95     {
96         return Reference< XMultiServiceFactory >( m_xORB, UNO_QUERY_THROW );
97     }
98 
99 //........................................................................
100 } // namespace pcr
101 //........................................................................
102 
103