1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loaddispatcher.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_______________________________________________
36 #include <dispatch/loaddispatcher.hxx>
37 #include <threadhelp/readguard.hxx>
38 #include <threadhelp/writeguard.hxx>
40 //_______________________________________________
42 #include <com/sun/star/frame/DispatchResultState.hpp>
44 //_______________________________________________
45 // includes of other projects
47 //_______________________________________________
52 namespace css
= ::com::sun::star
;
54 //_______________________________________________
57 /*-----------------------------------------------
59 -----------------------------------------------*/
60 LoadDispatcher::LoadDispatcher(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
61 const css::uno::Reference
< css::frame::XFrame
>& xOwnerFrame
,
62 const ::rtl::OUString sTargetName
,
63 sal_Int32 nSearchFlags
)
66 , m_xOwnerFrame (xOwnerFrame
)
67 , m_sTarget (sTargetName
)
68 , m_nSearchFlags(nSearchFlags
)
73 /*-----------------------------------------------
75 -----------------------------------------------*/
76 LoadDispatcher::~LoadDispatcher()
81 /*-----------------------------------------------
83 -----------------------------------------------*/
84 void SAL_CALL
LoadDispatcher::dispatchWithNotification(const css::util::URL
& aURL
,
85 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
86 const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
)
87 throw(css::uno::RuntimeException
)
89 impl_dispatch( aURL
, lArguments
, xListener
);
92 /*-----------------------------------------------
94 -----------------------------------------------*/
95 void SAL_CALL
LoadDispatcher::dispatch(const css::util::URL
& aURL
,
96 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
)
97 throw(css::uno::RuntimeException
)
99 impl_dispatch( aURL
, lArguments
, css::uno::Reference
< css::frame::XDispatchResultListener
>() );
102 /*-----------------------------------------------
104 -----------------------------------------------*/
105 css::uno::Any SAL_CALL
LoadDispatcher::dispatchWithReturnValue( const css::util::URL
& rURL
,
106 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
)
107 throw( css::uno::RuntimeException
)
109 return impl_dispatch( rURL
, lArguments
, css::uno::Reference
< css::frame::XDispatchResultListener
>());
112 /*-----------------------------------------------
114 -----------------------------------------------*/
115 void SAL_CALL
LoadDispatcher::addStatusListener(const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/,
116 const css::util::URL
& /*aURL*/ )
117 throw(css::uno::RuntimeException
)
121 /*-----------------------------------------------
123 -----------------------------------------------*/
124 void SAL_CALL
LoadDispatcher::removeStatusListener(const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/,
125 const css::util::URL
& /*aURL*/ )
126 throw(css::uno::RuntimeException
)
130 /*-----------------------------------------------
132 -----------------------------------------------*/
133 css::uno::Any
LoadDispatcher::impl_dispatch( const css::util::URL
& rURL
,
134 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
135 const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
)
137 // Attention: May be nobody outside hold such temp. dispatch object alive (because
138 // the container in which we resists isnt implemented threadsafe but updated by a timer
139 // and clear our reference ...) we should hold us self alive!
140 css::uno::Reference
< css::uno::XInterface
> xThis(static_cast< css::frame::XNotifyingDispatch
* >(this), css::uno::UNO_QUERY
);
142 // SAFE -> ----------------------------------
143 ReadGuard
aReadLock(m_aLock
);
145 // We are the only client of this load env object ... but
146 // may a dispatch request before is still in progress (?!).
147 // Then we should wait a little bit and block this new request.
148 // In case we run into the timeout, we should reject this new request
149 // and return "FAILED" as result. Otherwhise we can start this new operation.
150 if (!m_aLoader
.waitWhileLoading(2000)) // => 2 sec.
153 xListener
->dispatchFinished(
154 css::frame::DispatchResultEvent(xThis
, css::frame::DispatchResultState::DONTKNOW
, css::uno::Any())); // DONTKNOW? ... not realy started ... not realy failed :-)
157 css::uno::Reference
< css::frame::XFrame
> xBaseFrame(m_xOwnerFrame
.get(), css::uno::UNO_QUERY
);
158 if (!xBaseFrame
.is())
161 xListener
->dispatchFinished(
162 css::frame::DispatchResultEvent(xThis
, css::frame::DispatchResultState::FAILURE
, css::uno::Any()));
165 // OK ... now the internal loader seems to be useable for new requests
166 // and our owner frame seems to be valid for such operations.
167 // Initialize it with all new but needed properties and start the loading.
168 css::uno::Reference
< css::lang::XComponent
> xComponent
;
171 m_aLoader
.initializeLoading( rURL
.Complete
, lArguments
, xBaseFrame
, m_sTarget
, m_nSearchFlags
, (LoadEnv::EFeature
)(LoadEnv::E_ALLOW_CONTENTHANDLER
| LoadEnv::E_WORK_WITH_UI
));
172 m_aLoader
.startLoading();
173 m_aLoader
.waitWhileLoading(); // wait for ever!
174 xComponent
= m_aLoader
.getTargetComponent();
176 // TODO thinking about asynchronous operations and listener support
178 catch(const LoadEnvException
&)
179 { xComponent
.clear(); }
184 xListener
->dispatchFinished(
185 css::frame::DispatchResultEvent(xThis
, css::frame::DispatchResultState::SUCCESS
, css::uno::Any()));
187 xListener
->dispatchFinished(
188 css::frame::DispatchResultEvent(xThis
, css::frame::DispatchResultState::FAILURE
, css::uno::Any()));
191 // return the model - like loadComponentFromURL()
193 if ( xComponent
.is () )
194 aRet
= css::uno::makeAny( xComponent
);
197 // <- SAFE ----------------------------------
201 } // namespace framework