2006-07-10 15:15:21 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
|
|
*
|
|
|
|
* $RCSfile: componentcontext.cxx,v $
|
|
|
|
*
|
2006-09-17 16:10:11 +00:00
|
|
|
* $Revision: 1.4 $
|
2006-07-10 15:15:21 +00:00
|
|
|
*
|
2006-09-17 16:10:11 +00:00
|
|
|
* last change: $Author: obo $ $Date: 2006-09-17 17:10:11 $
|
2006-07-10 15:15:21 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 16:10:11 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_comphelper.hxx"
|
|
|
|
|
2006-07-10 15:15:21 +00:00
|
|
|
#ifndef COMPHELPER_COMPONENTCONTEXT_HXX
|
|
|
|
#include <comphelper/componentcontext.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** === begin UNO includes === **/
|
|
|
|
#ifndef _COM_SUN_STAR_LANG_NULLPOINTEREXCEPTION_HPP_
|
|
|
|
#include <com/sun/star/lang/NullPointerException.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_LANG_SERVICENOTREGISTEREDEXCEPTION_HPP_
|
|
|
|
#include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#endif
|
|
|
|
/** === end UNO includes === **/
|
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
namespace comphelper
|
|
|
|
{
|
|
|
|
//........................................................................
|
|
|
|
|
|
|
|
/** === begin UNO using === **/
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::uno::XComponentContext;
|
|
|
|
using ::com::sun::star::lang::NullPointerException;
|
|
|
|
using ::com::sun::star::lang::ServiceNotRegisteredException;
|
|
|
|
using ::com::sun::star::uno::Exception;
|
|
|
|
using ::com::sun::star::uno::Any;
|
|
|
|
using ::com::sun::star::uno::XInterface;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY_THROW;
|
|
|
|
using ::com::sun::star::lang::XMultiServiceFactory;
|
|
|
|
using ::com::sun::star::beans::XPropertySet;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
|
|
|
using ::com::sun::star::uno::RuntimeException;
|
|
|
|
/** === end UNO using === **/
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
//= ComponentContext
|
|
|
|
//====================================================================
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
ComponentContext::ComponentContext( const Reference< XComponentContext >& _rxContext )
|
|
|
|
:m_xContext( _rxContext )
|
|
|
|
{
|
|
|
|
if ( m_xContext.is() )
|
|
|
|
m_xORB = m_xContext->getServiceManager();
|
|
|
|
if ( !m_xORB.is() )
|
|
|
|
throw NullPointerException();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
ComponentContext::ComponentContext( const Reference< XMultiServiceFactory >& _rxLegacyFactory )
|
|
|
|
{
|
|
|
|
if ( !_rxLegacyFactory.is() )
|
|
|
|
throw NullPointerException();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference< XPropertySet > xFactoryProperties( _rxLegacyFactory, UNO_QUERY_THROW );
|
|
|
|
m_xContext = Reference< XComponentContext >(
|
|
|
|
xFactoryProperties->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ),
|
|
|
|
UNO_QUERY );
|
|
|
|
}
|
|
|
|
catch( const RuntimeException& ) { throw; }
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
throw RuntimeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_xContext.is() )
|
|
|
|
m_xORB = m_xContext->getServiceManager();
|
|
|
|
if ( !m_xORB.is() )
|
|
|
|
throw NullPointerException();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
Any ComponentContext::getContextValueByName( const ::rtl::OUString& _rName ) const
|
|
|
|
{
|
|
|
|
Any aReturn;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
aReturn = m_xContext->getValueByName( _rName );
|
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( sal_False, "ComponentContext::getContextValueByName: caught an exception!" );
|
|
|
|
}
|
|
|
|
return aReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
Reference< XInterface > ComponentContext::createComponent( const ::rtl::OUString& _rServiceName ) const
|
|
|
|
{
|
|
|
|
Reference< XInterface > xComponent(
|
|
|
|
m_xORB->createInstanceWithContext( _rServiceName, m_xContext )
|
|
|
|
);
|
|
|
|
if ( !xComponent.is() )
|
|
|
|
throw ServiceNotRegisteredException( _rServiceName, NULL );
|
|
|
|
return xComponent;
|
|
|
|
}
|
|
|
|
|
2006-08-28 14:10:34 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
Reference< XInterface > ComponentContext::getSingleton( const ::rtl::OUString& _rInstanceName )
|
|
|
|
{
|
|
|
|
::rtl::OUString sKey( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/" ) ) );
|
|
|
|
sKey += _rInstanceName;
|
|
|
|
return Reference< XInterface >( getContextValueByName( sKey ), UNO_QUERY );
|
|
|
|
}
|
|
|
|
|
2006-07-10 15:15:21 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
Reference< XMultiServiceFactory > ComponentContext::getLegacyServiceFactory() const
|
|
|
|
{
|
|
|
|
return Reference< XMultiServiceFactory >( m_xORB, UNO_QUERY_THROW );
|
|
|
|
}
|
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
} // namespace comphelper
|
|
|
|
//........................................................................
|
|
|
|
|