Hello Paolo,
Paolo Mantovani escribió:
In practice, if I well understand Frank's answer, using
createWithArguments/AndContext/AndWhatever things it's not better than simply
doing:
obj = CreateUNOService("service.name")
obj.initialize(Array(arg1, arg2, arg3))
because this is what (more or less) currently happens behind the scene
this simpler way will fail depending on how is the service implemented.
For example if we test this on the
com.sun.star.deployment.ui.PackageManagerDialog, with *this* new-style
service, one can not *first* call createUnoService() and *then*
initialize() passing to this last call the constructor's parameters,
because, as shown in the example bellow, initialize() "fails" == the
object returned by createUnoService() has no such method, as
XInitialization is not implemented.
'******************************************************************
REM "shared" opens the PackageManagerDialog with the shared layer selected
REM "user" opens the PackageManagerDialog with the user layer selected
REM This does not work in the new, OOo 3.0 dialog
Sub TEST_createInstanceWithArgumentsAndContext
Dim oPackagemanager as Object, oListener as Object
oPackagemanager = _
GetProcessServiceManager.createInstanceWithArgumentsAndContext(_
"com.sun.star.deployment.ui.PackageManagerDialog", _
Array(_
ThisComponent.CurrentController.Frame.ContainerWindow,_
"user"_
),_
GetDefaultContext()_
)
oPackagemanager.setDialogTitle("This is a test")
oListener = createUnoListener(_
"testPackageManagerDialog_", _
"com.sun.star.ui.dialogs.XDialogClosedListener")
oPackagemanager.startExecuteModal(oListener)
End Sub
'**************************************************************************
Sub TEST_first_createUnoService_then_initialize_FAILS
Dim oPackagemanager as Object, oListener as Object
'first instantiate using createUnoService
oPackagemanager = createUnoService(_
"com.sun.star.deployment.ui.PackageManagerDialog")
'then initialize...
'FAILS!
oPackagemanager.initialize(_
Array(_
ThisComponent.CurrentController.Frame.ContainerWindow,_
"shared"))
oPackagemanager.setDialogTitle("This is a test")
oListener = createUnoListener(_
"testPackageManagerDialog_", _
"com.sun.star.ui.dialogs.XDialogClosedListener")
oPackagemanager.startExecuteModal(oListener)
End Sub
'**************************************************************************
Sub testPackageManagerDialog_dialogClosed(oEv as Object)
End Sub
Sub testPackageManagerDialog_disposing(oEv as Object)
ENd Sub
'***************************************************************************
[NOTE: this is just a demo, and not the way the PackageManagerDialog is
to be used, or at least not how it's used in
Oxt_Handler::dispatchWithNotification()
framework/source/dispatch/oxt_handler.cxx 1.3 202 ss. Here the
PackageManagerDialog is instantiated at the service manager, and then
XJobExecutor::trigger() is called ]
This *may* not apply to *all* new-styles services, but in *this* case
it's due to the way the PackageManagerDialog is implemented: as
::com::sun::star::lang::XInitialization is not implemented, there is no
way to call XInitialization::initialize().
Other services, for example the CopyTableWizard
(http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/application/CopyTableWizard.html)
has two constructors, but implements XInitialization, so first
createUnoService() and then initialize() *may* [didn't try it] work with it.
Anyway, we, API clients, shouldn't in theory get worried about how
things are implemented, and rely instead only in the specification...
And OOo Basic programmers should have a way to instantiate new style
services at least as simple as createUnoService().
Regards
Ariel.
--
Ariel Constenla-Haile
La Plata, Argentina
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://www.ArielConstenlaHaile.com.ar/ooo/
"Aus der Kriegsschule des Lebens
- Was mich nicht umbringt,
macht mich härter."
Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]