if (
(!xFrame.is() ) &&
(!xWindow.is() ) &&
(!xController.is()) &&
(!xModel.is() )
)
{ throw css::lang::IllegalArgumentException(
u"Given module is not a frame nor a window, controller or model."_ustr, static_cast< ::cppu::OWeakObject* >(this), 1);
}
if (xFrame.is())
{
xController = xFrame->getController();
xWindow = xFrame->getComponentWindow();
} if (xController.is())
xModel = xController->getModel();
// modules are implemented by the deepest component in hierarchy ... // Means: model -> controller -> window // No fallbacks to higher components are allowed ! // Note : A frame provides access to module components only ... but it's not a module by himself.
if (sModule.isEmpty()) throw css::frame::UnknownModuleException(
u"Can not find suitable module for the given component."_ustr, static_cast< ::cppu::OWeakObject* >(this));
return sModule;
}
void SAL_CALL ModuleManager::replaceByName(const OUString& sName , const css::uno::Any& aValue)
{
::comphelper::SequenceAsHashMap lProps(aValue); if (lProps.empty() )
{ throw css::lang::IllegalArgumentException(
u"No properties given to replace part of module."_ustr, static_cast< cppu::OWeakObject * >(this), 2);
}
// get access to the element // Note: Don't use impl_getConfig() method here. Because it creates a readonly access only, further // it cache it as a member of this module manager instance. If we change some props there ... but don't // flush changes (because an error occurred) we will read them later. If we use a different config access // we can close it without a flush... and our read data won't be affected .-)
css::uno::Reference< css::uno::XInterface > xCfg = ::comphelper::ConfigurationHelper::openConfig(
m_xContext,
u"/org.openoffice.Setup/Office/Factories"_ustr,
::comphelper::EConfigurationModes::Standard);
css::uno::Reference< css::container::XNameAccess > xModules (xCfg, css::uno::UNO_QUERY_THROW);
css::uno::Reference< css::container::XNameReplace > xModule ;
xModules->getByName(sName) >>= xModule; if (!xModule.is())
{ throw css::uno::RuntimeException(
u"Was not able to get write access to the requested module entry inside configuration."_ustr, static_cast< cppu::OWeakObject * >(this));
}
for (autoconst& prop : lProps)
{ // let "NoSuchElementException" out ! We support the same API ... // and without a flush() at the end all changed data before will be ignored !
xModule->replaceByName(prop.first.maString, prop.second);
}
::comphelper::ConfigurationHelper::flush(xCfg);
}
css::uno::Any SAL_CALL ModuleManager::getByName(const OUString& sName)
{ // get access to the element
css::uno::Reference< css::container::XNameAccess > xModule; if (m_xCFG)
m_xCFG->getByName(sName) >>= xModule; if (!xModule.is())
{ throw css::uno::RuntimeException(
u"Was not able to get write access to the requested module entry inside configuration."_ustr, static_cast< cppu::OWeakObject * >(this));
}
// convert it to seq< PropertyValue > const css::uno::Sequence< OUString > lPropNames = xModule->getElementNames();
comphelper::SequenceAsHashMap lProps;
OUString ModuleManager::implts_identify(const css::uno::Reference< css::uno::XInterface >& xComponent)
{ // Search for an optional (!) interface XModule first. // It's used to overrule an existing service name. Used e.g. by our database form designer // which uses a writer module internally.
css::uno::Reference< css::frame::XModule > xModule(xComponent, css::uno::UNO_QUERY); if (xModule.is()) return xModule->getIdentifier();
// detect modules in a generic way... // comparing service names with configured entries...
css::uno::Reference< css::lang::XServiceInfo > xInfo(xComponent, css::uno::UNO_QUERY); if (!xInfo.is()) return OUString();
const css::uno::Sequence< OUString > lKnownModules = getElementNames(); for (const OUString& rName : lKnownModules)
{ if (xInfo->supportsService(rName)) return rName;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.