22#include <com/sun/star/frame/UnknownModuleException.hpp>
23#include <com/sun/star/frame/XFrame.hpp>
24#include <com/sun/star/frame/XController.hpp>
25#include <com/sun/star/frame/XModel.hpp>
26#include <com/sun/star/frame/XModule.hpp>
27#include <com/sun/star/lang/XServiceInfo.hpp>
28#include <com/sun/star/frame/XModuleManager2.hpp>
29#include <com/sun/star/container/XNameReplace.hpp>
30#include <com/sun/star/container/XContainerQuery.hpp>
31#include <com/sun/star/uno/XComponentContext.hpp>
45 public cppu::WeakImplHelper<
46 css::lang::XServiceInfo,
47 css::frame::XModuleManager2,
48 css::container::XContainerQuery >
55 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
61 css::uno::Reference< css::container::XNameAccess > m_xCFG;
65 explicit ModuleManager(css::uno::Reference< css::uno::XComponentContext > xContext);
67 ModuleManager(
const ModuleManager&) =
delete;
68 ModuleManager& operator=(
const ModuleManager&) =
delete;
74 OUString
const & ServiceName)
override;
76 virtual css::uno::Sequence< OUString > SAL_CALL
80 virtual OUString SAL_CALL identify(
const css::uno::Reference< css::uno::XInterface >& xModule)
override;
83 virtual void SAL_CALL replaceByName(
const OUString& sName ,
84 const css::uno::Any& aValue)
override;
87 virtual css::uno::Any SAL_CALL getByName(
const OUString& sName)
override;
89 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames()
override;
91 virtual sal_Bool SAL_CALL hasByName(
const OUString& sName)
override;
94 virtual css::uno::Type SAL_CALL getElementType()
override;
96 virtual sal_Bool SAL_CALL hasElements()
override;
99 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByQuery(
const OUString& sQuery)
override;
101 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByProperties(
const css::uno::Sequence< css::beans::NamedValue >& lProperties)
override;
125 OUString implts_identify(
const css::uno::Reference< css::uno::XInterface >& xComponent);
128ModuleManager::ModuleManager(css::uno::Reference< css::uno::XComponentContext > xContext)
134 m_xContext,
"/org.openoffice.Setup/Office/Factories",
136 css::uno::UNO_QUERY_THROW );
140OUString ModuleManager::getImplementationName()
142 return "com.sun.star.comp.framework.ModuleManager";
145sal_Bool ModuleManager::supportsService(OUString
const & ServiceName)
150css::uno::Sequence< OUString > ModuleManager::getSupportedServiceNames()
152 return {
"com.sun.star.frame.ModuleManager" };
155OUString SAL_CALL ModuleManager::identify(
const css::uno::Reference< css::uno::XInterface >& xModule)
158 css::uno::Reference< css::frame::XFrame >
xFrame (xModule, css::uno::UNO_QUERY);
159 css::uno::Reference< css::awt::XWindow > xWindow (xModule, css::uno::UNO_QUERY);
160 css::uno::Reference< css::frame::XController >
xController(xModule, css::uno::UNO_QUERY);
161 css::uno::Reference< css::frame::XModel >
xModel (xModule, css::uno::UNO_QUERY);
170 throw css::lang::IllegalArgumentException(
171 "Given module is not a frame nor a window, controller or model.",
179 xWindow =
xFrame->getComponentWindow();
191 sModule = implts_identify(xModel);
193 sModule = implts_identify(xController);
194 else if (xWindow.is())
195 sModule = implts_identify(xWindow);
197 if (sModule.isEmpty())
198 throw css::frame::UnknownModuleException(
199 "Can not find suitable module for the given component.",
205void SAL_CALL ModuleManager::replaceByName(
const OUString& sName ,
206 const css::uno::Any& aValue)
211 throw css::lang::IllegalArgumentException(
212 "No properties given to replace part of module.",
224 "/org.openoffice.Setup/Office/Factories",
226 css::uno::Reference< css::container::XNameAccess > xModules (xCfg, css::uno::UNO_QUERY_THROW);
227 css::uno::Reference< css::container::XNameReplace > xModule ;
229 xModules->getByName(sName) >>= xModule;
232 throw css::uno::RuntimeException(
233 "Was not able to get write access to the requested module entry inside configuration.",
237 for (
auto const& prop : lProps)
241 xModule->replaceByName(prop.first.maString, prop.second);
247css::uno::Any SAL_CALL ModuleManager::getByName(
const OUString& sName)
250 css::uno::Reference< css::container::XNameAccess > xModule;
252 m_xCFG->getByName(sName) >>= xModule;
255 throw css::uno::RuntimeException(
256 "Was not able to get write access to the requested module entry inside configuration.",
261 const css::uno::Sequence< OUString > lPropNames = xModule->getElementNames();
264 lProps[OUString(
"ooSetupFactoryModuleIdentifier")] <<=
sName;
265 for (
const OUString& sPropName : lPropNames)
267 lProps[sPropName] = xModule->getByName(sPropName);
273css::uno::Sequence< OUString > SAL_CALL ModuleManager::getElementNames()
275 return m_xCFG ? m_xCFG->getElementNames() : css::uno::Sequence<OUString>();
278sal_Bool SAL_CALL ModuleManager::hasByName(
const OUString& sName)
280 return m_xCFG && m_xCFG->hasByName(sName);
283css::uno::Type SAL_CALL ModuleManager::getElementType()
288sal_Bool SAL_CALL ModuleManager::hasElements()
290 return m_xCFG && m_xCFG->hasElements();
293css::uno::Reference< css::container::XEnumeration > SAL_CALL ModuleManager::createSubSetEnumerationByQuery(
const OUString&)
295 return css::uno::Reference< css::container::XEnumeration >();
298css::uno::Reference< css::container::XEnumeration > SAL_CALL ModuleManager::createSubSetEnumerationByProperties(
const css::uno::Sequence< css::beans::NamedValue >& lProperties)
301 const css::uno::Sequence< OUString > lModules = getElementNames();
302 ::std::vector< css::uno::Any > lResult;
304 for (
const OUString& rModuleName : lModules)
309 if (lModuleProps.
match(lSearchProps))
312 catch(
const css::uno::Exception&)
320OUString ModuleManager::implts_identify(
const css::uno::Reference< css::uno::XInterface >& xComponent)
325 css::uno::Reference< css::frame::XModule > xModule(xComponent, css::uno::UNO_QUERY);
327 return xModule->getIdentifier();
331 css::uno::Reference< css::lang::XServiceInfo > xInfo(xComponent, css::uno::UNO_QUERY);
335 const css::uno::Sequence< OUString > lKnownModules = getElementNames();
336 for (
const OUString& rName : lKnownModules)
338 if (xInfo->supportsService(rName))
347extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
349 css::uno::XComponentContext *context,
350 css::uno::Sequence<css::uno::Any>
const &)
352 return cppu::acquire(
new ModuleManager(context));
static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &sPackage, EConfigurationModes eMode)
static void flush(const css::uno::Reference< css::uno::XInterface > &xCFG)
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
bool match(const SequenceAsHashMap &rCheck) const
css::uno::Reference< css::uno::XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_ModuleManager_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel