@paramaURL unoURLwhichshouldbeexecuted @paramlArguments listofoptionalargumentsforthisrequest
*/ void SAL_CALL ServiceHandler::dispatch( const css::util::URL& aURL , const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/ )
{ // dispatch() is an [oneway] call ... and may our user release his reference to us immediately. // So we should hold us self alive till this call ends.
css::uno::Reference< css::frame::XNotifyingDispatch > xSelfHold(this);
implts_dispatch(aURL); // No notification for status listener!
}
@paramaURL unoURLwhichshouldbeexecuted @paramlArguments listofoptionalargumentsforthisrequest @paramxListener optionallistenerforstateevents
*/ void SAL_CALL ServiceHandler::dispatchWithNotification( const css::util::URL& aURL , const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/, const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
{ // This class was designed to die by reference. And if user release his reference to us immediately after calling this method // we can run into some problems. So we hold us self alive till this method ends. // Another reason: We can use this reference as source of sending event at the end too.
css::uno::Reference< css::frame::XNotifyingDispatch > xThis(this);
css::uno::Reference< css::uno::XInterface > xService = implts_dispatch(aURL); if (xListener.is())
{
css::frame::DispatchResultEvent aEvent; if (xService.is())
aEvent.State = css::frame::DispatchResultState::SUCCESS; else
aEvent.State = css::frame::DispatchResultState::FAILURE;
aEvent.Result <<= xService; // may NULL for state=FAILED!
aEvent.Source = xThis;
@return<NULL/>ifrequestedservicecouldn'tbecreatedsuccessfully; avalidreferenceotherwise.Thisreturnvaluecanbeusedtoindicate, ifdispatchwassuccessful.
*/
css::uno::Reference< css::uno::XInterface > ServiceHandler::implts_dispatch( const css::util::URL& aURL )
{ // extract service name and may optional given parameters from given URL // and use it to create and start the component
OUString sServiceAndArguments = aURL.Complete.copy(PROTOCOL_VALUE.getLength());
OUString sServiceName;
OUString sArguments;
if (sServiceName.isEmpty()) return css::uno::Reference< css::uno::XInterface >();
// If a service doesn't support an optional job executor interface - he can't get // any given parameters! // Because we can't know if we must call createInstanceWithArguments() or XJobExecutor::trigger() ...
css::uno::Reference< css::uno::XInterface > xService; try
{ // => a) a service starts running inside his own ctor and we create it only
xService = m_xContext->getServiceManager()->createInstanceWithContext(sServiceName, m_xContext); // or b) he implements the right interface and starts there (may with optional parameters)
css::uno::Reference< css::task::XJobExecutor > xExecutable(xService, css::uno::UNO_QUERY); if (xExecutable.is())
xExecutable->trigger(sArguments);
} // ignore all errors - inclusive runtime errors! // E.g. a script based service (written in Python) could not be executed // because it contains syntax errors, which was detected at runtime... catch(const css::uno::Exception&)
{
TOOLS_WARN_EXCEPTION("fwk.dispatch", "ignored");
xService.clear();
}
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.