24#include <com/sun/star/container/XContentEnumerationAccess.hpp>
25#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
42 ENSURE_OR_THROW( m_xMgr.is(),
"ProviderCache::ProviderCache() failed to obtain ServiceManager" );
54 ENSURE_OR_THROW( m_xMgr.is(),
"ProviderCache::ProviderCache() failed to obtain ServiceManager" );
58ProviderCache::~ProviderCache()
63ProviderCache::getProvider(
const OUString& providerName )
65 std::scoped_lock aGuard(
m_mutex );
67 ProviderDetails_hash::iterator h_it = m_hProviderDetailsCache.find( providerName );
68 if ( h_it != m_hProviderDetailsCache.end() )
70 if ( h_it->second.provider.is() )
72 provider = h_it->second.provider;
77 provider = createProvider( h_it->second );
84ProviderCache::getAllProviders()
89 std::scoped_lock aGuard(
m_mutex );
92 if ( !m_hProviderDetailsCache.empty() )
94 auto pproviders = providers.getArray();
95 sal_Int32 providerIndex = 0;
96 for (
auto& rDetail : m_hProviderDetailsCache)
99 if ( xScriptProvider.is() )
101 pproviders[ providerIndex++ ] = xScriptProvider;
108 xScriptProvider = createProvider(rDetail.second);
109 pproviders[ providerIndex++ ] = xScriptProvider;
118 if (providerIndex < providers.getLength())
120 providers.realloc( providerIndex );
126 SAL_WARN(
"scripting",
"no available providers, something very wrong!!!");
132ProviderCache::populateCache()
135 OUString serviceName;
136 std::scoped_lock aGuard(
m_mutex );
142 while ( xEnum->hasMoreElements() )
150 if ( serviceNames.hasElements() )
152 auto pName = std::find_if(serviceNames.begin(), serviceNames.end(),
153 [
this](
const OUString& rName) {
154 return rName.startsWith(
"com.sun.star.script.provider.ScriptProviderFor")
155 && !isInDenyList(rName);
157 if (
pName != serviceNames.end())
159 serviceName = *
pName;
162 m_hProviderDetailsCache[ serviceName ] = details;
170 throw css::lang::WrappedTargetRuntimeException(
171 "ProviderCache::populateCache: couldn't obtain XSingleComponentFactory for " + serviceName
183 details.
factory->createInstanceWithArgumentsAndContext( m_Sctx,
m_xContext ), UNO_QUERY_THROW );
188 throw css::lang::WrappedTargetRuntimeException(
189 "ProviderCache::createProvider() Error creating provider from factory. " + e.Message,
197ProviderCache::isInDenyList(
const OUString& serviceName )
const
Reference< XComponentContext > m_xContext
ProviderCache(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Sequence< css::uno::Any > &scriptContext)
#define ENSURE_OR_THROW(c, m)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
Any SAL_CALL getCaughtException()
css::uno::Reference< css::lang::XSingleComponentFactory > factory
css::uno::Reference< css::script::provider::XScriptProvider > provider