27#include <com/sun/star/beans/PropertyValue.hpp>
28#include <com/sun/star/beans/XPropertySet.hpp>
29#include <com/sun/star/configuration/theDefaultProvider.hpp>
30#include <com/sun/star/container/ElementExistException.hpp>
31#include <com/sun/star/container/XContainer.hpp>
32#include <com/sun/star/container/XContainerListener.hpp>
33#include <com/sun/star/lang/XServiceInfo.hpp>
34#include <com/sun/star/loader/CannotActivateFactoryException.hpp>
35#include <com/sun/star/frame/ModuleManager.hpp>
36#include <com/sun/star/frame/UnknownModuleException.hpp>
37#include <com/sun/star/frame/XFrame.hpp>
38#include <com/sun/star/frame/XModuleManager2.hpp>
39#include <com/sun/star/ui/XUIElementFactoryManager.hpp>
62static OUString
getHashKeyFromStrings( std::u16string_view aType, std::u16string_view aName, std::u16string_view aModuleName )
64 return OUString::Concat(aType) +
"^" +
aName +
"^" + aModuleName;
68 m_aPropType(
"Type" ),
69 m_aPropName(
"Name" ),
70 m_aPropModule(
"Module" ),
71 m_aPropFactory(
"FactoryImplementation" ),
72 m_sRoot(
std::move(_sRoot)),
84 if ( xContainer.is() )
93 FactoryManagerMap::const_iterator pIter =
102 return pIter->second;
106 size_t nIndex = rName.find(
'_' );
109 std::u16string_view
aName = rName.substr( 0,
nIndex+1 );
112 return pIter->second;
117 return pIter->second;
134 throw ElementExistException();
148 throw NoSuchElementException();
162 OUString aFactory = rEntry.first;
163 if ( !aFactory.isEmpty() )
167 aSeqSeq.realloc( aSeqSeq.getLength() + 1 );
175 aFactory.getToken( 0,
'^',
nToken ));
181 aFactory.getToken( 0,
'^',
nToken ));
275 "com.sun.star.configuration.ConfigurationAccess", aArgs ), UNO_QUERY );
277 catch (
const WrappedTargetException& )
294 for ( OUString
const & factoryName : aUIElementFactories )
306 if ( xContainer.is() )
316 aElement >>= xPropertySet;
318 if ( !xPropertySet.is() )
323 xPropertySet->getPropertyValue(
m_aPropType ) >>= rType;
324 xPropertySet->getPropertyValue(
m_aPropName ) >>= rName;
326 xPropertySet->getPropertyValue(
m_aPropFactory ) >>= rServiceSpecifier;
328 catch (
const css::beans::UnknownPropertyException& )
332 catch (
const css::lang::WrappedTargetException& )
345 css::lang::XServiceInfo,
346 css::ui::XUIElementFactoryManager> UIElementFactoryManager_BASE;
348class UIElementFactoryManager :
public UIElementFactoryManager_BASE
350 virtual void disposing(std::unique_lock<std::mutex>&)
override;
352 explicit UIElementFactoryManager(
const css::uno::Reference< css::uno::XComponentContext >& rxContext );
356 return "com.sun.star.comp.framework.UIElementFactoryManager";
366 return {
"com.sun.star.ui.UIElementFactoryManager"};
370 virtual css::uno::Reference< css::ui::XUIElement > SAL_CALL createUIElement(
const OUString& ResourceURL,
const css::uno::Sequence< css::beans::PropertyValue >& Args )
override;
373 virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getRegisteredFactories( )
override;
374 virtual css::uno::Reference< css::ui::XUIElementFactory > SAL_CALL getFactory(
const OUString& ResourceURL,
const OUString& ModuleIdentifier )
override;
375 virtual void SAL_CALL registerFactory(
const OUString& aType,
const OUString& aName,
const OUString& aModuleIdentifier,
const OUString& aFactoryImplementationName )
override;
376 virtual void SAL_CALL deregisterFactory(
const OUString& aType,
const OUString& aName,
const OUString& aModuleIdentifier )
override;
380 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
390 "/org.openoffice.Office.UI.Factories/Registered/UIElementFactories"))
393void UIElementFactoryManager::disposing(std::unique_lock<std::mutex>&)
395 m_pConfigAccess.clear();
400 const OUString& ResourceURL,
408 throw css::lang::DisposedException(
409 "disposed",
static_cast<OWeakObject *
>(
this));
415 m_pConfigAccess->readConfigurationData();
421 for (
auto const & arg : Args )
423 if ( arg.Name ==
"Frame")
425 if (arg.Name ==
"Module")
426 arg.Value >>= aModuleId;
435 if ( aModuleId.isEmpty() &&
xFrame.is() && xManager.is() )
439 if ( xUIElementFactory.is() )
440 return xUIElementFactory->createUIElement( ResourceURL, Args );
442 catch (
const UnknownModuleException& )
446 throw NoSuchElementException();
455 throw css::lang::DisposedException(
456 "disposed",
static_cast<OWeakObject *
>(
this));
462 m_pConfigAccess->readConfigurationData();
465 return m_pConfigAccess->getFactoriesDescription();
470 OUString aServiceSpecifier;
474 throw css::lang::DisposedException(
475 "disposed",
static_cast<OWeakObject *
>(
this));
481 m_pConfigAccess->readConfigurationData();
487 aServiceSpecifier = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
490 if ( !aServiceSpecifier.isEmpty() )
try
493 createInstanceWithContext(aServiceSpecifier,
m_xContext), UNO_QUERY);
494 SAL_WARN_IF(!
xFactory.is(),
"fwk.uielement",
"could not create factory: " << aServiceSpecifier);
497 catch (
const css::loader::CannotActivateFactoryException& )
499 SAL_WARN(
"fwk.uielement", aServiceSpecifier <<
500 " not available. This should happen only on mobile platforms.");
505void SAL_CALL UIElementFactoryManager::registerFactory(
const OUString& aType,
const OUString& aName,
const OUString& aModuleId,
const OUString& aFactoryImplementationName )
510 throw css::lang::DisposedException(
511 "disposed",
static_cast<OWeakObject *
>(
this));
517 m_pConfigAccess->readConfigurationData();
520 m_pConfigAccess->addFactorySpecifierToTypeNameModule( aType, aName, aModuleId, aFactoryImplementationName );
524void SAL_CALL UIElementFactoryManager::deregisterFactory(
const OUString& aType,
const OUString& aName,
const OUString& aModuleId )
529 throw css::lang::DisposedException(
530 "disposed",
static_cast<OWeakObject *
>(
this));
536 m_pConfigAccess->readConfigurationData();
539 m_pConfigAccess->removeFactorySpecifierFromTypeNameModule( aType, aName, aModuleId );
545extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
547 css::uno::XComponentContext *context,
548 css::uno::Sequence<css::uno::Any>
const &)
550 return cppu::acquire(
new UIElementFactoryManager(context));
ConfigurationAccess_FactoryManager(const css::uno::Reference< css::uno::XComponentContext > &rxContext, OUString _sRoot)
bool m_bConfigAccessInitialized
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
css::uno::Reference< css::container::XContainerListener > m_xConfigListener
css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > getFactoriesDescription() const
css::uno::Reference< css::container::XNameAccess > m_xConfigAccess
void removeFactorySpecifierFromTypeNameModule(std::u16string_view rType, std::u16string_view rName, std::u16string_view rModule)
OUString getFactorySpecifierFromTypeNameModule(std::u16string_view rType, std::u16string_view rName, std::u16string_view rModule) const
virtual void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
virtual ~ConfigurationAccess_FactoryManager() override
bool impl_getElementProps(const css::uno::Any &rElement, OUString &rType, OUString &rName, OUString &rModule, OUString &rServiceSpecifier) const
css::uno::Reference< css::lang::XMultiServiceFactory > m_xConfigProvider
void readConfigurationData()
FactoryManagerMap m_aFactoryManagerMap
void addFactorySpecifierToTypeNameModule(std::u16string_view rType, std::u16string_view rName, std::u16string_view rModule, const OUString &aServiceSpecifier)
Reference< XSingleServiceFactory > xFactory
css::uno::Reference< css::uno::XComponentContext > m_xContext
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static OUString getHashKeyFromStrings(std::u16string_view aCommandURL, std::u16string_view aModuleName)
void RetrieveTypeNameFromResourceURL(std::u16string_view aResourceURL, OUString &aType, OUString &aName)
Reference< XFrame > xFrame
bool m_bConfigAccessInitialized
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_UIElementFactoryManager_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)