From 35518c92365cc183ba6cce2a4d284a130c0ca13f Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 26 Mar 2020 15:04:47 +0100 Subject: Move all public Java classes to libreoffice.jar This moves the classes from juh.jar and ridl.jar to libreoffice.jar The goal is to have one single jar (and Java module, will be added later) which developers can include to work with LO. juh.jar and ridl.jar are kept as basically empty jars with libreoffice.jar on its classpath to keep backwards compatibility. This is a continuation of ae855bf48163ff64d94cfc34aff8e37abdb5518d and a preparation to have Java 9 module support. Change-Id: Ifbbfb97f60373d14256e62ae3122913bd17d5bbb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91930 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- Repository.mk | 1 + android/source/build.gradle | 3 +- bean/Jar_officebean.mk | 3 +- bean/JunitTest_bean_complex.mk | 2 +- bean/test/applet/oooapplet/OOoViewer.java | 5 +- bridges/Jar_java_uno.mk | 6 +- desktop/Jar_active_java.mk | 3 +- desktop/Jar_passive_java.mk | 3 +- desktop/scripts/unoinfo-mac.sh | 5 +- desktop/scripts/unoinfo.sh | 6 +- desktop/win32/source/unoinfo.cxx | 4 +- extensions/test/pgp/readme.txt | 2 +- .../languagetool/ExternalProject_languagetool.mk | 3 +- include/jvmfwk/framework.hxx | 6 +- instsetoo_native/CustomTarget_setup.mk | 2 +- javaunohelper/Jar_juh.mk | 32 +- javaunohelper/JunitTest_juh.mk | 14 +- .../com/sun/star/comp/helper/Bootstrap.java | 429 -------- .../sun/star/comp/helper/BootstrapException.java | 82 -- .../com/sun/star/comp/helper/ComponentContext.java | 308 ------ .../star/comp/helper/ComponentContextEntry.java | 64 -- .../sun/star/comp/helper/SharedLibraryLoader.java | 175 --- .../adapter/ByteArrayToXInputStreamAdapter.java | 117 --- .../adapter/InputStreamToXInputStreamAdapter.java | 145 --- .../OutputStreamToXOutputStreamAdapter.java | 80 -- .../adapter/XInputStreamToInputStreamAdapter.java | 218 ---- .../adapter/XOutputStreamToByteArrayAdapter.java | 94 -- .../XOutputStreamToOutputStreamAdapter.java | 117 --- .../com/sun/star/lib/uno/helper/ComponentBase.java | 136 --- .../com/sun/star/lib/uno/helper/Factory.java | 291 ----- .../star/lib/uno/helper/InterfaceContainer.java | 864 --------------- .../uno/helper/MultiTypeInterfaceContainer.java | 155 --- .../com/sun/star/lib/uno/helper/PropertySet.java | 1103 ------------------- .../sun/star/lib/uno/helper/PropertySetMixin.java | 1111 -------------------- .../com/sun/star/lib/uno/helper/UnoUrl.java | 401 ------- .../com/sun/star/lib/uno/helper/WeakAdapter.java | 94 -- .../com/sun/star/lib/uno/helper/WeakBase.java | 101 -- javaunohelper/util/manifest | 1 - jurt/Jar_jurt.mk | 2 +- nlpsolver/Jar_nlpsolver.mk | 3 +- odk/CustomTarget_javadoc.mk | 4 +- odk/config/cfgWin.js | 2 +- odk/config/setsdkenv_unix.sh.in | 2 +- odk/docs/install.html | 3 +- .../FirstSteps/build_FirstUnoContact.xml | 2 +- odk/examples/DevelopersGuide/OfficeBean/Makefile | 3 +- .../ScriptingFramework/SayHello/build.xml | 3 +- .../ScriptingFramework/ScriptSelector/build.xml | 3 +- qadevOOo/.classpath | 3 +- qadevOOo/Jar_OOoRunner.mk | 5 +- reportbuilder/Jar_reportbuilder.mk | 3 +- ridljar/Jar_libreoffice.mk | 133 +++ ridljar/Jar_ridl.mk | 99 +- ridljar/JunitTest_bridgefactory.mk | 2 +- ridljar/JunitTest_connections.mk | 2 +- ridljar/JunitTest_java.mk | 2 +- ridljar/JunitTest_java_remote.mk | 2 +- ridljar/JunitTest_remote.mk | 2 +- ridljar/JunitTest_typedesc.mk | 2 +- ridljar/JunitTest_uno.mk | 2 +- ridljar/JunitTest_urp.mk | 2 +- ridljar/JunitTest_util.mk | 2 +- ridljar/Module_ridljar.mk | 2 + ridljar/com/sun/star/comp/helper/Bootstrap.java | 429 ++++++++ .../sun/star/comp/helper/BootstrapException.java | 82 ++ .../com/sun/star/comp/helper/ComponentContext.java | 308 ++++++ .../star/comp/helper/ComponentContextEntry.java | 64 ++ .../sun/star/comp/helper/SharedLibraryLoader.java | 175 +++ .../adapter/ByteArrayToXInputStreamAdapter.java | 117 +++ .../adapter/InputStreamToXInputStreamAdapter.java | 145 +++ .../OutputStreamToXOutputStreamAdapter.java | 80 ++ .../adapter/XInputStreamToInputStreamAdapter.java | 218 ++++ .../adapter/XOutputStreamToByteArrayAdapter.java | 94 ++ .../XOutputStreamToOutputStreamAdapter.java | 117 +++ .../com/sun/star/lib/uno/helper/ComponentBase.java | 136 +++ ridljar/com/sun/star/lib/uno/helper/Factory.java | 291 +++++ .../star/lib/uno/helper/InterfaceContainer.java | 864 +++++++++++++++ .../uno/helper/MultiTypeInterfaceContainer.java | 155 +++ .../com/sun/star/lib/uno/helper/PropertySet.java | 1103 +++++++++++++++++++ .../sun/star/lib/uno/helper/PropertySetMixin.java | 1111 ++++++++++++++++++++ ridljar/com/sun/star/lib/uno/helper/UnoUrl.java | 401 +++++++ .../com/sun/star/lib/uno/helper/WeakAdapter.java | 94 ++ ridljar/com/sun/star/lib/uno/helper/WeakBase.java | 101 ++ ridljar/source/libreoffice/manifest | 0 .../com/sun/star/lib/unoloader/UnoClassLoader.java | 9 +- .../com/sun/star/lib/unoloader/UnoLoader.java | 2 +- ridljar/util/manifest | 9 + scripting/Jar_HelloWorld.mk | 3 +- scripting/Jar_Highlight.mk | 3 +- scripting/Jar_MemoryUsage.mk | 3 +- scripting/Jar_ScriptFramework.mk | 3 +- scripting/Jar_ScriptProviderForBeanShell.mk | 3 +- scripting/Jar_ScriptProviderForJava.mk | 3 +- scripting/Jar_ScriptProviderForJavaScript.mk | 3 +- smoketest/Jar_TestExtension.mk | 6 +- smoketest/Jar_smoketest.mk | 3 +- solenv/gbuild/CppunitTest.mk | 2 +- solenv/gbuild/JunitTest.mk | 2 +- swext/Jar_mediawiki.mk | 3 +- testtools/Jar_testComponent.mk | 7 +- toolkit/JunitTest_toolkit_complex.mk | 2 +- toolkit/test/accessibility/jawb.mf | 2 +- unoil/Jar_unoil.mk | 2 +- unotest/Jar_test-tools.mk | 6 +- unotest/Jar_test.mk | 6 +- ure/source/README | 18 +- ure/source/uretest/Makefile.pln | 10 +- wizards/Jar_commonwizards.mk | 3 +- wizards/Jar_form.mk | 3 +- wizards/Jar_query.mk | 3 +- wizards/Jar_report.mk | 3 +- wizards/Jar_reportbuilder.mk | 3 +- wizards/Jar_table.mk | 3 +- xmerge/Jar_XMergeBridge.mk | 3 +- xmerge/Jar_xmerge.mk | 3 +- 115 files changed, 6333 insertions(+), 6362 deletions(-) delete mode 100644 javaunohelper/com/sun/star/comp/helper/Bootstrap.java delete mode 100644 javaunohelper/com/sun/star/comp/helper/BootstrapException.java delete mode 100644 javaunohelper/com/sun/star/comp/helper/ComponentContext.java delete mode 100644 javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java delete mode 100644 javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/ComponentBase.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/Factory.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/WeakAdapter.java delete mode 100644 javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java create mode 100644 ridljar/Jar_libreoffice.mk create mode 100644 ridljar/com/sun/star/comp/helper/Bootstrap.java create mode 100644 ridljar/com/sun/star/comp/helper/BootstrapException.java create mode 100644 ridljar/com/sun/star/comp/helper/ComponentContext.java create mode 100644 ridljar/com/sun/star/comp/helper/ComponentContextEntry.java create mode 100644 ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java create mode 100644 ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java create mode 100644 ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java create mode 100644 ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java create mode 100644 ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java create mode 100644 ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java create mode 100644 ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/ComponentBase.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/Factory.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/InterfaceContainer.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/PropertySet.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/PropertySetMixin.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/UnoUrl.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/WeakAdapter.java create mode 100644 ridljar/com/sun/star/lib/uno/helper/WeakBase.java create mode 100644 ridljar/source/libreoffice/manifest diff --git a/Repository.mk b/Repository.mk index 66581f40b1c1..c02196c545d2 100644 --- a/Repository.mk +++ b/Repository.mk @@ -728,6 +728,7 @@ $(eval $(call gb_Helper_register_jars_for_install,URE,ure, \ java_uno \ juh \ jurt \ + libreoffice \ ridl \ unoloader \ )) diff --git a/android/source/build.gradle b/android/source/build.gradle index a672d0945c73..371d39d547f2 100644 --- a/android/source/build.gradle +++ b/android/source/build.gradle @@ -27,8 +27,7 @@ buildscript { dependencies { implementation fileTree(dir: "${liboInstdir}/${liboUREJavaFolder}", include: [ "java_uno.jar", - "juh.jar", - "ridl.jar", + "libreoffice.jar", "unoloader.jar" ]) implementation(name:'owncloud_android_lib', ext:'aar') diff --git a/bean/Jar_officebean.mk b/bean/Jar_officebean.mk index 424b4ab2a559..7bc8561ab033 100644 --- a/bean/Jar_officebean.mk +++ b/bean/Jar_officebean.mk @@ -11,8 +11,7 @@ $(eval $(call gb_Jar_Jar,officebean)) $(eval $(call gb_Jar_use_jars,officebean,\ - ridl \ - juh \ + libreoffice \ )) $(eval $(call gb_Jar_set_packageroot,officebean,com)) diff --git a/bean/JunitTest_bean_complex.mk b/bean/JunitTest_bean_complex.mk index 091fe544c6b7..42baf49cdce5 100644 --- a/bean/JunitTest_bean_complex.mk +++ b/bean/JunitTest_bean_complex.mk @@ -12,7 +12,7 @@ $(eval $(call gb_JunitTest_JunitTest,bean_complex)) $(eval $(call gb_JunitTest_use_jars,bean_complex,\ OOoRunner \ - ridl \ + libreoffice \ test \ officebean \ )) diff --git a/bean/test/applet/oooapplet/OOoViewer.java b/bean/test/applet/oooapplet/OOoViewer.java index d958032df221..14851e0eceee 100644 --- a/bean/test/applet/oooapplet/OOoViewer.java +++ b/bean/test/applet/oooapplet/OOoViewer.java @@ -45,9 +45,8 @@ public class OOoViewer extends Applet { String officeURL = url.toString(); URL[] arURL = new URL[] { new URL(officeURL + "/program/classes/officebean.jar"), - new URL(officeURL + "/program/classes/ridl.jar"), - new URL(officeURL + "/program/classes/java_uno.jar"), - new URL(officeURL + "/program/classes/juh.jar") + new URL(officeURL + "/program/classes/libreoffice.jar"), + new URL(officeURL + "/program/classes/java_uno.jar") }; m_loader = new CustomURLClassLoader(arURL); File fileProg = new File(s + "/program"); diff --git a/bridges/Jar_java_uno.mk b/bridges/Jar_java_uno.mk index ecaad3c4daa9..14be1adcc650 100644 --- a/bridges/Jar_java_uno.mk +++ b/bridges/Jar_java_uno.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,java_uno)) $(eval $(call gb_Jar_use_jars,java_uno,\ - jurt \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_set_manifest,java_uno,$(SRCDIR)/bridges/source/jni_uno/java/com/sun/star/bridges/jni_uno/manifest)) @@ -19,8 +18,7 @@ $(eval $(call gb_Jar_set_manifest,java_uno,$(SRCDIR)/bridges/source/jni_uno/java $(eval $(call gb_Jar_set_packageroot,java_uno,com)) $(eval $(call gb_Jar_add_manifest_classpath,java_uno,\ - ridl.jar \ - jurt.jar \ + libreoffice.jar \ $(if $(filter MACOSX,$(OS)),../../Frameworks/,../) \ )) diff --git a/desktop/Jar_active_java.mk b/desktop/Jar_active_java.mk index 6e1be1adaed3..48fb7425efb7 100644 --- a/desktop/Jar_active_java.mk +++ b/desktop/Jar_active_java.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_set_manifest,active_java,$(SRCDIR)/desktop/test/deployment/ $(eval $(call gb_Jar_set_packageroot,active_java,com)) $(eval $(call gb_Jar_use_jars,active_java, \ - juh \ - ridl \ + libreoffice \ )) # vim: set noet sw=4 ts=4: diff --git a/desktop/Jar_passive_java.mk b/desktop/Jar_passive_java.mk index 007a37e8e6d6..e2408ae5a09f 100644 --- a/desktop/Jar_passive_java.mk +++ b/desktop/Jar_passive_java.mk @@ -22,8 +22,7 @@ $(eval $(call gb_Jar_set_manifest,passive_java,$(SRCDIR)/desktop/test/deployment $(eval $(call gb_Jar_set_packageroot,passive_java,com)) $(eval $(call gb_Jar_use_jars,passive_java, \ - juh \ - ridl \ + libreoffice \ )) # vim: set noet sw=4 ts=4: diff --git a/desktop/scripts/unoinfo-mac.sh b/desktop/scripts/unoinfo-mac.sh index c8728a0e5e30..b67882db0015 100755 --- a/desktop/scripts/unoinfo-mac.sh +++ b/desktop/scripts/unoinfo-mac.sh @@ -36,9 +36,8 @@ c++) printf '%s' "$sd_prog/../Frameworks" ;; java) - printf '0%s\0%s\0%s' \ - "$sd_prog/../Resources/java/ridl.jar" \ - "$sd_prog/../Resources/java/juh.jar" \ + printf '0%s\0%s' \ + "$sd_prog/../Resources/java/libreoffice.jar" \ "$sd_prog" ;; *) diff --git a/desktop/scripts/unoinfo.sh b/desktop/scripts/unoinfo.sh index 297acf3169d8..14cba806447b 100755 --- a/desktop/scripts/unoinfo.sh +++ b/desktop/scripts/unoinfo.sh @@ -36,9 +36,9 @@ c++) printf '%s' "$sd_prog" ;; java) - printf '0%s\0%s\0%s' \ - "$sd_prog/classes/ridl.jar" \ - "$sd_prog/classes/juh.jar" "$sd_prog" + printf '0%s\0%s' \ + "$sd_prog/classes/libreoffice.jar" \ + "$sd_prog" ;; *) exit 1 diff --git a/desktop/win32/source/unoinfo.cxx b/desktop/win32/source/unoinfo.cxx index f86232feb64f..14cee8819dde 100644 --- a/desktop/win32/source/unoinfo.cxx +++ b/desktop/win32/source/unoinfo.cxx @@ -75,9 +75,7 @@ int wmain(int argc, wchar_t ** argv, wchar_t **) { } wchar_t path[MAX_PATH]; wchar_t * pathEnd = getBrandPath(path); - writePath(path, pathEnd, MY_STRING(L"classes\\ridl.jar")); - writeNull(); - writePath(path, pathEnd, MY_STRING(L"classes\\juh.jar")); + writePath(path, pathEnd, MY_STRING(L"classes\\libreoffice.jar")); writeNull(); writePath(path, pathEnd, MY_STRING(L"")); } else { diff --git a/extensions/test/pgp/readme.txt b/extensions/test/pgp/readme.txt index d1a63f6771ca..8d486877071f 100644 --- a/extensions/test/pgp/readme.txt +++ b/extensions/test/pgp/readme.txt @@ -17,7 +17,7 @@ Please note the semicolons! For the program to run make sure that the office has access - to classes.zip, ridl.jar, pgp.jar and swingall.jar. + to classes.zip, libreoffice.jar, pgp.jar and swingall.jar. Therefore do the necessary entries in Office/user/config/javarc diff --git a/external/languagetool/ExternalProject_languagetool.mk b/external/languagetool/ExternalProject_languagetool.mk index 0d96f4963acf..70b22a6aa10f 100644 --- a/external/languagetool/ExternalProject_languagetool.mk +++ b/external/languagetool/ExternalProject_languagetool.mk @@ -20,7 +20,8 @@ $(eval $(call gb_ExternalProject_use_jars,languagetool,\ unoil \ )) -$(call gb_ExternalProject_get_state_target,languagetool,build) : +$(call gb_ExternalProject_get_state_target,languagetool,build) : \ + $(call gb_Jar_get_target,libreoffice) cd "$(call gb_UnpackedTarball_get_dir,languagetool)" && \ $(ICECREAM_RUN) "$(ANT)" \ $(if $(verbose),-v,-q) \ diff --git a/include/jvmfwk/framework.hxx b/include/jvmfwk/framework.hxx index 3a4b3139045d..0b02a9e04447 100644 --- a/include/jvmfwk/framework.hxx +++ b/include/jvmfwk/framework.hxx @@ -98,13 +98,13 @@

regcomp -env:UNO_JAVA_JFW_JREHOME=file:///d:/j2re1.4.2 - -env:"UNO_JAVA_JFW_CLASSPATH=d:\\solver\\bin\\classes.jar;d:\\solver\\bin\\ridl.jar" + -env:"UNO_JAVA_JFW_CLASSPATH=d:\\solver\\bin\\classes.jar;d:\\solver\\bin\\libreoffice.jar" -register...

If UNO_JAVA_JFW_VENDOR_SETTINGS is not set then a plugin library must be specified. For example:

regcomp -env:UNO_JAVA_JFW_JREHOME=file:///d:/j2re1.4.2 - -env:"UNO_JAVA_JFW_CLASSPATH=d:\\solver\\bin\\classes.jar;d:\\solver\\bin\\ridl.jar" + -env:"UNO_JAVA_JFW_CLASSPATH=d:\\solver\\bin\\classes.jar;d:\\solver\\bin\\libreoffice.jar" -register...

Additional parameters for the Java VM can be provided. For every parameter @@ -114,7 +114,7 @@ regcomp -env:UNO_JAVA_JFW_PARAMETER_1=-Xdebug -env:UNO_JAVA_JFW_PARAMETER_2=-Xrunjdwp:transport=dt_socket,server=y,address=8100 -env:UNO_JAVA_JFW_JREHOME=file:///d:/j2re1.4.2 - -env:"UNO_JAVA_JFW_CLASSPATH=d:\\solver\\bin\\classes.jar;d:\\solver\\bin\\ridl.jar" + -env:"UNO_JAVA_JFW_CLASSPATH=d:\\solver\\bin\\classes.jar;d:\\solver\\bin\\libreoffice.jar" -register...

Here is a complete list of the bootstrap parameter for the direct mode: diff --git a/instsetoo_native/CustomTarget_setup.mk b/instsetoo_native/CustomTarget_setup.mk index 0f0f6158abc8..4d845441c6a6 100644 --- a/instsetoo_native/CustomTarget_setup.mk +++ b/instsetoo_native/CustomTarget_setup.mk @@ -69,7 +69,7 @@ $(call gb_CustomTarget_get_workdir,instsetoo_native/setup)/$(call gb_Helper_get_ && echo 'URE_MORE_JAVA_CLASSPATH_URLS=$(if $(SYSTEM_HSQLDB),$(HSQLDB_JAR))' \ && echo 'URE_OVERRIDE_JAVA_JFW_SHARED_DATA=$${BRAND_BASE_DIR}/$(LIBO_SHARE_FOLDER)/config/javasettings_$${_OS}_$${_ARCH}.xml' \ && echo 'URE_OVERRIDE_JAVA_JFW_USER_DATA=$${$${BRAND_BASE_DIR}/$(LIBO_ETC_FOLDER)/$(call gb_Helper_get_rcfile,bootstrap):UserInstallation}/user/config/javasettings_$${_OS}_$${_ARCH}.xml' \ - && echo 'URE_MORE_JAVA_TYPES=$${BRAND_BASE_DIR}/$(LIBO_SHARE_JAVA_FOLDER)/ridl.jar $${BRAND_BASE_DIR}/$(LIBO_SHARE_JAVA_FOLDER)/ScriptFramework.jar $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_UserUnoFile}:UNO_JAVA_CLASSPATH} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_SharedUnoFile}:UNO_JAVA_CLASSPATH} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_BundledUnoFile}:UNO_JAVA_CLASSPATH}' \ + && echo 'URE_MORE_JAVA_TYPES=$${BRAND_BASE_DIR}/$(LIBO_SHARE_JAVA_FOLDER)/libreoffice.jar $${BRAND_BASE_DIR}/$(LIBO_SHARE_JAVA_FOLDER)/ScriptFramework.jar $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_UserUnoFile}:UNO_JAVA_CLASSPATH} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_SharedUnoFile}:UNO_JAVA_CLASSPATH} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_BundledUnoFile}:UNO_JAVA_CLASSPATH}' \ && echo 'URE_MORE_SERVICES=$${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_UserUnoFile}:UNO_SERVICES} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_SharedUnoFile}:UNO_SERVICES} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_BundledUnoFile}:UNO_SERVICES} <$$ORIGIN/services>*' \ && echo 'URE_MORE_TYPES=<$$ORIGIN/types>* $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_UserUnoFile}:UNO_TYPES} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_SharedUnoFile}:UNO_TYPES} $${$${$$ORIGIN/$(call gb_Helper_get_rcfile,louno):PKG_BundledUnoFile}:UNO_TYPES}' \ ) > $@ diff --git a/javaunohelper/Jar_juh.mk b/javaunohelper/Jar_juh.mk index 7f90852eb6df..cf469200cd49 100644 --- a/javaunohelper/Jar_juh.mk +++ b/javaunohelper/Jar_juh.mk @@ -9,40 +9,10 @@ $(eval $(call gb_Jar_Jar,juh)) -$(eval $(call gb_Jar_use_jars,juh,\ - ridl \ -)) - -$(eval $(call gb_Jar_set_packageroot,juh,com)) - $(eval $(call gb_Jar_add_manifest_classpath,juh, \ - ridl.jar \ - $(if $(filter MACOSX,$(OS)),../../Frameworks/,../) \ + libreoffice.jar \ )) $(eval $(call gb_Jar_set_manifest,juh,$(SRCDIR)/javaunohelper/util/manifest)) -$(eval $(call gb_Jar_add_sourcefiles,juh,\ - javaunohelper/com/sun/star/comp/helper/Bootstrap \ - javaunohelper/com/sun/star/comp/helper/BootstrapException \ - javaunohelper/com/sun/star/comp/helper/ComponentContext \ - javaunohelper/com/sun/star/comp/helper/ComponentContextEntry \ - javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader \ - javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter \ - javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter \ - javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter \ - javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter \ - javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter \ - javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter \ - javaunohelper/com/sun/star/lib/uno/helper/ComponentBase \ - javaunohelper/com/sun/star/lib/uno/helper/Factory \ - javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer \ - javaunohelper/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer \ - javaunohelper/com/sun/star/lib/uno/helper/PropertySet \ - javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin \ - javaunohelper/com/sun/star/lib/uno/helper/UnoUrl \ - javaunohelper/com/sun/star/lib/uno/helper/WeakAdapter \ - javaunohelper/com/sun/star/lib/uno/helper/WeakBase \ -)) - # vim:set noet sw=4 ts=4: diff --git a/javaunohelper/JunitTest_juh.mk b/javaunohelper/JunitTest_juh.mk index d819cb237fc7..e5ccfa1c4716 100644 --- a/javaunohelper/JunitTest_juh.mk +++ b/javaunohelper/JunitTest_juh.mk @@ -16,22 +16,12 @@ $(eval $(call gb_JunitTest_set_defs,juh,\ $(eval $(call gb_JunitTest_use_jars,juh,\ OOoRunner \ - ridl \ + libreoffice \ )) -$(eval $(call gb_JunitTest_use_jar_classset,juh,ridljar)) +$(eval $(call gb_JunitTest_use_jar_classset,juh,libreoffice)) $(eval $(call gb_JunitTest_add_sourcefiles,juh,\ - javaunohelper/com/sun/star/comp/helper/Bootstrap \ - javaunohelper/com/sun/star/comp/helper/BootstrapException \ - javaunohelper/com/sun/star/comp/helper/ComponentContext \ - javaunohelper/com/sun/star/comp/helper/ComponentContextEntry \ - javaunohelper/com/sun/star/lib/uno/helper/ComponentBase \ - javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer \ - javaunohelper/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer \ - javaunohelper/com/sun/star/lib/uno/helper/PropertySet \ - javaunohelper/com/sun/star/lib/uno/helper/WeakAdapter \ - javaunohelper/com/sun/star/lib/uno/helper/WeakBase \ javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test \ javaunohelper/test/com/sun/star/lib/uno/helper/AWeakBase \ javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test \ diff --git a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java deleted file mode 100644 index edf21d7d2adf..000000000000 --- a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java +++ /dev/null @@ -1,429 +0,0 @@ -// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.comp.helper; - -import com.sun.star.bridge.UnoUrlResolver; -import com.sun.star.bridge.XUnoUrlResolver; -import com.sun.star.comp.loader.JavaLoader; -import com.sun.star.comp.servicemanager.ServiceManager; -import com.sun.star.container.XSet; -import com.sun.star.lang.XInitialization; -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.lang.XMultiComponentFactory; -import com.sun.star.lib.util.NativeLibraryLoader; -import com.sun.star.loader.XImplementationLoader; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XComponentContext; - -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Map; -import java.util.Random; - -/** Bootstrap offers functionality to obtain a context or simply - a service manager. - The service manager can create a few basic services, whose implementations are: -

- - Other services can be inserted into the service manager by - using its XSet interface: -
-        XSet xSet = UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
-        // insert the service manager
-        xSet.insert( aSingleComponentFactory );
-    
-*/ -public class Bootstrap { - - private static void insertBasicFactories( - XSet xSet, XImplementationLoader xImpLoader ) - throws Exception - { - // insert the factory of the loader - xSet.insert( xImpLoader.activate( - "com.sun.star.comp.loader.JavaLoader", null, null, null ) ); - - // insert the factory of the URLResolver - xSet.insert( xImpLoader.activate( - "com.sun.star.comp.urlresolver.UrlResolver", null, null, null ) ); - - // insert the bridgefactory - xSet.insert( xImpLoader.activate( - "com.sun.star.comp.bridgefactory.BridgeFactory", null, null, null ) ); - - // insert the connector - xSet.insert( xImpLoader.activate( - "com.sun.star.comp.connections.Connector", null, null, null ) ); - - // insert the acceptor - xSet.insert( xImpLoader.activate( - "com.sun.star.comp.connections.Acceptor", null, null, null ) ); - } - - /** - * Returns an array of default commandline options to start bootstrapped - * instance of soffice with. You may use it in connection with bootstrap - * method for example like this: - *
-     *     List list = Arrays.asList( Bootstrap.getDefaultOptions() );
-     *     list.remove("--nologo");
-     *     list.remove("--nodefault");
-     *     list.add("--invisible");
-     *
-     *     Bootstrap.bootstrap( list.toArray( new String[list.size()] );
-     * 
- * - * @return an array of default commandline options - * @see #bootstrap( String[] ) - * @since LibreOffice 5.1 - */ - public static final String[] getDefaultOptions() - { - return new String[] - { - "--nologo", - "--nodefault", - "--norestore", - "--nolockcheck" - }; - } - - /** - backwards compatibility stub. - @param context_entries the hash table contains mappings of entry names (type string) to - context entries (type class ComponentContextEntry). - @throws Exception if things go awry. - @return a new context. - */ - public static XComponentContext createInitialComponentContext( Hashtable context_entries ) - throws Exception - { - return createInitialComponentContext((Map) context_entries); - } - /** Bootstraps an initial component context with service manager and basic - jurt components inserted. - @param context_entries the hash table contains mappings of entry names (type string) to - context entries (type class ComponentContextEntry). - @throws Exception if things go awry. - @return a new context. - */ - public static XComponentContext createInitialComponentContext( Map context_entries ) - throws Exception - { - ServiceManager xSMgr = new ServiceManager(); - - XImplementationLoader xImpLoader = UnoRuntime.queryInterface( - XImplementationLoader.class, new JavaLoader() ); - XInitialization xInit = UnoRuntime.queryInterface( - XInitialization.class, xImpLoader ); - Object[] args = new Object [] { xSMgr }; - xInit.initialize( args ); - - // initial component context - if (context_entries == null) - context_entries = new HashMap( 1 ); - // add smgr - context_entries.put( - "/singletons/com.sun.star.lang.theServiceManager", - new ComponentContextEntry( null, xSMgr ) ); - // ... xxx todo: add standard entries - XComponentContext xContext = new ComponentContext( context_entries, null ); - - xSMgr.setDefaultContext(xContext); - - XSet xSet = UnoRuntime.queryInterface( XSet.class, xSMgr ); - // insert basic jurt factories - insertBasicFactories( xSet, xImpLoader ); - - return xContext; - } - - /** - * Bootstraps a servicemanager with the jurt base components registered. - * - * See also UNOIDL com.sun.star.lang.ServiceManager. - * - * @throws Exception if things go awry. - * @return a freshly bootstrapped service manager - */ - public static XMultiServiceFactory createSimpleServiceManager() throws Exception - { - return UnoRuntime.queryInterface( - XMultiServiceFactory.class, createInitialComponentContext( (Map) null ).getServiceManager() ); - } - - - /** Bootstraps the initial component context from a native UNO installation. - - @throws Exception if things go awry. - @return a freshly bootstrapped component context. - - See also - cppuhelper/defaultBootstrap_InitialComponentContext(). - */ - public static final XComponentContext defaultBootstrap_InitialComponentContext() - throws Exception - { - return defaultBootstrap_InitialComponentContext( (String) null, (Map) null ); - } - /** - * Backwards compatibility stub. - * - * @param ini_file - * ini_file (may be null: uno.rc besides cppuhelper lib) - * @param bootstrap_parameters - * bootstrap parameters (maybe null) - * - * @throws Exception if things go awry. - * @return a freshly bootstrapped component context. - */ - public static final XComponentContext defaultBootstrap_InitialComponentContext( - String ini_file, Hashtable bootstrap_parameters ) - throws Exception - { - return defaultBootstrap_InitialComponentContext(ini_file, (Map) bootstrap_parameters); - - } - /** Bootstraps the initial component context from a native UNO installation. - - See also - cppuhelper/defaultBootstrap_InitialComponentContext(). - - @param ini_file - ini_file (may be null: uno.rc besides cppuhelper lib) - @param bootstrap_parameters - bootstrap parameters (maybe null) - - @throws Exception if things go awry. - @return a freshly bootstrapped component context. - */ - public static final XComponentContext defaultBootstrap_InitialComponentContext( - String ini_file, Map bootstrap_parameters ) - throws Exception - { - // jni convenience: easier to iterate over array than calling Hashtable - String pairs [] = null; - if (null != bootstrap_parameters) - { - pairs = new String [ 2 * bootstrap_parameters.size() ]; - int n = 0; - for (Map.Entry bootstrap_parameter : bootstrap_parameters.entrySet()) { - pairs[ n++ ] = bootstrap_parameter.getKey(); - pairs[ n++ ] = bootstrap_parameter.getValue(); - } - } - - if (! m_loaded_juh) - { - if ("The Android Project".equals(System.getProperty("java.vendor"))) - { - // Find out if we are configured with DISABLE_DYNLOADING or - // not. Try to load the lo-bootstrap shared library which - // won't exist in the DISABLE_DYNLOADING case. (And which will - // be already loaded otherwise, so nothing unexpected happens - // that case.) Yeah, this would be simpler if I just could be - // bothered to keep a separate branch for DISABLE_DYNLOADING - // on Android, merging in master periodically, until I know - // for sure whether it is what I want, or not. - - boolean disable_dynloading = false; - try { - System.loadLibrary( "lo-bootstrap" ); - } catch ( UnsatisfiedLinkError e ) { - disable_dynloading = true; - } - - if (!disable_dynloading) - { - NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" ); - } - } - else - { - NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" ); - } - m_loaded_juh = true; - } - return UnoRuntime.queryInterface( - XComponentContext.class, - cppuhelper_bootstrap( - ini_file, pairs, Bootstrap.class.getClassLoader() ) ); - } - - private static boolean m_loaded_juh = false; - private static native Object cppuhelper_bootstrap( - String ini_file, String bootstrap_parameters [], ClassLoader loader ) - throws Exception; - - /** - * Bootstraps the component context from a UNO installation. - * - * @throws BootstrapException if things go awry. - * - * @return a bootstrapped component context. - * - * @since UDK 3.1.0 - */ - public static final XComponentContext bootstrap() - throws BootstrapException { - - String[] defaultArgArray = getDefaultOptions(); - return bootstrap( defaultArgArray ); - } - - /** - * Bootstraps the component context from a UNO installation. - * - * @param argArray - * an array of strings - commandline options to start instance of - * soffice with - * @see #getDefaultOptions() - * - * @throws BootstrapException if things go awry. - * - * @return a bootstrapped component context. - * - * @since LibreOffice 5.1 - */ - public static final XComponentContext bootstrap( String[] argArray ) - throws BootstrapException { - - XComponentContext xContext = null; - - try { - // create default local component context - XComponentContext xLocalContext = - createInitialComponentContext( (Map) null ); - if ( xLocalContext == null ) - throw new BootstrapException( "no local component context!" ); - - // find office executable relative to this class's class loader - String sOffice = - System.getProperty( "os.name" ).startsWith( "Windows" ) ? - "soffice.exe" : "soffice"; - File fOffice = NativeLibraryLoader.getResource( - Bootstrap.class.getClassLoader(), sOffice ); - if ( fOffice == null ) - throw new BootstrapException( "no office executable found!" ); - - // create random pipe name - String sPipeName = "uno" + - Long.toString(randomPipeName.nextLong() & 0x7fffffffffffffffL); - - // create call with arguments - String[] cmdArray = new String[ argArray.length + 2 ]; - cmdArray[0] = fOffice.getPath(); - cmdArray[1] = ( "--accept=pipe,name=" + sPipeName + ";urp;" ); - - System.arraycopy( argArray, 0, cmdArray, 2, argArray.length ); - - // start office process - Process p = Runtime.getRuntime().exec( cmdArray ); - pipe( p.getInputStream(), System.out, "CO> " ); - pipe( p.getErrorStream(), System.err, "CE> " ); - - // initial service manager - XMultiComponentFactory xLocalServiceManager = - xLocalContext.getServiceManager(); - if ( xLocalServiceManager == null ) - throw new BootstrapException( "no initial service manager!" ); - - // create a URL resolver - XUnoUrlResolver xUrlResolver = - UnoUrlResolver.create( xLocalContext ); - - // connection string - String sConnect = "uno:pipe,name=" + sPipeName + - ";urp;StarOffice.ComponentContext"; - - // wait until office is started - for (int i = 0;; ++i) { - try { - // try to connect to office - Object context = xUrlResolver.resolve( sConnect ); - xContext = UnoRuntime.queryInterface( - XComponentContext.class, context); - if ( xContext == null ) - throw new BootstrapException( "no component context!" ); - break; - } catch ( com.sun.star.connection.NoConnectException ex ) { - // Wait 500 ms, then try to connect again, but do not wait - // longer than 5 min (= 600 * 500 ms) total: - if (i == 600) { - throw new BootstrapException(ex); - } - Thread.sleep( 500 ); - } - } - } catch ( BootstrapException e ) { - throw e; - } catch ( java.lang.RuntimeException e ) { - throw e; - } catch ( java.lang.Exception e ) { - throw new BootstrapException( e ); - } - - return xContext; - } - - private static final Random randomPipeName = new Random(); - - private static void pipe( - final InputStream in, final PrintStream out, final String prefix ) { - - new Thread( "Pipe: " + prefix) { - @Override - public void run() { - try { - BufferedReader r = new BufferedReader( - new InputStreamReader(in, "UTF-8") ); - - for ( ; ; ) { - String s = r.readLine(); - if ( s == null ) { - break; - } - out.println( prefix + s ); - } - } catch ( UnsupportedEncodingException e ) { - e.printStackTrace( System.err ); - } catch ( java.io.IOException e ) { - e.printStackTrace( System.err ); - } - } - }.start(); - } -} - -// vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/javaunohelper/com/sun/star/comp/helper/BootstrapException.java b/javaunohelper/com/sun/star/comp/helper/BootstrapException.java deleted file mode 100644 index 11911bbc07e0..000000000000 --- a/javaunohelper/com/sun/star/comp/helper/BootstrapException.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.comp.helper; - -/** - * BootstrapException is a checked exception that wraps an exception - * thrown by the original target. - * - * @since UDK 3.1.0 - */ -public class BootstrapException extends java.lang.Exception { - - /** - * This field holds the target exception. - */ - private Exception m_target = null; - - /** - * Constructs a BootstrapException with null as - * the target exception. - */ - public BootstrapException() { - super(); - } - - /** - * Constructs a BootstrapException with the specified - * detail message. - * - * @param message the detail message - */ - public BootstrapException( String message ) { - super( message ); - } - - /** - * Constructs a BootstrapException with the specified - * detail message and a target exception. - * - * @param message the detail message - * @param target the target exception - */ - public BootstrapException( String message, Exception target ) { - super( message ); - m_target = target; - } - - /** - * Constructs a BootstrapException with a target exception. - * - * @param target the target exception - */ - public BootstrapException( Exception target ) { - super(); - m_target = target; - } - - /** - * Get the thrown target exception. - * - * @return the target exception - */ - public Exception getTargetException() { - return m_target; - } -} diff --git a/javaunohelper/com/sun/star/comp/helper/ComponentContext.java b/javaunohelper/com/sun/star/comp/helper/ComponentContext.java deleted file mode 100644 index 34649d563395..000000000000 --- a/javaunohelper/com/sun/star/comp/helper/ComponentContext.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.comp.helper; - -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.Any; - -import com.sun.star.uno.DeploymentException; -import com.sun.star.uno.XComponentContext; -import com.sun.star.lang.XMultiComponentFactory; -import com.sun.star.lang.XSingleComponentFactory; -import com.sun.star.lang.XComponent; -import com.sun.star.lang.XEventListener; -import com.sun.star.lang.EventObject; - -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Map; - - - -class Disposer implements XEventListener -{ - private final XComponent m_xComp; - - - Disposer( XComponent xComp ) - { - m_xComp = xComp; - } - - public void disposing( EventObject Source ) - { - m_xComp.dispose(); - } -} - -/** Component context implementation. -*/ -public class ComponentContext implements XComponentContext, XComponent -{ - private static final boolean DEBUG = false; - private static final String SMGR_NAME = "/singletons/com.sun.star.lang.theServiceManager"; - private static final String TDMGR_NAME = "/singletons/com.sun.star.reflection.theTypeDescriptionManager"; - - private Map m_table; - private XComponentContext m_xDelegate; - - private XMultiComponentFactory m_xSMgr; - private boolean m_bDisposeSMgr; - - private ArrayList m_eventListener; - - public ComponentContext( Hashtable table, XComponentContext xDelegate ) - { - this((Map) table, xDelegate); - } - - /** Ctor to create a component context passing a hashtable for values and a delegator - reference. Entries of the passed hashtable are either direct values or - ComponentContextEntry objects. - - @param table - entries - @param xDelegate - if values are not found, request is delegated to this object - */ - public ComponentContext( Map table, XComponentContext xDelegate ) - { - m_eventListener = new ArrayList(); - m_table = table; - m_xDelegate = xDelegate; - m_xSMgr = null; - m_bDisposeSMgr = false; - - Object o = table.get( SMGR_NAME ); - if (o != null) - { - if (o instanceof ComponentContextEntry) - { - o = ((ComponentContextEntry)o).m_value; - } - m_xSMgr = UnoRuntime.queryInterface( - XMultiComponentFactory.class, o ); - } - if (m_xSMgr != null) - { - m_bDisposeSMgr = true; - } - else if (m_xDelegate != null) - { - m_xSMgr = m_xDelegate.getServiceManager(); - } - - // listen for delegate - XComponent xComp = UnoRuntime.queryInterface( - XComponent.class, m_xDelegate ); - if (xComp != null) - { - xComp.addEventListener( new Disposer( this ) ); - } - } - - // XComponentContext impl - - public Object getValueByName( String rName ) - { - Object o = m_table.get( rName ); - if (o == null) - { - if (m_xDelegate != null) - { - return m_xDelegate.getValueByName( rName ); - } - else - { - return Any.VOID; - } - } - - if (!(o instanceof ComponentContextEntry)) - { - // direct value in map - return o; - } - - ComponentContextEntry entry = (ComponentContextEntry)o; - if (entry.m_lateInit == null) - { - return entry.m_value; - } - - Object xInstance = null; - try - { - String serviceName = (String)entry.m_lateInit; - if (serviceName != null) - { - if (m_xSMgr != null) - { - xInstance = m_xSMgr.createInstanceWithContext( serviceName, this ); - } - else - { - if (DEBUG) - System.err.println( "### no service manager instance for late init of singleton instance \"" + rName + "\"!" ); - } - } - else - { - XSingleComponentFactory xCompFac = UnoRuntime.queryInterface( XSingleComponentFactory.class, entry.m_lateInit ); - if (xCompFac != null) - { - xInstance = xCompFac.createInstanceWithContext( this ); - } - else - { - if (DEBUG) - System.err.println( "### neither service name nor service factory given for late init of singleton instance \"" + rName + "\"!" ); - } - } - } - catch (com.sun.star.uno.Exception exc) - { - if (DEBUG) - System.err.println( "### exception occurred on late init of singleton instance \"" + rName + "\": " + exc.getMessage() ); - } - - if (xInstance != null) - { - synchronized (entry) - { - if (entry.m_lateInit != null) - { - entry.m_value = xInstance; - entry.m_lateInit = null; - } - else // inited in the meantime - { - // dispose fresh service instance - XComponent xComp = UnoRuntime.queryInterface( - XComponent.class, xInstance ); - if (xComp != null) - { - xComp.dispose(); - } - } - } - } - else - { - if (DEBUG) - System.err.println( "### failed late init of singleton instance \"" + rName + "\"!" ); - } - return entry.m_value; - } - - public XMultiComponentFactory getServiceManager() - { - if (m_xSMgr == null) - { - throw new DeploymentException( - "null component context service manager" ); - } - return m_xSMgr; - } - - // XComponent impl - - public void dispose() - { - if (DEBUG) - System.err.print( "> disposing context " + this ); - - // fire events - EventObject evt = new EventObject( this ); - for (XEventListener listener : m_eventListener) - { - listener.disposing( evt ); - } - m_eventListener.clear(); - - XComponent tdmgr = null; - // dispose values, then service manager, then typedescription manager - for (Map.Entry entry : m_table.entrySet()) - { - String name = entry.getKey(); - if (! name.equals( SMGR_NAME )) - { - Object o = entry.getValue(); - if (o instanceof ComponentContextEntry) - { - o = ((ComponentContextEntry)o).m_value; - } - - XComponent xComp = UnoRuntime.queryInterface( XComponent.class, o ); - if (xComp != null) - { - if (name.equals( TDMGR_NAME )) - { - tdmgr = xComp; - } - else - { - xComp.dispose(); - } - } - } - } - m_table.clear(); - - // smgr - if (m_bDisposeSMgr) - { - XComponent xComp = UnoRuntime.queryInterface( - XComponent.class, m_xSMgr ); - if (xComp != null) - { - xComp.dispose(); - } - } - m_xSMgr = null; - - // tdmgr - if (tdmgr != null) - { - tdmgr.dispose(); - } - - if (DEBUG) - System.err.println( "... finished" ); - } - - public void addEventListener( XEventListener xListener ) - { - if (xListener == null) - throw new com.sun.star.uno.RuntimeException( "Listener must not be null" ); - if (m_eventListener.contains( xListener )) - throw new com.sun.star.uno.RuntimeException( "Listener already registered." ); - - m_eventListener.add( xListener ); - } - - public void removeEventListener( XEventListener xListener ) - { - if (xListener == null) - throw new com.sun.star.uno.RuntimeException( "Listener must not be null" ); - if (! m_eventListener.contains( xListener )) - throw new com.sun.star.uno.RuntimeException( "Listener is not registered." ); - - m_eventListener.remove( xListener ); - } -} diff --git a/javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java b/javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java deleted file mode 100644 index aa402d29c6d1..000000000000 --- a/javaunohelper/com/sun/star/comp/helper/ComponentContextEntry.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.comp.helper; - -/** Component context entry for constructing ComponentContext objects. -

- A ComponentContextEntry is separated into a late-init and direct-value - purpose. - The first one is commonly used for singleton objects of the component - context, that are raised on first-time retrieval of the key. - You have to pass a com.sun.star.lang.XSingleComponentFactory - or string (=> service name) object for this. -

-*/ -public class ComponentContextEntry -{ - /** if late init of service instance, set service name (String) or - component factory (XSingleComponentFactory), null otherwise - */ - public Object m_lateInit; - /** set entry value - */ - public Object m_value; - - /** Creating a late-init singleton entry component context entry. - The second parameter will be ignored and overwritten during - instantiation of the singleton instance. - - @param lateInit - object factory or service string - @param value - pass null (dummy separating from second constructor signature) - */ - public ComponentContextEntry( Object lateInit, Object value ) - { - this.m_lateInit = lateInit; - this.m_value = value; - } - /** Creating a direct value component context entry. - - @param value - pass null - */ - public ComponentContextEntry( Object value ) - { - this.m_lateInit = null; - this.m_value = value; - } -} diff --git a/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java b/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java deleted file mode 100644 index 035644efa0b8..000000000000 --- a/javaunohelper/com/sun/star/comp/helper/SharedLibraryLoader.java +++ /dev/null @@ -1,175 +0,0 @@ -// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.comp.helper; - -import com.sun.star.uno.UnoRuntime; -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.lang.XSingleServiceFactory; -import com.sun.star.registry.XRegistryKey; - -/** - * @deprecated use class Bootstrap bootstrapping a native UNO installation - * and use the shared library loader service. - * - * The SharedLibraryLoader class provides the functionality of the com.sun.star.loader.SharedLibrary - * service. - * - * See also UNOIDL com.sun.star.lang.ServiceManager. - * - * @see com.sun.star.loader.SharedLibrary - */ -@Deprecated -public class SharedLibraryLoader { - /** - * The default library which contains the SharedLibraryLoader component - */ - public static final String DEFAULT_LIBRARY = "shlibloader.uno"; - - /** - * The default implementation name - */ - public static final String DEFAULT_IMPLEMENTATION = "com.sun.star.comp.stoc.DLLComponentLoader"; - - static { - if ("The Android Project".equals(System.getProperty("java.vendor"))) { - // See corresponding code in - // javaunohelper/com/sun/star/comp/helper/Bootstrap.java for more - // comments. - - boolean disable_dynloading = false; - try { - System.loadLibrary("lo-bootstrap"); - } catch (UnsatisfiedLinkError e) { - disable_dynloading = true; - } - - if (!disable_dynloading) - System.loadLibrary("juh"); - } else - System.loadLibrary("juh"); - } - - private static native boolean component_writeInfo( - String libName, XMultiServiceFactory smgr, XRegistryKey regKey, - ClassLoader loader ); - - private static native Object component_getFactory( - String libName, String implName, XMultiServiceFactory smgr, - XRegistryKey regKey, ClassLoader loader ); - - /** - * Supplies the ServiceFactory of the default SharedLibraryLoader. - * The defaults are "shlibloader.uno" - * for the library and "com.sun.star.comp.stoc.DLLComponentLoader" - * for the component name. - * - * See also UNOIDL com.sun.star.lang.ServiceManager and - * com.sun.star.registry.RegistryKey. - * - * @return the factory for the "com.sun.star.comp.stoc.DLLComponentLoader" component. - * @param smgr the ServiceManager - * @param regKey the root registry key - * @see com.sun.star.loader.SharedLibrary - */ - public static XSingleServiceFactory getServiceFactory( - XMultiServiceFactory smgr, - XRegistryKey regKey ) - { - return UnoRuntime.queryInterface( - XSingleServiceFactory.class, - component_getFactory( - DEFAULT_LIBRARY, DEFAULT_IMPLEMENTATION, smgr, regKey, - SharedLibraryLoader.class.getClassLoader() ) ); - } - - /** - * Loads and returns a specific factory for a given library and implementation name. - * - * See also UNOIDL com.sun.star.lang.ServiceManager and - * com.sun.star.registry.RegistryKey. - * - * @return the factory of the component - * @param libName the name of the shared library - * @param impName the implementation name of the component - * @param smgr the ServiceManager - * @param regKey the root registry key - * @see com.sun.star.loader.SharedLibrary - */ - public static XSingleServiceFactory getServiceFactory( - String libName, - String impName, - XMultiServiceFactory smgr, - XRegistryKey regKey ) - { - return UnoRuntime.queryInterface( - XSingleServiceFactory.class, - component_getFactory( - libName, impName, smgr, regKey, - SharedLibraryLoader.class.getClassLoader() ) ); - } - - /** - * Registers the SharedLibraryLoader under a RegistryKey. - * - * See also UNOIDL com.sun.star.lang.ServiceManager and - * com.sun.star.registry.RegistryKey. - * - * @return true if the registration was successful - otherwise false - * @param smgr the ServiceManager - * @param regKey the root key under that the component should be registered - * @see com.sun.star.loader.SharedLibrary - */ - public static boolean writeRegistryServiceInfo( - com.sun.star.lang.XMultiServiceFactory smgr, - com.sun.star.registry.XRegistryKey regKey ) - { - return component_writeInfo( - DEFAULT_LIBRARY, smgr, regKey, - SharedLibraryLoader.class.getClassLoader() ); - } - - /** - * Registers the SharedLibraryLoader under a RegistryKey. - * - * See also UNOIDL com.sun.star.lang.ServiceManager and - * com.sun.star.registry.RegistryKey. - * - * @return true if the registration was successful - otherwise false - * @param libName name of the shared library - * @param smgr the ServiceManager - * @param regKey the root key under that the component should be registered - * @throws com.sun.star.registry.InvalidRegistryException - * if the registry is not valid. - * - * @see com.sun.star.loader.SharedLibrary - */ - public static boolean writeRegistryServiceInfo( - String libName, - com.sun.star.lang.XMultiServiceFactory smgr, - com.sun.star.registry.XRegistryKey regKey ) - - throws com.sun.star.registry.InvalidRegistryException, - com.sun.star.uno.RuntimeException - { - return component_writeInfo( - libName, smgr, regKey, SharedLibraryLoader.class.getClassLoader() ); - } -} - -// vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java deleted file mode 100644 index 2d3e9a8480b7..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.lib.uno.adapter; - -import com.sun.star.io.XInputStream; -import com.sun.star.io.XSeekable; -import com.sun.star.lib.uno.helper.ComponentBase; - -public final class ByteArrayToXInputStreamAdapter - extends ComponentBase - implements XInputStream, XSeekable -{ - - byte[] m_bytes; - int m_length; - int m_pos; - - boolean m_open; - - /** Creates a new instance of ByteArrayXInputStram */ - public ByteArrayToXInputStreamAdapter(byte[] bytes) { - init(bytes); - } - - public void init(byte[] bytes) { - m_bytes = bytes; - m_length = bytes.length; - m_pos = 0; - m_open = true; - } - - private void _check() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { - if (m_bytes == null) { - throw new com.sun.star.io.NotConnectedException("no bytes"); - } - if(!m_open) { - throw new com.sun.star.io.IOException("input closed"); - } - } - - public int available() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { - _check(); - long a = m_length - m_pos; - if (a != (int)a) - throw new com.sun.star.io.IOException("integer overflow"); - else { - return (int)a; - } - } - - public void closeInput() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { - _check(); - m_open = false; - } - - public int readBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { - _check(); - try { - int remain = (m_length - m_pos); - if (param > remain) param = remain; - /* ARGH!!! */ - if (values[0] == null){ - values[0] = new byte[param]; - } - System.arraycopy(m_bytes, m_pos, values[0], 0, param); - m_pos += param; - return param; - } catch (ArrayIndexOutOfBoundsException ex) { - throw new com.sun.star.io.BufferSizeExceededException(ex, "buffer overflow"); - } catch (Exception ex) { - throw new com.sun.star.io.IOException(ex, "error accessing buffer"); - } - } - - public int readSomeBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { - return readBytes(values, param); - } - - public void skipBytes(int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { - _check(); - if (param > (m_length - m_pos)) - throw new com.sun.star.io.BufferSizeExceededException("buffer overflow"); - m_pos += param; - } - - public long getLength() throws com.sun.star.io.IOException { - if (m_bytes != null) return m_length; - else throw new com.sun.star.io.IOException("no bytes"); - } - - public long getPosition() throws com.sun.star.io.IOException { - if (m_bytes != null) return m_pos; - else throw new com.sun.star.io.IOException("no bytes"); - } - - public void seek(long param) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException { - if (m_bytes != null){ - if (param < 0 || param > m_length) throw new com.sun.star.lang.IllegalArgumentException("invalid seek position"); - else m_pos = (int)param; - }else throw new com.sun.star.io.IOException("no bytes"); - } -} diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java deleted file mode 100644 index 3d60e5a1181a..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.lib.uno.adapter; - -import java.io.IOException; - -import com.sun.star.io.XInputStream; - -import java.io.InputStream; - -/** The InputStreamToInputXStreamAdapter wraps the - Java InputStream object into a - UNO XInputStream object. - This allows users to access an InputStream - as if it were an XInputStream. - */ -public final class InputStreamToXInputStreamAdapter implements XInputStream { - - /** - * Internal store to the InputStream - */ - private final InputStream iIn; - - /** - * Constructor. - * - * @param in The XInputStream to be - * accessed as an InputStream. - */ - public InputStreamToXInputStreamAdapter (InputStream in) - { - iIn = in; - } - - public int available() throws - com.sun.star.io.IOException - { - - int bytesAvail; - - try { - bytesAvail = iIn.available(); - } catch (IOException e) { - throw new com.sun.star.io.IOException(e); - } - - return bytesAvail; - } - - public void closeInput() throws - com.sun.star.io.IOException - { - try { - iIn.close(); - } catch (IOException e) { - throw new com.sun.star.io.IOException(e); - } - } - - public int readBytes(byte[][] b, int len) throws - com.sun.star.io.IOException - { - try { - long bytesRead; - if (len >iIn.available()) { - bytesRead = iIn.read(b[0], 0, iIn.available()); - } - else{ - bytesRead = iIn.read(b[0], 0, len); - } - // Casting bytesRead to an int is okay, since the user can - // only pass in an integer length to read, so the bytesRead - // must <= len. - - if (bytesRead <= 0) { - return 0; - } - return ((int)bytesRead); - - - } catch (IOException e) { - throw new com.sun.star.io.IOException("reader error", e); - } - } - - public int readSomeBytes(byte[][] b, int len) throws - com.sun.star.io.IOException - { - try { - long bytesRead; - if (len >iIn.available()) { - bytesRead = iIn.read(b[0], 0, iIn.available()); - } - else{ - bytesRead = iIn.read(b[0], 0, len); - } - // Casting bytesRead to an int is okay, since the user can - // only pass in an integer length to read, so the bytesRead - // must <= len. - - if (bytesRead <= 0) { - return 0; - } - return ((int)bytesRead); - - - } catch (IOException e) { - throw new com.sun.star.io.IOException("reader error", e); - } - } - - public void skipBytes(int n) throws - com.sun.star.io.IOException - { - try { - iIn.available(); - } catch (IOException e) { - throw new com.sun.star.io.IOException(e); - } - - do { - try { - n -= iIn.skip(n); - } catch (IOException e) { - throw new com.sun.star.io.IOException(e); - } - } while (n > 0); - } -} - diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java deleted file mode 100644 index 2842e3df05ce..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.adapter; - -import java.io.IOException; - -import com.sun.star.io.XOutputStream; - -import java.io.OutputStream; - -/** The OutputStreamToXOutputStreamAdapter wraps - a UNO XOutputStream into a Java OutputStream - object in a Java. This allows users to access an OutputStream - as if it were an XOutputStream. - */ -public final class OutputStreamToXOutputStreamAdapter implements XOutputStream { - - /** - * Internal handle to the OutputStream - */ - OutputStream iOut; - - /** - * Constructor. - * - * @param out The XOutputStream to be - * accessed as an OutputStream. - */ - public OutputStreamToXOutputStreamAdapter(OutputStream out) { - iOut = out; - } - - public void closeOutput() throws - com.sun.star.io.IOException - { - try { - iOut.close(); - } catch (IOException e) { - throw new com.sun.star.io.IOException(e); - } - } - - public void flush() throws - com.sun.star.io.IOException - { - try { - iOut.flush(); - } catch (IOException e) { - throw new com.sun.star.io.IOException(e); - } - } - - public void writeBytes(byte[] b) throws - com.sun.star.io.IOException - { - - try { - iOut.write(b); - } catch (IOException e) { - throw new com.sun.star.io.IOException(e); - } - } - -} diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java deleted file mode 100644 index 25f1798fbada..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.lib.uno.adapter; - -import java.io.IOException; - -import com.sun.star.io.XInputStream; - -import java.io.InputStream; - -/** - * The XInputStreamToInputStreamAdapter wraps - * the UNO XInputStream object in a Java - * InputStream. This allows users to access - * an XInputStream as if it were an - * InputStream. - */ -public final class XInputStreamToInputStreamAdapter extends InputStream { - - /** - * Internal handle to the XInputStream - */ - private final XInputStream xin; - - /** - * Constructor. - * - * @param in The XInputStream to be - * accessed as an InputStream. - */ - public XInputStreamToInputStreamAdapter (XInputStream in) { - xin = in; - } - - @Override - public int available() throws IOException { - - int bytesAvail; - - try { - bytesAvail = xin.available(); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - - return bytesAvail; - } - - @Override - public void close() throws IOException { - try { - xin.closeInput(); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } - - @Override - public int read () throws IOException { - byte [][] tmp = new byte [1][1]; - try { - long bytesRead = xin.readBytes(tmp, 1); - - if (bytesRead <= 0) { - return (-1); - } else { - int tmpInt = tmp[0][0]; - if (tmpInt< 0 ){ - tmpInt = 256 +tmpInt; - } - return tmpInt; - } - - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } - - @Override - public int read (byte[] b) throws IOException { - - byte [][] tmp = new byte [1][b.length]; - int bytesRead; - - try { - bytesRead = xin.readBytes(tmp, b.length); - if (bytesRead <= 0) { - return -1; - } else if (bytesRead < b.length) { - System.arraycopy(tmp[0], 0, b, 0, bytesRead); - } else { - System.arraycopy(tmp[0], 0, b, 0, b.length); - } - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - - return bytesRead; - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - byte [][] tmp = new byte [1][b.length]; - try { - long bytesRead; - int av = xin.available(); - if ( av != 0 && len > av) { - bytesRead = xin.readBytes(tmp, av); - } - else{ - bytesRead = xin.readBytes(tmp,len); - } - // Casting bytesRead to an int is okay, since the user can - // only pass in an integer length to read, so the bytesRead - // must <= len. - - if (bytesRead <= 0) { - return -1; - } else if (bytesRead < len) { - System.arraycopy(tmp[0], 0, b, off, (int)bytesRead); - } else { - System.arraycopy(tmp[0], 0, b, off, len); - } - - return ((int)bytesRead); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } - - @Override - public long skip(long n) throws IOException { - - int avail; - long tmpLongVal = n; - int tmpIntVal; - - try { - avail = xin.available(); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - - do { - if (tmpLongVal >= Integer.MAX_VALUE) { - tmpIntVal = Integer.MAX_VALUE; - } else { - // Casting is safe here. - tmpIntVal = (int)tmpLongVal; - } - tmpLongVal -= tmpIntVal; - - try { - xin.skipBytes(tmpIntVal); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } while (tmpLongVal > 0); - - if ( avail != 0 && avail < n) { - return avail; - } else { - return n; - } - } - - /** - * Tests if this input stream supports the mark and reset methods. - * The markSupported method of - * XInputStreamToInputStreamAdapter returns false. - * - * @return false - */ - @Override - public boolean markSupported() { - return false; - } - - @Override - public synchronized void mark(int readlimit) { - // Not supported. - } - - @Override - public synchronized void reset() throws IOException { - // Not supported. - } -} - diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java deleted file mode 100644 index 48871277a75f..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.lib.uno.adapter; - -import com.sun.star.io.*; -import com.sun.star.lib.uno.helper.ComponentBase; - -public final class XOutputStreamToByteArrayAdapter - extends ComponentBase - implements XOutputStream -{ - private static final int initialSize = 100240; // 10 kb - private int size = 0; - private int position = 0; - private boolean externalBuffer = false; - private byte[] buffer; - - /** Creates a new instance of ByteArrayXOutputStream */ - public XOutputStreamToByteArrayAdapter() { - this(null); - } - - public XOutputStreamToByteArrayAdapter(byte[] aBuffer) { - if (aBuffer != null) { - externalBuffer = true; - buffer = aBuffer; - size = buffer.length; - } else { - size = initialSize; - buffer = new byte[size]; - } - } - - public byte[] getBuffer() { - return buffer; - } - - public void closeOutput() - throws com.sun.star.io.NotConnectedException, - com.sun.star.io.BufferSizeExceededException, - com.sun.star.io.IOException - { - // trim buffer - if ( buffer.length > position && !externalBuffer ) - { - byte[] newBuffer = new byte[position]; - System.arraycopy(buffer, 0, newBuffer, 0, position); - buffer = newBuffer; - } - } - - public void flush() - throws com.sun.star.io.NotConnectedException, - com.sun.star.io.BufferSizeExceededException, - com.sun.star.io.IOException - { - } - - public void writeBytes(byte[] values) - throws com.sun.star.io.NotConnectedException, - com.sun.star.io.BufferSizeExceededException, - com.sun.star.io.IOException - { - if ( values.length > size-position ) - { - if ( externalBuffer ) - throw new BufferSizeExceededException("out of buffer space, cannot grow external buffer"); - while ( values.length > size-position ) { - size *= 2; - } - byte[] newBuffer = new byte[size]; - System.arraycopy(buffer, 0, newBuffer, 0, position); - buffer = newBuffer; - } - System.arraycopy(values, 0, buffer, position, values.length); - position += values.length; - } - -} diff --git a/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java b/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java deleted file mode 100644 index 8104cf42fa3c..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.adapter; - -import java.io.IOException; - -import com.sun.star.io.XOutputStream; - -import java.io.OutputStream; - -/** - * The XOutputStreamToOutputStreamAdapter wraps - * the UNO XOutputStream object in a Java - * OutputStream. This allows users to access - * an XOutputStream as if it were an - * OutputStream. - */ -public final class XOutputStreamToOutputStreamAdapter extends OutputStream { - - /** - * Internal handle to the XInputStream - */ - XOutputStream xout; - - /** - * Constructor. - * - * @param out The XOutputStream to be - * accessed as an OutputStream. - */ - public XOutputStreamToOutputStreamAdapter(XOutputStream out) { - xout = out; - } - - @Override - public void close() throws IOException { - try { - xout.closeOutput(); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } - - @Override - public void flush() throws IOException { - try { - xout.flush(); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } - - @Override - public void write(byte[] b) throws IOException { - - try { - xout.writeBytes(b); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } - - @Override - public void write(byte[] b, int off, int len) throws IOException { - - byte[] tmp = new byte[len]; - - // Copy the input array into a temp array, and write it out. - - System.arraycopy(b, off, tmp, 0, len); - - try { - xout.writeBytes(tmp); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } - - @Override - public void write(int b) throws IOException { - - byte [] oneByte = new byte [1]; - oneByte[0] = (byte) b; - - try { - xout.writeBytes(oneByte); - } catch (Exception e) { - IOException newEx = new IOException(e.getMessage()); - newEx.initCause(e); - throw newEx; - } - } -} diff --git a/javaunohelper/com/sun/star/lib/uno/helper/ComponentBase.java b/javaunohelper/com/sun/star/lib/uno/helper/ComponentBase.java deleted file mode 100644 index d886ef7020d5..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/ComponentBase.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.helper; -import com.sun.star.lang.XComponent; -import com.sun.star.lang.XEventListener; -import com.sun.star.lang.EventObject; -import com.sun.star.uno.Type; - -/** This class can be used as the base class for UNO components. In addition to the functionality ,which - * is inherited from WeakBase, it implements com.sun.star.lang.XComponent. - */ -public class ComponentBase extends WeakBase implements XComponent -{ - private static final boolean DEBUG= false; - protected MultiTypeInterfaceContainer listenerContainer; - protected boolean bInDispose= false; - protected boolean bDisposed= false; - static final Type EVT_LISTENER_TYPE= new Type(XEventListener.class); - - - /** Creates a new instance of CompBase */ - public ComponentBase() - { - super(); - listenerContainer= new MultiTypeInterfaceContainer(); - } - - /** Override to perform extra clean-up work. Provided for subclasses. It is - called during dispose() - */ - protected void preDisposing() - { - } - /** Override to become notified right before the disposing action is performed. - */ - protected void postDisposing() - { - } - - - /** Method of XComponent. It is called by the owning client when the component is not needed - * anymore. The registered listeners are notified that this method has been called. - */ - public void dispose() - { - // Determine in a thread-safe way if this is the first call to this method. - // Only then we proceed with the notification of event listeners. - // It is an error to call this method more than once. - boolean bDoDispose= false; - synchronized (this) - { - if ( ! bInDispose && ! bDisposed) - { - bDoDispose= true; - bInDispose= true; - } - } - // The notification occurs in an unsynchronized block in order to avoid - // deadlocks if one of the listeners calls back in a different thread on - // a synchronized method which uses the same object. - if (bDoDispose) - { - try - { - preDisposing(); - listenerContainer.disposeAndClear(new EventObject(this)); - //notify subclasses that disposing is in progress - postDisposing(); - } - finally - { - // finally makes sure that the flags are set even if a RuntimeException is thrown. - // That ensures that this function is only called once. - synchronized (this) - { - bDisposed= true; - bInDispose= false; - } - } - } - else - { - // in a multithreaded environment, it can't be avoided, that dispose is called twice. - // However this condition is traced, because it MAY indicate an error. - if (DEBUG) - System.out.println("OComponentHelper::dispose() - dispose called twice" ); - } - } - - /** Method of XComponent. - */ - public void removeEventListener(XEventListener xEventListener) - { - listenerContainer.removeInterface( EVT_LISTENER_TYPE, xEventListener); - } - - public void addEventListener(XEventListener listener) - { - boolean bDoDispose= false; - synchronized (this) - { - if (bDisposed || bInDispose) - bDoDispose= true; - else - listenerContainer.addInterface(EVT_LISTENER_TYPE, listener); - } - if (bDoDispose ) - { - listener.disposing( new EventObject(this)); - } - } - - @Override - protected void finalize() throws Throwable - { - if ( ! bInDispose && ! bDisposed) - dispose(); - super.finalize(); - } -} diff --git a/javaunohelper/com/sun/star/lib/uno/helper/Factory.java b/javaunohelper/com/sun/star/lib/uno/helper/Factory.java deleted file mode 100644 index 056d9549d552..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/Factory.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.lib.uno.helper; - -import com.sun.star.uno.XComponentContext; -import com.sun.star.lang.XSingleComponentFactory; -import com.sun.star.lang.XServiceInfo; -import com.sun.star.lang.XInitialization; -import com.sun.star.registry.XRegistryKey; -import com.sun.star.uno.UnoRuntime; - - -/** Factory helper class supporting com.sun.star.lang.XServiceInfo and - com.sun.star.lang.XSingleComponentFactory. - -

- Note: This factory implementation does not support lang.XSingleServiceFactory. -

-*/ -public class Factory - extends ComponentBase - implements XSingleComponentFactory, XServiceInfo -{ - private static final boolean DEBUG = false; - - /** Creates an object factory supporting interfaces - com.sun.star.lang.XSingleComponentFactory and - com.sun.star.lang.XServiceInfo - - @param impl_class - implementation class - @param impl_name - implementation name - @param supported_services - services implemented - @return - object factory - - @since UDK 3.2.13 - */ - public static XSingleComponentFactory createComponentFactory( - Class impl_class, String impl_name, String supported_services [] ) - throws com.sun.star.uno.RuntimeException - { - return new Factory( impl_class, impl_name, supported_services ); - } - - /** Creates an object factory supporting interfaces - com.sun.star.lang.XSingleComponentFactory and - com.sun.star.lang.XServiceInfo - - The implementation name is the name of the implementation class. - - @param impl_class - implementation class - @param supported_services - services implemented - @return - object factory - */ - public static XSingleComponentFactory createComponentFactory( - Class impl_class, String supported_services [] ) - throws com.sun.star.uno.RuntimeException - { - return createComponentFactory( - impl_class, impl_class.getName(), supported_services ); - } - /** Writes component's implementation info to given registry key. - - @param impl_name - name of implementation - @param supported_services - supported services of implementation - @param xKey - registry key to write to - @return - success - */ - public static boolean writeRegistryServiceInfo( - String impl_name, String supported_services [], XRegistryKey xKey ) - { - try - { - XRegistryKey xNewKey = xKey.createKey( "/" + impl_name + "/UNO/SERVICES" ); - for ( int nPos = 0; nPos < supported_services.length; ++nPos ) - { - xNewKey.createKey( supported_services[ nPos ] ); - } - return true; - } - catch (com.sun.star.registry.InvalidRegistryException exc) - { - if (DEBUG) - { - System.err.println( - "##### " + Factory.class.getName() + ".writeRegistryServiceInfo -- exc: " + - exc.toString() ); - } - } - return false; - } - - - private final String m_impl_name; - private final String [] m_supported_services; - private final Class m_impl_class; - private final java.lang.reflect.Method m_method; - private final java.lang.reflect.Constructor m_ctor; - - private Factory( - Class impl_class, String impl_name, String supported_services [] ) - throws com.sun.star.uno.DeploymentException - { - m_impl_name = impl_name; - m_supported_services = supported_services; - m_impl_class = impl_class; - - Class params [] = new Class [] { XComponentContext.class }; - - if (!java.lang.reflect.Modifier.isPublic( impl_class.getModifiers() )) - { - throw new com.sun.star.uno.DeploymentException("class " + impl_class + " is not public"); - } - - java.lang.reflect.Method tmpMethod = null; - try - { - // seeking for "public static Object __create( XComponentContext )" - tmpMethod = m_impl_class.getMethod( "__create", params ); - int mod = tmpMethod.getModifiers(); - if (!tmpMethod.getReturnType().equals( Object.class ) || - !java.lang.reflect.Modifier.isStatic( mod ) || - !java.lang.reflect.Modifier.isPublic( mod )) - { - tmpMethod = null; - } - } - catch (Exception exc) - { - } - m_method = tmpMethod; - - - java.lang.reflect.Constructor tmpCtor = null; - if (null == m_method) - { - try - { - // ctor with context - tmpCtor = m_impl_class.getConstructor( params ); - } - catch (Exception exc) - { - } - if (tmpCtor != null) - { - if (!java.lang.reflect.Modifier.isPublic( tmpCtor.getModifiers() )) - { - throw new com.sun.star.uno.DeploymentException("constructor with XComponentContext param for class " + impl_class + " is not public"); - } - } - else - { - // else take default ctor - java.lang.reflect.Constructor defaultCtor; - try - { - defaultCtor = m_impl_class.getConstructor(new Class[0]); - } - catch (Exception exc2) - { - throw new com.sun.star.uno.DeploymentException(exc2, "class " + impl_class + " has no means of creating it, cannot find a __create method or a useful constructor."); - } - if (!java.lang.reflect.Modifier.isPublic( defaultCtor.getModifiers() )) - { - throw new com.sun.star.uno.DeploymentException("default constructor for class " + impl_class + " is not public"); - } - } - } - m_ctor = tmpCtor; - } - - - private Object instantiate( XComponentContext xContext ) - throws com.sun.star.uno.Exception - { - try - { - if (DEBUG) - System.out.print( "instantiating " + m_impl_class.toString() + " using " ); - if (null != m_method) - { - if (DEBUG) - System.out.println( "__create( XComponentContext )..." ); - return m_method.invoke( null, new Object [] { xContext } ); - } - if (null != m_ctor) - { - if (DEBUG) - System.out.println( "ctor( XComponentContext )..." ); - return m_ctor.newInstance( new Object [] { xContext } ); - } - if (DEBUG) - System.out.println( "default ctor..." ); - return m_impl_class.newInstance(); // default ctor - } - catch (java.lang.reflect.InvocationTargetException exc) - { - Throwable targetException = exc.getTargetException(); - if (targetException instanceof java.lang.RuntimeException) - throw (java.lang.RuntimeException)targetException; - else if (targetException instanceof com.sun.star.uno.RuntimeException) - throw (com.sun.star.uno.RuntimeException)targetException; - else if (targetException instanceof com.sun.star.uno.Exception) - throw (com.sun.star.uno.Exception)targetException; - else - throw new com.sun.star.uno.Exception(targetException, targetException.getMessage(), this); - } - catch (IllegalAccessException exc) - { - throw new com.sun.star.uno.RuntimeException( exc, exc.getMessage(), this); - } - catch (InstantiationException exc) - { - throw new com.sun.star.uno.RuntimeException( exc, exc.getMessage(), this); - } - } - // XSingleComponentFactory impl - - public final Object createInstanceWithContext( - XComponentContext xContext ) - throws com.sun.star.uno.Exception - { - return instantiate( xContext ); - } - - public final Object createInstanceWithArgumentsAndContext( - Object arguments [], XComponentContext xContext ) - throws com.sun.star.uno.Exception - { - Object inst = instantiate( xContext ); - XInitialization xInit = UnoRuntime.queryInterface( - XInitialization.class, inst ); - if (null == xInit) - { - throw new com.sun.star.lang.IllegalArgumentException( - "cannot pass arguments to component; no XInitialization implemented!", this, - (short)0 ); - } - xInit.initialize( arguments ); - return inst; - } - - // XServiceInfo impl - - public final String getImplementationName() - { - return m_impl_name; - } - - public final boolean supportsService( String service_name ) - { - for ( int nPos = 0; nPos < m_supported_services.length; ++nPos ) - { - if (m_supported_services[ nPos ].equals( service_name )) - return true; - } - return false; - } - - public final String [] getSupportedServiceNames() - { - return m_supported_services; - } -} - diff --git a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java b/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java deleted file mode 100644 index e858ced81fd8..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/InterfaceContainer.java +++ /dev/null @@ -1,864 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.helper; - -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Collection; - -import com.sun.star.lang.EventObject; -import com.sun.star.lang.XEventListener; -import com.sun.star.uno.UnoRuntime; - -/** - * This class is a container for interfaces. - * - * It is intended to be used as storage for UNO interface of a specific type. - * The client has to ensure that the container contains only elements of the same - * type. If one needs to store different types, then one uses OMultiTypeInterfaceContainer. - * When the client calls disposeAndClear, the contained objects are queried for - * com.sun.star.lang.XEventListener and disposing is called. Afterwards - * the list cannot be used anymore. - * - * This list does not allow null values. - * All methods are thread-safe. The same holds true for - * iterators, issued by this class. Several iterators can exist at the same time and can also - * be modified (java.util.ListIterator.add, java.util.ListIterator.remove etc.). To make this work, - * the InterfaceContainer provides the iterators with copies of the list's data. - * The add and remove calls on the iterator modify the data in the iterator's list as well as - * in InterfaceContainer. Modification on InterfaceContainer, however, are not - * synchronized with existing iterators. For example - *
- * InterfaceContainer cont= new InterfaceContainer();
- * ListIterator it= cont.listIterator();
- *
- * cont.add( someInterface);
- * // one cannot obtain someInterface through iterator it,
- * // instead get a new iterator
- * it= cont.listIterator();
- * // it now keeps a fresh copy of cont and hence contains someInterface
- *
- * // Adding an interface on the iterator will cause the interface also to be added
- * // to InterfaceContainer
- * it.add( someOtherInterface);
- * // someOtherInterface is now in it and cont
- * ListIterator it2= cont.listIterator();
- * //someOtherInterface can also be obtained by all newly created iterators, e.g. it2.
- * 
- * - * The add and remove methods of an iterator work on a particular location within a list, - * dependent on what the value of the iterator's cursor is. After the call the value at the - * appropriate position has been modified. Since the iterator received a copy of InterfaceContainer's - * data, InterfaceContainer may have been modified (by List methods or through other iterators). - * Therefore both data sets may not contain the same elements anymore. Consequently, a List method - * that modifies data, does not modify InterfaceContainer's data at a certain index - * (according to the iterators cursor). Instead, new elements are added at the end of list. When - * Iterator.remove is called, then the first occurrence of that element in InterfaceContainer - * is removed. - * ListIterator.set is not supported. - * - * A lot of methods resemble those of the to java.util.List interface, although - * this class does not implement it. However, the list iterators returned, for example by - * the listIterator method implement the java.util.ListIterator interface. - * Implementing the List interface would mean to support all none - optional methods as - * prescribed by the interface declaration. Among those is the subList method which returns - * a range of values of the list's data wrapped in a List implementation. Changes to the sub - * list have to cause changes in the main list. This is a problem, since this class is to be - * used in a multi-threaded environment. The sub list could work on a copy as the iterators - * do, but all the functions which work on a given index could not be properly supported. - * Unfortunately, the List interface documentation states that all optional methods implemented - * by the list have to be implemented in the sub list. That would mean to do without all those - * critical methods, although they might work well in the "main list" (as opposed to sub list). - */ -public class InterfaceContainer implements Cloneable -{ - static final boolean DEBUG= false; - /** - * The array buffer into which the elements of the ArrayList are stored. - * The capacity of the ArrayList is the length of this array buffer. - */ - Object elementData[]; - - /** - * The size of the ArrayList (the number of elements it contains). - */ - private int size; - - - /** Creates a new instance of InterfaceContainer */ - public InterfaceContainer() - { - this(10); - } - /** - * Constructs an empty list with the specified initial capacity. - * - * @param initialCapacity the initial capacity of the list. - * @exception IllegalArgumentException if the specified initial capacity - * is negative - */ - public InterfaceContainer(int initialCapacity) - { - if (initialCapacity < 0) - throw new java.lang.IllegalArgumentException("Illegal Capacity: "+ - initialCapacity); - this.elementData = new Object[initialCapacity]; - } - - private InterfaceContainer(Object[] data) { - elementData = data; - size = elementData == null ? 0 : elementData.length; - } - - /** - * Trims the capacity of this ArrayList instance to be the - * list's current size. An application can use this operation to minimize - * the storage of an ArrayList instance. - */ - synchronized public void trimToSize() - { - int oldCapacity = elementData.length; - if (size < oldCapacity) - { - Object oldData[] = elementData; - elementData = new Object[size]; - System.arraycopy(oldData, 0, elementData, 0, size); - } - } - - /** - * Increases the capacity of this ArrayList instance, if - * necessary, to ensure that it can hold at least the number of elements - * specified by the minimum capacity argument. - * - * @param minCapacity the desired minimum capacity. - */ - synchronized public void ensureCapacity(int minCapacity) - { - int oldCapacity = elementData.length; - if (minCapacity > oldCapacity) - { - Object oldData[] = elementData; - int newCapacity = (oldCapacity * 3)/2 + 1; - if (newCapacity < minCapacity) - newCapacity = minCapacity; - elementData = new Object[newCapacity]; - System.arraycopy(oldData, 0, elementData, 0, size); - } - } - - /** - * Appends the specified element to the end of this list. - * - * @param o element to be appended to this list. - * @return true (as per the general contract of Collection.add). - */ - synchronized public boolean add(Object o) - { - boolean ret= false; - if (elementData != null && o != null) - { - ensureCapacity(size + 1); // Increments modCount!! - elementData[size++] = o; - ret= true; - } - return ret; - } - - /** - * Inserts the specified element at the specified position in this - * list. Shifts the element currently at that position (if any) and - * any subsequent elements to the right (adds one to their indices). - * - * @param index index at which the specified element is to be inserted. - * @param element element to be inserted. - * @throws IndexOutOfBoundsException if index is out of range - * (index < 0 || index > size()). - */ - synchronized public void add(int index, Object element) - { - if (elementData != null && element != null) - { - if (index > size || index < 0) - throw new IndexOutOfBoundsException( - "Index: "+index+", Size: "+size); - - ensureCapacity(size+1); - System.arraycopy(elementData, index, elementData, index + 1, - size - index); - elementData[index] = element; - size++; - } - } - - - /** - * Appends all of the elements in the specified Collection to the end of - * this list, in the order that they are returned by the - * specified Collection's Iterator. The behavior of this operation is - * undefined if the specified Collection is modified while the operation - * is in progress. (This implies that the behavior of this call is - * undefined if the specified Collection is this list, and this - * list is nonempty.) - * - * @param c the elements to be inserted into this list. - * @throws IndexOutOfBoundsException if index out of range (index - * < 0 || index > size()). - * @return true if an element was inserted. - */ - synchronized public boolean addAll(Collection c) - { - int numNew = c.size(); - ensureCapacity(size + numNew); - - Iterator e = c.iterator(); - for (int i=0; i(index - * < 0 || index > size()). - * @return true if an element was inserted. - */ - synchronized public boolean addAll(int index, Collection c) - { - boolean ret= false; - if (elementData != null) - { - if (index > size || index < 0) - throw new IndexOutOfBoundsException( - "Index: "+index+", Size: "+size); - // only add the non-null elements - int sizeCol= c.size(); - Object[] arColl= new Object[sizeCol]; - Iterator icol= c.iterator(); - int curIndex= 0; - for (int i=0; i < sizeCol; i++) - { - Object o= icol.next(); - if (o != null) - arColl[curIndex++]= o; - } - int numNew = curIndex; - ensureCapacity(size + numNew); // Increments modCount!! - - int numMoved = size - index; - if (numMoved > 0) - System.arraycopy(elementData, index, elementData, index + numNew, - numMoved); - - for (int i=0; itrue if this list contains the specified element. - * - * @param elem element whose presence in this List is to be tested. - * @return true if this list contains the specified element. - */ - synchronized public boolean contains(Object elem) - { - return indexOf(elem) >= 0; - } - - synchronized public boolean containsAll(Collection collection) - { - boolean retVal= true; - if (elementData != null && collection != null) - { - Iterator it= collection.iterator(); - while (it.hasNext()) - { - Object obj= it.next(); - if (!contains(obj)) - { - retVal= false; - break; - } - } - } - return retVal; - } - /** - * Returns the element at the specified position in this list. - * - * @param index index of element to return. - * @return the element at the specified position in this list. - * @throws IndexOutOfBoundsException if index is out of range (index - * < 0 || index >= size()). - */ - synchronized public Object get(int index) - { - if (elementData != null) - { - RangeCheck(index); - return elementData[index]; - } - return null; - } - - /** - * Searches for the first occurrence of the given argument, testing - * for equality using the equals method. - * - * @param elem an object. - * @return the index of the first occurrence of the argument in this - * list; returns -1 if the object is not found. - * @see Object#equals(Object) - */ - synchronized public int indexOf(Object elem) - { - if (elementData == null || elem == null) { - return -1; - } - - int index= -1; - - for (int i = 0; i < size; i++) - { - if (elem == elementData[i]) - { - index= i; - break; - } - } - - if (index == -1) - { - for (int i = 0; i < size; i++) - { - if (UnoRuntime.areSame(elem, elementData[i])) - { - index= i; - break; - } - } - } - return index; - } - /** - * Tests if this list has no elements. - * - * @return true if this list has no elements; - * false otherwise. - */ - synchronized public boolean isEmpty() - { - return size == 0; - } - - synchronized public Iterator iterator() - { - if (elementData != null) - { - InterfaceContainer aCopy= (InterfaceContainer) clone(); - return new Itr(aCopy); - } - return null; - } - /** - * Returns the index of the last occurrence of the specified object in - * this list. - * - * @param elem the desired element. - * @return the index of the last occurrence of the specified object in - * this list; returns -1 if the object is not found. - */ - synchronized public int lastIndexOf(Object elem) - { - if (elementData == null || elem == null) { - return -1; - } - - int index= -1; - - for (int i = size-1; i >= 0; i--) - { - if (elem == elementData[i]) - { - index= i; - break; - } - } - if (index == -1) - { - for (int i = size-1; i >= 0; i--) - { - if (UnoRuntime.areSame(elem, elementData[i])) - { - index= i; - break; - } - } - } - return index; - } - - /** - * Returns a shallow copy of this ArrayList instance. The contained - * references are copied but the objects not. - * - * @return a clone of this List instance. - */ - @Override - synchronized public Object clone() - { - Object[] data; - if (elementData == null) { - data = null; - } else { - data = new Object[size]; - System.arraycopy(elementData, 0, data, 0, size); - } - return new InterfaceContainer(data); - } - synchronized public ListIterator listIterator() - { - return listIterator(0); - } - - /** The iterator keeps a copy of the list. Changes to InterfaceContainer do not - * affect the data of the iterator. Conversely, changes to the iterator are effect - * InterfaceContainer. - * @param index the starting offset into the list. - * @return a new iterator. - */ - synchronized public ListIterator listIterator(int index) - { - if (elementData != null) - { - InterfaceContainer aCopy= (InterfaceContainer) clone(); - return new LstItr(aCopy, index); - } - return null; - } - /** - * Removes the element at the specified position in this list. - * Shifts any subsequent elements to the left (subtracts one from their - * indices). - * - * @param index the index of the element to removed. - * @return the element that was removed from the list. - * @throws IndexOutOfBoundsException if index out of range (index - * < 0 || index >= size()). - */ - synchronized public Object remove(int index) - { - Object ret= null; - if (elementData != null) - { - RangeCheck(index); - ret= elementData[index]; - - int numMoved = size - index - 1; - if (numMoved > 0) - System.arraycopy(elementData, index+1, elementData, index, - numMoved); - elementData[--size] = null; // Let gc do its work - } - return ret; - } - - - /** Parameter obj may... or may not. What did the original author want - * to tell us here? - * @param obj the object to be removed. - * @return true if obj was successfully removed from the list. - */ - synchronized public boolean remove(Object obj) - { - boolean ret= false; - if (elementData != null && obj != null) - { - int index= indexOf(obj); - if (index != -1) - { - ret= true; - remove(index); - } - } - return ret; - } - - synchronized public boolean removeAll(Collection collection) - { - boolean retVal= false; - if (elementData != null && collection != null) - { - Iterator it= collection.iterator(); - while (it.hasNext()) - { - Object obj= it.next(); - boolean bMod= remove( obj); - if (bMod) - retVal= true; - } - } - return retVal; - } - - synchronized public boolean retainAll(Collection collection) - { - if (elementData == null || collection == null) { - return false; - } - - boolean retVal= false; - // iterate over data - Object[] arRetained= new Object[size]; - int indexRetained= 0; - for(int i= 0; i < size; i++) - { - Object curElem= elementData[i]; - // try to find the element in collection - Iterator itColl= collection.iterator(); - boolean bExists= false; - while (itColl.hasNext()) - { - if (curElem == itColl.next()) - { - // current element is in collection - bExists= true; - break; - } - } - if (!bExists) - { - itColl= collection.iterator(); - while (itColl.hasNext()) - { - Object o= itColl.next(); - if (o != null && UnoRuntime.areSame(o, curElem)) - { - bExists= true; - break; - } - } - } - if (bExists) - arRetained[indexRetained++]= curElem; - } - retVal= size != indexRetained; - if (indexRetained > 0) - { - elementData= arRetained; - size= indexRetained; - } - return retVal; - } - - - /** Not supported. - * @param index index of element to replace. - * @param element element to be stored at the specified position. - * @return the element previously at the specified position. - * @throws IndexOutOfBoundsException if index out of range - * (index < 0 || index >= size()). - */ - synchronized public Object set(int index, Object element) - { - Object ret= null; - if (elementData != null && element != null) - { - RangeCheck(index); - ret = elementData[index]; - elementData[index] = element; - } - return ret; - } - - /** - * Returns the number of elements in this list. - * - * @return the number of elements in this list. - */ - synchronized public int size() - { - if (elementData != null) - return size; - return 0; - } - - - /** - * Returns an array containing all of the elements in this list - * in the correct order. - * - * @return an array containing all of the elements in this list - * in the correct order. - */ - synchronized public Object[] toArray() - { - if (elementData != null) - { - Object[] result = new Object[size]; - System.arraycopy(elementData, 0, result, 0, size); - return result; - } - return null; - } - - /** - * Returns an array containing all of the elements in this list in the - * correct order. The runtime type of the returned array is that of the - * specified array. If the list fits in the specified array, it is - * returned therein. Otherwise, a new array is allocated with the runtime - * type of the specified array and the size of this list.

- * - * If the list fits in the specified array with room to spare (i.e., the - * array has more elements than the list), the element in the array - * immediately following the end of the collection is set to - * null. This is useful in determining the length of the list - * only if the caller knows that the list does not contain any - * null elements. - * - * @param a the array into which the elements of the list are to - * be stored, if it is big enough; otherwise, a new array of the - * same runtime type is allocated for this purpose. - * @return an array containing the elements of the list. - * @throws ArrayStoreException if the runtime type of a is not a supertype - * of the runtime type of every element in this list. - */ - synchronized public Object[] toArray(Object a[]) - { - if (a.length < size) - a = (Object[])java.lang.reflect.Array.newInstance( - a.getClass().getComponentType(), size); - if (elementData != null) - System.arraycopy(elementData, 0, a, 0, size); - - if (a.length > size) - a[size] = null; - - return a; - } - - /** - * Check if the given index is in range. If not, throw an appropriate - * runtime exception. - */ - private void RangeCheck(int index) - { - if (index >= size || index < 0) - throw new IndexOutOfBoundsException( - "Index: "+index+", Size: "+size); - } - - public void disposeAndClear(EventObject evt) - { - Iterator aIt; - synchronized (this) - { - aIt= iterator(); - // Release containers if new entries occur in disposing; - // set the member to null, the iterator delete the values - clear(); - elementData= null; - size= 0; - } - if (aIt != null) - { - while( aIt.hasNext() ) - { - try - { - Object o= aIt.next(); - XEventListener evtListener= UnoRuntime.queryInterface( - XEventListener.class, o); - if( evtListener != null ) - evtListener.disposing( evt ); - } - catch ( RuntimeException e) - { - // be robust, if e.g. a remote bridge has disposed already. - // there is no way, to delegate the error to the caller :o(. - } - } - } - } - - - private class Itr implements Iterator - { - InterfaceContainer dataIt; - /** - * Index of element to be returned by subsequent call to next. - */ - int cursor= 0; - /** - * Index of element returned by most recent call to next or - * previous. Reset to -1 if this element is deleted by a call - * to remove. - */ - int lastRet = -1; - - /** The object that has been returned by most recent call to next - * or previous. Reset to null if this element is deleted by a call - * to remove. - */ - Object lastRetObj= null; - - Itr(InterfaceContainer _data) - { - dataIt= _data; - } - - synchronized public boolean hasNext() - { - return cursor !=dataIt.size(); - } - - public synchronized Object next() - { - try - { - Object next = dataIt.get(cursor); - lastRet = cursor++; - lastRetObj= next; - return next; - } - catch(java.lang.IndexOutOfBoundsException e) - { - java.util.NoSuchElementException ex2 = new java.util.NoSuchElementException(); - ex2.initCause(e); - throw ex2; - } - } - - /** Removes the interface from the list, that has been last returned by a - * call to next(). This is done according to the specification of the interface - * method. The element is also removed from InterfaceContainer but independent - * of the location. If the element is multiple times in InterfaceContainer then - * it is up to the java.util.ArrayList implementation what element is removed. - */ - public synchronized void remove() - { - if (lastRet == -1) - throw new IllegalStateException(); - // Remove the entry from InterfaceContainer. - InterfaceContainer.this.remove(lastRetObj); - dataIt.remove(lastRet); - - if (lastRet < cursor) - cursor--; - lastRet = -1; - lastRetObj= null; - } - } - - private class LstItr extends Itr implements ListIterator - { - - LstItr(InterfaceContainer _data, int _index) - { - super(_data); - cursor= _index; - } - - /** Inserts an element to the iterators list according to the specification - * of this interface method. The element is also added to InterfaceContainer - * but its location within the list cannot be guaranteed. - */ - public synchronized void add(Object o) - { - InterfaceContainer.this.add(o); - dataIt.add(cursor++, o); - lastRet = -1; - lastRetObj= null; - } - - synchronized public boolean hasPrevious() - { - return cursor != 0; - } - - synchronized public int nextIndex() - { - return cursor; - } - - public synchronized Object previous() - { - try - { - Object previous = dataIt.get(--cursor); - lastRet = cursor; - lastRetObj= previous; - return previous; - } catch(IndexOutOfBoundsException e) - { - java.util.NoSuchElementException ex2 = new java.util.NoSuchElementException(); - ex2.initCause(e); - throw ex2; - } - } - - synchronized public int previousIndex() - { - return cursor-1; - } - - /** This is not possible since several iterators can modify InterfaceContainer - */ - public synchronized void set(Object o) - { - throw new UnsupportedOperationException(); - } - - - } // class LstItr -} - diff --git a/javaunohelper/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java b/javaunohelper/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java deleted file mode 100644 index 9b061f81c217..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.helper; -import com.sun.star.uno.Type; -import com.sun.star.lang.EventObject; -import java.util.HashMap; -import java.util.Map; -import java.util.Iterator; - -public class MultiTypeInterfaceContainer -{ - - private final Map map= new HashMap(); - - /** only returns types which have at least one value in InterfaceContainer - * return value can contain an element null, if someone called - * addInterface (null, interf) - * @return an array of types in this container. - */ - synchronized public Type[] getContainedTypes() - { - int size; - Type[] retVal= null; - - if ( (size=map.size()) > 0) - { - Type [] arTypes= new Type[size]; - - int countTypes= 0; - for (Map.Entry entry : map.entrySet()) - { - InterfaceContainer cont= entry.getValue(); - if (cont != null && cont.size() > 0) - { - Object key = entry.getKey(); - if (key == null) - arTypes[countTypes++]= new Type(); - else if (key instanceof Type) - arTypes[countTypes++]= (Type) key; - else if (key instanceof Class) - arTypes[countTypes++]= new Type((Class) key); - else - arTypes[countTypes++]= new Type(key.getClass()); - } - } - - if (countTypes != size) - { - retVal= new Type[countTypes]; - System.arraycopy(arTypes, 0, retVal, 0, countTypes); - } - else - retVal= arTypes; - } - if (retVal == null) - retVal= new Type[0]; - return retVal; - } - - /** param key can be null - * @param key the object for which the container should be retrieved. - * @return the container that contains the object key, if any. - */ - synchronized public InterfaceContainer getContainer(Object key) - { - InterfaceContainer retVal= null; - for (Map.Entry entry : map.entrySet()) - { - Object obj= entry.getKey(); - if (obj == null && key == null) - { - retVal= map.get(null); - break; - } - else if( obj != null && obj.equals(key)) - { - retVal= entry.getValue(); - break; - } - } - return retVal; - } - - - synchronized public int addInterface(Object ckey, Object iface) - { - //If the key is a Type then it does not matter if the objects are different - // if they represent the same type. This is because Types overrides hashCode and - // equals. For example: - // Type a= new Type(XInterface.class); - // Type b= new Type(XInterface.class); - // Although a != b , the map interprets both as being the same. - InterfaceContainer cont= map.get(ckey); - if (cont != null) - { - cont.add(iface); - } - else - { - cont= new InterfaceContainer(); - cont.add(iface); - map.put(ckey, cont); - } - return cont.size(); - } - - - synchronized public int removeInterface(Object key, Object iface) - { - int retVal= 0; - InterfaceContainer cont= map.get(key); - if (cont != null) - { - cont.remove(iface); - retVal= cont.size(); - } - return retVal; - } - - public void disposeAndClear(EventObject evt) - { - Iterator it= null; - synchronized(this) - { - it= map.values().iterator(); - } - while (it.hasNext() ) { - it.next().disposeAndClear(evt); - } - } - - synchronized public void clear() - { - Iterator it= map.values().iterator(); - while (it.hasNext()) { - it.next().clear(); - } - } -} diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java deleted file mode 100644 index 67a4f0c98062..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySet.java +++ /dev/null @@ -1,1103 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package com.sun.star.lib.uno.helper; - -import com.sun.star.uno.Type; -import com.sun.star.lang.EventObject; -import com.sun.star.lang.WrappedTargetException; -import com.sun.star.uno.TypeClass; -import com.sun.star.uno.AnyConverter; -import com.sun.star.uno.XInterface; -import com.sun.star.uno.Any; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.beans.XPropertyChangeListener; -import com.sun.star.beans.XVetoableChangeListener; -import com.sun.star.beans.PropertyChangeEvent; -import com.sun.star.beans.XPropertySet; -import com.sun.star.beans.Property; -import com.sun.star.beans.PropertyAttribute; -import com.sun.star.beans.UnknownPropertyException; -import com.sun.star.beans.XPropertiesChangeListener; -import com.sun.star.beans.XPropertySetInfo; -import com.sun.star.beans.XFastPropertySet; -import com.sun.star.beans.PropertyVetoException; -import com.sun.star.beans.XMultiPropertySet; -import java.util.Iterator; -import java.util.Collection; -import java.util.HashMap; -import java.lang.reflect.Field; -import com.sun.star.lang.DisposedException; - - -/** This class is an implementation of the interfaces com.sun.star.beans.XPropertySet, - * com.sun.star.beans.XFastPropertySet and com.sun.star.beans.XMultiPropertySet. This - * class has to be inherited to be used. The values of properties are stored in member - * variables of the inheriting class. By overriding the methods - * {@link #convertPropertyValue convertPropertyValue}, - * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and - * {@link #getPropertyValue(Property)} one can determine how - * property values are stored. - * When using the supplied implementations of this class then the member variables which - * hold property values have to be declared in the class which inherits last in the inheriting - * chain and they have to be public

- * Properties have to be registered by one of the registerProperty methods. They take among other - * arguments an Object named id which has to be a String that represents the name of - * the member variable. The registering has to occur in the constructor of the inheriting class. - * It is no allowed to add or change properties later on.

- * Example: - *

- *  public class Foo extends PropertySet
- *  {
- *      protected int intProp;
- *
- *      public Foo()
- *      {
- *          registerProperty("PropertyA", 0, new Type(int.class), (short)0, "intProp");
- *      }
- *  }
- *
- *  
- */ -public class PropertySet extends ComponentBase implements XPropertySet, XFastPropertySet, -XMultiPropertySet -{ - private HashMap _nameToPropertyMap; - private HashMap _handleToPropertyMap; - private HashMap _propertyToIdMap; - private Property[] arProperties; - - private int lastHandle= 1; - - protected XPropertySetInfo propertySetInfo; - protected MultiTypeInterfaceContainer aBoundLC= new MultiTypeInterfaceContainer(); - protected MultiTypeInterfaceContainer aVetoableLC= new MultiTypeInterfaceContainer(); - public PropertySet() - { - super(); - initMappings(); - } - - /** Registers a property with this helper class and associates the argument id with it. - * id is used to identify the storage of the property value. How property values are stored - * and retrieved is determined by the methods {@link #convertPropertyValue convertPropertyValue}, - * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and {@link #getPropertyValue(Property) getPropertyValue} - * These methods expect id to be a String which represents the name of a member variable - * which holds the property value. - * Only properties which are registered can be accessed. Registration has to occur during - * initialization of the inheriting class (i.e. within the constructor). - * @param prop The property to be registered. - * @param id Identifies the properties storage. - * @see #getPropertyId - */ - protected void registerProperty(Property prop, Object id) - { - putProperty(prop); - assignPropertyId(prop, id); - } - - /** Registers a property with this helper class and associates the argument id with it. - * It does the same as {@link #registerProperty(Property, Object)}. The first four - * arguments are used to construct a Property object. - * Registration has to occur during - * initialization of the inheriting class (i.e. within the constructor) - * @param name The property's name (Property.Name). - * @param handle The property's handle (Property.Handle). - * @param type The property's type (Property.Type). - * @param attributes The property's attributes (Property.Attributes). - * @param id Identifies the property's storage. - */ - protected void registerProperty(String name, int handle, Type type, short attributes, Object id) - { - Property p= new Property(name, handle, type, attributes); - registerProperty(p, id); - } - - /** Registers a property with this class and associates the argument id with it. - * It does the same as {@link #registerProperty(Property, Object)}. The first three - * arguments are used to construct a Property object. The value for the Property.Handle - * is generated and does not have to be specified here. Use this method for registering - * a property if you do not care about the Property's handles. - * Registration has to occur during - * initialization of the inheriting class (i.e. within the constructor). - * @param name The property's name (Property.Name). - * @param type The property's type (Property.Type). - * @param attributes The property's attributes (Property.Attributes). - * @param id Identifies the property's storage. - */ - protected void registerProperty(String name, Type type, short attributes, Object id) - { - Property p= new Property(name, lastHandle++, type, attributes); - registerProperty(p, id); - } - - /** Registers a property with this class. This method expects that property values - * are stored in member variables as is the case if the methods convertPropertyValue, - * setPropertyValueNoBroadcast and getPropertyValue(Property) are not overridden. - * It is presumed that the type of the member variable - * corresponds Property.Type. For example, if the TypeClass of Property.Type is to be - * a TypeClass.SHORT then the member must be a short or java.lang.Short. - * The handle for the property is generated.
- * If there is no member with the specified name or if the member has an incompatible type - * then a com.sun.star.uno.RuntimeException is thrown. - * @param propertyName The name of the property. - * @param memberName The name of the member variable that holds the value of the property. - * @param attributes The property attributes. - */ - protected void registerProperty(String propertyName, String memberName, short attributes) - { - Field propField= null; - try - { - propField= getClass().getDeclaredField(memberName); - } - catch (NoSuchFieldException e) - { - throw new com.sun.star.uno.RuntimeException(e, "there is no member variable: " + memberName); - } - Class cl= propField.getType(); - Type t= new Type(cl); - if (t.getTypeClass() != TypeClass.UNKNOWN) - { - Property p= new Property(propertyName, lastHandle++, t, attributes); - registerProperty(p,memberName); - } - else - throw new com.sun.star.uno.RuntimeException("the member has an unknown type: " + memberName); - } - - /** Registers a property with this class. - * It is presumed that the name of property is equal to the name of the member variable - * that holds the property value. - * @param propertyName The name of the property and the member variable that holds the property's value. - * @param attributes The property attributes. - * @see #registerProperty(String, String, short) - */ - protected void registerProperty(String propertyName, short attributes) - { - registerProperty(propertyName, propertyName, attributes); - } - - - - /** Returns the Property object for a given property name or null if that property does - * not exists (i.e. it has not been registered). Override this method - * if you want to implement your own mapping from property names to Property objects. - * Then you also have to override {@link #initMappings}, {@link #getProperties()} and - * {@link #putProperty(Property)}. - * @param propertyName The name of the property (Property.Name) - * @return The Property object with the name propertyName. - */ - protected Property getProperty(String propertyName) - { - return _nameToPropertyMap.get(propertyName); - } - - /** Returns the Property object with a handle (Property.Handle) as specified by the argument - * nHandle. The method returns null if there is no such property (i.e. it has not - * been registered). Override this method if you want to implement your own mapping from handles - * to Property objects. Then you also have to override {@link #initMappings}, {@link #putProperty(Property)}. - * @param nHandle The handle of the property (Property.Handle). - * @return The Property object with the handle nHandle - */ - protected Property getPropertyByHandle(int nHandle) - { - return _handleToPropertyMap.get(Integer.valueOf(nHandle)); - } - - /** Returns an array of all Property objects or an array of length null if there - * are no properties. Override this method if you want to implement your own mapping from names - * to Property objects. Then you also have to override {@link #initMappings}, {@link #getProperty(String)} and - * {@link #putProperty}. - * @return Array of all Property objects. - */ - protected Property[] getProperties() - { - if (arProperties == null) - { - Collection values= _nameToPropertyMap.values(); - arProperties= values.toArray(new Property[_nameToPropertyMap.size()]); - } - return arProperties; - } - - /** Stores a Property object so that it can be retrieved subsequently by - * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. - * Override this method if you want to implement your own mapping from handles - * to Property objects and names to Property objects. Then you also need to override {@link #initMappings}, - * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. - * @param prop The Property object that is to be stored. - */ - protected void putProperty(Property prop) - { - _nameToPropertyMap.put(prop.Name, prop); - if (prop.Handle != -1) - _handleToPropertyMap.put(Integer.valueOf(prop.Handle), prop); - } - - /** Assigns an identifier object to a Property object so that the identifier - * can be obtained by {@link #getPropertyId getPropertyId} later on. The identifier - * is used to specify a certain storage for the property's value. If you do not - * override {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} or {@link #getPropertyValue(Property)} - * then the argument id has to be a String that equals the name of - * the member variable that holds the Property's value. - * Override this method if you want to implement your own mapping from Property objects to ids or - * if you need ids of a type other than String. - * Then you also need to override {@link #initMappings initMappings} and {@link #getPropertyId getPropertyId}. - * @param prop The Property object that is being assigned an id. - * @param id The object which identifies the storage used for the property's value. - * @see #registerProperty(Property, Object) - */ - protected void assignPropertyId(Property prop, Object id) - { - if (id instanceof String && ((String) id).length() != 0) - _propertyToIdMap.put(prop, id); - } - - /** Returns the identifier object for a certain Property. The object must have been - * previously assigned to the Property object by {@link #assignPropertyId assignPropertyId}. - * Override this method if you want to implement your own mapping from Property objects to ids. - * Then you also need to override {@link #initMappings initMappings} and {@link #assignPropertyId assignPropertyId}. - * @param prop The property for which the id is to be retrieved. - * @return The id object that identifies the storage used for the property's value. - * @see #registerProperty(Property, Object) - */ - protected Object getPropertyId(Property prop) - { - return _propertyToIdMap.get(prop); - } - - /** Initializes data structures used for mappings of property names to property object, - * property handles to property objects and property objects to id objects. - * Override this method if you want to implement your own mappings. Then you also need to - * override {@link #putProperty putProperty},{@link #getProperty getProperty}, {@link #getPropertyByHandle}, - * {@link #assignPropertyId assignPropertyId} and {@link #getPropertyId getPropertyId}. - */ - protected void initMappings() - { - _nameToPropertyMap= new HashMap(); - _handleToPropertyMap= new HashMap(); - _propertyToIdMap= new HashMap(); - } - - /** Makes sure that listeners which are kept in aBoundLC (XPropertyChangeListener) and aVetoableLC - * (XVetoableChangeListener) receive a disposing call. Also those listeners are released. - */ - @Override - protected void postDisposing() - { - // Create an event with this as sender - EventObject aEvt= new EventObject(this); - - // inform all listeners to release this object - aBoundLC.disposeAndClear(aEvt); - aVetoableLC.disposeAndClear(aEvt); - } - - //XPropertySet ---------------------------------------------------- - synchronized public void addPropertyChangeListener(String str, XPropertyChangeListener xPropertyChangeListener) - throws UnknownPropertyException, WrappedTargetException - { - // only add listeners if you are not disposed - if (! bInDispose && ! bDisposed) - { - if (str.length() > 0) - { - Property prop= getProperty(str); - if (prop == null) - throw new UnknownPropertyException("Property " + str + " is unknown"); - - // Add listener for a certain property - if ((prop.Attributes & PropertyAttribute.BOUND) > 0) - aBoundLC.addInterface(str, xPropertyChangeListener); - else - //ignore silently - return; - } - else - // Add listener for all properties - listenerContainer.addInterface(XPropertyChangeListener.class, xPropertyChangeListener); - } - } - //XPropertySet ---------------------------------------------------- - synchronized public void addVetoableChangeListener(String str, com.sun.star.beans.XVetoableChangeListener xVetoableChangeListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException - { - // only add listeners if you are not disposed - if (! bInDispose && ! bDisposed) - { - if (str.length() > 0) - { - Property prop= getProperty(str); - if (prop == null) - throw new UnknownPropertyException("Property " + str + " is unknown"); - - // Add listener for a certain property - if ((prop.Attributes & PropertyAttribute.CONSTRAINED) > 0) - aVetoableLC.addInterface(str, xVetoableChangeListener); - else - //ignore silently - return; - } - else - // Add listener for all properties - listenerContainer.addInterface(XVetoableChangeListener.class, xVetoableChangeListener); - } - } - //XPropertySet ---------------------------------------------------- - public synchronized com.sun.star.beans.XPropertySetInfo getPropertySetInfo() - { - if (propertySetInfo == null) - propertySetInfo= new PropertySetInfo(); - return propertySetInfo; - } - //XPropertySet ---------------------------------------------------- - public Object getPropertyValue(String name) throws UnknownPropertyException, WrappedTargetException - { - Object ret= null; - if (bInDispose || bDisposed) - throw new com.sun.star.lang.DisposedException("The component has been disposed already"); - - Property prop= getProperty(name); - if (prop == null) - throw new UnknownPropertyException("The property " + name + " is unknown"); - - synchronized (this) - { - ret= getPropertyValue(prop); - } - // null must not be returned. Either a void any is returned or an any containing - // an interface type and a null reference. - if (ret == null) - { - if (prop.Type.getTypeClass() == TypeClass.INTERFACE) - ret= new Any(prop.Type, null); - else - ret= new Any(new Type(void.class), null); - } - return ret; - } - - //XPropertySet ---------------------------------------------------- - synchronized public void removePropertyChangeListener(String propName, XPropertyChangeListener listener) throws UnknownPropertyException, WrappedTargetException - { // all listeners are automatically released in a dispose call - if (!bInDispose && !bDisposed) - { - if (propName.length() > 0) - { - Property prop = getProperty(propName); - if (prop == null) - throw new UnknownPropertyException("Property " + propName + " is unknown"); - aBoundLC.removeInterface(propName, listener); - } - else - listenerContainer.removeInterface(XPropertyChangeListener.class, listener); - } - } - - //XPropertySet ---------------------------------------------------- - synchronized public void removeVetoableChangeListener(String propName, XVetoableChangeListener listener) throws UnknownPropertyException, WrappedTargetException - {// all listeners are automatically released in a dispose call - if (!bInDispose && !bDisposed) - { - if (propName.length() > 0) - { - Property prop = getProperty(propName); - if (prop == null) - throw new UnknownPropertyException("Property " + propName + " is unknown"); - aVetoableLC.removeInterface(propName, listener); - } - else - listenerContainer.removeInterface(XVetoableChangeListener.class, listener); - } - } - - //XPropertySet ---------------------------------------------------- - /** Sets the value of a property. - * The idl description for this interfaces, stipulates that the argument value is an Any. Since a java.lang.Object - * reference has the same meaning as an Any this function accepts - * java anys (com.sun.star.uno.Any) and all other appropriate objects as arguments. The value argument can be one - * of these: - *
    - *
  • java.lang.Boolean
  • - *
  • java.lang.Character
  • - *
  • java.lang.Byte
  • - *
  • java.lang.Short
  • - *
  • java.lang.Integer
  • - *
  • java.lang.Long
  • - *
  • java.lang.Float
  • - *
  • java.lang.Double
  • - *
  • String
  • - *
  • com.sun.star.uno.Type
  • - *
  • objects which implement UNO interfaces
  • - *
  • arrays which contain elements of the types above
  • - *
  • com.sun.star.uno.Any containing an instance of one of the above types
  • - *
- * - * Properties can have the attribute com.sun.star.beans.PropertyAttribute.MAYBEVOID, which means that the value - * (not the type) can be void. In order to assign a void value to a property one can either pass an Any which - * contains a null reference or pass null directly. In both cases the null reference is only accepted if - * the PropertyAttribute.MAYBEVOID attribute is set for the property. - * - * Properties which have the attribute MAYBEVOID set (Property.Attributes) can have a void value. The following - * considerations presume that the Property has that attribute set. Further, when mentioning an Any's value we - * actually refer to the object returned by Any.getObject. - * If the argument value is null, or it is an Any whose value is null (but with a valid Type) - * then the member variable used for storing the property's value is set to null. - * Therefore those properties can only be stored in objects - * and primitive types are not allowed (one can use the wrapper classes instead,e.g. java.lang.Byte) . - * If a property's value is kept in a member variable of type Any and that reference is still null - * then when setPropertyValue is called with - * value = null then the member variable is assigned an Any with type void and a null value. - * Or if the argument is an Any with a null value then it is assigned to the member variable. - * Further, if the variable already - * references an Any and setPropertyValue is called with value = null, then the variable is assigned - * a new Any with the same type as the previously referenced Any and with a null value. - * @param name The name of the property. - * @param value The new value of the property. - * * */ - public void setPropertyValue(String name, Object value) throws UnknownPropertyException, - PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException - { - Property prop= getProperty(name); - if (prop == null) - throw new UnknownPropertyException("Property " + name + " is unknown"); - setPropertyValue(prop, value); - } - - /** Sets the value of a property. It checks if the property's attributes (READONLY,MAYBEVOID), allow that the - * new value can be set. It also causes the notification of listeners. - * @param prop The property whose value is to be set. - * @param value The new value for the property. - * - * @throws UnknownPropertyException - * See com.sun.star.beans.XPropertySet - * @throws PropertyVetoException - * See com.sun.star.beans.XPropertySet - * @throws WrappedTargetException - * See com.sun.star.beans.XPropertySet - */ - protected void setPropertyValue(Property prop, Object value) throws UnknownPropertyException, - PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException - { - if ((prop.Attributes & PropertyAttribute.READONLY) == PropertyAttribute.READONLY) - throw new com.sun.star.beans.PropertyVetoException(); - // The value may be null only if MAYBEVOID attribute is set - boolean bVoidValue; - if (value instanceof Any) - bVoidValue= ((Any) value).getObject() == null; - else - bVoidValue= value == null; - if (bVoidValue && (prop.Attributes & PropertyAttribute.MAYBEVOID) == 0) - throw new com.sun.star.lang.IllegalArgumentException("The property must have a value; the MAYBEVOID attribute is not set!"); - if (bInDispose || bDisposed) - throw new DisposedException("Component is already disposed"); - - //Check if the argument is allowed - boolean bValueOk; - if (value instanceof Any) - bValueOk= checkType(((Any) value).getObject()); - else - bValueOk= checkType(value); - if (! bValueOk) - throw new com.sun.star.lang.IllegalArgumentException("No valid UNO type"); - - - boolean bConversionOk= false; - Object[] outConvertedVal= new Object[1]; - Object[] outOldValue= new Object[1]; - synchronized (this) - { - bConversionOk= convertPropertyValue(prop, outConvertedVal, outOldValue, value); - } - - //The next step following the conversion is to set the new value of the property. Prior to this - // the XVetoableChangeListener s have to be notified. - if (bConversionOk) - { - // If the property is CONSTRAINED, then we must notify XVetoableChangeListener. The listener can throw a com.sun.star.lang.beans.PropertyVetoException which - // will cause this method to return (the exception is not caught here). - fire( new Property[]{prop}, outConvertedVal, outOldValue, true); - - synchronized (this) - { - setPropertyValueNoBroadcast(prop, outConvertedVal[0]); - } - // fire a change event (XPropertyChangeListener, PropertyAttribute.BOUND - fire( new Property[]{prop}, outConvertedVal, outOldValue, false); - } - } - - /** Converts a value in a way so that it is appropriate for storing as a property value, that is - * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} can process the value without any further - * conversion. This implementation presumes that - * the values are stored in member variables of the furthest inheriting class. For example, - * class A inherits this class then members of class A - * can hold property values. If there is a class B which inherits A then only members of B can hold - * property values. The variables must be public. A property must have been registered (e.g. by - * {@link #registerProperty(Property, Object)} in order for this method to work. The identifier argument (type Object) - * used in the registerProperty methods must - * be a String, which is, the name of the member variable that holds the property value. - * If one opts to store values differently then one may override - * this method, as well as {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and - * {@link #getPropertyValue(Property) getPropertyValue(Property)}. - * This method is always called as a result of a call to one of the setter methods, such as - * {@link #setPropertyValue(String,Object) XPropertySet.setPropertyValue}, - * {@link #setFastPropertyValue XFastPropertySet.setFastPropertyValue} - * and {@link #setPropertyValues XMultiPropertySet.setPropertyValues}. - * If this method fails, that is, it returns false or throws an exception, then no listeners are notified and the - * property value, that was intended to be changed, remains untouched. - * - * This method does not have to deal with property attributes, such as - * PropertyAttribute.READONLY or PropertyAttribute.MAYBEVOID. The processing of these attributes occurs - * in the calling methods. - * - * Only if this method returns successfully further processing, such - * as listener notification and finally the modification of the property's value, will occur. - * - * The actual modification of a property's value is done by {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} - * which is called subsequent to convertPropertyValue. - *

- * This method converts values by help of the com.sun.star.uno.AnyConverter which only does a few widening - * conversions on integer types and floating point types. For example, there is the property PropA with a Type equivalent - * to int.class and the - * value of the property is to be stored in a member variable of type int with name intProp. Then setPropertyValue is - * called: - *

-     *  set.setPropertyValue( "PropA", Byte.valueOf( (byte)111));
-     *  
- * At some point setPropertyValue will call convertPropertyValue and pass in the Byte object. Since we allow - * that Byte values can be used with the property and know that the value is to be stored in intProp (type int) - * we convert the Byte object into an Integer object which is then returned in the out-parameter newVal. This - * conversion is actually performed by the AnyConverter. Later - * the setPropertyValueNoBroadcast is called with that Integer object and the int value can be easily extracted - * from the object and be assigned to the member intProp. - *

- * The method handles Any arguments the same as Object arguments. That is, the setVal argument can - * be a java.lang.Boolean or a com.sun.star.uno.Any containing a java.lang.Boolean. Likewise, a member - * containing a property value can be a com.sun.star.uno.Any or a java.lang.Object. - * Then, no conversion is necessary, since they can hold all possible values. However, if - * the member is an Object and setVal is an Any then the object contained in the any is assigned to - * the member. The extra type information which exists as Type object in the Any will get lost. If this is not - * intended then use an Any variable rather than an Object. - * - * If a member is an Object or Any and the argument setVal is an Object, other than String or array, - * then it is presumed to be a UNO object and queried for XInterface. If successful, the out-param newVal - * returns the XInterface. - * - * If a member is a UNO interface, then setVal is queried for this interface and the result is returned. - * If setVal is null then newVal will be null too after return. - *

- * If a property value is stored using a primitive type the out-parameters - * curVal and newVal contain the respective wrapper class (e.g.java.lang.Byte, etc.). - * curVal is used in calls to the XVetoableChangeListener and XPropertyChangeListener. - * - * @param property - in-param property for which the data is to be converted. - * @param newVal - out-param which contains the converted value on return. - * @param curVal - out-param the current value of the property. It is used in calls to the - * XVetoableChangeListener and XPropertyChangeListener. - * @param setVal - in-param. The value that is to be converted so that it matches Property and the internally used - * dataformat for that property. - * @return true - Conversion was successful. newVal contains a valid value for the property. false - - * conversion failed for some reason. - * - * @throws UnknownPropertyException - * See com.sun.star.beans.XPropertySet - * @throws com.sun.star.lang.IllegalArgumentException The value provided is unfit for the property. - * @throws com.sun.star.lang.WrappedTargetException - An exception occurred during the conversion, that is to be made known - * to the caller. - */ - protected boolean convertPropertyValue(Property property, Object[] newVal, Object[]curVal, Object setVal) - throws com.sun.star.lang.IllegalArgumentException, WrappedTargetException, UnknownPropertyException - { - boolean ret= true; - try - { - // get the member name - String sMember= (String) getPropertyId(property); - if (sMember != null) - { - // use reflection to obtain the field that holds the property value - // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to - // also get inherited fields, but only those which are public. - Field propField= getClass().getDeclaredField(sMember); - if (propField != null) - { - curVal[0]= propField.get(this); - Class memberClass= propField.getType(); - - // MAYBEVOID: if setVal == null or it is an Any and getObject returns null, then a void value is to be set - // This works only if there are no primitive types. For those we use the respective wrapper classes. - // In this implementation, a null reference means void value. - boolean bVoidValue= false; - boolean bAnyVal= setVal instanceof Any; - if (bAnyVal) - bVoidValue= ((Any) setVal).getObject() == null; - else - bVoidValue= setVal == null; - if (bVoidValue && memberClass.isPrimitive()) - throw new com.sun.star.lang.IllegalArgumentException("The implementation does not support the MAYBEVOID attribute for this property"); - - Object convObj= null; - //The member that keeps the value of the Property is an Any. It can contain all possible - //types, therefore a conversion is not necessary. - if (memberClass.equals(Any.class)) - { - if (bAnyVal) - //parameter setVal is also an Any and can be used without further processing - convObj= setVal; - else - { - // Parameter setVal is not an Any. We need to construct an Any that contains - // the argument setVal. - // If setVal is an interface implementation then, we cannot construct the - // Any with setVal.getClass(), because the Any.Type._typeClass would be TypeClass.UNKNOWN. - // We try to get an XInterface of setVal and set an XInterface type. - if (setVal instanceof XInterface) - { - XInterface xint= UnoRuntime.queryInterface(XInterface.class, setVal); - if (xint != null) - convObj= new Any(new Type(XInterface.class), xint); - } - // The member is an any, and the past in argument was null reference (MAYBEVOID is set) - else if (setVal == null) - { - // if the any member is still null we create a void any - if (curVal[0] == null) - convObj= new Any(new Type(), null); - else - { - //otherwise we create an Any with the same type as a value of null; - convObj= new Any( ((Any)curVal[0]).getType(), null); - } - } - else - convObj= new Any(new Type(setVal.getClass()), setVal); - } - } - else - convObj= convert(memberClass, setVal); - newVal[0]= convObj; - } - } - else - throw new UnknownPropertyException("Property " + property.Name + " is unknown"); - } - catch (java.lang.NoSuchFieldException e) - { - throw new WrappedTargetException(e, "Field does not exist", this, e); - } - catch (java.lang.IllegalAccessException e) - { - throw new WrappedTargetException(e, "", this ,e); - } - return ret; - } - - private boolean checkType(Object obj) - { - return obj == null - || obj instanceof Boolean - || obj instanceof Character - || obj instanceof Number - || obj instanceof String - || obj instanceof XInterface - || obj instanceof Type - || obj instanceof com.sun.star.uno.Enum - || obj.getClass().isArray(); - } - - // Param object can be an Any or other object. If obj is null then the return value is null - private Object convert( Class cl, Object obj) throws com.sun.star.lang.IllegalArgumentException - { - Object retVal= null; - //The member that keeps the value of the Property is an Object.Objects are similar to Anys in that they can - // hold all types. - if (obj == null || (obj instanceof Any && ((Any) obj).getObject() == null)) - {} - else if(cl.equals(Object.class)) - { - if (obj instanceof Any) - obj= ((Any) obj).getObject(); - retVal= obj; - } - else if(cl.equals(boolean.class)) - retVal= Boolean.valueOf(AnyConverter.toBoolean(obj)); - else if (cl.equals(char.class)) - retVal= new Character(AnyConverter.toChar(obj)); - else if (cl.equals(byte.class)) - retVal= Byte.valueOf(AnyConverter.toByte(obj)); - else if (cl.equals(short.class)) - retVal= Short.valueOf(AnyConverter.toShort(obj)); - else if (cl.equals(int.class)) - retVal= Integer.valueOf(AnyConverter.toInt(obj)); - else if (cl.equals(long.class)) - retVal= Long.valueOf(AnyConverter.toLong(obj)); - else if (cl.equals(float.class)) - retVal= new Float(AnyConverter.toFloat(obj)); - else if (cl.equals(double.class)) - retVal= new Double(AnyConverter.toDouble(obj)); - else if (cl.equals(String.class)) - retVal= AnyConverter.toString(obj); - else if (cl.isArray()) - retVal= AnyConverter.toArray(obj); - else if (cl.equals(Type.class)) - retVal= AnyConverter.toType(obj); - else if (cl.equals(Boolean.class)) - retVal= Boolean.valueOf(AnyConverter.toBoolean(obj)); - else if (cl.equals(Character.class)) - retVal= new Character(AnyConverter.toChar(obj)); - else if (cl.equals(Byte.class)) - retVal= Byte.valueOf(AnyConverter.toByte(obj)); - else if (cl.equals(Short.class)) - retVal= Short.valueOf(AnyConverter.toShort(obj)); - else if (cl.equals(Integer.class)) - retVal= Integer.valueOf(AnyConverter.toInt(obj)); - else if (cl.equals(Long.class)) - retVal= Long.valueOf(AnyConverter.toLong(obj)); - else if (cl.equals(Float.class)) - retVal= new Float(AnyConverter.toFloat(obj)); - else if (cl.equals(Double.class)) - retVal= new Double(AnyConverter.toDouble(obj)); - else if (XInterface.class.isAssignableFrom(cl)) - retVal= AnyConverter.toObject(new Type(cl), obj); - else if (com.sun.star.uno.Enum.class.isAssignableFrom(cl)) - retVal= AnyConverter.toObject(new Type(cl), obj); - else - throw new com.sun.star.lang.IllegalArgumentException("Could not convert the argument"); - return retVal; - } - - /** Sets the value of a property. In this implementation property values are stored in member variables - * (see {@link #convertPropertyValue convertPropertyValue} Notification of property listeners - * does not occur in this method. By overriding this method one can take full control about how property values - * are stored. But then, the {@link #convertPropertyValue convertPropertyValue} and - * {@link #getPropertyValue(Property)} must be overridden too. - * - * A Property with the MAYBEVOID attribute set, is stored as null value. Therefore the member variable must be - * an Object in order to make use of the property attribute. An exception is Any. The Any variable can be initially null, but - * once it is set the reference will not become null again. If the value is to be set to - * void then a new Any will be stored - * with a valid type but without a value (i.e. Any.getObject returns null). - * If a property has the READONLY attribute set, and one of the setter methods, such as setPropertyValue, has been - * called, then this method is not going to be called. - * @param property the property for which the new value is set - * @param newVal the new value for the property. - * @throws com.sun.star.lang.WrappedTargetException An exception, which has to be made known to the caller, - * occurred during the setting of the value. - */ - protected void setPropertyValueNoBroadcast(Property property, Object newVal) - throws WrappedTargetException - { - try - { - // get the member name - String sMember= (String) getPropertyId(property); - if (sMember != null) - { - // use reflection to obtain the field that holds the property value - // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to - // also get inherited fields, but only those which are public. - Field propField= getClass().getDeclaredField(sMember); - if (propField != null) - propField.set(this, newVal); - } - } - catch(java.lang.Exception e) - { - throw new WrappedTargetException(e, "PropertySet.setPropertyValueNoBroadcast", this, e); - } - } - /** Retrieves the value of a property. This implementation presumes that the values are stored in member variables - * of the furthest inheriting class (see {@link #convertPropertyValue convertPropertyValue}) and that the - * variables are public. The property must have - * been registered, for example by {@link #registerProperty(Property, Object)}. The identifier Object argument - * must have been a String which was the name of the member variable holding the property value. - * When properties are to be stored differently one has to override this method as well as - * {@link #convertPropertyValue} and {@link #setPropertyValueNoBroadcast}.
- * If a value is stored in a variable of a primitive type then this method returns an instance of the respective - * wrapper class (e.g. java.lang.Boolean). - * @param property The property for which the value is to be retrieved. - * @return The value of the property. - */ - protected Object getPropertyValue(Property property) - { - Object ret= null; - try - { - // get the member name - String sMember= (String) getPropertyId(property); - if (sMember != null) - { - // use reflection to obtain the field that holds the property value - // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to - // also get inherited fields, but only those which are public. - Field propField= getClass().getDeclaredField(sMember); - if (propField != null) - ret= propField.get(this); - } - } - catch(java.lang.NoSuchFieldException e) - { - throw new java.lang.RuntimeException(e); - } - catch(java.lang.IllegalAccessException e) - { - throw new java.lang.RuntimeException(e); - } - return ret; - } - - /** - * This method fires events to XPropertyChangeListener,XVetoableChangeListener and - * XPropertiesChangeListener event sinks. - * To distinguish what listeners are to be called the argument bVetoable is to be set to true if - * a XVetoableChangeListener is meant. For XPropertyChangeListener and XPropertiesChangeListener - * it is to be set to false. - * - * @param properties Properties which will be or have been affected. - * @param newValues the new values of the properties. - * @param oldValues the old values of the properties. - * @param bVetoable true means fire to VetoableChangeListener, false means fire to - * XPropertyChangedListener and XMultiPropertyChangedListener. - * - * @throws PropertyVetoException - * if a vetoable listener throws it. - */ - protected void fire( - Property[] properties, - Object[] newValues, - Object[] oldValues, - boolean bVetoable ) throws PropertyVetoException - { - // Only fire, if one or more properties changed - int nNumProps= properties.length; - if (nNumProps > 0) - { - PropertyChangeEvent[] arEvts= new PropertyChangeEvent[nNumProps]; - int nAffectedProps= 0; - // Loop over all changed properties to fill the event struct - for (int i= 0; i < nNumProps; i++) - { - if ((bVetoable && (properties[i].Attributes & PropertyAttribute.CONSTRAINED) > 0) - || (!bVetoable && (properties[i].Attributes & PropertyAttribute.BOUND) > 0)) - { - arEvts[i]= new PropertyChangeEvent(this, properties[i].Name, false, - properties[i].Handle, oldValues[i], newValues[i]); - nAffectedProps++; - } - } - // fire the events for all changed properties - for (int i= 0; i < nAffectedProps; i++) - { - // get the listener container for the property name - InterfaceContainer lc; - if (bVetoable) - lc= aVetoableLC.getContainer(arEvts[i].PropertyName); - else - lc= aBoundLC.getContainer(arEvts[i].PropertyName); - Iterator it = lc != null ? lc.iterator() : null; - if (it != null) - { - while( it.hasNext()) - { - Object listener= it.next(); - if (bVetoable) - ((XVetoableChangeListener) listener).vetoableChange(arEvts[i]); - else - ((XPropertyChangeListener) listener).propertyChange(arEvts[i]); - } - } - // broadcast to all listeners with "" property name - if(bVetoable) - lc= listenerContainer.getContainer(XVetoableChangeListener.class); - else - lc= listenerContainer.getContainer(XPropertyChangeListener.class); - it = lc != null ? lc.iterator() : null; - if (it != null) - { - while(it.hasNext() ) - { - Object listener= it.next(); - if( bVetoable ) // fire change Events? - ((XVetoableChangeListener) listener).vetoableChange(arEvts[i]); - else - ((XPropertyChangeListener) listener).propertyChange(arEvts[i]); - } - } - } - // fire at XPropertiesChangeListeners - // if nAffectedProps == 0 then there are no BOUND properties - if (!bVetoable && nAffectedProps > 0) - { - - PropertyChangeEvent[] arReduced= new PropertyChangeEvent[nAffectedProps]; - System.arraycopy(arEvts, 0, arReduced, 0, nAffectedProps); - InterfaceContainer lc= listenerContainer.getContainer(XPropertiesChangeListener.class); - Iterator it = lc != null ? lc.iterator() : null; - if (it != null) - { - while (it.hasNext()) - { - XPropertiesChangeListener listener = (XPropertiesChangeListener) it.next(); - // fire the whole event sequence to the XPropertiesChangeListener's - listener.propertiesChange( arEvts ); - } - } - } - } - } - // XFastPropertySet-------------------------------------------------------------------------------- - public void setFastPropertyValue(int nHandle, Object aValue ) throws UnknownPropertyException, - PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException - { - Property prop= getPropertyByHandle(nHandle); - if (prop == null) - throw new UnknownPropertyException(" The property with handle : " + nHandle +" is unknown"); - setPropertyValue(prop, aValue); - } - - // XFastPropertySet -------------------------------------------------------------------------------- - public Object getFastPropertyValue(int nHandle ) throws UnknownPropertyException, - WrappedTargetException - { - Property prop= getPropertyByHandle(nHandle); - if (prop == null) - throw new UnknownPropertyException("The property with handle : " + nHandle + " is unknown"); - return getPropertyValue(prop); - } - - // XMultiPropertySet ----------------------------------------------------------------------------------- - public void addPropertiesChangeListener(String[] propNames, XPropertiesChangeListener listener) - { - listenerContainer.addInterface(XPropertiesChangeListener.class, listener); - } - - // XMultiPropertySet ----------------------------------------------------------------------------------- - public void firePropertiesChangeEvent(String[] propNames, XPropertiesChangeListener listener) - { - // Build the events. - PropertyChangeEvent[] arEvents= new PropertyChangeEvent[propNames.length]; - int eventCount= 0; - // get a snapshot of the current property values - synchronized (this) - { - for (int i= 0; i < propNames.length; i++) - { - Property prop= getProperty(propNames[i]); - if (prop != null) - { - Object value= null; - try - { - value= getPropertyValue(prop); - } - catch(Exception e) - { - continue; - } - arEvents[eventCount]= new PropertyChangeEvent(this, prop.Name, - false, prop.Handle, value, value); - eventCount++; - } - } - } - - // fire events from unsynchronized section so as to prevent deadlocks - if (eventCount > 0) - { - // Reallocate the array of the events if necessary - if (arEvents.length != eventCount) - { - PropertyChangeEvent[] arPropsTmp= new PropertyChangeEvent[eventCount]; - System.arraycopy(arEvents, 0, arPropsTmp, 0, eventCount); - arEvents= arPropsTmp; - } - listener.propertiesChange(arEvents); - } - } - // XMultiPropertySet ----------------------------------------------------------------------------------- - /** If a value for a property could not be retrieved then the respective element in the returned - * array has the value null. - */ - public Object[] getPropertyValues(String[] propNames) - { - Object[] arValues= new Object[propNames.length]; - synchronized (this) - { - for (int i= 0; i < propNames.length; i++) - { - Object value= null; - try - { - value= getPropertyValue(propNames[i]); - } - catch (Exception e) - { - } - arValues[i]= value; - } - } - return arValues; - } - // XMultiPropertySet ----------------------------------------------------------------------------------- - public void removePropertiesChangeListener(XPropertiesChangeListener xPropertiesChangeListener) - { - listenerContainer.removeInterface(XPropertiesChangeListener.class, xPropertiesChangeListener); - } - // XMultiPropertySet ----------------------------------------------------------------------------------- - /** If the array of property names contains an unknown property then it will be ignored. - */ - public void setPropertyValues(String[] propNames, Object[] values) throws PropertyVetoException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException - { - for (int i= 0; i < propNames.length; i++) - { - try - { - setPropertyValue(propNames[i], values[i]); - } - catch (UnknownPropertyException e) - { - continue; - } - - } - } - - private class PropertySetInfo implements XPropertySetInfo - { - public com.sun.star.beans.Property[] getProperties() - { - return PropertySet.this.getProperties(); - } - - public com.sun.star.beans.Property getPropertyByName(String name) throws UnknownPropertyException - { - return getProperty(name); - } - - public boolean hasPropertyByName(String name) - { - return getProperty(name) != null; - } - - } -} - - - - - diff --git a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java b/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java deleted file mode 100644 index 0c050d676928..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/PropertySetMixin.java +++ /dev/null @@ -1,1111 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.helper; - -import com.sun.star.beans.Property; -import com.sun.star.beans.PropertyAttribute; -import com.sun.star.beans.PropertyChangeEvent; -import com.sun.star.beans.PropertyState; -import com.sun.star.beans.PropertyValue; -import com.sun.star.beans.PropertyVetoException; -import com.sun.star.beans.UnknownPropertyException; -import com.sun.star.beans.XPropertyChangeListener; -import com.sun.star.beans.XPropertySetInfo; -import com.sun.star.beans.XVetoableChangeListener; -import com.sun.star.container.NoSuchElementException; -import com.sun.star.container.XHierarchicalNameAccess; -import com.sun.star.lang.DisposedException; -import com.sun.star.lang.EventObject; -import com.sun.star.lang.WrappedTargetException; -import com.sun.star.lang.WrappedTargetRuntimeException; -import com.sun.star.reflection.XCompoundTypeDescription; -import com.sun.star.reflection.XIdlClass; -import com.sun.star.reflection.XIdlField2; -import com.sun.star.reflection.XIndirectTypeDescription; -import com.sun.star.reflection.XInterfaceAttributeTypeDescription2; -import com.sun.star.reflection.XInterfaceMemberTypeDescription; -import com.sun.star.reflection.XInterfaceTypeDescription2; -import com.sun.star.reflection.XStructTypeDescription; -import com.sun.star.reflection.XTypeDescription; -import com.sun.star.reflection.theCoreReflection; -import com.sun.star.uno.Any; -import com.sun.star.uno.AnyConverter; -import com.sun.star.uno.Type; -import com.sun.star.uno.TypeClass; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.uno.XComponentContext; -import com.sun.star.uno.XInterface; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; - -/** - A helper mixin to implement certain UNO interfaces related to property set - handling on top of the attributes of a given UNO interface type. - -

A client will mix in this class by keeping a reference to an instance of - this class, and forwarding all methods of (a subset of the interfaces) - com.sun.star.beans.XPropertySet, - com.sun.star.beans.XFastPropertySet, and - com.sun.star.beans.XPropertyAccess to it.

- -

Client code should not use the monitors associated with instances of this - class, as they are used for internal purposes.

- - @since UDK 3.2 -*/ -public final class PropertySetMixin { - /** - The constructor. - - @param context the component context used by this instance; must not be - null, and must supply the - com.sun.star.reflection.theCoreReflection and - com.sun.star.reflection.theTypeDescriptionManager singletons - - @param object the client UNO object into which this instance is mixed in; - must not be null, and must support the given type - - @param type the UNO interface type whose attributes are mapped to - properties; must not be null, and must represent a UNO interface type - - @param absentOptional a list of optional properties that are not present, - and should thus not be visible via - com.sun.star.beans.XPropertySet.getPropertySetInfo, - com.sun.star.beans.XPropertySet.addPropertyChangeListener, - com.sun.star.beans.XPropertySet.removePropertyChangeListener, - com.sun.star.beans.XPropertySet.addVetoableChangeListener, - and com.sun.star.beans.XPropertySet.removeVetoableChangeListener; null is treated the same as an - empty list; if non-null, the given array must not be modified after it is - passed to this constructor. For consistency reasons, the given - absentOptional should only contain the names of attributes - that represent optional properties that are not present (that is, the - attribute getters and setters always throw a - com.sun.star.beans.UnknownPropertyException), and should - contain each such name only once. If an optional property is not present - (that is, the corresponding attribute getter and setter always throw a - com.sun.star.beans.UnknownPropertyException) but is not - contained in the given absentOptional, then it will be - visible via - com.sun.star.beans.XPropertySet.getPropertySetInfo as a - com.sun.star.beans.Property with a set - com.sun.star.beans.PropertyAttribute.OPTIONAL. If the given - object does not implement - com.sun.star.beans.XPropertySet, then the given - absentOptional is effectively ignored and can be null or - empty. - */ - public PropertySetMixin( - XComponentContext context, XInterface object, Type type, - String[] absentOptional) - { - this.context = context; - this.object = object; - this.type = type; - this.absentOptional = absentOptional; - idlClass = getReflection(type.getTypeName()); - XTypeDescription ifc; - try { - XHierarchicalNameAccess xhna = UnoRuntime.queryInterface( - XHierarchicalNameAccess.class, - context.getValueByName( - "/singletons/com.sun.star.reflection." - + "theTypeDescriptionManager")); - ifc = UnoRuntime.queryInterface( - XTypeDescription.class, - xhna.getByHierarchicalName(type.getTypeName())); - } catch (NoSuchElementException e) { - throw new RuntimeException(e); - } - HashMap map = new HashMap(); - ArrayList handleNames = new ArrayList(); - initProperties(ifc, map, handleNames, new HashSet()); - properties = map; - handleMap = handleNames.toArray(new String[handleNames.size()]); - } - - /** - A method used by clients when implementing UNO interface type attribute - setter functions. - -

First, this method checks whether this instance has already been - disposed (see {@link #dispose}), and throws a - com.sun.star.beans.DisposedException if applicable. For a - constrained attribute (whose setter can explicitly raise - com.sun.star.beans.PropertyVetoException), this method - notifies any com.sun.star.beans.XVetoableChangeListeners. - For a bound attribute, this method modifies the passed-in - bound so that it can afterwards be used to notify any - com.sun.star.beans.XPropertyChangeListeners. This method - should be called before storing the new attribute value, and - bound.notifyListeners() should be called exactly once after - storing the new attribute value (in case the attribute is bound; - otherwise, calling bound.notifyListeners() is ignored). - Furthermore, bound.notifyListeners() and this method have to - be called from the same thread.

- - @param propertyName the name of the property (which is the same as the - name of the attribute that is going to be set) - - @param oldValue the property value corresponding to the old attribute - value. This is only used as - com.sun.star.beans.PropertyChangeEvent.OldValue, which is - rather useless, anyway (see “Using the Observer Pattern” in - - OpenOffice.org Coding Guidelines). If the attribute - that is going to be set is neither bound nor constrained, or if - com.sun.star.beans.PropertyChangeEvent.OldValue should not - be set, {@link Any#VOID} can be used instead. - - @param newValue the property value corresponding to the new - attribute value. This is only used as - com.sun.star.beans.PropertyChangeEvent.NewValue, which is - rather useless, anyway (see “Using the Observer Pattern” in - - OpenOffice.org Coding Guidelines), unless the - attribute that is going to be set is constrained. If the attribute - that is going to be set is neither bound nor constrained, or if it is - only bound but - com.sun.star.beans.PropertyChangeEvent.NewValue should not - be set, {@link Any#VOID} can be used instead. - - @param bound a reference to a fresh {@link BoundListeners} instance - (which has not been passed to this method before, and on which - {@link BoundListeners#notifyListeners} has not yet been called); may only - be null if the attribute that is going to be set is not bound - - @throws PropertyVetoException if a vetoable listener throws it. - */ - public void prepareSet( - String propertyName, Object oldValue, Object newValue, - BoundListeners bound) - throws PropertyVetoException - { - // assert properties.get(propertyName) != null; - Property p = properties.get(propertyName).property; - ArrayList specificVeto = null; - ArrayList unspecificVeto = null; - synchronized (this) { - if (disposed) { - throw new DisposedException("disposed", object); - } - if ((p.Attributes & PropertyAttribute.CONSTRAINED) != 0) { - ArrayList o = vetoListeners.get(propertyName); - if (o != null) { - specificVeto = new ArrayList(o); - } - o = vetoListeners.get(""); - if (o != null) { - unspecificVeto = new ArrayList(o); - } - } - if ((p.Attributes & PropertyAttribute.BOUND) != 0) { - // assert bound != null; - ArrayList o = boundListeners.get(propertyName); - if (o != null) { - bound.specificListeners = new ArrayList(o); - } - o = boundListeners.get(""); - if (o != null) { - bound.unspecificListeners = new ArrayList(o); - } - } - } - if ((p.Attributes & PropertyAttribute.CONSTRAINED) != 0) { - PropertyChangeEvent event = new PropertyChangeEvent( - object, propertyName, false, p.Handle, oldValue, newValue); - if (specificVeto != null) { - for (Iterator i = specificVeto.iterator(); i.hasNext();) { - try { - i.next().vetoableChange(event); - } catch (DisposedException e) {} - } - } - if (unspecificVeto != null) { - for (Iterator i = unspecificVeto.iterator(); i.hasNext();) { - try { - i.next().vetoableChange(event); - } catch (DisposedException e) {} - } - } - } - if ((p.Attributes & PropertyAttribute.BOUND) != 0) { - // assert bound != null; - bound.event = new PropertyChangeEvent( - object, propertyName, false, p.Handle, oldValue, newValue); - } - } - - /** - A simplified version of {@link #prepareSet(String, Object, Object, - PropertySetMixin.BoundListeners)}. - -

This method is useful for attributes that are not constrained.

- - @param propertyName the name of the property (which is the same as the - name of the attribute that is going to be set) - - @param bound a reference to a fresh {@link BoundListeners} instance - (which has not been passed to this method before, and on which - {@link BoundListeners#notifyListeners} has not yet been called); may only - be null if the attribute that is going to be set is not bound - */ - public void prepareSet(String propertyName, BoundListeners bound) { - try { - prepareSet(propertyName, Any.VOID, Any.VOID, bound); - } catch (PropertyVetoException e) { - throw new RuntimeException("unexpected " + e); - } - } - - /** - Marks this instance as being disposed. - -

See com.sun.star.lang.XComponent for the general concept - of disposing UNO objects. On the first call to this method, all - registered listeners - (com.sun.star.beans.XPropertyChangeListeners and - com.sun.star.beans.XVetoableChangeListeners) are notified of - the disposing source. Any subsequent calls to this method are - ignored.

- */ - public void dispose() { - HashMap> bound; - HashMap> veto; - synchronized (this) { - bound = boundListeners; - boundListeners = null; - veto = vetoListeners; - vetoListeners = null; - disposed = true; - } - EventObject event = new EventObject(object); - if (bound != null) { - for (Iterator> i = bound.values().iterator(); i.hasNext();) { - for (Iterator j = i.next().iterator(); j.hasNext();) - { - j.next().disposing(event); - } - } - } - if (veto != null) { - for (Iterator> i = veto.values().iterator(); i.hasNext();) { - for (Iterator j = i.next().iterator(); j.hasNext();) - { - j.next().disposing(event); - } - } - } - } - - /** - Implements - com.sun.star.beans.XPropertySet.getPropertySetInfo. - @return See com.sun.star.beans.XPropertySet - */ - public XPropertySetInfo getPropertySetInfo() { - return new Info(properties); - } - - /** - Implements com.sun.star.beans.XPropertySet.setPropertyValue. - @param propertyName - See com.sun.star.beans.XPropertySet - @param value - See com.sun.star.beans.XPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XPropertySet - @throws PropertyVetoException - See com.sun.star.beans.XPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XPropertySet - */ - public void setPropertyValue(String propertyName, Object value) - throws UnknownPropertyException, PropertyVetoException, - com.sun.star.lang.IllegalArgumentException, WrappedTargetException - { - setProperty(propertyName, value, false, false, (short) 1); - } - - /** - Implements com.sun.star.beans.XPropertySet.getPropertyValue. - @param propertyName - See com.sun.star.beans.XPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XPropertySet - @return - See com.sun.star.beans.XPropertySet - */ - public Object getPropertyValue(String propertyName) - throws UnknownPropertyException, WrappedTargetException - { - return getProperty(propertyName, null); - } - - /** - Implements - com.sun.star.beans.XPropertySet.addPropertyChangeListener. - -

If a listener is added more than once, it will receive all relevant - notifications multiple times.

- - @param propertyName - See com.sun.star.beans.XPropertySet - @param listener - See com.sun.star.beans.XPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XPropertySet - */ - public void addPropertyChangeListener( - String propertyName, XPropertyChangeListener listener) - throws UnknownPropertyException, WrappedTargetException - { - // assert listener != null; - checkUnknown(propertyName); - boolean disp; - synchronized (this) { - disp = disposed; - if (!disp) { - ArrayList v = boundListeners.get(propertyName); - if (v == null) { - v = new ArrayList(); - boundListeners.put(propertyName, v); - } - v.add(listener); - } - } - if (disp) { - listener.disposing(new EventObject(object)); - } - } - - /** - Implements - com.sun.star.beans.XPropertySet.removePropertyChangeListener. - - @param propertyName - See com.sun.star.beans.XPropertySet - @param listener - See com.sun.star.beans.XPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XPropertySet - */ - public void removePropertyChangeListener( - String propertyName, XPropertyChangeListener listener) - throws UnknownPropertyException, WrappedTargetException - { - // assert listener != null; - checkUnknown(propertyName); - synchronized (this) { - if (boundListeners != null) { - ArrayList v = boundListeners.get(propertyName); - if (v != null) { - v.remove(listener); - } - } - } - } - - /** - Implements - com.sun.star.beans.XPropertySet.addVetoableChangeListener. - -

If a listener is added more than once, it will receive all relevant - notifications multiple times.

- - @param propertyName - See com.sun.star.beans.XPropertySet - @param listener - See com.sun.star.beans.XPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XPropertySet - */ - public void addVetoableChangeListener( - String propertyName, XVetoableChangeListener listener) - throws UnknownPropertyException, WrappedTargetException - { - // assert listener != null; - checkUnknown(propertyName); - boolean disp; - synchronized (this) { - disp = disposed; - if (!disp) { - ArrayList v = vetoListeners.get(propertyName); - if (v == null) { - v = new ArrayList(); - vetoListeners.put(propertyName, v); - } - v.add(listener); - } - } - if (disp) { - listener.disposing(new EventObject(object)); - } - } - - /** - Implements - com.sun.star.beans.XPropertySet.removeVetoableChangeListener. - - @param propertyName - See com.sun.star.beans.XPropertySet - @param listener - See com.sun.star.beans.XPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XPropertySet - */ - public void removeVetoableChangeListener( - String propertyName, XVetoableChangeListener listener) - throws UnknownPropertyException, WrappedTargetException - { - // assert listener != null; - checkUnknown(propertyName); - synchronized (this) { - if (vetoListeners != null) { - ArrayList v = vetoListeners.get(propertyName); - if (v != null) { - v.remove(listener); - } - } - } - } - - /** - Implements - com.sun.star.beans.XFastPropertySet.setFastPropertyValue. - - @param handle - See com.sun.star.beans.XFastPropertySet - @param value - See com.sun.star.beans.XFastPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XFastPropertySet - @throws PropertyVetoException - See com.sun.star.beans.XFastPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XFastPropertySet - */ - public void setFastPropertyValue(int handle, Object value) - throws UnknownPropertyException, PropertyVetoException, - com.sun.star.lang.IllegalArgumentException, WrappedTargetException - { - setProperty(translateHandle(handle), value, false, false, (short) 1); - } - - /** - Implements - com.sun.star.beans.XFastPropertySet.getFastPropertyValue. - - @param handle - See com.sun.star.beans.XFastPropertySet - @throws UnknownPropertyException - See com.sun.star.beans.XFastPropertySet - @throws WrappedTargetException - See com.sun.star.beans.XFastPropertySet - @return - See com.sun.star.beans.XFastPropertySet - */ - public Object getFastPropertyValue(int handle) - throws UnknownPropertyException, WrappedTargetException - { - return getProperty(translateHandle(handle), null); - } - - /** - Implements - com.sun.star.beans.XPropertyAccess.getPropertyValues. - - @return - See com.sun.star.beans.XPropertyAccess - */ - public PropertyValue[] getPropertyValues() { - PropertyValue[] s = new PropertyValue[handleMap.length]; - int n = 0; - for (int i = 0; i < handleMap.length; ++i) { - PropertyState[] state = new PropertyState[1]; - Object value; - try { - value = getProperty(handleMap[i], state); - } catch (UnknownPropertyException e) { - continue; - } catch (WrappedTargetException e) { - throw new WrappedTargetRuntimeException(e.getCause(), - e.getMessage(), object, e.TargetException); - } - s[n++] = new PropertyValue(handleMap[i], i, value, state[0]); - } - if (n < handleMap.length) { - PropertyValue[] s2 = new PropertyValue[n]; - System.arraycopy(s, 0, s2, 0, n); - s = s2; - } - return s; - } - - /** - Implements - com.sun.star.beans.XPropertyAccess.setPropertyValues. - - @param props - See com.sun.star.beans.XPropertyAccess - @throws UnknownPropertyException - See com.sun.star.beans.XPropertyAccess - @throws PropertyVetoException - See com.sun.star.beans.XPropertyAccess - @throws WrappedTargetException - See com.sun.star.beans.XPropertyAccess - */ - public void setPropertyValues(PropertyValue[] props) - throws UnknownPropertyException, PropertyVetoException, - com.sun.star.lang.IllegalArgumentException, WrappedTargetException - { - for (int i = 0; i < props.length; ++i) { - if (props[i].Handle != -1 - && !props[i].Name.equals(translateHandle(props[i].Handle))) - { - throw new UnknownPropertyException( - ("name " + props[i].Name + " does not match handle " - + props[i].Handle), - object); - } - setProperty( - props[i].Name, props[i].Value, - props[i].State == PropertyState.AMBIGUOUS_VALUE, - props[i].State == PropertyState.DEFAULT_VALUE, (short) 0); - } - } - - /** - A class used by clients of {@link PropertySetMixin} when implementing UNO - interface type attribute setter functions. - - @see #prepareSet(String, Object, Object, PropertySetMixin.BoundListeners) - */ - public static final class BoundListeners { - - /** - Notifies any - com.sun.star.beans.XPropertyChangeListeners. - - @see #prepareSet(String, Object, Object, - PropertySetMixin.BoundListeners) - */ - public void notifyListeners() { - if (specificListeners != null) { - for (Iterator i = specificListeners.iterator(); i.hasNext();) { - try { - i.next().propertyChange(event); - } catch (DisposedException e) {} - } - } - if (unspecificListeners != null) { - for (Iterator i = unspecificListeners.iterator(); i.hasNext();) - { - try { - i.next().propertyChange(event); - } catch (DisposedException e) {} - } - } - } - - private ArrayList specificListeners = null; - private ArrayList unspecificListeners = null; - private PropertyChangeEvent event = null; - } - - private XIdlClass getReflection(String typeName) { - return theCoreReflection.get(context).forName(typeName); - } - - private void initProperties( - XTypeDescription type, HashMap map, ArrayList handleNames, HashSet seen) - { - XInterfaceTypeDescription2 ifc = UnoRuntime.queryInterface( - XInterfaceTypeDescription2.class, resolveTypedefs(type)); - if (!seen.add(ifc.getName())) { - return; - } - XTypeDescription[] bases = ifc.getBaseTypes(); - for (int i = 0; i < bases.length; ++i) { - initProperties(bases[i], map, handleNames, seen); - } - XInterfaceMemberTypeDescription[] members = ifc.getMembers(); - for (int i = 0; i < members.length; ++i) { - if (members[i].getTypeClass() == TypeClass.INTERFACE_ATTRIBUTE) - { - XInterfaceAttributeTypeDescription2 attr = - UnoRuntime.queryInterface( - XInterfaceAttributeTypeDescription2.class, - members[i]); - short attrAttribs = 0; - if (attr.isBound()) { - attrAttribs |= PropertyAttribute.BOUND; - } - boolean setUnknown = false; - if (attr.isReadOnly()) { - attrAttribs |= PropertyAttribute.READONLY; - setUnknown = true; - } - XCompoundTypeDescription[] excs = attr.getGetExceptions(); - boolean getUnknown = false; - //XXX Special interpretation of getter/setter exceptions - // only works if the specified exceptions are of the exact - // type, not of a supertype: - for (int j = 0; j < excs.length; ++j) { - if (excs[j].getName().equals( - "com.sun.star.beans.UnknownPropertyException")) - { - getUnknown = true; - break; - } - } - excs = attr.getSetExceptions(); - for (int j = 0; j < excs.length; ++j) { - if (excs[j].getName().equals( - "com.sun.star.beans.UnknownPropertyException")) - { - setUnknown = true; - } else if (excs[j].getName().equals( - "com.sun.star.beans." - + "PropertyVetoException")) - { - attrAttribs |= PropertyAttribute.CONSTRAINED; - } - } - if (getUnknown && setUnknown) { - attrAttribs |= PropertyAttribute.OPTIONAL; - } - XTypeDescription t = attr.getType(); - for (;;) { - t = resolveTypedefs(t); - short n; - if (t.getName().startsWith( - "com.sun.star.beans.Ambiguous<")) - { - n = PropertyAttribute.MAYBEAMBIGUOUS; - } else if (t.getName().startsWith( - "com.sun.star.beans.Defaulted<")) - { - n = PropertyAttribute.MAYBEDEFAULT; - } else if (t.getName().startsWith( - "com.sun.star.beans.Optional<")) - { - n = PropertyAttribute.MAYBEVOID; - } else { - break; - } - attrAttribs |= n; - t = UnoRuntime.queryInterface(XStructTypeDescription.class, t).getTypeArguments()[0]; - } - String name = members[i].getMemberName(); - boolean present = true; - if (absentOptional != null) { - for (int j = 0; j < absentOptional.length; ++j) { - if (name.equals(absentOptional[j])) { - present = false; - break; - } - } - } - if (map.put( - name, - new PropertyData( - new Property( - name, handleNames.size(), - new Type(t.getName(), t.getTypeClass()), - attrAttribs), - present)) - != null) - { - throw new RuntimeException( - "inconsistent UNO type registry"); - } - handleNames.add(name); - } - } - } - - private String translateHandle(int handle) throws UnknownPropertyException { - if (handle < 0 || handle >= handleMap.length) { - throw new UnknownPropertyException("bad handle " + handle, object); - } - return handleMap[handle]; - } - - private void setProperty( - String name, Object value, boolean isAmbiguous, boolean isDefaulted, - short illegalArgumentPosition) - throws UnknownPropertyException, PropertyVetoException, - com.sun.star.lang.IllegalArgumentException, WrappedTargetException - { - PropertyData p = properties.get(name); - if (p == null) { - throw new UnknownPropertyException(name, object); - } - if ((isAmbiguous - && (p.property.Attributes & PropertyAttribute.MAYBEAMBIGUOUS) == 0) - || (isDefaulted - && ((p.property.Attributes & PropertyAttribute.MAYBEDEFAULT) - == 0))) - { - throw new com.sun.star.lang.IllegalArgumentException( - ("flagging as ambiguous/defaulted non-ambiguous/defaulted" - + " property " + name), - object, illegalArgumentPosition); - - } - XIdlField2 f = UnoRuntime.queryInterface( - XIdlField2.class, idlClass.getField(name)); - Object[] o = new Object[] { - new Any(type, UnoRuntime.queryInterface(type, object)) }; - Object v = wrapValue( - value, - UnoRuntime.queryInterface( - XIdlField2.class, idlClass.getField(name)).getType(), - (p.property.Attributes & PropertyAttribute.MAYBEAMBIGUOUS) != 0, - isAmbiguous, - (p.property.Attributes & PropertyAttribute.MAYBEDEFAULT) != 0, - isDefaulted, - (p.property.Attributes & PropertyAttribute.MAYBEVOID) != 0); - try { - f.set(o, v); - } catch (com.sun.star.lang.IllegalArgumentException e) { - if (e.ArgumentPosition == 1) { - throw new com.sun.star.lang.IllegalArgumentException(e, - e.getMessage(), object, illegalArgumentPosition); - } else { - throw new RuntimeException(e); - } - } catch (com.sun.star.lang.IllegalAccessException e) { - //TODO Clarify whether PropertyVetoException is the correct - // exception to throw when trying to set a read-only property: - throw new PropertyVetoException(e, - "cannot set read-only property " + name, object); - } catch (WrappedTargetRuntimeException e) { - //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not - // guaranteed to originate directly within XIdlField2.get (and thus - // have the expected semantics); it might also be passed through - // from lower layers. - if (new Type(UnknownPropertyException.class).isSupertypeOf( - AnyConverter.getType(e.TargetException)) - && (p.property.Attributes & PropertyAttribute.OPTIONAL) != 0) - { - throw new UnknownPropertyException(e, name, object); - } else if (new Type(PropertyVetoException.class).isSupertypeOf( - AnyConverter.getType(e.TargetException)) - && ((p.property.Attributes - & PropertyAttribute.CONSTRAINED) - != 0)) - { - throw new PropertyVetoException(e, name, object); - } else { - throw new WrappedTargetException(e.getCause(), - e.getMessage(), object, e.TargetException); - } - } - } - - Object getProperty(String name, PropertyState[] state) - throws UnknownPropertyException, WrappedTargetException - { - PropertyData p = properties.get(name); - if (p == null) { - throw new UnknownPropertyException(name, object); - } - XIdlField2 field = UnoRuntime.queryInterface( - XIdlField2.class, idlClass.getField(name)); - Object value; - try { - value = field.get( - new Any(type, UnoRuntime.queryInterface(type, object))); - } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException(e); - } catch (WrappedTargetRuntimeException e) { - //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not - // guaranteed to originate directly within XIdlField2.get (and thus - // have the expected semantics); it might also be passed through - // from lower layers. - if (new Type(UnknownPropertyException.class).isSupertypeOf( - AnyConverter.getType(e.TargetException)) - && (p.property.Attributes & PropertyAttribute.OPTIONAL) != 0) - { - throw new UnknownPropertyException(e, name, object); - } else { - throw new WrappedTargetException(e.getCause(), - e.getMessage(), object, e.TargetException); - } - } - boolean undoAmbiguous - = (p.property.Attributes & PropertyAttribute.MAYBEAMBIGUOUS) != 0; - boolean undoDefaulted - = (p.property.Attributes & PropertyAttribute.MAYBEDEFAULT) != 0; - boolean undoOptional - = (p.property.Attributes & PropertyAttribute.MAYBEVOID) != 0; - boolean isAmbiguous = false; - boolean isDefaulted = false; - while (undoAmbiguous || undoDefaulted || undoOptional) { - String typeName = AnyConverter.getType(value).getTypeName(); - if (undoAmbiguous - && typeName.startsWith("com.sun.star.beans.Ambiguous<")) - { - XIdlClass ambiguous = getReflection(typeName); - try { - isAmbiguous = AnyConverter.toBoolean( - UnoRuntime.queryInterface( - XIdlField2.class, - ambiguous.getField("IsAmbiguous")).get(value)); - value = UnoRuntime.queryInterface( - XIdlField2.class, - ambiguous.getField("Value")).get(value); - } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException(e); - } - undoAmbiguous = false; - } else if (undoDefaulted - && typeName.startsWith("com.sun.star.beans.Defaulted<")) - { - XIdlClass defaulted = getReflection(typeName); - try { - isDefaulted = AnyConverter.toBoolean( - UnoRuntime.queryInterface( - XIdlField2.class, - defaulted.getField("IsDefaulted")).get(value)); - value = UnoRuntime.queryInterface( - XIdlField2.class, - defaulted.getField("Value")).get(value); - } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException(e); - } - undoDefaulted = false; - } else if (undoOptional - && typeName.startsWith("com.sun.star.beans.Optional<")) - { - XIdlClass optional = getReflection(typeName); - try { - boolean present = AnyConverter.toBoolean( - UnoRuntime.queryInterface( - XIdlField2.class, - optional.getField("IsPresent")).get(value)); - if (!present) { - value = Any.VOID; - break; - } - value = UnoRuntime.queryInterface( - XIdlField2.class, - optional.getField("Value")).get(value); - } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException(e); - } - undoOptional = false; - } else { - throw new RuntimeException( - "unexpected type of attribute " + name); - } - } - if (state != null) { - //XXX If isAmbiguous && isDefaulted, arbitrarily choose - // AMBIGUOUS_VALUE over DEFAULT_VALUE: - state[0] = isAmbiguous - ? PropertyState.AMBIGUOUS_VALUE - : isDefaulted - ? PropertyState.DEFAULT_VALUE : PropertyState.DIRECT_VALUE; - } - return value; - } - - private Object wrapValue( - Object value, XIdlClass type, boolean wrapAmbiguous, - boolean isAmbiguous, boolean wrapDefaulted, boolean isDefaulted, - boolean wrapOptional) - { - if (wrapAmbiguous - && type.getName().startsWith("com.sun.star.beans.Ambiguous<")) - { - Object[] strct = new Object[1]; - type.createObject(strct); - try { - XIdlField2 field = UnoRuntime.queryInterface( - XIdlField2.class, type.getField("Value")); - field.set( - strct, - wrapValue( - value, field.getType(), false, false, wrapDefaulted, - isDefaulted, wrapOptional)); - UnoRuntime.queryInterface( - XIdlField2.class, type.getField("IsAmbiguous")).set( - strct, Boolean.valueOf(isAmbiguous)); - } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException(e); - } catch (com.sun.star.lang.IllegalAccessException e) { - throw new RuntimeException(e); - } - return strct[0]; - } else if (wrapDefaulted - && type.getName().startsWith( - "com.sun.star.beans.Defaulted<")) - { - Object[] strct = new Object[1]; - type.createObject(strct); - try { - XIdlField2 field = UnoRuntime.queryInterface( - XIdlField2.class, type.getField("Value")); - field.set( - strct, - wrapValue( - value, field.getType(), wrapAmbiguous, isAmbiguous, - false, false, wrapOptional)); - UnoRuntime.queryInterface( - XIdlField2.class, type.getField("IsDefaulted")).set( - strct, Boolean.valueOf(isDefaulted)); - } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException(e); - } catch (com.sun.star.lang.IllegalAccessException e) { - throw new RuntimeException(e); - } - return strct[0]; - } else if (wrapOptional - && type.getName().startsWith("com.sun.star.beans.Optional<")) - { - Object[] strct = new Object[1]; - type.createObject(strct); - boolean present = !AnyConverter.isVoid(value); - try { - UnoRuntime.queryInterface( - XIdlField2.class, type.getField("IsPresent")).set( - strct, Boolean.valueOf(present)); - if (present) { - XIdlField2 field = UnoRuntime.queryInterface( - XIdlField2.class, type.getField("Value")); - field.set( - strct, - wrapValue( - value, field.getType(), wrapAmbiguous, isAmbiguous, - wrapDefaulted, isDefaulted, false)); - } - } catch (com.sun.star.lang.IllegalArgumentException e) { - throw new RuntimeException(e); - } catch (com.sun.star.lang.IllegalAccessException e) { - throw new RuntimeException(e); - } - return strct[0]; - } else { - if (wrapAmbiguous || wrapDefaulted || wrapOptional) { - throw new RuntimeException("unexpected type of attribute"); - } - return value; - } - } - - private static XTypeDescription resolveTypedefs(XTypeDescription type) { - while (type.getTypeClass() == TypeClass.TYPEDEF) { - type = UnoRuntime.queryInterface( - XIndirectTypeDescription.class, type).getReferencedType(); - } - return type; - } - - private PropertyData get(Object object, String propertyName) - throws UnknownPropertyException - { - PropertyData p = properties.get(propertyName); - if (p == null || !p.present) { - throw new UnknownPropertyException(propertyName, object); - } - return p; - } - - private void checkUnknown(String propertyName) - throws UnknownPropertyException - { - if (propertyName.length() != 0) { - get(this, propertyName); - } - } - - private static final class PropertyData { - public PropertyData(Property property, boolean present) { - this.property = property; - this.present = present; - } - - public final Property property; - public final boolean present; - } - - private final class Info extends WeakBase implements XPropertySetInfo - { - public Info(Map properties) { - this.properties = properties; - } - - public Property[] getProperties() { - ArrayList al = new ArrayList(properties.size()); - for (Iterator i = properties.values().iterator(); i.hasNext();) { - PropertyData p = i.next(); - if (p.present) { - al.add(p.property); - } - } - return al.toArray(new Property[al.size()]); - } - - public Property getPropertyByName(String name) - throws UnknownPropertyException - { - return get(this, name).property; - } - - public boolean hasPropertyByName(String name) { - PropertyData p = properties.get(name); - return p != null && p.present; - } - - private final Map properties; - } - - private final XComponentContext context; - private final XInterface object; - private final Type type; - private final String[] absentOptional; - private final XIdlClass idlClass; - private final Map properties; // from String to Property - private final String[] handleMap; - - private HashMap> boundListeners - = new HashMap>(); - // from String to Vector of XPropertyChangeListener - private HashMap> vetoListeners - = new HashMap>(); - // from String to Vector of XVetoableChangeListener - private boolean disposed = false; -} diff --git a/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java b/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java deleted file mode 100644 index 8bb4d26432d9..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/UnoUrl.java +++ /dev/null @@ -1,401 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.helper; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.HashMap; - -/** - * Object representation and parsing of Uno Urls, - * which allow to locate a named Uno object in a - * different process. A Uno Url consists of the - * specification of a connection, protocol and - * rootOid delimited with a ';'. - * The syntax of a Uno Url is - * - * - * [uno:]connection-type,parameters;protocol-name,parameters;objectname"; - * - * - * An example Uno Url will look like this: - * - * - * socket,host=localhost,port=2002;urp;StarOffice.ServiceManager - * - * - * For more information about Uno Url please consult - * - * http://udk.openoffice.org/common/man/spec/uno-url.html - * - * Usage: - * - * - * UnoUrl url = UnoUrl.parseUnoUrl("socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"); - * - */ -public class UnoUrl { - - private static final String FORMAT_ERROR = - "syntax: [uno:]connection-type,parameters;protocol-name,parameters;objectname"; - - private static final String VALUE_CHAR_SET = "!$&'()*+-./:?@_~"; - private static final String OID_CHAR_SET = VALUE_CHAR_SET + ",="; - - private final UnoUrlPart connection; - private final UnoUrlPart protocol; - private final String rootOid; - - private static class UnoUrlPart { - - private final String partTypeName; - private final HashMap partParameters; - private final String uninterpretedParameterString; - - public UnoUrlPart( - String uninterpretedParameterString, - String partTypeName, - HashMap partParameters) { - this.uninterpretedParameterString = uninterpretedParameterString; - this.partTypeName = partTypeName; - this.partParameters = partParameters; - } - - public String getPartTypeName() { - return partTypeName; - } - - public HashMap getPartParameters() { - return partParameters; - } - - public String getUninterpretedParameterString() { - return uninterpretedParameterString; - } - - public String getUninterpretedString() { - StringBuffer buf = new StringBuffer(partTypeName); - if (uninterpretedParameterString.length() > 0) { - buf.append(','); - buf.append(uninterpretedParameterString); - } - return buf.toString(); - } - } - - private UnoUrl( - UnoUrlPart connectionPart, - UnoUrlPart protocolPart, - String rootOid) { - this.connection = connectionPart; - this.protocol = protocolPart; - this.rootOid = rootOid; - } - - /** - * Returns the name of the connection of this - * Uno Url. Encoded characters are not allowed. - * - * @return The connection name as string. - */ - public String getConnection() { - return connection.getPartTypeName(); - } - - /** - * Returns the name of the protocol of this - * Uno Url. Encoded characters are not allowed. - * - * @return The protocol name as string. - */ - public String getProtocol() { - return protocol.getPartTypeName(); - } - - /** - * Return the object name. Encoded character are - * not allowed. - * - * @return The object name as String. - */ - public String getRootOid() { - return rootOid; - } - - /** - * Returns the protocol parameters as - * a Hashmap with key/value pairs. Encoded - * characters like '%41' are decoded. - * - * @return a HashMap with key/value pairs for protocol parameters. - */ - public HashMap getProtocolParameters() { - return protocol.getPartParameters(); - } - - /** - * Returns the connection parameters as - * a Hashmap with key/value pairs. Encoded - * characters like '%41' are decoded. - * - * @return a HashMap with key/value pairs for connection parameters. - */ - public HashMap getConnectionParameters() { - return connection.getPartParameters(); - } - - /** - * Returns the raw specification of the protocol - * parameters. Encoded characters like '%41' are - * not decoded. - * - * @return The uninterpreted protocol parameters as string. - */ - public String getProtocolParametersAsString() { - return protocol.getUninterpretedParameterString(); - } - - /** - * Returns the raw specification of the connection - * parameters. Encoded characters like '%41' are - * not decoded. - * - * @return The uninterpreted connection parameters as string. - */ - public String getConnectionParametersAsString() { - return connection.getUninterpretedParameterString(); - } - - /** - * Returns the raw specification of the protocol - * name and parameters. Encoded characters like '%41' are - * not decoded. - * - * @return The uninterpreted protocol name and parameters as string. - */ - public String getProtocolAndParametersAsString() { - return protocol.getUninterpretedString(); - } - - /** - * Returns the raw specification of the connection - * name and parameters. Encoded characters like '%41' are - * not decoded. - * - * @return The uninterpreted connection name and parameters as string. - */ - public String getConnectionAndParametersAsString() { - return connection.getUninterpretedString(); - } - - private static String decodeUTF8(String s) - throws com.sun.star.lang.IllegalArgumentException { - - if (!s.contains("%")) { - return s; - } - try { - int length = s.length(); - ByteBuffer bb = ByteBuffer.allocate(length); - for (int i = 0; i < length; i++) { - int ch = s.charAt(i); - - if (ch == '%') { - if (i+3 > length) - throw new com.sun.star.lang.IllegalArgumentException( - "Incomplete trailing escape (%) pattern"); - try { - ch = Integer.parseInt(s.substring(i+1,i+3),16); - } catch (NumberFormatException e) { - throw new com.sun.star.lang.IllegalArgumentException(e); - } - if (ch < 0) - throw new com.sun.star.lang.IllegalArgumentException( - "Illegal hex characters in escape (%) pattern - negative value"); - i+=2; - } - - bb.put((byte) (ch & 0xFF)); - } - - byte[] bytes = new byte[bb.position()]; - System.arraycopy(bb.array(), 0, bytes, 0, bytes.length); - return new String(bytes, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new com.sun.star.lang.IllegalArgumentException(e, - "Couldn't convert parameter string to UTF-8 string"); - } - } - - private static HashMap buildParamHashMap(String paramString) - throws com.sun.star.lang.IllegalArgumentException { - HashMap params = new HashMap(); - - int pos = 0; - - while (true) { - char c = ','; - - StringBuffer sb = new StringBuffer(); - while ((pos < paramString.length()) - && ((c = paramString.charAt(pos++)) != '=')) { - sb.append(c); - } - String aKey = sb.toString(); - - sb = new StringBuffer(); - while ((pos < paramString.length()) - && ((c = paramString.charAt(pos++)) != ',') - && c != ';') { - sb.append(c); - } - String aValue = sb.toString(); - - if ((aKey.length() > 0) && (aValue.length() > 0)) { - - if (!isAlphaNumeric(aKey)) { - throw new com.sun.star.lang.IllegalArgumentException( - "The parameter key '" - + aKey - + "' may only consist of alpha numeric ASCII characters."); - } - - if (!isValidString(aValue, VALUE_CHAR_SET + "%")) { - throw new com.sun.star.lang.IllegalArgumentException( - "The parameter value for key '" + aKey + "' contains illegal characters."); - } - - params.put(aKey, decodeUTF8(aValue)); - } - - if ((pos >= paramString.length()) || (c != ',')) - break; - - } - - return params; - } - - private static UnoUrlPart parseUnoUrlPart(String thePart) - throws com.sun.star.lang.IllegalArgumentException { - String partName; - String theParamPart; - int index = thePart.indexOf(','); - if (index != -1) { - partName = thePart.substring(0, index).trim(); - theParamPart = thePart.substring(index + 1).trim(); - } else { - partName = thePart; - theParamPart = ""; - } - - if (!isAlphaNumeric(partName)) { - throw new com.sun.star.lang.IllegalArgumentException( - "The part name '" - + partName - + "' may only consist of alpha numeric ASCII characters."); - } - - HashMap params = buildParamHashMap(theParamPart); - - return new UnoUrlPart(theParamPart, partName, params); - } - - private static boolean isAlphaNumeric(String s) { - return isValidString(s, null); - } - - private static boolean isValidString(String identifier, String validCharSet) { - - int len = identifier.length(); - - for (int i = 0; i < len; i++) { - - int ch = identifier.charAt(i); - - boolean isValidChar = - ('A' <= ch && ch <= 'Z') - || ('a' <= ch && ch <= 'z') - || ('0' <= ch && ch <= '9'); - - if (!isValidChar && (validCharSet != null)) { - isValidChar = (validCharSet.indexOf(ch) != -1); - } - - if (!isValidChar) - return false; - } - - return true; - } - - /** - * Parses the given Uno Url and returns - * an in memory object representation. - * - * @param unoUrl The given uno URl as string. - * @return Object representation of class UnoUrl. - * @throws IllegalArgumentException if Url cannot be parsed. - */ - public static UnoUrl parseUnoUrl(String unoUrl) - throws com.sun.star.lang.IllegalArgumentException { - - String url = unoUrl; - - int index = url.indexOf(':'); - if (index != -1) { - String unoStr = url.substring(0, index).trim(); - if (!"uno".equals(unoStr)) { - throw new com.sun.star.lang.IllegalArgumentException( - "Uno Urls must start with 'uno:'. " + FORMAT_ERROR); - } - } - - url = url.substring(index + 1).trim(); - - index = url.indexOf(';'); - if (index == -1) { - throw new com.sun.star.lang.IllegalArgumentException("'"+unoUrl+"' is an invalid Uno Url. " + FORMAT_ERROR); - } - - String connection = url.substring(0, index).trim(); - url = url.substring(index + 1).trim(); - - UnoUrlPart connectionPart = parseUnoUrlPart(connection); - - index = url.indexOf(';'); - if (index == -1) { - throw new com.sun.star.lang.IllegalArgumentException("'"+unoUrl+"' is an invalid Uno Url. " + FORMAT_ERROR); - } - - String protocol = url.substring(0, index).trim(); - url = url.substring(index + 1).trim(); - - UnoUrlPart protocolPart = parseUnoUrlPart(protocol); - - String rootOid = url.trim(); - if (!isValidString(rootOid, OID_CHAR_SET)) { - throw new com.sun.star.lang.IllegalArgumentException( - "Root OID '"+ rootOid + "' contains illegal characters."); - } - - return new UnoUrl(connectionPart, protocolPart, rootOid); - - } - -} diff --git a/javaunohelper/com/sun/star/lib/uno/helper/WeakAdapter.java b/javaunohelper/com/sun/star/lib/uno/helper/WeakAdapter.java deleted file mode 100644 index 67e01ac3276d..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/WeakAdapter.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.helper; -import java.lang.ref.WeakReference; -import com.sun.star.uno.XAdapter; -import com.sun.star.uno.XReference; -import java.util.List; -import java.util.Collections; -import java.util.LinkedList; - -/** An XAdapter implementation that holds a weak reference (java.lang.ref.WeakReference) - * to an object. Clients can register listener (com.sun.star.lang.XReference) which - * are notified when the object (the one which is kept weak) is being finalized. That - * is, that object is being destroyed because there are not any hard references - * to it. - */ -public class WeakAdapter implements XAdapter -{ - // references the XWeak implementation - private final WeakReference m_weakRef; - // contains XReference objects registered by addReference - private final List m_xreferenceList; - - /** - *@param component the object that is to be held weak - */ - public WeakAdapter(Object component) - { - m_weakRef= new WeakReference(component); - m_xreferenceList= Collections.synchronizedList( new LinkedList()); - } - - /** Called by the XWeak implementation (WeakBase) when it is being finalized. - * It is only being called once. - * The registered XReference listeners are notified. On notification they are - * to unregister themselves. The notification is thread-safe. However, it is possible - * to add a listener during the notification process, which will never receive a - * notification. To prevent this, one would have to synchronize this method with - * the addReference method. But this can result in deadlocks in a multi-threaded - * environment. - */ - void referentDying() - { - //synchronized call - XReference[] references= m_xreferenceList.toArray(new XReference[m_xreferenceList.size()]); - for (int i= references.length; i > 0; i--) - { - references[i-1].dispose(); - } - } - - /** Method of com.sun.star.uno.XAdapter. It is called to obtain a hard reference - * to the object which is kept weak by this instance. - * @return hard reference to the object - */ - public Object queryAdapted() - { - return m_weakRef.get(); - } - - /** Method of com.sun.star.uno.XAdapter. Called by clients to register listener which - * are notified when the weak object is dying. - *@param xReference a listener - */ - public void removeReference(XReference xReference) - { - m_xreferenceList.remove(xReference); - } - - /** Method of com.sun.star.uno.XAdapter. Called by clients to unregister listeners. - *@param xReference listener - */ - public void addReference(XReference xReference) - { - m_xreferenceList.add(xReference); - } -} - diff --git a/javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java b/javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java deleted file mode 100644 index ac175d3a6d5d..000000000000 --- a/javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -package com.sun.star.lib.uno.helper; -import com.sun.star.uno.XWeak; -import com.sun.star.uno.XAdapter; -import com.sun.star.lang.XTypeProvider; -import com.sun.star.uno.Type; -import java.util.ArrayList; -import java.util.Map; -import java.util.HashMap; - - -/** This class can be used as the base class for UNO components. It implements the capability - * to be kept weak (com.sun.star.uno.XWeak) and it implements com.sun.star.lang.XTypeProvider - * which is necessary for using the component with StarBasic. - */ -public class WeakBase implements XWeak, XTypeProvider -{ - // Contains all WeakAdapter which have been created in this class - // They have to be notified when this object dies - private WeakAdapter m_adapter; - - protected static Map,Type[]> _mapTypes = new HashMap,Type[]>(); - - /** Method of XWeak. The returned XAdapter implementation can be used to keep - * a weak reference to this object. - * @return a com.sun.star.uno.XAdapter implementation. - */ - synchronized public XAdapter queryAdapter() - { - if (m_adapter == null) - m_adapter= new WeakAdapter(this); - return m_adapter; - } - - /** Override of Object.finalize. When there are no references to this object anymore - * then the garbage collector calls this method. Thereby causing the adapter object - * to be notified. The adapter, in turn, notifies all listeners (com.sun.star.uno.XReference) - */ - @Override - protected void finalize() throws java.lang.Throwable - { - if (m_adapter != null) - m_adapter.referentDying(); - super.finalize(); - } - - /** Method of XTypeProvider. It returns an array of Type objects which represent - * all implemented UNO interfaces of this object. - * @return Type objects of all implemented interfaces. - */ - public Type[] getTypes() - { - Type[] arTypes= _mapTypes.get( getClass()); - if (arTypes == null) - { - ArrayList vec= new ArrayList(); - Class currentClass= getClass(); - do - { - Class interfaces[]= currentClass.getInterfaces(); - for(int i = 0; i < interfaces.length; ++ i) - { - // Test if it is a UNO interface - if (com.sun.star.uno.XInterface.class.isAssignableFrom(interfaces[i])) - vec.add(new Type(interfaces[i])); - } - // get the superclass the currentClass inherits from - currentClass= currentClass.getSuperclass(); - } while (currentClass != null); - - Type types[]= vec.toArray(new Type[vec.size()]); - _mapTypes.put(getClass(), types); - arTypes= types; - } - return arTypes; - } - - /** Obsolete method of XTypeProvider. - */ - public byte[] getImplementationId() - { - return new byte[0]; - } -} diff --git a/javaunohelper/util/manifest b/javaunohelper/util/manifest index f89dc5414f0c..5c77968cd97c 100644 --- a/javaunohelper/util/manifest +++ b/javaunohelper/util/manifest @@ -1,2 +1 @@ -Sealed: true UNO-Type-Path: diff --git a/jurt/Jar_jurt.mk b/jurt/Jar_jurt.mk index 77b0657ab57f..faf917fc3ae2 100644 --- a/jurt/Jar_jurt.mk +++ b/jurt/Jar_jurt.mk @@ -10,7 +10,7 @@ $(eval $(call gb_Jar_Jar,jurt)) $(eval $(call gb_Jar_add_manifest_classpath,jurt, \ - ridl.jar \ + libreoffice.jar \ )) # vim:set noet sw=4 ts=4: diff --git a/nlpsolver/Jar_nlpsolver.mk b/nlpsolver/Jar_nlpsolver.mk index 47119cb59bf2..3203b012d80f 100644 --- a/nlpsolver/Jar_nlpsolver.mk +++ b/nlpsolver/Jar_nlpsolver.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_Jar,nlpsolver)) $(eval $(call gb_Jar_use_jars,nlpsolver,\ - ridl \ - juh \ + libreoffice \ java_uno \ EvolutionarySolver \ )) diff --git a/odk/CustomTarget_javadoc.mk b/odk/CustomTarget_javadoc.mk index eefc26fd58ec..acb205610d5c 100644 --- a/odk/CustomTarget_javadoc.mk +++ b/odk/CustomTarget_javadoc.mk @@ -29,7 +29,7 @@ $(call gb_CustomTarget_get_workdir,odk/docs/java/ref)/%.html : \ touch $@ $(call gb_CustomTarget_get_workdir,odk/docs/java/ref)/javadoc_log.txt : \ - $(call gb_Jar_get_target,ridl) + $(call gb_Jar_get_target,libreoffice) $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),JDC,1) $(call gb_Trace_StartRange,$(subst $(WORKDIR)/,,$@),JDC) $(call gb_Helper_abbreviate_dirs,\ @@ -39,7 +39,7 @@ $(call gb_CustomTarget_get_workdir,odk/docs/java/ref)/javadoc_log.txt : \ -tag attention:a:"Attention:" \ -d $(dir $@) \ -sourcepath "$(SRCDIR)/ridljar/source/unoloader$(gb_CLASSPATHSEP)$(SRCDIR)/ridljar$(gb_CLASSPATHSEP)$(SRCDIR)/jurt$(gb_CLASSPATHSEP)$(SRCDIR)/javaunohelper" \ - -classpath $(call gb_Jar_get_target,ridl) \ + -classpath $(call gb_Jar_get_target,libreoffice) \ -linkoffline ../../common/reg $(SRCDIR)/odk/docs/java-uno \ -linkoffline http://java.sun.com/j2se/1.5/docs/api $(SRCDIR)/odk/docs/java \ $(odk_JAVAPACKAGES) \ diff --git a/odk/config/cfgWin.js b/odk/config/cfgWin.js index 9ca5888f33ef..128f3e2eafd5 100644 --- a/odk/config/cfgWin.js +++ b/odk/config/cfgWin.js @@ -953,7 +953,7 @@ function writeBatFile(fdir, file) "set OO_SDK_OFFICE_JAVA_DIR=%OFFICE_PROGRAM_PATH%\\classes\n" + "\n" + "REM Set classpath\n" + - "set CLASSPATH=%OO_SDK_URE_JAVA_DIR%\\juh.jar;%OO_SDK_URE_JAVA_DIR%\\ridl.jar;%OO_SDK_URE_JAVA_DIR%\\unoloader.jar\n" + + "set CLASSPATH=%OO_SDK_URE_JAVA_DIR%\\libreoffice.jar;%OO_SDK_URE_JAVA_DIR%\\unoloader.jar\n" + "\n" + "REM Add directory of the SDK tools to the path.\n" + "set PATH=%OO_SDK_HOME%\\bin;%OO_SDK_URE_BIN_DIR%;%OO_SDK_OFFICE_BIN_DIR%;%OO_SDK_HOME%\\WINexample.out\\bin;%PATH%\n" + diff --git a/odk/config/setsdkenv_unix.sh.in b/odk/config/setsdkenv_unix.sh.in index f9f3a7c2a773..7feda4159e01 100644 --- a/odk/config/setsdkenv_unix.sh.in +++ b/odk/config/setsdkenv_unix.sh.in @@ -200,7 +200,7 @@ esac PATH=${OO_SDK_HOME}/bin:${OO_SDK_OUT}/${exampleout}/bin:${OO_SDK_URE_BIN_DIR}:${OFFICE_PROGRAM_PATH}:${PATH} # Set the classpath -CLASSPATH=${OO_SDK_URE_JAVA_DIR}/juh.jar:${OO_SDK_URE_JAVA_DIR}/ridl.jar:${OO_SDK_URE_JAVA_DIR}/unoloader.jar:${CLASSPATH} +CLASSPATH=${OO_SDK_URE_JAVA_DIR}/libreoffice.jar:${OO_SDK_URE_JAVA_DIR}/unoloader.jar:${CLASSPATH} export CLASSPATH diff --git a/odk/docs/install.html b/odk/docs/install.html index 3a5782a9b050..59c8fbf2758e 100644 --- a/odk/docs/install.html +++ b/odk/docs/install.html @@ -387,8 +387,7 @@ CLASSPATH - =$OO_SDK_URE_JAVA_DIR/juh.jar; - $OO_SDK_URE_JAVA_DIR/ridl.jar; + =$OO_SDK_URE_JAVA_DIR/libreoffice.jar; $OO_SDK_URE_JAVA_DIR/unoloader.jar; $CLASSPATH

The classpath will be set or extended to diff --git a/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml b/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml index 6d17348ed479..4dec9aa7ee7c 100644 --- a/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml +++ b/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml @@ -28,7 +28,7 @@ + files="libreoffice.jar"/> diff --git a/odk/examples/DevelopersGuide/OfficeBean/Makefile b/odk/examples/DevelopersGuide/OfficeBean/Makefile index ea5baadc1636..09c10d05d722 100644 --- a/odk/examples/DevelopersGuide/OfficeBean/Makefile +++ b/odk/examples/DevelopersGuide/OfficeBean/Makefile @@ -51,8 +51,7 @@ JAVAFILES = \ CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/$(PACKAGE)/%.class,$(JAVAFILES)) SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),\ - $(PATH_SEPARATOR)$(URE_CLASSES_DIR)/ridl.jar\ - $(PATH_SEPARATOR)$(URE_CLASSES_DIR)/juh.jar\ + $(PATH_SEPARATOR)$(URE_CLASSES_DIR)/libreoffice.jar\ $(PATH_SEPARATOR)$(OFFICE_CLASSES_DIR)/officebean.jar\ $(PATH_SEPARATOR)$(OUT_COMP_CLASS)) diff --git a/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/build.xml b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/build.xml index a3bf61fc7345..b79ac64ae483 100644 --- a/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/build.xml +++ b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/build.xml @@ -41,8 +41,7 @@ - - + diff --git a/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/build.xml b/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/build.xml index b3fc997e695a..c290030465ba 100644 --- a/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/build.xml +++ b/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/build.xml @@ -41,8 +41,7 @@ - - + diff --git a/qadevOOo/.classpath b/qadevOOo/.classpath index d8828a72c283..81adde6656f5 100644 --- a/qadevOOo/.classpath +++ b/qadevOOo/.classpath @@ -9,8 +9,7 @@ - - + diff --git a/qadevOOo/Jar_OOoRunner.mk b/qadevOOo/Jar_OOoRunner.mk index b3f7f3333258..a526ad0ca163 100644 --- a/qadevOOo/Jar_OOoRunner.mk +++ b/qadevOOo/Jar_OOoRunner.mk @@ -14,14 +14,13 @@ gb_JavaClassSet_JAVACDEBUG:= -g $(eval $(call gb_Jar_Jar,OOoRunner)) $(eval $(call gb_Jar_add_manifest_classpath,OOoRunner,\ - ridl.jar \ + libreoffice.jar \ )) $(eval $(call gb_Jar_set_manifest,OOoRunner,$(SRCDIR)/qadevOOo/runner/manifest)) $(eval $(call gb_Jar_use_jars,OOoRunner,\ - ridl \ - juh \ + libreoffice \ java_uno \ )) diff --git a/reportbuilder/Jar_reportbuilder.mk b/reportbuilder/Jar_reportbuilder.mk index 83778dd0fbf4..101ebc9330b7 100644 --- a/reportbuilder/Jar_reportbuilder.mk +++ b/reportbuilder/Jar_reportbuilder.mk @@ -11,8 +11,7 @@ $(eval $(call gb_Jar_Jar,reportbuilder)) $(eval $(call gb_Jar_use_jars,reportbuilder,\ java_uno \ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_use_externals,reportbuilder,\ diff --git a/ridljar/Jar_libreoffice.mk b/ridljar/Jar_libreoffice.mk new file mode 100644 index 000000000000..4d0f5ef2545f --- /dev/null +++ b/ridljar/Jar_libreoffice.mk @@ -0,0 +1,133 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Jar_Jar,libreoffice)) + +$(eval $(call gb_Jar_use_customtargets,libreoffice,\ + ridljar/javamaker \ + unoil/javamaker \ +)) + +$(eval $(call gb_Jar_use_jars,libreoffice, \ + unoloader \ +)) + +$(eval $(call gb_Jar_set_packageroot,libreoffice,com)) + +$(eval $(call gb_Jar_set_manifest,libreoffice,$(SRCDIR)/ridljar/util/manifest)) + +$(eval $(call gb_Jar_add_manifest_classpath,libreoffice, \ + unoloader.jar \ + $(if $(filter MACOSX,$(OS)),../../Frameworks/,../) \ +)) + +$(eval $(call gb_Jar_add_packagedirs,libreoffice,\ + $(call gb_CustomTarget_get_workdir,ridljar/javamaker)/com \ + $(call gb_CustomTarget_get_workdir,unoil/javamaker)/com \ +)) + +$(eval $(call gb_Jar_add_sourcefiles,libreoffice,\ + ridljar/com/sun/star/comp/bridgefactory/BridgeFactory \ + ridljar/com/sun/star/comp/connections/Acceptor \ + ridljar/com/sun/star/comp/connections/Connector \ + ridljar/com/sun/star/comp/connections/ConstantInstanceProvider \ + ridljar/com/sun/star/comp/connections/Implementation \ + ridljar/com/sun/star/comp/connections/PipedConnection \ + ridljar/com/sun/star/comp/helper/Bootstrap \ + ridljar/com/sun/star/comp/helper/BootstrapException \ + ridljar/com/sun/star/comp/helper/ComponentContext \ + ridljar/com/sun/star/comp/helper/ComponentContextEntry \ + ridljar/com/sun/star/comp/helper/SharedLibraryLoader \ + ridljar/com/sun/star/comp/loader/FactoryHelper \ + ridljar/com/sun/star/comp/loader/JavaLoader \ + ridljar/com/sun/star/comp/loader/JavaLoaderFactory \ + ridljar/com/sun/star/comp/loader/RegistrationClassFinder \ + ridljar/com/sun/star/comp/servicemanager/ServiceManager \ + ridljar/com/sun/star/comp/urlresolver/UrlResolver \ + ridljar/com/sun/star/lib/connections/pipe/PipeConnection \ + ridljar/com/sun/star/lib/connections/pipe/pipeAcceptor \ + ridljar/com/sun/star/lib/connections/pipe/pipeConnector \ + ridljar/com/sun/star/lib/connections/socket/ConnectionDescriptor \ + ridljar/com/sun/star/lib/connections/socket/SocketConnection \ + ridljar/com/sun/star/lib/connections/socket/socketAcceptor \ + ridljar/com/sun/star/lib/connections/socket/socketConnector \ + ridljar/com/sun/star/lib/uno/Proxy \ + ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter \ + ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter \ + ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter \ + ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter \ + ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter \ + ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter \ + ridljar/com/sun/star/lib/uno/bridges/java_remote/BridgedObject \ + ridljar/com/sun/star/lib/uno/bridges/java_remote/ProxyFactory \ + ridljar/com/sun/star/lib/uno/bridges/java_remote/RequestHandler \ + ridljar/com/sun/star/lib/uno/bridges/java_remote/XConnectionInputStream_Adapter \ + ridljar/com/sun/star/lib/uno/bridges/java_remote/XConnectionOutputStream_Adapter \ + ridljar/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge \ + ridljar/com/sun/star/lib/uno/environments/java/java_environment \ + ridljar/com/sun/star/lib/uno/environments/remote/IProtocol \ + ridljar/com/sun/star/lib/uno/environments/remote/IReceiver \ + ridljar/com/sun/star/lib/uno/environments/remote/IThreadPool \ + ridljar/com/sun/star/lib/uno/environments/remote/JavaThreadPool \ + ridljar/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory \ + ridljar/com/sun/star/lib/uno/environments/remote/Job \ + ridljar/com/sun/star/lib/uno/environments/remote/JobQueue \ + ridljar/com/sun/star/lib/uno/environments/remote/Message \ + ridljar/com/sun/star/lib/uno/environments/remote/NativeThreadPool \ + ridljar/com/sun/star/lib/uno/environments/remote/ThreadId \ + ridljar/com/sun/star/lib/uno/environments/remote/ThreadPoolManager \ + ridljar/com/sun/star/lib/uno/environments/remote/remote_environment \ + ridljar/com/sun/star/lib/uno/helper/ComponentBase \ + ridljar/com/sun/star/lib/uno/helper/Factory \ + ridljar/com/sun/star/lib/uno/helper/InterfaceContainer \ + ridljar/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer \ + ridljar/com/sun/star/lib/uno/helper/PropertySet \ + ridljar/com/sun/star/lib/uno/helper/PropertySetMixin \ + ridljar/com/sun/star/lib/uno/helper/UnoUrl \ + ridljar/com/sun/star/lib/uno/helper/WeakAdapter \ + ridljar/com/sun/star/lib/uno/helper/WeakBase \ + ridljar/com/sun/star/lib/uno/protocols/urp/Cache \ + ridljar/com/sun/star/lib/uno/protocols/urp/Marshal \ + ridljar/com/sun/star/lib/uno/protocols/urp/PendingRequests \ + ridljar/com/sun/star/lib/uno/protocols/urp/Unmarshal \ + ridljar/com/sun/star/lib/uno/protocols/urp/UrpMessage \ + ridljar/com/sun/star/lib/uno/protocols/urp/urp \ + ridljar/com/sun/star/lib/uno/typedesc/FieldDescription \ + ridljar/com/sun/star/lib/uno/typedesc/MemberDescriptionHelper \ + ridljar/com/sun/star/lib/uno/typedesc/MethodDescription \ + ridljar/com/sun/star/lib/uno/typedesc/TypeDescription \ + ridljar/com/sun/star/lib/uno/typeinfo/AttributeTypeInfo \ + ridljar/com/sun/star/lib/uno/typeinfo/ConstantTypeInfo \ + ridljar/com/sun/star/lib/uno/typeinfo/MemberTypeInfo \ + ridljar/com/sun/star/lib/uno/typeinfo/MethodTypeInfo \ + ridljar/com/sun/star/lib/uno/typeinfo/ParameterTypeInfo \ + ridljar/com/sun/star/lib/uno/typeinfo/TypeInfo \ + ridljar/com/sun/star/lib/util/AsynchronousFinalizer \ + ridljar/com/sun/star/lib/util/DisposeListener \ + ridljar/com/sun/star/lib/util/DisposeNotifier \ + ridljar/com/sun/star/lib/util/NativeLibraryLoader \ + ridljar/com/sun/star/lib/util/StringHelper \ + ridljar/com/sun/star/lib/util/UrlToFileMapper \ + ridljar/com/sun/star/lib/util/WeakMap \ + ridljar/com/sun/star/uno/Any \ + ridljar/com/sun/star/uno/AnyConverter \ + ridljar/com/sun/star/uno/Ascii \ + ridljar/com/sun/star/uno/AsciiString \ + ridljar/com/sun/star/uno/Enum \ + ridljar/com/sun/star/uno/IBridge \ + ridljar/com/sun/star/uno/IEnvironment \ + ridljar/com/sun/star/uno/IMapping \ + ridljar/com/sun/star/uno/IQueryInterface \ + ridljar/com/sun/star/uno/MappingException \ + ridljar/com/sun/star/uno/Type \ + ridljar/com/sun/star/uno/UnoRuntime \ + ridljar/com/sun/star/uno/WeakReference \ +)) + +# vim:set noet sw=4 ts=4: diff --git a/ridljar/Jar_ridl.mk b/ridljar/Jar_ridl.mk index 6fc4688f0eab..5ebd4589b093 100644 --- a/ridljar/Jar_ridl.mk +++ b/ridljar/Jar_ridl.mk @@ -9,105 +9,8 @@ $(eval $(call gb_Jar_Jar,ridl)) -$(eval $(call gb_Jar_use_customtargets,ridl,\ - ridljar/javamaker \ - unoil/javamaker \ -)) - -$(eval $(call gb_Jar_use_jars,ridl, \ - unoloader \ -)) - -$(eval $(call gb_Jar_set_packageroot,ridl,com)) - -$(eval $(call gb_Jar_set_manifest,ridl,$(SRCDIR)/ridljar/util/manifest)) - $(eval $(call gb_Jar_add_manifest_classpath,ridl, \ - unoloader.jar \ - $(if $(filter MACOSX,$(OS)),../../Frameworks/,../) \ -)) - -$(eval $(call gb_Jar_add_packagedirs,ridl,\ - $(call gb_CustomTarget_get_workdir,ridljar/javamaker)/com \ - $(call gb_CustomTarget_get_workdir,unoil/javamaker)/com \ -)) - -$(eval $(call gb_Jar_add_sourcefiles,ridl,\ - ridljar/com/sun/star/comp/bridgefactory/BridgeFactory \ - ridljar/com/sun/star/comp/connections/Acceptor \ - ridljar/com/sun/star/comp/connections/Connector \ - ridljar/com/sun/star/comp/connections/ConstantInstanceProvider \ - ridljar/com/sun/star/comp/connections/Implementation \ - ridljar/com/sun/star/comp/connections/PipedConnection \ - ridljar/com/sun/star/comp/loader/FactoryHelper \ - ridljar/com/sun/star/comp/loader/JavaLoader \ - ridljar/com/sun/star/comp/loader/JavaLoaderFactory \ - ridljar/com/sun/star/comp/loader/RegistrationClassFinder \ - ridljar/com/sun/star/comp/servicemanager/ServiceManager \ - ridljar/com/sun/star/comp/urlresolver/UrlResolver \ - ridljar/com/sun/star/lib/connections/pipe/PipeConnection \ - ridljar/com/sun/star/lib/connections/pipe/pipeAcceptor \ - ridljar/com/sun/star/lib/connections/pipe/pipeConnector \ - ridljar/com/sun/star/lib/connections/socket/ConnectionDescriptor \ - ridljar/com/sun/star/lib/connections/socket/SocketConnection \ - ridljar/com/sun/star/lib/connections/socket/socketAcceptor \ - ridljar/com/sun/star/lib/connections/socket/socketConnector \ - ridljar/com/sun/star/lib/uno/Proxy \ - ridljar/com/sun/star/lib/uno/bridges/java_remote/BridgedObject \ - ridljar/com/sun/star/lib/uno/bridges/java_remote/ProxyFactory \ - ridljar/com/sun/star/lib/uno/bridges/java_remote/RequestHandler \ - ridljar/com/sun/star/lib/uno/bridges/java_remote/XConnectionInputStream_Adapter \ - ridljar/com/sun/star/lib/uno/bridges/java_remote/XConnectionOutputStream_Adapter \ - ridljar/com/sun/star/lib/uno/bridges/java_remote/java_remote_bridge \ - ridljar/com/sun/star/lib/uno/environments/java/java_environment \ - ridljar/com/sun/star/lib/uno/environments/remote/IProtocol \ - ridljar/com/sun/star/lib/uno/environments/remote/IReceiver \ - ridljar/com/sun/star/lib/uno/environments/remote/IThreadPool \ - ridljar/com/sun/star/lib/uno/environments/remote/JavaThreadPool \ - ridljar/com/sun/star/lib/uno/environments/remote/JavaThreadPoolFactory \ - ridljar/com/sun/star/lib/uno/environments/remote/Job \ - ridljar/com/sun/star/lib/uno/environments/remote/JobQueue \ - ridljar/com/sun/star/lib/uno/environments/remote/Message \ - ridljar/com/sun/star/lib/uno/environments/remote/NativeThreadPool \ - ridljar/com/sun/star/lib/uno/environments/remote/ThreadId \ - ridljar/com/sun/star/lib/uno/environments/remote/ThreadPoolManager \ - ridljar/com/sun/star/lib/uno/environments/remote/remote_environment \ - ridljar/com/sun/star/lib/uno/protocols/urp/Cache \ - ridljar/com/sun/star/lib/uno/protocols/urp/Marshal \ - ridljar/com/sun/star/lib/uno/protocols/urp/PendingRequests \ - ridljar/com/sun/star/lib/uno/protocols/urp/Unmarshal \ - ridljar/com/sun/star/lib/uno/protocols/urp/UrpMessage \ - ridljar/com/sun/star/lib/uno/protocols/urp/urp \ - ridljar/com/sun/star/lib/uno/typedesc/FieldDescription \ - ridljar/com/sun/star/lib/uno/typedesc/MemberDescriptionHelper \ - ridljar/com/sun/star/lib/uno/typedesc/MethodDescription \ - ridljar/com/sun/star/lib/uno/typedesc/TypeDescription \ - ridljar/com/sun/star/lib/uno/typeinfo/AttributeTypeInfo \ - ridljar/com/sun/star/lib/uno/typeinfo/ConstantTypeInfo \ - ridljar/com/sun/star/lib/uno/typeinfo/MemberTypeInfo \ - ridljar/com/sun/star/lib/uno/typeinfo/MethodTypeInfo \ - ridljar/com/sun/star/lib/uno/typeinfo/ParameterTypeInfo \ - ridljar/com/sun/star/lib/uno/typeinfo/TypeInfo \ - ridljar/com/sun/star/lib/util/AsynchronousFinalizer \ - ridljar/com/sun/star/lib/util/DisposeListener \ - ridljar/com/sun/star/lib/util/DisposeNotifier \ - ridljar/com/sun/star/lib/util/NativeLibraryLoader \ - ridljar/com/sun/star/lib/util/StringHelper \ - ridljar/com/sun/star/lib/util/UrlToFileMapper \ - ridljar/com/sun/star/lib/util/WeakMap \ - ridljar/com/sun/star/uno/Any \ - ridljar/com/sun/star/uno/AnyConverter \ - ridljar/com/sun/star/uno/Ascii \ - ridljar/com/sun/star/uno/AsciiString \ - ridljar/com/sun/star/uno/Enum \ - ridljar/com/sun/star/uno/IBridge \ - ridljar/com/sun/star/uno/IEnvironment \ - ridljar/com/sun/star/uno/IMapping \ - ridljar/com/sun/star/uno/IQueryInterface \ - ridljar/com/sun/star/uno/MappingException \ - ridljar/com/sun/star/uno/Type \ - ridljar/com/sun/star/uno/UnoRuntime \ - ridljar/com/sun/star/uno/WeakReference \ + libreoffice.jar \ )) # vim:set noet sw=4 ts=4: diff --git a/ridljar/JunitTest_bridgefactory.mk b/ridljar/JunitTest_bridgefactory.mk index bbf846152c44..c50dbcf6d37d 100644 --- a/ridljar/JunitTest_bridgefactory.mk +++ b/ridljar/JunitTest_bridgefactory.mk @@ -13,7 +13,7 @@ $(eval $(call gb_Jar_use_customtargets,ridl_bridgefactory, \ ridljar/javamaker \ )) -$(eval $(call gb_JunitTest_use_jar_classset,ridl_bridgefactory,ridl)) +$(eval $(call gb_JunitTest_use_jar_classset,ridl_bridgefactory,libreoffice)) $(eval $(call gb_JunitTest_add_classpath,ridl_bridgefactory,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) diff --git a/ridljar/JunitTest_connections.mk b/ridljar/JunitTest_connections.mk index 54cfc27e000c..8c8496e35707 100644 --- a/ridljar/JunitTest_connections.mk +++ b/ridljar/JunitTest_connections.mk @@ -13,7 +13,7 @@ $(eval $(call gb_Jar_use_customtargets,ridl_connections, \ ridljar/javamaker \ )) -$(eval $(call gb_JunitTest_use_jar_classset,ridl_connections,ridl)) +$(eval $(call gb_JunitTest_use_jar_classset,ridl_connections,libreoffice)) $(eval $(call gb_JunitTest_add_classpath,ridl_connections,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) diff --git a/ridljar/JunitTest_java.mk b/ridljar/JunitTest_java.mk index e1a53dba8a3a..be174cfe2805 100644 --- a/ridljar/JunitTest_java.mk +++ b/ridljar/JunitTest_java.mk @@ -13,7 +13,7 @@ $(eval $(call gb_Jar_use_customtargets,ridl_java, \ ridljar/javamaker \ )) -$(eval $(call gb_JunitTest_use_jar_classset,ridl_java,ridl)) +$(eval $(call gb_JunitTest_use_jar_classset,ridl_java,libreoffice)) $(eval $(call gb_JunitTest_add_classpath,ridl_java,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) diff --git a/ridljar/JunitTest_java_remote.mk b/ridljar/JunitTest_java_remote.mk index 38482d2b1e50..2039e1282885 100644 --- a/ridljar/JunitTest_java_remote.mk +++ b/ridljar/JunitTest_java_remote.mk @@ -17,7 +17,7 @@ $(eval $(call gb_Jar_use_customtargets,ridl_java_remote, \ ridljar/javamaker \ )) -$(eval $(call gb_JunitTest_use_jar_classset,ridl_java_remote,ridl)) +$(eval $(call gb_JunitTest_use_jar_classset,ridl_java_remote,libreoffice)) $(eval $(call gb_JunitTest_add_classpath,ridl_java_remote,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) diff --git a/ridljar/JunitTest_remote.mk b/ridljar/JunitTest_remote.mk index a0c94d5caa92..340618676163 100644 --- a/ridljar/JunitTest_remote.mk +++ b/ridljar/JunitTest_remote.mk @@ -13,7 +13,7 @@ $(eval $(call gb_Jar_use_customtargets,ridl_remote, \ ridljar/javamaker \ )) -$(eval $(call gb_JunitTest_use_jar_classset,ridl_remote,ridl)) +$(eval $(call gb_JunitTest_use_jar_classset,ridl_remote,libreoffice)) $(eval $(call gb_JunitTest_add_classpath,ridl_remote,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) diff --git a/ridljar/JunitTest_typedesc.mk b/ridljar/JunitTest_typedesc.mk index 6a2bf779471a..4497731aafa8 100644 --- a/ridljar/JunitTest_typedesc.mk +++ b/ridljar/JunitTest_typedesc.mk @@ -10,7 +10,7 @@ $(eval $(call gb_JunitTest_JunitTest,ridljar_typedesc)) $(eval $(call gb_JunitTest_use_jars,ridljar_typedesc,\ - ridl \ + libreoffice \ )) $(eval $(call gb_JunitTest_add_sourcefiles,ridljar_typedesc,\ diff --git a/ridljar/JunitTest_uno.mk b/ridljar/JunitTest_uno.mk index e0a7ff4574a4..885c5fc437ce 100644 --- a/ridljar/JunitTest_uno.mk +++ b/ridljar/JunitTest_uno.mk @@ -11,7 +11,7 @@ $(eval $(call gb_JunitTest_JunitTest,ridljar_uno)) $(eval $(call gb_JunitTest_use_jars,ridljar_uno,\ OOoRunner \ - ridl \ + libreoffice \ )) $(eval $(call gb_JunitTest_add_sourcefiles,ridljar_uno,\ diff --git a/ridljar/JunitTest_urp.mk b/ridljar/JunitTest_urp.mk index 760f81992060..3f5f76eae339 100644 --- a/ridljar/JunitTest_urp.mk +++ b/ridljar/JunitTest_urp.mk @@ -14,7 +14,7 @@ $(eval $(call gb_JunitTest_use_customtargets,ridl_urp,\ ridljar/javamaker \ )) -$(eval $(call gb_JunitTest_use_jar_classset,ridl_urp,ridl)) +$(eval $(call gb_JunitTest_use_jar_classset,ridl_urp,libreoffice)) $(eval $(call gb_JunitTest_add_classpath,ridl_urp,$(call gb_CustomTarget_get_workdir,ridljar/javamaker))) diff --git a/ridljar/JunitTest_util.mk b/ridljar/JunitTest_util.mk index 2be75f61f2e9..2896e5760476 100644 --- a/ridljar/JunitTest_util.mk +++ b/ridljar/JunitTest_util.mk @@ -11,7 +11,7 @@ $(eval $(call gb_JunitTest_JunitTest,ridljar_util)) $(eval $(call gb_JunitTest_use_jars,ridljar_util,\ OOoRunner \ - ridl \ + libreoffice \ )) $(eval $(call gb_JunitTest_add_sourcefiles,ridljar_util,\ diff --git a/ridljar/Module_ridljar.mk b/ridljar/Module_ridljar.mk index daa0f1835be7..3d286c546151 100644 --- a/ridljar/Module_ridljar.mk +++ b/ridljar/Module_ridljar.mk @@ -10,8 +10,10 @@ $(eval $(call gb_Module_Module,ridljar)) ifneq ($(ENABLE_JAVA),) + $(eval $(call gb_Module_add_targets,ridljar,\ CustomTarget_javamaker \ + Jar_libreoffice \ Jar_ridl \ Jar_unoloader \ )) diff --git a/ridljar/com/sun/star/comp/helper/Bootstrap.java b/ridljar/com/sun/star/comp/helper/Bootstrap.java new file mode 100644 index 000000000000..edf21d7d2adf --- /dev/null +++ b/ridljar/com/sun/star/comp/helper/Bootstrap.java @@ -0,0 +1,429 @@ +// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.comp.helper; + +import com.sun.star.bridge.UnoUrlResolver; +import com.sun.star.bridge.XUnoUrlResolver; +import com.sun.star.comp.loader.JavaLoader; +import com.sun.star.comp.servicemanager.ServiceManager; +import com.sun.star.container.XSet; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lib.util.NativeLibraryLoader; +import com.sun.star.loader.XImplementationLoader; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Random; + +/** Bootstrap offers functionality to obtain a context or simply + a service manager. + The service manager can create a few basic services, whose implementations are: +

    +
  • com.sun.star.comp.loader.JavaLoader
  • +
  • com.sun.star.comp.urlresolver.UrlResolver
  • +
  • com.sun.star.comp.bridgefactory.BridgeFactory
  • +
  • com.sun.star.comp.connections.Connector
  • +
  • com.sun.star.comp.connections.Acceptor
  • +
  • com.sun.star.comp.servicemanager.ServiceManager
  • +
+ + Other services can be inserted into the service manager by + using its XSet interface: +
+        XSet xSet = UnoRuntime.queryInterface( XSet.class, aMultiComponentFactory );
+        // insert the service manager
+        xSet.insert( aSingleComponentFactory );
+    
+*/ +public class Bootstrap { + + private static void insertBasicFactories( + XSet xSet, XImplementationLoader xImpLoader ) + throws Exception + { + // insert the factory of the loader + xSet.insert( xImpLoader.activate( + "com.sun.star.comp.loader.JavaLoader", null, null, null ) ); + + // insert the factory of the URLResolver + xSet.insert( xImpLoader.activate( + "com.sun.star.comp.urlresolver.UrlResolver", null, null, null ) ); + + // insert the bridgefactory + xSet.insert( xImpLoader.activate( + "com.sun.star.comp.bridgefactory.BridgeFactory", null, null, null ) ); + + // insert the connector + xSet.insert( xImpLoader.activate( + "com.sun.star.comp.connections.Connector", null, null, null ) ); + + // insert the acceptor + xSet.insert( xImpLoader.activate( + "com.sun.star.comp.connections.Acceptor", null, null, null ) ); + } + + /** + * Returns an array of default commandline options to start bootstrapped + * instance of soffice with. You may use it in connection with bootstrap + * method for example like this: + *
+     *     List list = Arrays.asList( Bootstrap.getDefaultOptions() );
+     *     list.remove("--nologo");
+     *     list.remove("--nodefault");
+     *     list.add("--invisible");
+     *
+     *     Bootstrap.bootstrap( list.toArray( new String[list.size()] );
+     * 
+ * + * @return an array of default commandline options + * @see #bootstrap( String[] ) + * @since LibreOffice 5.1 + */ + public static final String[] getDefaultOptions() + { + return new String[] + { + "--nologo", + "--nodefault", + "--norestore", + "--nolockcheck" + }; + } + + /** + backwards compatibility stub. + @param context_entries the hash table contains mappings of entry names (type string) to + context entries (type class ComponentContextEntry). + @throws Exception if things go awry. + @return a new context. + */ + public static XComponentContext createInitialComponentContext( Hashtable context_entries ) + throws Exception + { + return createInitialComponentContext((Map) context_entries); + } + /** Bootstraps an initial component context with service manager and basic + jurt components inserted. + @param context_entries the hash table contains mappings of entry names (type string) to + context entries (type class ComponentContextEntry). + @throws Exception if things go awry. + @return a new context. + */ + public static XComponentContext createInitialComponentContext( Map context_entries ) + throws Exception + { + ServiceManager xSMgr = new ServiceManager(); + + XImplementationLoader xImpLoader = UnoRuntime.queryInterface( + XImplementationLoader.class, new JavaLoader() ); + XInitialization xInit = UnoRuntime.queryInterface( + XInitialization.class, xImpLoader ); + Object[] args = new Object [] { xSMgr }; + xInit.initialize( args ); + + // initial component context + if (context_entries == null) + context_entries = new HashMap( 1 ); + // add smgr + context_entries.put( + "/singletons/com.sun.star.lang.theServiceManager", + new ComponentContextEntry( null, xSMgr ) ); + // ... xxx todo: add standard entries + XComponentContext xContext = new ComponentContext( context_entries, null ); + + xSMgr.setDefaultContext(xContext); + + XSet xSet = UnoRuntime.queryInterface( XSet.class, xSMgr ); + // insert basic jurt factories + insertBasicFactories( xSet, xImpLoader ); + + return xContext; + } + + /** + * Bootstraps a servicemanager with the jurt base components registered. + * + * See also UNOIDL com.sun.star.lang.ServiceManager. + * + * @throws Exception if things go awry. + * @return a freshly bootstrapped service manager + */ + public static XMultiServiceFactory createSimpleServiceManager() throws Exception + { + return UnoRuntime.queryInterface( + XMultiServiceFactory.class, createInitialComponentContext( (Map) null ).getServiceManager() ); + } + + + /** Bootstraps the initial component context from a native UNO installation. + + @throws Exception if things go awry. + @return a freshly bootstrapped component context. + + See also + cppuhelper/defaultBootstrap_InitialComponentContext(). + */ + public static final XComponentContext defaultBootstrap_InitialComponentContext() + throws Exception + { + return defaultBootstrap_InitialComponentContext( (String) null, (Map) null ); + } + /** + * Backwards compatibility stub. + * + * @param ini_file + * ini_file (may be null: uno.rc besides cppuhelper lib) + * @param bootstrap_parameters + * bootstrap parameters (maybe null) + * + * @throws Exception if things go awry. + * @return a freshly bootstrapped component context. + */ + public static final XComponentContext defaultBootstrap_InitialComponentContext( + String ini_file, Hashtable bootstrap_parameters ) + throws Exception + { + return defaultBootstrap_InitialComponentContext(ini_file, (Map) bootstrap_parameters); + + } + /** Bootstraps the initial component context from a native UNO installation. + + See also + cppuhelper/defaultBootstrap_InitialComponentContext(). + + @param ini_file + ini_file (may be null: uno.rc besides cppuhelper lib) + @param bootstrap_parameters + bootstrap parameters (maybe null) + + @throws Exception if things go awry. + @return a freshly bootstrapped component context. + */ + public static final XComponentContext defaultBootstrap_InitialComponentContext( + String ini_file, Map bootstrap_parameters ) + throws Exception + { + // jni convenience: easier to iterate over array than calling Hashtable + String pairs [] = null; + if (null != bootstrap_parameters) + { + pairs = new String [ 2 * bootstrap_parameters.size() ]; + int n = 0; + for (Map.Entry bootstrap_parameter : bootstrap_parameters.entrySet()) { + pairs[ n++ ] = bootstrap_parameter.getKey(); + pairs[ n++ ] = bootstrap_parameter.getValue(); + } + } + + if (! m_loaded_juh) + { + if ("The Android Project".equals(System.getProperty("java.vendor"))) + { + // Find out if we are configured with DISABLE_DYNLOADING or + // not. Try to load the lo-bootstrap shared library which + // won't exist in the DISABLE_DYNLOADING case. (And which will + // be already loaded otherwise, so nothing unexpected happens + // that case.) Yeah, this would be simpler if I just could be + // bothered to keep a separate branch for DISABLE_DYNLOADING + // on Android, merging in master periodically, until I know + // for sure whether it is what I want, or not. + + boolean disable_dynloading = false; + try { + System.loadLibrary( "lo-bootstrap" ); + } catch ( UnsatisfiedLinkError e ) { + disable_dynloading = true; + } + + if (!disable_dynloading) + { + NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" ); + } + } + else + { + NativeLibraryLoader.loadLibrary( Bootstrap.class.getClassLoader(), "juh" ); + } + m_loaded_juh = true; + } + return UnoRuntime.queryInterface( + XComponentContext.class, + cppuhelper_bootstrap( + ini_file, pairs, Bootstrap.class.getClassLoader() ) ); + } + + private static boolean m_loaded_juh = false; + private static native Object cppuhelper_bootstrap( + String ini_file, String bootstrap_parameters [], ClassLoader loader ) + throws Exception; + + /** + * Bootstraps the component context from a UNO installation. + * + * @throws BootstrapException if things go awry. + * + * @return a bootstrapped component context. + * + * @since UDK 3.1.0 + */ + public static final XComponentContext bootstrap() + throws BootstrapException { + + String[] defaultArgArray = getDefaultOptions(); + return bootstrap( defaultArgArray ); + } + + /** + * Bootstraps the component context from a UNO installation. + * + * @param argArray + * an array of strings - commandline options to start instance of + * soffice with + * @see #getDefaultOptions() + * + * @throws BootstrapException if things go awry. + * + * @return a bootstrapped component context. + * + * @since LibreOffice 5.1 + */ + public static final XComponentContext bootstrap( String[] argArray ) + throws BootstrapException { + + XComponentContext xContext = null; + + try { + // create default local component context + XComponentContext xLocalContext = + createInitialComponentContext( (Map) null ); + if ( xLocalContext == null ) + throw new BootstrapException( "no local component context!" ); + + // find office executable relative to this class's class loader + String sOffice = + System.getProperty( "os.name" ).startsWith( "Windows" ) ? + "soffice.exe" : "soffice"; + File fOffice = NativeLibraryLoader.getResource( + Bootstrap.class.getClassLoader(), sOffice ); + if ( fOffice == null ) + throw new BootstrapException( "no office executable found!" ); + + // create random pipe name + String sPipeName = "uno" + + Long.toString(randomPipeName.nextLong() & 0x7fffffffffffffffL); + + // create call with arguments + String[] cmdArray = new String[ argArray.length + 2 ]; + cmdArray[0] = fOffice.getPath(); + cmdArray[1] = ( "--accept=pipe,name=" + sPipeName + ";urp;" ); + + System.arraycopy( argArray, 0, cmdArray, 2, argArray.length ); + + // start office process + Process p = Runtime.getRuntime().exec( cmdArray ); + pipe( p.getInputStream(), System.out, "CO> " ); + pipe( p.getErrorStream(), System.err, "CE> " ); + + // initial service manager + XMultiComponentFactory xLocalServiceManager = + xLocalContext.getServiceManager(); + if ( xLocalServiceManager == null ) + throw new BootstrapException( "no initial service manager!" ); + + // create a URL resolver + XUnoUrlResolver xUrlResolver = + UnoUrlResolver.create( xLocalContext ); + + // connection string + String sConnect = "uno:pipe,name=" + sPipeName + + ";urp;StarOffice.ComponentContext"; + + // wait until office is started + for (int i = 0;; ++i) { + try { + // try to connect to office + Object context = xUrlResolver.resolve( sConnect ); + xContext = UnoRuntime.queryInterface( + XComponentContext.class, context); + if ( xContext == null ) + throw new BootstrapException( "no component context!" ); + break; + } catch ( com.sun.star.connection.NoConnectException ex ) { + // Wait 500 ms, then try to connect again, but do not wait + // longer than 5 min (= 600 * 500 ms) total: + if (i == 600) { + throw new BootstrapException(ex); + } + Thread.sleep( 500 ); + } + } + } catch ( BootstrapException e ) { + throw e; + } catch ( java.lang.RuntimeException e ) { + throw e; + } catch ( java.lang.Exception e ) { + throw new BootstrapException( e ); + } + + return xContext; + } + + private static final Random randomPipeName = new Random(); + + private static void pipe( + final InputStream in, final PrintStream out, final String prefix ) { + + new Thread( "Pipe: " + prefix) { + @Override + public void run() { + try { + BufferedReader r = new BufferedReader( + new InputStreamReader(in, "UTF-8") ); + + for ( ; ; ) { + String s = r.readLine(); + if ( s == null ) { + break; + } + out.println( prefix + s ); + } + } catch ( UnsupportedEncodingException e ) { + e.printStackTrace( System.err ); + } catch ( java.io.IOException e ) { + e.printStackTrace( System.err ); + } + } + }.start(); + } +} + +// vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/ridljar/com/sun/star/comp/helper/BootstrapException.java b/ridljar/com/sun/star/comp/helper/BootstrapException.java new file mode 100644 index 000000000000..11911bbc07e0 --- /dev/null +++ b/ridljar/com/sun/star/comp/helper/BootstrapException.java @@ -0,0 +1,82 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.comp.helper; + +/** + * BootstrapException is a checked exception that wraps an exception + * thrown by the original target. + * + * @since UDK 3.1.0 + */ +public class BootstrapException extends java.lang.Exception { + + /** + * This field holds the target exception. + */ + private Exception m_target = null; + + /** + * Constructs a BootstrapException with null as + * the target exception. + */ + public BootstrapException() { + super(); + } + + /** + * Constructs a BootstrapException with the specified + * detail message. + * + * @param message the detail message + */ + public BootstrapException( String message ) { + super( message ); + } + + /** + * Constructs a BootstrapException with the specified + * detail message and a target exception. + * + * @param message the detail message + * @param target the target exception + */ + public BootstrapException( String message, Exception target ) { + super( message ); + m_target = target; + } + + /** + * Constructs a BootstrapException with a target exception. + * + * @param target the target exception + */ + public BootstrapException( Exception target ) { + super(); + m_target = target; + } + + /** + * Get the thrown target exception. + * + * @return the target exception + */ + public Exception getTargetException() { + return m_target; + } +} diff --git a/ridljar/com/sun/star/comp/helper/ComponentContext.java b/ridljar/com/sun/star/comp/helper/ComponentContext.java new file mode 100644 index 000000000000..34649d563395 --- /dev/null +++ b/ridljar/com/sun/star/comp/helper/ComponentContext.java @@ -0,0 +1,308 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.comp.helper; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.Any; + +import com.sun.star.uno.DeploymentException; +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XEventListener; +import com.sun.star.lang.EventObject; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Map; + + + +class Disposer implements XEventListener +{ + private final XComponent m_xComp; + + + Disposer( XComponent xComp ) + { + m_xComp = xComp; + } + + public void disposing( EventObject Source ) + { + m_xComp.dispose(); + } +} + +/** Component context implementation. +*/ +public class ComponentContext implements XComponentContext, XComponent +{ + private static final boolean DEBUG = false; + private static final String SMGR_NAME = "/singletons/com.sun.star.lang.theServiceManager"; + private static final String TDMGR_NAME = "/singletons/com.sun.star.reflection.theTypeDescriptionManager"; + + private Map m_table; + private XComponentContext m_xDelegate; + + private XMultiComponentFactory m_xSMgr; + private boolean m_bDisposeSMgr; + + private ArrayList m_eventListener; + + public ComponentContext( Hashtable table, XComponentContext xDelegate ) + { + this((Map) table, xDelegate); + } + + /** Ctor to create a component context passing a hashtable for values and a delegator + reference. Entries of the passed hashtable are either direct values or + ComponentContextEntry objects. + + @param table + entries + @param xDelegate + if values are not found, request is delegated to this object + */ + public ComponentContext( Map table, XComponentContext xDelegate ) + { + m_eventListener = new ArrayList(); + m_table = table; + m_xDelegate = xDelegate; + m_xSMgr = null; + m_bDisposeSMgr = false; + + Object o = table.get( SMGR_NAME ); + if (o != null) + { + if (o instanceof ComponentContextEntry) + { + o = ((ComponentContextEntry)o).m_value; + } + m_xSMgr = UnoRuntime.queryInterface( + XMultiComponentFactory.class, o ); + } + if (m_xSMgr != null) + { + m_bDisposeSMgr = true; + } + else if (m_xDelegate != null) + { + m_xSMgr = m_xDelegate.getServiceManager(); + } + + // listen for delegate + XComponent xComp = UnoRuntime.queryInterface( + XComponent.class, m_xDelegate ); + if (xComp != null) + { + xComp.addEventListener( new Disposer( this ) ); + } + } + + // XComponentContext impl + + public Object getValueByName( String rName ) + { + Object o = m_table.get( rName ); + if (o == null) + { + if (m_xDelegate != null) + { + return m_xDelegate.getValueByName( rName ); + } + else + { + return Any.VOID; + } + } + + if (!(o instanceof ComponentContextEntry)) + { + // direct value in map + return o; + } + + ComponentContextEntry entry = (ComponentContextEntry)o; + if (entry.m_lateInit == null) + { + return entry.m_value; + } + + Object xInstance = null; + try + { + String serviceName = (String)entry.m_lateInit; + if (serviceName != null) + { + if (m_xSMgr != null) + { + xInstance = m_xSMgr.createInstanceWithContext( serviceName, this ); + } + else + { + if (DEBUG) + System.err.println( "### no service manager instance for late init of singleton instance \"" + rName + "\"!" ); + } + } + else + { + XSingleComponentFactory xCompFac = UnoRuntime.queryInterface( XSingleComponentFactory.class, entry.m_lateInit ); + if (xCompFac != null) + { + xInstance = xCompFac.createInstanceWithContext( this ); + } + else + { + if (DEBUG) + System.err.println( "### neither service name nor service factory given for late init of singleton instance \"" + rName + "\"!" ); + } + } + } + catch (com.sun.star.uno.Exception exc) + { + if (DEBUG) + System.err.println( "### exception occurred on late init of singleton instance \"" + rName + "\": " + exc.getMessage() ); + } + + if (xInstance != null) + { + synchronized (entry) + { + if (entry.m_lateInit != null) + { + entry.m_value = xInstance; + entry.m_lateInit = null; + } + else // inited in the meantime + { + // dispose fresh service instance + XComponent xComp = UnoRuntime.queryInterface( + XComponent.class, xInstance ); + if (xComp != null) + { + xComp.dispose(); + } + } + } + } + else + { + if (DEBUG) + System.err.println( "### failed late init of singleton instance \"" + rName + "\"!" ); + } + return entry.m_value; + } + + public XMultiComponentFactory getServiceManager() + { + if (m_xSMgr == null) + { + throw new DeploymentException( + "null component context service manager" ); + } + return m_xSMgr; + } + + // XComponent impl + + public void dispose() + { + if (DEBUG) + System.err.print( "> disposing context " + this ); + + // fire events + EventObject evt = new EventObject( this ); + for (XEventListener listener : m_eventListener) + { + listener.disposing( evt ); + } + m_eventListener.clear(); + + XComponent tdmgr = null; + // dispose values, then service manager, then typedescription manager + for (Map.Entry entry : m_table.entrySet()) + { + String name = entry.getKey(); + if (! name.equals( SMGR_NAME )) + { + Object o = entry.getValue(); + if (o instanceof ComponentContextEntry) + { + o = ((ComponentContextEntry)o).m_value; + } + + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, o ); + if (xComp != null) + { + if (name.equals( TDMGR_NAME )) + { + tdmgr = xComp; + } + else + { + xComp.dispose(); + } + } + } + } + m_table.clear(); + + // smgr + if (m_bDisposeSMgr) + { + XComponent xComp = UnoRuntime.queryInterface( + XComponent.class, m_xSMgr ); + if (xComp != null) + { + xComp.dispose(); + } + } + m_xSMgr = null; + + // tdmgr + if (tdmgr != null) + { + tdmgr.dispose(); + } + + if (DEBUG) + System.err.println( "... finished" ); + } + + public void addEventListener( XEventListener xListener ) + { + if (xListener == null) + throw new com.sun.star.uno.RuntimeException( "Listener must not be null" ); + if (m_eventListener.contains( xListener )) + throw new com.sun.star.uno.RuntimeException( "Listener already registered." ); + + m_eventListener.add( xListener ); + } + + public void removeEventListener( XEventListener xListener ) + { + if (xListener == null) + throw new com.sun.star.uno.RuntimeException( "Listener must not be null" ); + if (! m_eventListener.contains( xListener )) + throw new com.sun.star.uno.RuntimeException( "Listener is not registered." ); + + m_eventListener.remove( xListener ); + } +} diff --git a/ridljar/com/sun/star/comp/helper/ComponentContextEntry.java b/ridljar/com/sun/star/comp/helper/ComponentContextEntry.java new file mode 100644 index 000000000000..aa402d29c6d1 --- /dev/null +++ b/ridljar/com/sun/star/comp/helper/ComponentContextEntry.java @@ -0,0 +1,64 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.comp.helper; + +/** Component context entry for constructing ComponentContext objects. +

+ A ComponentContextEntry is separated into a late-init and direct-value + purpose. + The first one is commonly used for singleton objects of the component + context, that are raised on first-time retrieval of the key. + You have to pass a com.sun.star.lang.XSingleComponentFactory + or string (=> service name) object for this. +

+*/ +public class ComponentContextEntry +{ + /** if late init of service instance, set service name (String) or + component factory (XSingleComponentFactory), null otherwise + */ + public Object m_lateInit; + /** set entry value + */ + public Object m_value; + + /** Creating a late-init singleton entry component context entry. + The second parameter will be ignored and overwritten during + instantiation of the singleton instance. + + @param lateInit + object factory or service string + @param value + pass null (dummy separating from second constructor signature) + */ + public ComponentContextEntry( Object lateInit, Object value ) + { + this.m_lateInit = lateInit; + this.m_value = value; + } + /** Creating a direct value component context entry. + + @param value + pass null + */ + public ComponentContextEntry( Object value ) + { + this.m_lateInit = null; + this.m_value = value; + } +} diff --git a/ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java b/ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java new file mode 100644 index 000000000000..035644efa0b8 --- /dev/null +++ b/ridljar/com/sun/star/comp/helper/SharedLibraryLoader.java @@ -0,0 +1,175 @@ +// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.comp.helper; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.registry.XRegistryKey; + +/** + * @deprecated use class Bootstrap bootstrapping a native UNO installation + * and use the shared library loader service. + * + * The SharedLibraryLoader class provides the functionality of the com.sun.star.loader.SharedLibrary + * service. + * + * See also UNOIDL com.sun.star.lang.ServiceManager. + * + * @see com.sun.star.loader.SharedLibrary + */ +@Deprecated +public class SharedLibraryLoader { + /** + * The default library which contains the SharedLibraryLoader component + */ + public static final String DEFAULT_LIBRARY = "shlibloader.uno"; + + /** + * The default implementation name + */ + public static final String DEFAULT_IMPLEMENTATION = "com.sun.star.comp.stoc.DLLComponentLoader"; + + static { + if ("The Android Project".equals(System.getProperty("java.vendor"))) { + // See corresponding code in + // javaunohelper/com/sun/star/comp/helper/Bootstrap.java for more + // comments. + + boolean disable_dynloading = false; + try { + System.loadLibrary("lo-bootstrap"); + } catch (UnsatisfiedLinkError e) { + disable_dynloading = true; + } + + if (!disable_dynloading) + System.loadLibrary("juh"); + } else + System.loadLibrary("juh"); + } + + private static native boolean component_writeInfo( + String libName, XMultiServiceFactory smgr, XRegistryKey regKey, + ClassLoader loader ); + + private static native Object component_getFactory( + String libName, String implName, XMultiServiceFactory smgr, + XRegistryKey regKey, ClassLoader loader ); + + /** + * Supplies the ServiceFactory of the default SharedLibraryLoader. + * The defaults are "shlibloader.uno" + * for the library and "com.sun.star.comp.stoc.DLLComponentLoader" + * for the component name. + * + * See also UNOIDL com.sun.star.lang.ServiceManager and + * com.sun.star.registry.RegistryKey. + * + * @return the factory for the "com.sun.star.comp.stoc.DLLComponentLoader" component. + * @param smgr the ServiceManager + * @param regKey the root registry key + * @see com.sun.star.loader.SharedLibrary + */ + public static XSingleServiceFactory getServiceFactory( + XMultiServiceFactory smgr, + XRegistryKey regKey ) + { + return UnoRuntime.queryInterface( + XSingleServiceFactory.class, + component_getFactory( + DEFAULT_LIBRARY, DEFAULT_IMPLEMENTATION, smgr, regKey, + SharedLibraryLoader.class.getClassLoader() ) ); + } + + /** + * Loads and returns a specific factory for a given library and implementation name. + * + * See also UNOIDL com.sun.star.lang.ServiceManager and + * com.sun.star.registry.RegistryKey. + * + * @return the factory of the component + * @param libName the name of the shared library + * @param impName the implementation name of the component + * @param smgr the ServiceManager + * @param regKey the root registry key + * @see com.sun.star.loader.SharedLibrary + */ + public static XSingleServiceFactory getServiceFactory( + String libName, + String impName, + XMultiServiceFactory smgr, + XRegistryKey regKey ) + { + return UnoRuntime.queryInterface( + XSingleServiceFactory.class, + component_getFactory( + libName, impName, smgr, regKey, + SharedLibraryLoader.class.getClassLoader() ) ); + } + + /** + * Registers the SharedLibraryLoader under a RegistryKey. + * + * See also UNOIDL com.sun.star.lang.ServiceManager and + * com.sun.star.registry.RegistryKey. + * + * @return true if the registration was successful - otherwise false + * @param smgr the ServiceManager + * @param regKey the root key under that the component should be registered + * @see com.sun.star.loader.SharedLibrary + */ + public static boolean writeRegistryServiceInfo( + com.sun.star.lang.XMultiServiceFactory smgr, + com.sun.star.registry.XRegistryKey regKey ) + { + return component_writeInfo( + DEFAULT_LIBRARY, smgr, regKey, + SharedLibraryLoader.class.getClassLoader() ); + } + + /** + * Registers the SharedLibraryLoader under a RegistryKey. + * + * See also UNOIDL com.sun.star.lang.ServiceManager and + * com.sun.star.registry.RegistryKey. + * + * @return true if the registration was successful - otherwise false + * @param libName name of the shared library + * @param smgr the ServiceManager + * @param regKey the root key under that the component should be registered + * @throws com.sun.star.registry.InvalidRegistryException + * if the registry is not valid. + * + * @see com.sun.star.loader.SharedLibrary + */ + public static boolean writeRegistryServiceInfo( + String libName, + com.sun.star.lang.XMultiServiceFactory smgr, + com.sun.star.registry.XRegistryKey regKey ) + + throws com.sun.star.registry.InvalidRegistryException, + com.sun.star.uno.RuntimeException + { + return component_writeInfo( + libName, smgr, regKey, SharedLibraryLoader.class.getClassLoader() ); + } +} + +// vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java new file mode 100644 index 000000000000..2d3e9a8480b7 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java @@ -0,0 +1,117 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.lib.uno.adapter; + +import com.sun.star.io.XInputStream; +import com.sun.star.io.XSeekable; +import com.sun.star.lib.uno.helper.ComponentBase; + +public final class ByteArrayToXInputStreamAdapter + extends ComponentBase + implements XInputStream, XSeekable +{ + + byte[] m_bytes; + int m_length; + int m_pos; + + boolean m_open; + + /** Creates a new instance of ByteArrayXInputStram */ + public ByteArrayToXInputStreamAdapter(byte[] bytes) { + init(bytes); + } + + public void init(byte[] bytes) { + m_bytes = bytes; + m_length = bytes.length; + m_pos = 0; + m_open = true; + } + + private void _check() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { + if (m_bytes == null) { + throw new com.sun.star.io.NotConnectedException("no bytes"); + } + if(!m_open) { + throw new com.sun.star.io.IOException("input closed"); + } + } + + public int available() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { + _check(); + long a = m_length - m_pos; + if (a != (int)a) + throw new com.sun.star.io.IOException("integer overflow"); + else { + return (int)a; + } + } + + public void closeInput() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException { + _check(); + m_open = false; + } + + public int readBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { + _check(); + try { + int remain = (m_length - m_pos); + if (param > remain) param = remain; + /* ARGH!!! */ + if (values[0] == null){ + values[0] = new byte[param]; + } + System.arraycopy(m_bytes, m_pos, values[0], 0, param); + m_pos += param; + return param; + } catch (ArrayIndexOutOfBoundsException ex) { + throw new com.sun.star.io.BufferSizeExceededException(ex, "buffer overflow"); + } catch (Exception ex) { + throw new com.sun.star.io.IOException(ex, "error accessing buffer"); + } + } + + public int readSomeBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { + return readBytes(values, param); + } + + public void skipBytes(int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException { + _check(); + if (param > (m_length - m_pos)) + throw new com.sun.star.io.BufferSizeExceededException("buffer overflow"); + m_pos += param; + } + + public long getLength() throws com.sun.star.io.IOException { + if (m_bytes != null) return m_length; + else throw new com.sun.star.io.IOException("no bytes"); + } + + public long getPosition() throws com.sun.star.io.IOException { + if (m_bytes != null) return m_pos; + else throw new com.sun.star.io.IOException("no bytes"); + } + + public void seek(long param) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException { + if (m_bytes != null){ + if (param < 0 || param > m_length) throw new com.sun.star.lang.IllegalArgumentException("invalid seek position"); + else m_pos = (int)param; + }else throw new com.sun.star.io.IOException("no bytes"); + } +} diff --git a/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java new file mode 100644 index 000000000000..3d60e5a1181a --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/adapter/InputStreamToXInputStreamAdapter.java @@ -0,0 +1,145 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.lib.uno.adapter; + +import java.io.IOException; + +import com.sun.star.io.XInputStream; + +import java.io.InputStream; + +/** The InputStreamToInputXStreamAdapter wraps the + Java InputStream object into a + UNO XInputStream object. + This allows users to access an InputStream + as if it were an XInputStream. + */ +public final class InputStreamToXInputStreamAdapter implements XInputStream { + + /** + * Internal store to the InputStream + */ + private final InputStream iIn; + + /** + * Constructor. + * + * @param in The XInputStream to be + * accessed as an InputStream. + */ + public InputStreamToXInputStreamAdapter (InputStream in) + { + iIn = in; + } + + public int available() throws + com.sun.star.io.IOException + { + + int bytesAvail; + + try { + bytesAvail = iIn.available(); + } catch (IOException e) { + throw new com.sun.star.io.IOException(e); + } + + return bytesAvail; + } + + public void closeInput() throws + com.sun.star.io.IOException + { + try { + iIn.close(); + } catch (IOException e) { + throw new com.sun.star.io.IOException(e); + } + } + + public int readBytes(byte[][] b, int len) throws + com.sun.star.io.IOException + { + try { + long bytesRead; + if (len >iIn.available()) { + bytesRead = iIn.read(b[0], 0, iIn.available()); + } + else{ + bytesRead = iIn.read(b[0], 0, len); + } + // Casting bytesRead to an int is okay, since the user can + // only pass in an integer length to read, so the bytesRead + // must <= len. + + if (bytesRead <= 0) { + return 0; + } + return ((int)bytesRead); + + + } catch (IOException e) { + throw new com.sun.star.io.IOException("reader error", e); + } + } + + public int readSomeBytes(byte[][] b, int len) throws + com.sun.star.io.IOException + { + try { + long bytesRead; + if (len >iIn.available()) { + bytesRead = iIn.read(b[0], 0, iIn.available()); + } + else{ + bytesRead = iIn.read(b[0], 0, len); + } + // Casting bytesRead to an int is okay, since the user can + // only pass in an integer length to read, so the bytesRead + // must <= len. + + if (bytesRead <= 0) { + return 0; + } + return ((int)bytesRead); + + + } catch (IOException e) { + throw new com.sun.star.io.IOException("reader error", e); + } + } + + public void skipBytes(int n) throws + com.sun.star.io.IOException + { + try { + iIn.available(); + } catch (IOException e) { + throw new com.sun.star.io.IOException(e); + } + + do { + try { + n -= iIn.skip(n); + } catch (IOException e) { + throw new com.sun.star.io.IOException(e); + } + } while (n > 0); + } +} + diff --git a/ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java new file mode 100644 index 000000000000..2842e3df05ce --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/adapter/OutputStreamToXOutputStreamAdapter.java @@ -0,0 +1,80 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.adapter; + +import java.io.IOException; + +import com.sun.star.io.XOutputStream; + +import java.io.OutputStream; + +/** The OutputStreamToXOutputStreamAdapter wraps + a UNO XOutputStream into a Java OutputStream + object in a Java. This allows users to access an OutputStream + as if it were an XOutputStream. + */ +public final class OutputStreamToXOutputStreamAdapter implements XOutputStream { + + /** + * Internal handle to the OutputStream + */ + OutputStream iOut; + + /** + * Constructor. + * + * @param out The XOutputStream to be + * accessed as an OutputStream. + */ + public OutputStreamToXOutputStreamAdapter(OutputStream out) { + iOut = out; + } + + public void closeOutput() throws + com.sun.star.io.IOException + { + try { + iOut.close(); + } catch (IOException e) { + throw new com.sun.star.io.IOException(e); + } + } + + public void flush() throws + com.sun.star.io.IOException + { + try { + iOut.flush(); + } catch (IOException e) { + throw new com.sun.star.io.IOException(e); + } + } + + public void writeBytes(byte[] b) throws + com.sun.star.io.IOException + { + + try { + iOut.write(b); + } catch (IOException e) { + throw new com.sun.star.io.IOException(e); + } + } + +} diff --git a/ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java new file mode 100644 index 000000000000..25f1798fbada --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/adapter/XInputStreamToInputStreamAdapter.java @@ -0,0 +1,218 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.lib.uno.adapter; + +import java.io.IOException; + +import com.sun.star.io.XInputStream; + +import java.io.InputStream; + +/** + * The XInputStreamToInputStreamAdapter wraps + * the UNO XInputStream object in a Java + * InputStream. This allows users to access + * an XInputStream as if it were an + * InputStream. + */ +public final class XInputStreamToInputStreamAdapter extends InputStream { + + /** + * Internal handle to the XInputStream + */ + private final XInputStream xin; + + /** + * Constructor. + * + * @param in The XInputStream to be + * accessed as an InputStream. + */ + public XInputStreamToInputStreamAdapter (XInputStream in) { + xin = in; + } + + @Override + public int available() throws IOException { + + int bytesAvail; + + try { + bytesAvail = xin.available(); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + + return bytesAvail; + } + + @Override + public void close() throws IOException { + try { + xin.closeInput(); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } + + @Override + public int read () throws IOException { + byte [][] tmp = new byte [1][1]; + try { + long bytesRead = xin.readBytes(tmp, 1); + + if (bytesRead <= 0) { + return (-1); + } else { + int tmpInt = tmp[0][0]; + if (tmpInt< 0 ){ + tmpInt = 256 +tmpInt; + } + return tmpInt; + } + + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } + + @Override + public int read (byte[] b) throws IOException { + + byte [][] tmp = new byte [1][b.length]; + int bytesRead; + + try { + bytesRead = xin.readBytes(tmp, b.length); + if (bytesRead <= 0) { + return -1; + } else if (bytesRead < b.length) { + System.arraycopy(tmp[0], 0, b, 0, bytesRead); + } else { + System.arraycopy(tmp[0], 0, b, 0, b.length); + } + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + + return bytesRead; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + byte [][] tmp = new byte [1][b.length]; + try { + long bytesRead; + int av = xin.available(); + if ( av != 0 && len > av) { + bytesRead = xin.readBytes(tmp, av); + } + else{ + bytesRead = xin.readBytes(tmp,len); + } + // Casting bytesRead to an int is okay, since the user can + // only pass in an integer length to read, so the bytesRead + // must <= len. + + if (bytesRead <= 0) { + return -1; + } else if (bytesRead < len) { + System.arraycopy(tmp[0], 0, b, off, (int)bytesRead); + } else { + System.arraycopy(tmp[0], 0, b, off, len); + } + + return ((int)bytesRead); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } + + @Override + public long skip(long n) throws IOException { + + int avail; + long tmpLongVal = n; + int tmpIntVal; + + try { + avail = xin.available(); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + + do { + if (tmpLongVal >= Integer.MAX_VALUE) { + tmpIntVal = Integer.MAX_VALUE; + } else { + // Casting is safe here. + tmpIntVal = (int)tmpLongVal; + } + tmpLongVal -= tmpIntVal; + + try { + xin.skipBytes(tmpIntVal); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } while (tmpLongVal > 0); + + if ( avail != 0 && avail < n) { + return avail; + } else { + return n; + } + } + + /** + * Tests if this input stream supports the mark and reset methods. + * The markSupported method of + * XInputStreamToInputStreamAdapter returns false. + * + * @return false + */ + @Override + public boolean markSupported() { + return false; + } + + @Override + public synchronized void mark(int readlimit) { + // Not supported. + } + + @Override + public synchronized void reset() throws IOException { + // Not supported. + } +} + diff --git a/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java new file mode 100644 index 000000000000..48871277a75f --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java @@ -0,0 +1,94 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.lib.uno.adapter; + +import com.sun.star.io.*; +import com.sun.star.lib.uno.helper.ComponentBase; + +public final class XOutputStreamToByteArrayAdapter + extends ComponentBase + implements XOutputStream +{ + private static final int initialSize = 100240; // 10 kb + private int size = 0; + private int position = 0; + private boolean externalBuffer = false; + private byte[] buffer; + + /** Creates a new instance of ByteArrayXOutputStream */ + public XOutputStreamToByteArrayAdapter() { + this(null); + } + + public XOutputStreamToByteArrayAdapter(byte[] aBuffer) { + if (aBuffer != null) { + externalBuffer = true; + buffer = aBuffer; + size = buffer.length; + } else { + size = initialSize; + buffer = new byte[size]; + } + } + + public byte[] getBuffer() { + return buffer; + } + + public void closeOutput() + throws com.sun.star.io.NotConnectedException, + com.sun.star.io.BufferSizeExceededException, + com.sun.star.io.IOException + { + // trim buffer + if ( buffer.length > position && !externalBuffer ) + { + byte[] newBuffer = new byte[position]; + System.arraycopy(buffer, 0, newBuffer, 0, position); + buffer = newBuffer; + } + } + + public void flush() + throws com.sun.star.io.NotConnectedException, + com.sun.star.io.BufferSizeExceededException, + com.sun.star.io.IOException + { + } + + public void writeBytes(byte[] values) + throws com.sun.star.io.NotConnectedException, + com.sun.star.io.BufferSizeExceededException, + com.sun.star.io.IOException + { + if ( values.length > size-position ) + { + if ( externalBuffer ) + throw new BufferSizeExceededException("out of buffer space, cannot grow external buffer"); + while ( values.length > size-position ) { + size *= 2; + } + byte[] newBuffer = new byte[size]; + System.arraycopy(buffer, 0, newBuffer, 0, position); + buffer = newBuffer; + } + System.arraycopy(values, 0, buffer, position, values.length); + position += values.length; + } + +} diff --git a/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java new file mode 100644 index 000000000000..8104cf42fa3c --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/adapter/XOutputStreamToOutputStreamAdapter.java @@ -0,0 +1,117 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.adapter; + +import java.io.IOException; + +import com.sun.star.io.XOutputStream; + +import java.io.OutputStream; + +/** + * The XOutputStreamToOutputStreamAdapter wraps + * the UNO XOutputStream object in a Java + * OutputStream. This allows users to access + * an XOutputStream as if it were an + * OutputStream. + */ +public final class XOutputStreamToOutputStreamAdapter extends OutputStream { + + /** + * Internal handle to the XInputStream + */ + XOutputStream xout; + + /** + * Constructor. + * + * @param out The XOutputStream to be + * accessed as an OutputStream. + */ + public XOutputStreamToOutputStreamAdapter(XOutputStream out) { + xout = out; + } + + @Override + public void close() throws IOException { + try { + xout.closeOutput(); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } + + @Override + public void flush() throws IOException { + try { + xout.flush(); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } + + @Override + public void write(byte[] b) throws IOException { + + try { + xout.writeBytes(b); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + + byte[] tmp = new byte[len]; + + // Copy the input array into a temp array, and write it out. + + System.arraycopy(b, off, tmp, 0, len); + + try { + xout.writeBytes(tmp); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } + + @Override + public void write(int b) throws IOException { + + byte [] oneByte = new byte [1]; + oneByte[0] = (byte) b; + + try { + xout.writeBytes(oneByte); + } catch (Exception e) { + IOException newEx = new IOException(e.getMessage()); + newEx.initCause(e); + throw newEx; + } + } +} diff --git a/ridljar/com/sun/star/lib/uno/helper/ComponentBase.java b/ridljar/com/sun/star/lib/uno/helper/ComponentBase.java new file mode 100644 index 000000000000..d886ef7020d5 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/ComponentBase.java @@ -0,0 +1,136 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.helper; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XEventListener; +import com.sun.star.lang.EventObject; +import com.sun.star.uno.Type; + +/** This class can be used as the base class for UNO components. In addition to the functionality ,which + * is inherited from WeakBase, it implements com.sun.star.lang.XComponent. + */ +public class ComponentBase extends WeakBase implements XComponent +{ + private static final boolean DEBUG= false; + protected MultiTypeInterfaceContainer listenerContainer; + protected boolean bInDispose= false; + protected boolean bDisposed= false; + static final Type EVT_LISTENER_TYPE= new Type(XEventListener.class); + + + /** Creates a new instance of CompBase */ + public ComponentBase() + { + super(); + listenerContainer= new MultiTypeInterfaceContainer(); + } + + /** Override to perform extra clean-up work. Provided for subclasses. It is + called during dispose() + */ + protected void preDisposing() + { + } + /** Override to become notified right before the disposing action is performed. + */ + protected void postDisposing() + { + } + + + /** Method of XComponent. It is called by the owning client when the component is not needed + * anymore. The registered listeners are notified that this method has been called. + */ + public void dispose() + { + // Determine in a thread-safe way if this is the first call to this method. + // Only then we proceed with the notification of event listeners. + // It is an error to call this method more than once. + boolean bDoDispose= false; + synchronized (this) + { + if ( ! bInDispose && ! bDisposed) + { + bDoDispose= true; + bInDispose= true; + } + } + // The notification occurs in an unsynchronized block in order to avoid + // deadlocks if one of the listeners calls back in a different thread on + // a synchronized method which uses the same object. + if (bDoDispose) + { + try + { + preDisposing(); + listenerContainer.disposeAndClear(new EventObject(this)); + //notify subclasses that disposing is in progress + postDisposing(); + } + finally + { + // finally makes sure that the flags are set even if a RuntimeException is thrown. + // That ensures that this function is only called once. + synchronized (this) + { + bDisposed= true; + bInDispose= false; + } + } + } + else + { + // in a multithreaded environment, it can't be avoided, that dispose is called twice. + // However this condition is traced, because it MAY indicate an error. + if (DEBUG) + System.out.println("OComponentHelper::dispose() - dispose called twice" ); + } + } + + /** Method of XComponent. + */ + public void removeEventListener(XEventListener xEventListener) + { + listenerContainer.removeInterface( EVT_LISTENER_TYPE, xEventListener); + } + + public void addEventListener(XEventListener listener) + { + boolean bDoDispose= false; + synchronized (this) + { + if (bDisposed || bInDispose) + bDoDispose= true; + else + listenerContainer.addInterface(EVT_LISTENER_TYPE, listener); + } + if (bDoDispose ) + { + listener.disposing( new EventObject(this)); + } + } + + @Override + protected void finalize() throws Throwable + { + if ( ! bInDispose && ! bDisposed) + dispose(); + super.finalize(); + } +} diff --git a/ridljar/com/sun/star/lib/uno/helper/Factory.java b/ridljar/com/sun/star/lib/uno/helper/Factory.java new file mode 100644 index 000000000000..056d9549d552 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/Factory.java @@ -0,0 +1,291 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.lib.uno.helper; + +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.XInitialization; +import com.sun.star.registry.XRegistryKey; +import com.sun.star.uno.UnoRuntime; + + +/** Factory helper class supporting com.sun.star.lang.XServiceInfo and + com.sun.star.lang.XSingleComponentFactory. + +

+ Note: This factory implementation does not support lang.XSingleServiceFactory. +

+*/ +public class Factory + extends ComponentBase + implements XSingleComponentFactory, XServiceInfo +{ + private static final boolean DEBUG = false; + + /** Creates an object factory supporting interfaces + com.sun.star.lang.XSingleComponentFactory and + com.sun.star.lang.XServiceInfo + + @param impl_class + implementation class + @param impl_name + implementation name + @param supported_services + services implemented + @return + object factory + + @since UDK 3.2.13 + */ + public static XSingleComponentFactory createComponentFactory( + Class impl_class, String impl_name, String supported_services [] ) + throws com.sun.star.uno.RuntimeException + { + return new Factory( impl_class, impl_name, supported_services ); + } + + /** Creates an object factory supporting interfaces + com.sun.star.lang.XSingleComponentFactory and + com.sun.star.lang.XServiceInfo + + The implementation name is the name of the implementation class. + + @param impl_class + implementation class + @param supported_services + services implemented + @return + object factory + */ + public static XSingleComponentFactory createComponentFactory( + Class impl_class, String supported_services [] ) + throws com.sun.star.uno.RuntimeException + { + return createComponentFactory( + impl_class, impl_class.getName(), supported_services ); + } + /** Writes component's implementation info to given registry key. + + @param impl_name + name of implementation + @param supported_services + supported services of implementation + @param xKey + registry key to write to + @return + success + */ + public static boolean writeRegistryServiceInfo( + String impl_name, String supported_services [], XRegistryKey xKey ) + { + try + { + XRegistryKey xNewKey = xKey.createKey( "/" + impl_name + "/UNO/SERVICES" ); + for ( int nPos = 0; nPos < supported_services.length; ++nPos ) + { + xNewKey.createKey( supported_services[ nPos ] ); + } + return true; + } + catch (com.sun.star.registry.InvalidRegistryException exc) + { + if (DEBUG) + { + System.err.println( + "##### " + Factory.class.getName() + ".writeRegistryServiceInfo -- exc: " + + exc.toString() ); + } + } + return false; + } + + + private final String m_impl_name; + private final String [] m_supported_services; + private final Class m_impl_class; + private final java.lang.reflect.Method m_method; + private final java.lang.reflect.Constructor m_ctor; + + private Factory( + Class impl_class, String impl_name, String supported_services [] ) + throws com.sun.star.uno.DeploymentException + { + m_impl_name = impl_name; + m_supported_services = supported_services; + m_impl_class = impl_class; + + Class params [] = new Class [] { XComponentContext.class }; + + if (!java.lang.reflect.Modifier.isPublic( impl_class.getModifiers() )) + { + throw new com.sun.star.uno.DeploymentException("class " + impl_class + " is not public"); + } + + java.lang.reflect.Method tmpMethod = null; + try + { + // seeking for "public static Object __create( XComponentContext )" + tmpMethod = m_impl_class.getMethod( "__create", params ); + int mod = tmpMethod.getModifiers(); + if (!tmpMethod.getReturnType().equals( Object.class ) || + !java.lang.reflect.Modifier.isStatic( mod ) || + !java.lang.reflect.Modifier.isPublic( mod )) + { + tmpMethod = null; + } + } + catch (Exception exc) + { + } + m_method = tmpMethod; + + + java.lang.reflect.Constructor tmpCtor = null; + if (null == m_method) + { + try + { + // ctor with context + tmpCtor = m_impl_class.getConstructor( params ); + } + catch (Exception exc) + { + } + if (tmpCtor != null) + { + if (!java.lang.reflect.Modifier.isPublic( tmpCtor.getModifiers() )) + { + throw new com.sun.star.uno.DeploymentException("constructor with XComponentContext param for class " + impl_class + " is not public"); + } + } + else + { + // else take default ctor + java.lang.reflect.Constructor defaultCtor; + try + { + defaultCtor = m_impl_class.getConstructor(new Class[0]); + } + catch (Exception exc2) + { + throw new com.sun.star.uno.DeploymentException(exc2, "class " + impl_class + " has no means of creating it, cannot find a __create method or a useful constructor."); + } + if (!java.lang.reflect.Modifier.isPublic( defaultCtor.getModifiers() )) + { + throw new com.sun.star.uno.DeploymentException("default constructor for class " + impl_class + " is not public"); + } + } + } + m_ctor = tmpCtor; + } + + + private Object instantiate( XComponentContext xContext ) + throws com.sun.star.uno.Exception + { + try + { + if (DEBUG) + System.out.print( "instantiating " + m_impl_class.toString() + " using " ); + if (null != m_method) + { + if (DEBUG) + System.out.println( "__create( XComponentContext )..." ); + return m_method.invoke( null, new Object [] { xContext } ); + } + if (null != m_ctor) + { + if (DEBUG) + System.out.println( "ctor( XComponentContext )..." ); + return m_ctor.newInstance( new Object [] { xContext } ); + } + if (DEBUG) + System.out.println( "default ctor..." ); + return m_impl_class.newInstance(); // default ctor + } + catch (java.lang.reflect.InvocationTargetException exc) + { + Throwable targetException = exc.getTargetException(); + if (targetException instanceof java.lang.RuntimeException) + throw (java.lang.RuntimeException)targetException; + else if (targetException instanceof com.sun.star.uno.RuntimeException) + throw (com.sun.star.uno.RuntimeException)targetException; + else if (targetException instanceof com.sun.star.uno.Exception) + throw (com.sun.star.uno.Exception)targetException; + else + throw new com.sun.star.uno.Exception(targetException, targetException.getMessage(), this); + } + catch (IllegalAccessException exc) + { + throw new com.sun.star.uno.RuntimeException( exc, exc.getMessage(), this); + } + catch (InstantiationException exc) + { + throw new com.sun.star.uno.RuntimeException( exc, exc.getMessage(), this); + } + } + // XSingleComponentFactory impl + + public final Object createInstanceWithContext( + XComponentContext xContext ) + throws com.sun.star.uno.Exception + { + return instantiate( xContext ); + } + + public final Object createInstanceWithArgumentsAndContext( + Object arguments [], XComponentContext xContext ) + throws com.sun.star.uno.Exception + { + Object inst = instantiate( xContext ); + XInitialization xInit = UnoRuntime.queryInterface( + XInitialization.class, inst ); + if (null == xInit) + { + throw new com.sun.star.lang.IllegalArgumentException( + "cannot pass arguments to component; no XInitialization implemented!", this, + (short)0 ); + } + xInit.initialize( arguments ); + return inst; + } + + // XServiceInfo impl + + public final String getImplementationName() + { + return m_impl_name; + } + + public final boolean supportsService( String service_name ) + { + for ( int nPos = 0; nPos < m_supported_services.length; ++nPos ) + { + if (m_supported_services[ nPos ].equals( service_name )) + return true; + } + return false; + } + + public final String [] getSupportedServiceNames() + { + return m_supported_services; + } +} + diff --git a/ridljar/com/sun/star/lib/uno/helper/InterfaceContainer.java b/ridljar/com/sun/star/lib/uno/helper/InterfaceContainer.java new file mode 100644 index 000000000000..e858ced81fd8 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/InterfaceContainer.java @@ -0,0 +1,864 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.helper; + +import java.util.Iterator; +import java.util.ListIterator; +import java.util.Collection; + +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XEventListener; +import com.sun.star.uno.UnoRuntime; + +/** + * This class is a container for interfaces. + * + * It is intended to be used as storage for UNO interface of a specific type. + * The client has to ensure that the container contains only elements of the same + * type. If one needs to store different types, then one uses OMultiTypeInterfaceContainer. + * When the client calls disposeAndClear, the contained objects are queried for + * com.sun.star.lang.XEventListener and disposing is called. Afterwards + * the list cannot be used anymore. + * + * This list does not allow null values. + * All methods are thread-safe. The same holds true for + * iterators, issued by this class. Several iterators can exist at the same time and can also + * be modified (java.util.ListIterator.add, java.util.ListIterator.remove etc.). To make this work, + * the InterfaceContainer provides the iterators with copies of the list's data. + * The add and remove calls on the iterator modify the data in the iterator's list as well as + * in InterfaceContainer. Modification on InterfaceContainer, however, are not + * synchronized with existing iterators. For example + *
+ * InterfaceContainer cont= new InterfaceContainer();
+ * ListIterator it= cont.listIterator();
+ *
+ * cont.add( someInterface);
+ * // one cannot obtain someInterface through iterator it,
+ * // instead get a new iterator
+ * it= cont.listIterator();
+ * // it now keeps a fresh copy of cont and hence contains someInterface
+ *
+ * // Adding an interface on the iterator will cause the interface also to be added
+ * // to InterfaceContainer
+ * it.add( someOtherInterface);
+ * // someOtherInterface is now in it and cont
+ * ListIterator it2= cont.listIterator();
+ * //someOtherInterface can also be obtained by all newly created iterators, e.g. it2.
+ * 
+ * + * The add and remove methods of an iterator work on a particular location within a list, + * dependent on what the value of the iterator's cursor is. After the call the value at the + * appropriate position has been modified. Since the iterator received a copy of InterfaceContainer's + * data, InterfaceContainer may have been modified (by List methods or through other iterators). + * Therefore both data sets may not contain the same elements anymore. Consequently, a List method + * that modifies data, does not modify InterfaceContainer's data at a certain index + * (according to the iterators cursor). Instead, new elements are added at the end of list. When + * Iterator.remove is called, then the first occurrence of that element in InterfaceContainer + * is removed. + * ListIterator.set is not supported. + * + * A lot of methods resemble those of the to java.util.List interface, although + * this class does not implement it. However, the list iterators returned, for example by + * the listIterator method implement the java.util.ListIterator interface. + * Implementing the List interface would mean to support all none - optional methods as + * prescribed by the interface declaration. Among those is the subList method which returns + * a range of values of the list's data wrapped in a List implementation. Changes to the sub + * list have to cause changes in the main list. This is a problem, since this class is to be + * used in a multi-threaded environment. The sub list could work on a copy as the iterators + * do, but all the functions which work on a given index could not be properly supported. + * Unfortunately, the List interface documentation states that all optional methods implemented + * by the list have to be implemented in the sub list. That would mean to do without all those + * critical methods, although they might work well in the "main list" (as opposed to sub list). + */ +public class InterfaceContainer implements Cloneable +{ + static final boolean DEBUG= false; + /** + * The array buffer into which the elements of the ArrayList are stored. + * The capacity of the ArrayList is the length of this array buffer. + */ + Object elementData[]; + + /** + * The size of the ArrayList (the number of elements it contains). + */ + private int size; + + + /** Creates a new instance of InterfaceContainer */ + public InterfaceContainer() + { + this(10); + } + /** + * Constructs an empty list with the specified initial capacity. + * + * @param initialCapacity the initial capacity of the list. + * @exception IllegalArgumentException if the specified initial capacity + * is negative + */ + public InterfaceContainer(int initialCapacity) + { + if (initialCapacity < 0) + throw new java.lang.IllegalArgumentException("Illegal Capacity: "+ + initialCapacity); + this.elementData = new Object[initialCapacity]; + } + + private InterfaceContainer(Object[] data) { + elementData = data; + size = elementData == null ? 0 : elementData.length; + } + + /** + * Trims the capacity of this ArrayList instance to be the + * list's current size. An application can use this operation to minimize + * the storage of an ArrayList instance. + */ + synchronized public void trimToSize() + { + int oldCapacity = elementData.length; + if (size < oldCapacity) + { + Object oldData[] = elementData; + elementData = new Object[size]; + System.arraycopy(oldData, 0, elementData, 0, size); + } + } + + /** + * Increases the capacity of this ArrayList instance, if + * necessary, to ensure that it can hold at least the number of elements + * specified by the minimum capacity argument. + * + * @param minCapacity the desired minimum capacity. + */ + synchronized public void ensureCapacity(int minCapacity) + { + int oldCapacity = elementData.length; + if (minCapacity > oldCapacity) + { + Object oldData[] = elementData; + int newCapacity = (oldCapacity * 3)/2 + 1; + if (newCapacity < minCapacity) + newCapacity = minCapacity; + elementData = new Object[newCapacity]; + System.arraycopy(oldData, 0, elementData, 0, size); + } + } + + /** + * Appends the specified element to the end of this list. + * + * @param o element to be appended to this list. + * @return true (as per the general contract of Collection.add). + */ + synchronized public boolean add(Object o) + { + boolean ret= false; + if (elementData != null && o != null) + { + ensureCapacity(size + 1); // Increments modCount!! + elementData[size++] = o; + ret= true; + } + return ret; + } + + /** + * Inserts the specified element at the specified position in this + * list. Shifts the element currently at that position (if any) and + * any subsequent elements to the right (adds one to their indices). + * + * @param index index at which the specified element is to be inserted. + * @param element element to be inserted. + * @throws IndexOutOfBoundsException if index is out of range + * (index < 0 || index > size()). + */ + synchronized public void add(int index, Object element) + { + if (elementData != null && element != null) + { + if (index > size || index < 0) + throw new IndexOutOfBoundsException( + "Index: "+index+", Size: "+size); + + ensureCapacity(size+1); + System.arraycopy(elementData, index, elementData, index + 1, + size - index); + elementData[index] = element; + size++; + } + } + + + /** + * Appends all of the elements in the specified Collection to the end of + * this list, in the order that they are returned by the + * specified Collection's Iterator. The behavior of this operation is + * undefined if the specified Collection is modified while the operation + * is in progress. (This implies that the behavior of this call is + * undefined if the specified Collection is this list, and this + * list is nonempty.) + * + * @param c the elements to be inserted into this list. + * @throws IndexOutOfBoundsException if index out of range (index + * < 0 || index > size()). + * @return true if an element was inserted. + */ + synchronized public boolean addAll(Collection c) + { + int numNew = c.size(); + ensureCapacity(size + numNew); + + Iterator e = c.iterator(); + for (int i=0; i(index + * < 0 || index > size()). + * @return true if an element was inserted. + */ + synchronized public boolean addAll(int index, Collection c) + { + boolean ret= false; + if (elementData != null) + { + if (index > size || index < 0) + throw new IndexOutOfBoundsException( + "Index: "+index+", Size: "+size); + // only add the non-null elements + int sizeCol= c.size(); + Object[] arColl= new Object[sizeCol]; + Iterator icol= c.iterator(); + int curIndex= 0; + for (int i=0; i < sizeCol; i++) + { + Object o= icol.next(); + if (o != null) + arColl[curIndex++]= o; + } + int numNew = curIndex; + ensureCapacity(size + numNew); // Increments modCount!! + + int numMoved = size - index; + if (numMoved > 0) + System.arraycopy(elementData, index, elementData, index + numNew, + numMoved); + + for (int i=0; itrue if this list contains the specified element. + * + * @param elem element whose presence in this List is to be tested. + * @return true if this list contains the specified element. + */ + synchronized public boolean contains(Object elem) + { + return indexOf(elem) >= 0; + } + + synchronized public boolean containsAll(Collection collection) + { + boolean retVal= true; + if (elementData != null && collection != null) + { + Iterator it= collection.iterator(); + while (it.hasNext()) + { + Object obj= it.next(); + if (!contains(obj)) + { + retVal= false; + break; + } + } + } + return retVal; + } + /** + * Returns the element at the specified position in this list. + * + * @param index index of element to return. + * @return the element at the specified position in this list. + * @throws IndexOutOfBoundsException if index is out of range (index + * < 0 || index >= size()). + */ + synchronized public Object get(int index) + { + if (elementData != null) + { + RangeCheck(index); + return elementData[index]; + } + return null; + } + + /** + * Searches for the first occurrence of the given argument, testing + * for equality using the equals method. + * + * @param elem an object. + * @return the index of the first occurrence of the argument in this + * list; returns -1 if the object is not found. + * @see Object#equals(Object) + */ + synchronized public int indexOf(Object elem) + { + if (elementData == null || elem == null) { + return -1; + } + + int index= -1; + + for (int i = 0; i < size; i++) + { + if (elem == elementData[i]) + { + index= i; + break; + } + } + + if (index == -1) + { + for (int i = 0; i < size; i++) + { + if (UnoRuntime.areSame(elem, elementData[i])) + { + index= i; + break; + } + } + } + return index; + } + /** + * Tests if this list has no elements. + * + * @return true if this list has no elements; + * false otherwise. + */ + synchronized public boolean isEmpty() + { + return size == 0; + } + + synchronized public Iterator iterator() + { + if (elementData != null) + { + InterfaceContainer aCopy= (InterfaceContainer) clone(); + return new Itr(aCopy); + } + return null; + } + /** + * Returns the index of the last occurrence of the specified object in + * this list. + * + * @param elem the desired element. + * @return the index of the last occurrence of the specified object in + * this list; returns -1 if the object is not found. + */ + synchronized public int lastIndexOf(Object elem) + { + if (elementData == null || elem == null) { + return -1; + } + + int index= -1; + + for (int i = size-1; i >= 0; i--) + { + if (elem == elementData[i]) + { + index= i; + break; + } + } + if (index == -1) + { + for (int i = size-1; i >= 0; i--) + { + if (UnoRuntime.areSame(elem, elementData[i])) + { + index= i; + break; + } + } + } + return index; + } + + /** + * Returns a shallow copy of this ArrayList instance. The contained + * references are copied but the objects not. + * + * @return a clone of this List instance. + */ + @Override + synchronized public Object clone() + { + Object[] data; + if (elementData == null) { + data = null; + } else { + data = new Object[size]; + System.arraycopy(elementData, 0, data, 0, size); + } + return new InterfaceContainer(data); + } + synchronized public ListIterator listIterator() + { + return listIterator(0); + } + + /** The iterator keeps a copy of the list. Changes to InterfaceContainer do not + * affect the data of the iterator. Conversely, changes to the iterator are effect + * InterfaceContainer. + * @param index the starting offset into the list. + * @return a new iterator. + */ + synchronized public ListIterator listIterator(int index) + { + if (elementData != null) + { + InterfaceContainer aCopy= (InterfaceContainer) clone(); + return new LstItr(aCopy, index); + } + return null; + } + /** + * Removes the element at the specified position in this list. + * Shifts any subsequent elements to the left (subtracts one from their + * indices). + * + * @param index the index of the element to removed. + * @return the element that was removed from the list. + * @throws IndexOutOfBoundsException if index out of range (index + * < 0 || index >= size()). + */ + synchronized public Object remove(int index) + { + Object ret= null; + if (elementData != null) + { + RangeCheck(index); + ret= elementData[index]; + + int numMoved = size - index - 1; + if (numMoved > 0) + System.arraycopy(elementData, index+1, elementData, index, + numMoved); + elementData[--size] = null; // Let gc do its work + } + return ret; + } + + + /** Parameter obj may... or may not. What did the original author want + * to tell us here? + * @param obj the object to be removed. + * @return true if obj was successfully removed from the list. + */ + synchronized public boolean remove(Object obj) + { + boolean ret= false; + if (elementData != null && obj != null) + { + int index= indexOf(obj); + if (index != -1) + { + ret= true; + remove(index); + } + } + return ret; + } + + synchronized public boolean removeAll(Collection collection) + { + boolean retVal= false; + if (elementData != null && collection != null) + { + Iterator it= collection.iterator(); + while (it.hasNext()) + { + Object obj= it.next(); + boolean bMod= remove( obj); + if (bMod) + retVal= true; + } + } + return retVal; + } + + synchronized public boolean retainAll(Collection collection) + { + if (elementData == null || collection == null) { + return false; + } + + boolean retVal= false; + // iterate over data + Object[] arRetained= new Object[size]; + int indexRetained= 0; + for(int i= 0; i < size; i++) + { + Object curElem= elementData[i]; + // try to find the element in collection + Iterator itColl= collection.iterator(); + boolean bExists= false; + while (itColl.hasNext()) + { + if (curElem == itColl.next()) + { + // current element is in collection + bExists= true; + break; + } + } + if (!bExists) + { + itColl= collection.iterator(); + while (itColl.hasNext()) + { + Object o= itColl.next(); + if (o != null && UnoRuntime.areSame(o, curElem)) + { + bExists= true; + break; + } + } + } + if (bExists) + arRetained[indexRetained++]= curElem; + } + retVal= size != indexRetained; + if (indexRetained > 0) + { + elementData= arRetained; + size= indexRetained; + } + return retVal; + } + + + /** Not supported. + * @param index index of element to replace. + * @param element element to be stored at the specified position. + * @return the element previously at the specified position. + * @throws IndexOutOfBoundsException if index out of range + * (index < 0 || index >= size()). + */ + synchronized public Object set(int index, Object element) + { + Object ret= null; + if (elementData != null && element != null) + { + RangeCheck(index); + ret = elementData[index]; + elementData[index] = element; + } + return ret; + } + + /** + * Returns the number of elements in this list. + * + * @return the number of elements in this list. + */ + synchronized public int size() + { + if (elementData != null) + return size; + return 0; + } + + + /** + * Returns an array containing all of the elements in this list + * in the correct order. + * + * @return an array containing all of the elements in this list + * in the correct order. + */ + synchronized public Object[] toArray() + { + if (elementData != null) + { + Object[] result = new Object[size]; + System.arraycopy(elementData, 0, result, 0, size); + return result; + } + return null; + } + + /** + * Returns an array containing all of the elements in this list in the + * correct order. The runtime type of the returned array is that of the + * specified array. If the list fits in the specified array, it is + * returned therein. Otherwise, a new array is allocated with the runtime + * type of the specified array and the size of this list.

+ * + * If the list fits in the specified array with room to spare (i.e., the + * array has more elements than the list), the element in the array + * immediately following the end of the collection is set to + * null. This is useful in determining the length of the list + * only if the caller knows that the list does not contain any + * null elements. + * + * @param a the array into which the elements of the list are to + * be stored, if it is big enough; otherwise, a new array of the + * same runtime type is allocated for this purpose. + * @return an array containing the elements of the list. + * @throws ArrayStoreException if the runtime type of a is not a supertype + * of the runtime type of every element in this list. + */ + synchronized public Object[] toArray(Object a[]) + { + if (a.length < size) + a = (Object[])java.lang.reflect.Array.newInstance( + a.getClass().getComponentType(), size); + if (elementData != null) + System.arraycopy(elementData, 0, a, 0, size); + + if (a.length > size) + a[size] = null; + + return a; + } + + /** + * Check if the given index is in range. If not, throw an appropriate + * runtime exception. + */ + private void RangeCheck(int index) + { + if (index >= size || index < 0) + throw new IndexOutOfBoundsException( + "Index: "+index+", Size: "+size); + } + + public void disposeAndClear(EventObject evt) + { + Iterator aIt; + synchronized (this) + { + aIt= iterator(); + // Release containers if new entries occur in disposing; + // set the member to null, the iterator delete the values + clear(); + elementData= null; + size= 0; + } + if (aIt != null) + { + while( aIt.hasNext() ) + { + try + { + Object o= aIt.next(); + XEventListener evtListener= UnoRuntime.queryInterface( + XEventListener.class, o); + if( evtListener != null ) + evtListener.disposing( evt ); + } + catch ( RuntimeException e) + { + // be robust, if e.g. a remote bridge has disposed already. + // there is no way, to delegate the error to the caller :o(. + } + } + } + } + + + private class Itr implements Iterator + { + InterfaceContainer dataIt; + /** + * Index of element to be returned by subsequent call to next. + */ + int cursor= 0; + /** + * Index of element returned by most recent call to next or + * previous. Reset to -1 if this element is deleted by a call + * to remove. + */ + int lastRet = -1; + + /** The object that has been returned by most recent call to next + * or previous. Reset to null if this element is deleted by a call + * to remove. + */ + Object lastRetObj= null; + + Itr(InterfaceContainer _data) + { + dataIt= _data; + } + + synchronized public boolean hasNext() + { + return cursor !=dataIt.size(); + } + + public synchronized Object next() + { + try + { + Object next = dataIt.get(cursor); + lastRet = cursor++; + lastRetObj= next; + return next; + } + catch(java.lang.IndexOutOfBoundsException e) + { + java.util.NoSuchElementException ex2 = new java.util.NoSuchElementException(); + ex2.initCause(e); + throw ex2; + } + } + + /** Removes the interface from the list, that has been last returned by a + * call to next(). This is done according to the specification of the interface + * method. The element is also removed from InterfaceContainer but independent + * of the location. If the element is multiple times in InterfaceContainer then + * it is up to the java.util.ArrayList implementation what element is removed. + */ + public synchronized void remove() + { + if (lastRet == -1) + throw new IllegalStateException(); + // Remove the entry from InterfaceContainer. + InterfaceContainer.this.remove(lastRetObj); + dataIt.remove(lastRet); + + if (lastRet < cursor) + cursor--; + lastRet = -1; + lastRetObj= null; + } + } + + private class LstItr extends Itr implements ListIterator + { + + LstItr(InterfaceContainer _data, int _index) + { + super(_data); + cursor= _index; + } + + /** Inserts an element to the iterators list according to the specification + * of this interface method. The element is also added to InterfaceContainer + * but its location within the list cannot be guaranteed. + */ + public synchronized void add(Object o) + { + InterfaceContainer.this.add(o); + dataIt.add(cursor++, o); + lastRet = -1; + lastRetObj= null; + } + + synchronized public boolean hasPrevious() + { + return cursor != 0; + } + + synchronized public int nextIndex() + { + return cursor; + } + + public synchronized Object previous() + { + try + { + Object previous = dataIt.get(--cursor); + lastRet = cursor; + lastRetObj= previous; + return previous; + } catch(IndexOutOfBoundsException e) + { + java.util.NoSuchElementException ex2 = new java.util.NoSuchElementException(); + ex2.initCause(e); + throw ex2; + } + } + + synchronized public int previousIndex() + { + return cursor-1; + } + + /** This is not possible since several iterators can modify InterfaceContainer + */ + public synchronized void set(Object o) + { + throw new UnsupportedOperationException(); + } + + + } // class LstItr +} + diff --git a/ridljar/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java b/ridljar/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java new file mode 100644 index 000000000000..9b061f81c217 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer.java @@ -0,0 +1,155 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.helper; +import com.sun.star.uno.Type; +import com.sun.star.lang.EventObject; +import java.util.HashMap; +import java.util.Map; +import java.util.Iterator; + +public class MultiTypeInterfaceContainer +{ + + private final Map map= new HashMap(); + + /** only returns types which have at least one value in InterfaceContainer + * return value can contain an element null, if someone called + * addInterface (null, interf) + * @return an array of types in this container. + */ + synchronized public Type[] getContainedTypes() + { + int size; + Type[] retVal= null; + + if ( (size=map.size()) > 0) + { + Type [] arTypes= new Type[size]; + + int countTypes= 0; + for (Map.Entry entry : map.entrySet()) + { + InterfaceContainer cont= entry.getValue(); + if (cont != null && cont.size() > 0) + { + Object key = entry.getKey(); + if (key == null) + arTypes[countTypes++]= new Type(); + else if (key instanceof Type) + arTypes[countTypes++]= (Type) key; + else if (key instanceof Class) + arTypes[countTypes++]= new Type((Class) key); + else + arTypes[countTypes++]= new Type(key.getClass()); + } + } + + if (countTypes != size) + { + retVal= new Type[countTypes]; + System.arraycopy(arTypes, 0, retVal, 0, countTypes); + } + else + retVal= arTypes; + } + if (retVal == null) + retVal= new Type[0]; + return retVal; + } + + /** param key can be null + * @param key the object for which the container should be retrieved. + * @return the container that contains the object key, if any. + */ + synchronized public InterfaceContainer getContainer(Object key) + { + InterfaceContainer retVal= null; + for (Map.Entry entry : map.entrySet()) + { + Object obj= entry.getKey(); + if (obj == null && key == null) + { + retVal= map.get(null); + break; + } + else if( obj != null && obj.equals(key)) + { + retVal= entry.getValue(); + break; + } + } + return retVal; + } + + + synchronized public int addInterface(Object ckey, Object iface) + { + //If the key is a Type then it does not matter if the objects are different + // if they represent the same type. This is because Types overrides hashCode and + // equals. For example: + // Type a= new Type(XInterface.class); + // Type b= new Type(XInterface.class); + // Although a != b , the map interprets both as being the same. + InterfaceContainer cont= map.get(ckey); + if (cont != null) + { + cont.add(iface); + } + else + { + cont= new InterfaceContainer(); + cont.add(iface); + map.put(ckey, cont); + } + return cont.size(); + } + + + synchronized public int removeInterface(Object key, Object iface) + { + int retVal= 0; + InterfaceContainer cont= map.get(key); + if (cont != null) + { + cont.remove(iface); + retVal= cont.size(); + } + return retVal; + } + + public void disposeAndClear(EventObject evt) + { + Iterator it= null; + synchronized(this) + { + it= map.values().iterator(); + } + while (it.hasNext() ) { + it.next().disposeAndClear(evt); + } + } + + synchronized public void clear() + { + Iterator it= map.values().iterator(); + while (it.hasNext()) { + it.next().clear(); + } + } +} diff --git a/ridljar/com/sun/star/lib/uno/helper/PropertySet.java b/ridljar/com/sun/star/lib/uno/helper/PropertySet.java new file mode 100644 index 000000000000..67a4f0c98062 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/PropertySet.java @@ -0,0 +1,1103 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.lib.uno.helper; + +import com.sun.star.uno.Type; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.uno.TypeClass; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.XInterface; +import com.sun.star.uno.Any; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.beans.PropertyChangeEvent; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertiesChangeListener; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XFastPropertySet; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.XMultiPropertySet; +import java.util.Iterator; +import java.util.Collection; +import java.util.HashMap; +import java.lang.reflect.Field; +import com.sun.star.lang.DisposedException; + + +/** This class is an implementation of the interfaces com.sun.star.beans.XPropertySet, + * com.sun.star.beans.XFastPropertySet and com.sun.star.beans.XMultiPropertySet. This + * class has to be inherited to be used. The values of properties are stored in member + * variables of the inheriting class. By overriding the methods + * {@link #convertPropertyValue convertPropertyValue}, + * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and + * {@link #getPropertyValue(Property)} one can determine how + * property values are stored. + * When using the supplied implementations of this class then the member variables which + * hold property values have to be declared in the class which inherits last in the inheriting + * chain and they have to be public

+ * Properties have to be registered by one of the registerProperty methods. They take among other + * arguments an Object named id which has to be a String that represents the name of + * the member variable. The registering has to occur in the constructor of the inheriting class. + * It is no allowed to add or change properties later on.

+ * Example: + *

+ *  public class Foo extends PropertySet
+ *  {
+ *      protected int intProp;
+ *
+ *      public Foo()
+ *      {
+ *          registerProperty("PropertyA", 0, new Type(int.class), (short)0, "intProp");
+ *      }
+ *  }
+ *
+ *  
+ */ +public class PropertySet extends ComponentBase implements XPropertySet, XFastPropertySet, +XMultiPropertySet +{ + private HashMap _nameToPropertyMap; + private HashMap _handleToPropertyMap; + private HashMap _propertyToIdMap; + private Property[] arProperties; + + private int lastHandle= 1; + + protected XPropertySetInfo propertySetInfo; + protected MultiTypeInterfaceContainer aBoundLC= new MultiTypeInterfaceContainer(); + protected MultiTypeInterfaceContainer aVetoableLC= new MultiTypeInterfaceContainer(); + public PropertySet() + { + super(); + initMappings(); + } + + /** Registers a property with this helper class and associates the argument id with it. + * id is used to identify the storage of the property value. How property values are stored + * and retrieved is determined by the methods {@link #convertPropertyValue convertPropertyValue}, + * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and {@link #getPropertyValue(Property) getPropertyValue} + * These methods expect id to be a String which represents the name of a member variable + * which holds the property value. + * Only properties which are registered can be accessed. Registration has to occur during + * initialization of the inheriting class (i.e. within the constructor). + * @param prop The property to be registered. + * @param id Identifies the properties storage. + * @see #getPropertyId + */ + protected void registerProperty(Property prop, Object id) + { + putProperty(prop); + assignPropertyId(prop, id); + } + + /** Registers a property with this helper class and associates the argument id with it. + * It does the same as {@link #registerProperty(Property, Object)}. The first four + * arguments are used to construct a Property object. + * Registration has to occur during + * initialization of the inheriting class (i.e. within the constructor) + * @param name The property's name (Property.Name). + * @param handle The property's handle (Property.Handle). + * @param type The property's type (Property.Type). + * @param attributes The property's attributes (Property.Attributes). + * @param id Identifies the property's storage. + */ + protected void registerProperty(String name, int handle, Type type, short attributes, Object id) + { + Property p= new Property(name, handle, type, attributes); + registerProperty(p, id); + } + + /** Registers a property with this class and associates the argument id with it. + * It does the same as {@link #registerProperty(Property, Object)}. The first three + * arguments are used to construct a Property object. The value for the Property.Handle + * is generated and does not have to be specified here. Use this method for registering + * a property if you do not care about the Property's handles. + * Registration has to occur during + * initialization of the inheriting class (i.e. within the constructor). + * @param name The property's name (Property.Name). + * @param type The property's type (Property.Type). + * @param attributes The property's attributes (Property.Attributes). + * @param id Identifies the property's storage. + */ + protected void registerProperty(String name, Type type, short attributes, Object id) + { + Property p= new Property(name, lastHandle++, type, attributes); + registerProperty(p, id); + } + + /** Registers a property with this class. This method expects that property values + * are stored in member variables as is the case if the methods convertPropertyValue, + * setPropertyValueNoBroadcast and getPropertyValue(Property) are not overridden. + * It is presumed that the type of the member variable + * corresponds Property.Type. For example, if the TypeClass of Property.Type is to be + * a TypeClass.SHORT then the member must be a short or java.lang.Short. + * The handle for the property is generated.
+ * If there is no member with the specified name or if the member has an incompatible type + * then a com.sun.star.uno.RuntimeException is thrown. + * @param propertyName The name of the property. + * @param memberName The name of the member variable that holds the value of the property. + * @param attributes The property attributes. + */ + protected void registerProperty(String propertyName, String memberName, short attributes) + { + Field propField= null; + try + { + propField= getClass().getDeclaredField(memberName); + } + catch (NoSuchFieldException e) + { + throw new com.sun.star.uno.RuntimeException(e, "there is no member variable: " + memberName); + } + Class cl= propField.getType(); + Type t= new Type(cl); + if (t.getTypeClass() != TypeClass.UNKNOWN) + { + Property p= new Property(propertyName, lastHandle++, t, attributes); + registerProperty(p,memberName); + } + else + throw new com.sun.star.uno.RuntimeException("the member has an unknown type: " + memberName); + } + + /** Registers a property with this class. + * It is presumed that the name of property is equal to the name of the member variable + * that holds the property value. + * @param propertyName The name of the property and the member variable that holds the property's value. + * @param attributes The property attributes. + * @see #registerProperty(String, String, short) + */ + protected void registerProperty(String propertyName, short attributes) + { + registerProperty(propertyName, propertyName, attributes); + } + + + + /** Returns the Property object for a given property name or null if that property does + * not exists (i.e. it has not been registered). Override this method + * if you want to implement your own mapping from property names to Property objects. + * Then you also have to override {@link #initMappings}, {@link #getProperties()} and + * {@link #putProperty(Property)}. + * @param propertyName The name of the property (Property.Name) + * @return The Property object with the name propertyName. + */ + protected Property getProperty(String propertyName) + { + return _nameToPropertyMap.get(propertyName); + } + + /** Returns the Property object with a handle (Property.Handle) as specified by the argument + * nHandle. The method returns null if there is no such property (i.e. it has not + * been registered). Override this method if you want to implement your own mapping from handles + * to Property objects. Then you also have to override {@link #initMappings}, {@link #putProperty(Property)}. + * @param nHandle The handle of the property (Property.Handle). + * @return The Property object with the handle nHandle + */ + protected Property getPropertyByHandle(int nHandle) + { + return _handleToPropertyMap.get(Integer.valueOf(nHandle)); + } + + /** Returns an array of all Property objects or an array of length null if there + * are no properties. Override this method if you want to implement your own mapping from names + * to Property objects. Then you also have to override {@link #initMappings}, {@link #getProperty(String)} and + * {@link #putProperty}. + * @return Array of all Property objects. + */ + protected Property[] getProperties() + { + if (arProperties == null) + { + Collection values= _nameToPropertyMap.values(); + arProperties= values.toArray(new Property[_nameToPropertyMap.size()]); + } + return arProperties; + } + + /** Stores a Property object so that it can be retrieved subsequently by + * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. + * Override this method if you want to implement your own mapping from handles + * to Property objects and names to Property objects. Then you also need to override {@link #initMappings}, + * {@link #getProperty(String)},{@link #getProperties()},{@link #getPropertyByHandle(int)}. + * @param prop The Property object that is to be stored. + */ + protected void putProperty(Property prop) + { + _nameToPropertyMap.put(prop.Name, prop); + if (prop.Handle != -1) + _handleToPropertyMap.put(Integer.valueOf(prop.Handle), prop); + } + + /** Assigns an identifier object to a Property object so that the identifier + * can be obtained by {@link #getPropertyId getPropertyId} later on. The identifier + * is used to specify a certain storage for the property's value. If you do not + * override {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} or {@link #getPropertyValue(Property)} + * then the argument id has to be a String that equals the name of + * the member variable that holds the Property's value. + * Override this method if you want to implement your own mapping from Property objects to ids or + * if you need ids of a type other than String. + * Then you also need to override {@link #initMappings initMappings} and {@link #getPropertyId getPropertyId}. + * @param prop The Property object that is being assigned an id. + * @param id The object which identifies the storage used for the property's value. + * @see #registerProperty(Property, Object) + */ + protected void assignPropertyId(Property prop, Object id) + { + if (id instanceof String && ((String) id).length() != 0) + _propertyToIdMap.put(prop, id); + } + + /** Returns the identifier object for a certain Property. The object must have been + * previously assigned to the Property object by {@link #assignPropertyId assignPropertyId}. + * Override this method if you want to implement your own mapping from Property objects to ids. + * Then you also need to override {@link #initMappings initMappings} and {@link #assignPropertyId assignPropertyId}. + * @param prop The property for which the id is to be retrieved. + * @return The id object that identifies the storage used for the property's value. + * @see #registerProperty(Property, Object) + */ + protected Object getPropertyId(Property prop) + { + return _propertyToIdMap.get(prop); + } + + /** Initializes data structures used for mappings of property names to property object, + * property handles to property objects and property objects to id objects. + * Override this method if you want to implement your own mappings. Then you also need to + * override {@link #putProperty putProperty},{@link #getProperty getProperty}, {@link #getPropertyByHandle}, + * {@link #assignPropertyId assignPropertyId} and {@link #getPropertyId getPropertyId}. + */ + protected void initMappings() + { + _nameToPropertyMap= new HashMap(); + _handleToPropertyMap= new HashMap(); + _propertyToIdMap= new HashMap(); + } + + /** Makes sure that listeners which are kept in aBoundLC (XPropertyChangeListener) and aVetoableLC + * (XVetoableChangeListener) receive a disposing call. Also those listeners are released. + */ + @Override + protected void postDisposing() + { + // Create an event with this as sender + EventObject aEvt= new EventObject(this); + + // inform all listeners to release this object + aBoundLC.disposeAndClear(aEvt); + aVetoableLC.disposeAndClear(aEvt); + } + + //XPropertySet ---------------------------------------------------- + synchronized public void addPropertyChangeListener(String str, XPropertyChangeListener xPropertyChangeListener) + throws UnknownPropertyException, WrappedTargetException + { + // only add listeners if you are not disposed + if (! bInDispose && ! bDisposed) + { + if (str.length() > 0) + { + Property prop= getProperty(str); + if (prop == null) + throw new UnknownPropertyException("Property " + str + " is unknown"); + + // Add listener for a certain property + if ((prop.Attributes & PropertyAttribute.BOUND) > 0) + aBoundLC.addInterface(str, xPropertyChangeListener); + else + //ignore silently + return; + } + else + // Add listener for all properties + listenerContainer.addInterface(XPropertyChangeListener.class, xPropertyChangeListener); + } + } + //XPropertySet ---------------------------------------------------- + synchronized public void addVetoableChangeListener(String str, com.sun.star.beans.XVetoableChangeListener xVetoableChangeListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException + { + // only add listeners if you are not disposed + if (! bInDispose && ! bDisposed) + { + if (str.length() > 0) + { + Property prop= getProperty(str); + if (prop == null) + throw new UnknownPropertyException("Property " + str + " is unknown"); + + // Add listener for a certain property + if ((prop.Attributes & PropertyAttribute.CONSTRAINED) > 0) + aVetoableLC.addInterface(str, xVetoableChangeListener); + else + //ignore silently + return; + } + else + // Add listener for all properties + listenerContainer.addInterface(XVetoableChangeListener.class, xVetoableChangeListener); + } + } + //XPropertySet ---------------------------------------------------- + public synchronized com.sun.star.beans.XPropertySetInfo getPropertySetInfo() + { + if (propertySetInfo == null) + propertySetInfo= new PropertySetInfo(); + return propertySetInfo; + } + //XPropertySet ---------------------------------------------------- + public Object getPropertyValue(String name) throws UnknownPropertyException, WrappedTargetException + { + Object ret= null; + if (bInDispose || bDisposed) + throw new com.sun.star.lang.DisposedException("The component has been disposed already"); + + Property prop= getProperty(name); + if (prop == null) + throw new UnknownPropertyException("The property " + name + " is unknown"); + + synchronized (this) + { + ret= getPropertyValue(prop); + } + // null must not be returned. Either a void any is returned or an any containing + // an interface type and a null reference. + if (ret == null) + { + if (prop.Type.getTypeClass() == TypeClass.INTERFACE) + ret= new Any(prop.Type, null); + else + ret= new Any(new Type(void.class), null); + } + return ret; + } + + //XPropertySet ---------------------------------------------------- + synchronized public void removePropertyChangeListener(String propName, XPropertyChangeListener listener) throws UnknownPropertyException, WrappedTargetException + { // all listeners are automatically released in a dispose call + if (!bInDispose && !bDisposed) + { + if (propName.length() > 0) + { + Property prop = getProperty(propName); + if (prop == null) + throw new UnknownPropertyException("Property " + propName + " is unknown"); + aBoundLC.removeInterface(propName, listener); + } + else + listenerContainer.removeInterface(XPropertyChangeListener.class, listener); + } + } + + //XPropertySet ---------------------------------------------------- + synchronized public void removeVetoableChangeListener(String propName, XVetoableChangeListener listener) throws UnknownPropertyException, WrappedTargetException + {// all listeners are automatically released in a dispose call + if (!bInDispose && !bDisposed) + { + if (propName.length() > 0) + { + Property prop = getProperty(propName); + if (prop == null) + throw new UnknownPropertyException("Property " + propName + " is unknown"); + aVetoableLC.removeInterface(propName, listener); + } + else + listenerContainer.removeInterface(XVetoableChangeListener.class, listener); + } + } + + //XPropertySet ---------------------------------------------------- + /** Sets the value of a property. + * The idl description for this interfaces, stipulates that the argument value is an Any. Since a java.lang.Object + * reference has the same meaning as an Any this function accepts + * java anys (com.sun.star.uno.Any) and all other appropriate objects as arguments. The value argument can be one + * of these: + *
    + *
  • java.lang.Boolean
  • + *
  • java.lang.Character
  • + *
  • java.lang.Byte
  • + *
  • java.lang.Short
  • + *
  • java.lang.Integer
  • + *
  • java.lang.Long
  • + *
  • java.lang.Float
  • + *
  • java.lang.Double
  • + *
  • String
  • + *
  • com.sun.star.uno.Type
  • + *
  • objects which implement UNO interfaces
  • + *
  • arrays which contain elements of the types above
  • + *
  • com.sun.star.uno.Any containing an instance of one of the above types
  • + *
+ * + * Properties can have the attribute com.sun.star.beans.PropertyAttribute.MAYBEVOID, which means that the value + * (not the type) can be void. In order to assign a void value to a property one can either pass an Any which + * contains a null reference or pass null directly. In both cases the null reference is only accepted if + * the PropertyAttribute.MAYBEVOID attribute is set for the property. + * + * Properties which have the attribute MAYBEVOID set (Property.Attributes) can have a void value. The following + * considerations presume that the Property has that attribute set. Further, when mentioning an Any's value we + * actually refer to the object returned by Any.getObject. + * If the argument value is null, or it is an Any whose value is null (but with a valid Type) + * then the member variable used for storing the property's value is set to null. + * Therefore those properties can only be stored in objects + * and primitive types are not allowed (one can use the wrapper classes instead,e.g. java.lang.Byte) . + * If a property's value is kept in a member variable of type Any and that reference is still null + * then when setPropertyValue is called with + * value = null then the member variable is assigned an Any with type void and a null value. + * Or if the argument is an Any with a null value then it is assigned to the member variable. + * Further, if the variable already + * references an Any and setPropertyValue is called with value = null, then the variable is assigned + * a new Any with the same type as the previously referenced Any and with a null value. + * @param name The name of the property. + * @param value The new value of the property. + * * */ + public void setPropertyValue(String name, Object value) throws UnknownPropertyException, + PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + Property prop= getProperty(name); + if (prop == null) + throw new UnknownPropertyException("Property " + name + " is unknown"); + setPropertyValue(prop, value); + } + + /** Sets the value of a property. It checks if the property's attributes (READONLY,MAYBEVOID), allow that the + * new value can be set. It also causes the notification of listeners. + * @param prop The property whose value is to be set. + * @param value The new value for the property. + * + * @throws UnknownPropertyException + * See com.sun.star.beans.XPropertySet + * @throws PropertyVetoException + * See com.sun.star.beans.XPropertySet + * @throws WrappedTargetException + * See com.sun.star.beans.XPropertySet + */ + protected void setPropertyValue(Property prop, Object value) throws UnknownPropertyException, + PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + if ((prop.Attributes & PropertyAttribute.READONLY) == PropertyAttribute.READONLY) + throw new com.sun.star.beans.PropertyVetoException(); + // The value may be null only if MAYBEVOID attribute is set + boolean bVoidValue; + if (value instanceof Any) + bVoidValue= ((Any) value).getObject() == null; + else + bVoidValue= value == null; + if (bVoidValue && (prop.Attributes & PropertyAttribute.MAYBEVOID) == 0) + throw new com.sun.star.lang.IllegalArgumentException("The property must have a value; the MAYBEVOID attribute is not set!"); + if (bInDispose || bDisposed) + throw new DisposedException("Component is already disposed"); + + //Check if the argument is allowed + boolean bValueOk; + if (value instanceof Any) + bValueOk= checkType(((Any) value).getObject()); + else + bValueOk= checkType(value); + if (! bValueOk) + throw new com.sun.star.lang.IllegalArgumentException("No valid UNO type"); + + + boolean bConversionOk= false; + Object[] outConvertedVal= new Object[1]; + Object[] outOldValue= new Object[1]; + synchronized (this) + { + bConversionOk= convertPropertyValue(prop, outConvertedVal, outOldValue, value); + } + + //The next step following the conversion is to set the new value of the property. Prior to this + // the XVetoableChangeListener s have to be notified. + if (bConversionOk) + { + // If the property is CONSTRAINED, then we must notify XVetoableChangeListener. The listener can throw a com.sun.star.lang.beans.PropertyVetoException which + // will cause this method to return (the exception is not caught here). + fire( new Property[]{prop}, outConvertedVal, outOldValue, true); + + synchronized (this) + { + setPropertyValueNoBroadcast(prop, outConvertedVal[0]); + } + // fire a change event (XPropertyChangeListener, PropertyAttribute.BOUND + fire( new Property[]{prop}, outConvertedVal, outOldValue, false); + } + } + + /** Converts a value in a way so that it is appropriate for storing as a property value, that is + * {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} can process the value without any further + * conversion. This implementation presumes that + * the values are stored in member variables of the furthest inheriting class. For example, + * class A inherits this class then members of class A + * can hold property values. If there is a class B which inherits A then only members of B can hold + * property values. The variables must be public. A property must have been registered (e.g. by + * {@link #registerProperty(Property, Object)} in order for this method to work. The identifier argument (type Object) + * used in the registerProperty methods must + * be a String, which is, the name of the member variable that holds the property value. + * If one opts to store values differently then one may override + * this method, as well as {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} and + * {@link #getPropertyValue(Property) getPropertyValue(Property)}. + * This method is always called as a result of a call to one of the setter methods, such as + * {@link #setPropertyValue(String,Object) XPropertySet.setPropertyValue}, + * {@link #setFastPropertyValue XFastPropertySet.setFastPropertyValue} + * and {@link #setPropertyValues XMultiPropertySet.setPropertyValues}. + * If this method fails, that is, it returns false or throws an exception, then no listeners are notified and the + * property value, that was intended to be changed, remains untouched. + * + * This method does not have to deal with property attributes, such as + * PropertyAttribute.READONLY or PropertyAttribute.MAYBEVOID. The processing of these attributes occurs + * in the calling methods. + * + * Only if this method returns successfully further processing, such + * as listener notification and finally the modification of the property's value, will occur. + * + * The actual modification of a property's value is done by {@link #setPropertyValueNoBroadcast setPropertyValueNoBroadcast} + * which is called subsequent to convertPropertyValue. + *

+ * This method converts values by help of the com.sun.star.uno.AnyConverter which only does a few widening + * conversions on integer types and floating point types. For example, there is the property PropA with a Type equivalent + * to int.class and the + * value of the property is to be stored in a member variable of type int with name intProp. Then setPropertyValue is + * called: + *

+     *  set.setPropertyValue( "PropA", Byte.valueOf( (byte)111));
+     *  
+ * At some point setPropertyValue will call convertPropertyValue and pass in the Byte object. Since we allow + * that Byte values can be used with the property and know that the value is to be stored in intProp (type int) + * we convert the Byte object into an Integer object which is then returned in the out-parameter newVal. This + * conversion is actually performed by the AnyConverter. Later + * the setPropertyValueNoBroadcast is called with that Integer object and the int value can be easily extracted + * from the object and be assigned to the member intProp. + *

+ * The method handles Any arguments the same as Object arguments. That is, the setVal argument can + * be a java.lang.Boolean or a com.sun.star.uno.Any containing a java.lang.Boolean. Likewise, a member + * containing a property value can be a com.sun.star.uno.Any or a java.lang.Object. + * Then, no conversion is necessary, since they can hold all possible values. However, if + * the member is an Object and setVal is an Any then the object contained in the any is assigned to + * the member. The extra type information which exists as Type object in the Any will get lost. If this is not + * intended then use an Any variable rather than an Object. + * + * If a member is an Object or Any and the argument setVal is an Object, other than String or array, + * then it is presumed to be a UNO object and queried for XInterface. If successful, the out-param newVal + * returns the XInterface. + * + * If a member is a UNO interface, then setVal is queried for this interface and the result is returned. + * If setVal is null then newVal will be null too after return. + *

+ * If a property value is stored using a primitive type the out-parameters + * curVal and newVal contain the respective wrapper class (e.g.java.lang.Byte, etc.). + * curVal is used in calls to the XVetoableChangeListener and XPropertyChangeListener. + * + * @param property - in-param property for which the data is to be converted. + * @param newVal - out-param which contains the converted value on return. + * @param curVal - out-param the current value of the property. It is used in calls to the + * XVetoableChangeListener and XPropertyChangeListener. + * @param setVal - in-param. The value that is to be converted so that it matches Property and the internally used + * dataformat for that property. + * @return true - Conversion was successful. newVal contains a valid value for the property. false - + * conversion failed for some reason. + * + * @throws UnknownPropertyException + * See com.sun.star.beans.XPropertySet + * @throws com.sun.star.lang.IllegalArgumentException The value provided is unfit for the property. + * @throws com.sun.star.lang.WrappedTargetException - An exception occurred during the conversion, that is to be made known + * to the caller. + */ + protected boolean convertPropertyValue(Property property, Object[] newVal, Object[]curVal, Object setVal) + throws com.sun.star.lang.IllegalArgumentException, WrappedTargetException, UnknownPropertyException + { + boolean ret= true; + try + { + // get the member name + String sMember= (String) getPropertyId(property); + if (sMember != null) + { + // use reflection to obtain the field that holds the property value + // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to + // also get inherited fields, but only those which are public. + Field propField= getClass().getDeclaredField(sMember); + if (propField != null) + { + curVal[0]= propField.get(this); + Class memberClass= propField.getType(); + + // MAYBEVOID: if setVal == null or it is an Any and getObject returns null, then a void value is to be set + // This works only if there are no primitive types. For those we use the respective wrapper classes. + // In this implementation, a null reference means void value. + boolean bVoidValue= false; + boolean bAnyVal= setVal instanceof Any; + if (bAnyVal) + bVoidValue= ((Any) setVal).getObject() == null; + else + bVoidValue= setVal == null; + if (bVoidValue && memberClass.isPrimitive()) + throw new com.sun.star.lang.IllegalArgumentException("The implementation does not support the MAYBEVOID attribute for this property"); + + Object convObj= null; + //The member that keeps the value of the Property is an Any. It can contain all possible + //types, therefore a conversion is not necessary. + if (memberClass.equals(Any.class)) + { + if (bAnyVal) + //parameter setVal is also an Any and can be used without further processing + convObj= setVal; + else + { + // Parameter setVal is not an Any. We need to construct an Any that contains + // the argument setVal. + // If setVal is an interface implementation then, we cannot construct the + // Any with setVal.getClass(), because the Any.Type._typeClass would be TypeClass.UNKNOWN. + // We try to get an XInterface of setVal and set an XInterface type. + if (setVal instanceof XInterface) + { + XInterface xint= UnoRuntime.queryInterface(XInterface.class, setVal); + if (xint != null) + convObj= new Any(new Type(XInterface.class), xint); + } + // The member is an any, and the past in argument was null reference (MAYBEVOID is set) + else if (setVal == null) + { + // if the any member is still null we create a void any + if (curVal[0] == null) + convObj= new Any(new Type(), null); + else + { + //otherwise we create an Any with the same type as a value of null; + convObj= new Any( ((Any)curVal[0]).getType(), null); + } + } + else + convObj= new Any(new Type(setVal.getClass()), setVal); + } + } + else + convObj= convert(memberClass, setVal); + newVal[0]= convObj; + } + } + else + throw new UnknownPropertyException("Property " + property.Name + " is unknown"); + } + catch (java.lang.NoSuchFieldException e) + { + throw new WrappedTargetException(e, "Field does not exist", this, e); + } + catch (java.lang.IllegalAccessException e) + { + throw new WrappedTargetException(e, "", this ,e); + } + return ret; + } + + private boolean checkType(Object obj) + { + return obj == null + || obj instanceof Boolean + || obj instanceof Character + || obj instanceof Number + || obj instanceof String + || obj instanceof XInterface + || obj instanceof Type + || obj instanceof com.sun.star.uno.Enum + || obj.getClass().isArray(); + } + + // Param object can be an Any or other object. If obj is null then the return value is null + private Object convert( Class cl, Object obj) throws com.sun.star.lang.IllegalArgumentException + { + Object retVal= null; + //The member that keeps the value of the Property is an Object.Objects are similar to Anys in that they can + // hold all types. + if (obj == null || (obj instanceof Any && ((Any) obj).getObject() == null)) + {} + else if(cl.equals(Object.class)) + { + if (obj instanceof Any) + obj= ((Any) obj).getObject(); + retVal= obj; + } + else if(cl.equals(boolean.class)) + retVal= Boolean.valueOf(AnyConverter.toBoolean(obj)); + else if (cl.equals(char.class)) + retVal= new Character(AnyConverter.toChar(obj)); + else if (cl.equals(byte.class)) + retVal= Byte.valueOf(AnyConverter.toByte(obj)); + else if (cl.equals(short.class)) + retVal= Short.valueOf(AnyConverter.toShort(obj)); + else if (cl.equals(int.class)) + retVal= Integer.valueOf(AnyConverter.toInt(obj)); + else if (cl.equals(long.class)) + retVal= Long.valueOf(AnyConverter.toLong(obj)); + else if (cl.equals(float.class)) + retVal= new Float(AnyConverter.toFloat(obj)); + else if (cl.equals(double.class)) + retVal= new Double(AnyConverter.toDouble(obj)); + else if (cl.equals(String.class)) + retVal= AnyConverter.toString(obj); + else if (cl.isArray()) + retVal= AnyConverter.toArray(obj); + else if (cl.equals(Type.class)) + retVal= AnyConverter.toType(obj); + else if (cl.equals(Boolean.class)) + retVal= Boolean.valueOf(AnyConverter.toBoolean(obj)); + else if (cl.equals(Character.class)) + retVal= new Character(AnyConverter.toChar(obj)); + else if (cl.equals(Byte.class)) + retVal= Byte.valueOf(AnyConverter.toByte(obj)); + else if (cl.equals(Short.class)) + retVal= Short.valueOf(AnyConverter.toShort(obj)); + else if (cl.equals(Integer.class)) + retVal= Integer.valueOf(AnyConverter.toInt(obj)); + else if (cl.equals(Long.class)) + retVal= Long.valueOf(AnyConverter.toLong(obj)); + else if (cl.equals(Float.class)) + retVal= new Float(AnyConverter.toFloat(obj)); + else if (cl.equals(Double.class)) + retVal= new Double(AnyConverter.toDouble(obj)); + else if (XInterface.class.isAssignableFrom(cl)) + retVal= AnyConverter.toObject(new Type(cl), obj); + else if (com.sun.star.uno.Enum.class.isAssignableFrom(cl)) + retVal= AnyConverter.toObject(new Type(cl), obj); + else + throw new com.sun.star.lang.IllegalArgumentException("Could not convert the argument"); + return retVal; + } + + /** Sets the value of a property. In this implementation property values are stored in member variables + * (see {@link #convertPropertyValue convertPropertyValue} Notification of property listeners + * does not occur in this method. By overriding this method one can take full control about how property values + * are stored. But then, the {@link #convertPropertyValue convertPropertyValue} and + * {@link #getPropertyValue(Property)} must be overridden too. + * + * A Property with the MAYBEVOID attribute set, is stored as null value. Therefore the member variable must be + * an Object in order to make use of the property attribute. An exception is Any. The Any variable can be initially null, but + * once it is set the reference will not become null again. If the value is to be set to + * void then a new Any will be stored + * with a valid type but without a value (i.e. Any.getObject returns null). + * If a property has the READONLY attribute set, and one of the setter methods, such as setPropertyValue, has been + * called, then this method is not going to be called. + * @param property the property for which the new value is set + * @param newVal the new value for the property. + * @throws com.sun.star.lang.WrappedTargetException An exception, which has to be made known to the caller, + * occurred during the setting of the value. + */ + protected void setPropertyValueNoBroadcast(Property property, Object newVal) + throws WrappedTargetException + { + try + { + // get the member name + String sMember= (String) getPropertyId(property); + if (sMember != null) + { + // use reflection to obtain the field that holds the property value + // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to + // also get inherited fields, but only those which are public. + Field propField= getClass().getDeclaredField(sMember); + if (propField != null) + propField.set(this, newVal); + } + } + catch(java.lang.Exception e) + { + throw new WrappedTargetException(e, "PropertySet.setPropertyValueNoBroadcast", this, e); + } + } + /** Retrieves the value of a property. This implementation presumes that the values are stored in member variables + * of the furthest inheriting class (see {@link #convertPropertyValue convertPropertyValue}) and that the + * variables are public. The property must have + * been registered, for example by {@link #registerProperty(Property, Object)}. The identifier Object argument + * must have been a String which was the name of the member variable holding the property value. + * When properties are to be stored differently one has to override this method as well as + * {@link #convertPropertyValue} and {@link #setPropertyValueNoBroadcast}.
+ * If a value is stored in a variable of a primitive type then this method returns an instance of the respective + * wrapper class (e.g. java.lang.Boolean). + * @param property The property for which the value is to be retrieved. + * @return The value of the property. + */ + protected Object getPropertyValue(Property property) + { + Object ret= null; + try + { + // get the member name + String sMember= (String) getPropertyId(property); + if (sMember != null) + { + // use reflection to obtain the field that holds the property value + // Class.getDeclaredFields does not return inherited fields. One could use Class.getFields to + // also get inherited fields, but only those which are public. + Field propField= getClass().getDeclaredField(sMember); + if (propField != null) + ret= propField.get(this); + } + } + catch(java.lang.NoSuchFieldException e) + { + throw new java.lang.RuntimeException(e); + } + catch(java.lang.IllegalAccessException e) + { + throw new java.lang.RuntimeException(e); + } + return ret; + } + + /** + * This method fires events to XPropertyChangeListener,XVetoableChangeListener and + * XPropertiesChangeListener event sinks. + * To distinguish what listeners are to be called the argument bVetoable is to be set to true if + * a XVetoableChangeListener is meant. For XPropertyChangeListener and XPropertiesChangeListener + * it is to be set to false. + * + * @param properties Properties which will be or have been affected. + * @param newValues the new values of the properties. + * @param oldValues the old values of the properties. + * @param bVetoable true means fire to VetoableChangeListener, false means fire to + * XPropertyChangedListener and XMultiPropertyChangedListener. + * + * @throws PropertyVetoException + * if a vetoable listener throws it. + */ + protected void fire( + Property[] properties, + Object[] newValues, + Object[] oldValues, + boolean bVetoable ) throws PropertyVetoException + { + // Only fire, if one or more properties changed + int nNumProps= properties.length; + if (nNumProps > 0) + { + PropertyChangeEvent[] arEvts= new PropertyChangeEvent[nNumProps]; + int nAffectedProps= 0; + // Loop over all changed properties to fill the event struct + for (int i= 0; i < nNumProps; i++) + { + if ((bVetoable && (properties[i].Attributes & PropertyAttribute.CONSTRAINED) > 0) + || (!bVetoable && (properties[i].Attributes & PropertyAttribute.BOUND) > 0)) + { + arEvts[i]= new PropertyChangeEvent(this, properties[i].Name, false, + properties[i].Handle, oldValues[i], newValues[i]); + nAffectedProps++; + } + } + // fire the events for all changed properties + for (int i= 0; i < nAffectedProps; i++) + { + // get the listener container for the property name + InterfaceContainer lc; + if (bVetoable) + lc= aVetoableLC.getContainer(arEvts[i].PropertyName); + else + lc= aBoundLC.getContainer(arEvts[i].PropertyName); + Iterator it = lc != null ? lc.iterator() : null; + if (it != null) + { + while( it.hasNext()) + { + Object listener= it.next(); + if (bVetoable) + ((XVetoableChangeListener) listener).vetoableChange(arEvts[i]); + else + ((XPropertyChangeListener) listener).propertyChange(arEvts[i]); + } + } + // broadcast to all listeners with "" property name + if(bVetoable) + lc= listenerContainer.getContainer(XVetoableChangeListener.class); + else + lc= listenerContainer.getContainer(XPropertyChangeListener.class); + it = lc != null ? lc.iterator() : null; + if (it != null) + { + while(it.hasNext() ) + { + Object listener= it.next(); + if( bVetoable ) // fire change Events? + ((XVetoableChangeListener) listener).vetoableChange(arEvts[i]); + else + ((XPropertyChangeListener) listener).propertyChange(arEvts[i]); + } + } + } + // fire at XPropertiesChangeListeners + // if nAffectedProps == 0 then there are no BOUND properties + if (!bVetoable && nAffectedProps > 0) + { + + PropertyChangeEvent[] arReduced= new PropertyChangeEvent[nAffectedProps]; + System.arraycopy(arEvts, 0, arReduced, 0, nAffectedProps); + InterfaceContainer lc= listenerContainer.getContainer(XPropertiesChangeListener.class); + Iterator it = lc != null ? lc.iterator() : null; + if (it != null) + { + while (it.hasNext()) + { + XPropertiesChangeListener listener = (XPropertiesChangeListener) it.next(); + // fire the whole event sequence to the XPropertiesChangeListener's + listener.propertiesChange( arEvts ); + } + } + } + } + } + // XFastPropertySet-------------------------------------------------------------------------------- + public void setFastPropertyValue(int nHandle, Object aValue ) throws UnknownPropertyException, + PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + Property prop= getPropertyByHandle(nHandle); + if (prop == null) + throw new UnknownPropertyException(" The property with handle : " + nHandle +" is unknown"); + setPropertyValue(prop, aValue); + } + + // XFastPropertySet -------------------------------------------------------------------------------- + public Object getFastPropertyValue(int nHandle ) throws UnknownPropertyException, + WrappedTargetException + { + Property prop= getPropertyByHandle(nHandle); + if (prop == null) + throw new UnknownPropertyException("The property with handle : " + nHandle + " is unknown"); + return getPropertyValue(prop); + } + + // XMultiPropertySet ----------------------------------------------------------------------------------- + public void addPropertiesChangeListener(String[] propNames, XPropertiesChangeListener listener) + { + listenerContainer.addInterface(XPropertiesChangeListener.class, listener); + } + + // XMultiPropertySet ----------------------------------------------------------------------------------- + public void firePropertiesChangeEvent(String[] propNames, XPropertiesChangeListener listener) + { + // Build the events. + PropertyChangeEvent[] arEvents= new PropertyChangeEvent[propNames.length]; + int eventCount= 0; + // get a snapshot of the current property values + synchronized (this) + { + for (int i= 0; i < propNames.length; i++) + { + Property prop= getProperty(propNames[i]); + if (prop != null) + { + Object value= null; + try + { + value= getPropertyValue(prop); + } + catch(Exception e) + { + continue; + } + arEvents[eventCount]= new PropertyChangeEvent(this, prop.Name, + false, prop.Handle, value, value); + eventCount++; + } + } + } + + // fire events from unsynchronized section so as to prevent deadlocks + if (eventCount > 0) + { + // Reallocate the array of the events if necessary + if (arEvents.length != eventCount) + { + PropertyChangeEvent[] arPropsTmp= new PropertyChangeEvent[eventCount]; + System.arraycopy(arEvents, 0, arPropsTmp, 0, eventCount); + arEvents= arPropsTmp; + } + listener.propertiesChange(arEvents); + } + } + // XMultiPropertySet ----------------------------------------------------------------------------------- + /** If a value for a property could not be retrieved then the respective element in the returned + * array has the value null. + */ + public Object[] getPropertyValues(String[] propNames) + { + Object[] arValues= new Object[propNames.length]; + synchronized (this) + { + for (int i= 0; i < propNames.length; i++) + { + Object value= null; + try + { + value= getPropertyValue(propNames[i]); + } + catch (Exception e) + { + } + arValues[i]= value; + } + } + return arValues; + } + // XMultiPropertySet ----------------------------------------------------------------------------------- + public void removePropertiesChangeListener(XPropertiesChangeListener xPropertiesChangeListener) + { + listenerContainer.removeInterface(XPropertiesChangeListener.class, xPropertiesChangeListener); + } + // XMultiPropertySet ----------------------------------------------------------------------------------- + /** If the array of property names contains an unknown property then it will be ignored. + */ + public void setPropertyValues(String[] propNames, Object[] values) throws PropertyVetoException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException + { + for (int i= 0; i < propNames.length; i++) + { + try + { + setPropertyValue(propNames[i], values[i]); + } + catch (UnknownPropertyException e) + { + continue; + } + + } + } + + private class PropertySetInfo implements XPropertySetInfo + { + public com.sun.star.beans.Property[] getProperties() + { + return PropertySet.this.getProperties(); + } + + public com.sun.star.beans.Property getPropertyByName(String name) throws UnknownPropertyException + { + return getProperty(name); + } + + public boolean hasPropertyByName(String name) + { + return getProperty(name) != null; + } + + } +} + + + + + diff --git a/ridljar/com/sun/star/lib/uno/helper/PropertySetMixin.java b/ridljar/com/sun/star/lib/uno/helper/PropertySetMixin.java new file mode 100644 index 000000000000..0c050d676928 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/PropertySetMixin.java @@ -0,0 +1,1111 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.helper; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyAttribute; +import com.sun.star.beans.PropertyChangeEvent; +import com.sun.star.beans.PropertyState; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XHierarchicalNameAccess; +import com.sun.star.lang.DisposedException; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.WrappedTargetRuntimeException; +import com.sun.star.reflection.XCompoundTypeDescription; +import com.sun.star.reflection.XIdlClass; +import com.sun.star.reflection.XIdlField2; +import com.sun.star.reflection.XIndirectTypeDescription; +import com.sun.star.reflection.XInterfaceAttributeTypeDescription2; +import com.sun.star.reflection.XInterfaceMemberTypeDescription; +import com.sun.star.reflection.XInterfaceTypeDescription2; +import com.sun.star.reflection.XStructTypeDescription; +import com.sun.star.reflection.XTypeDescription; +import com.sun.star.reflection.theCoreReflection; +import com.sun.star.uno.Any; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.Type; +import com.sun.star.uno.TypeClass; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.XInterface; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; + +/** + A helper mixin to implement certain UNO interfaces related to property set + handling on top of the attributes of a given UNO interface type. + +

A client will mix in this class by keeping a reference to an instance of + this class, and forwarding all methods of (a subset of the interfaces) + com.sun.star.beans.XPropertySet, + com.sun.star.beans.XFastPropertySet, and + com.sun.star.beans.XPropertyAccess to it.

+ +

Client code should not use the monitors associated with instances of this + class, as they are used for internal purposes.

+ + @since UDK 3.2 +*/ +public final class PropertySetMixin { + /** + The constructor. + + @param context the component context used by this instance; must not be + null, and must supply the + com.sun.star.reflection.theCoreReflection and + com.sun.star.reflection.theTypeDescriptionManager singletons + + @param object the client UNO object into which this instance is mixed in; + must not be null, and must support the given type + + @param type the UNO interface type whose attributes are mapped to + properties; must not be null, and must represent a UNO interface type + + @param absentOptional a list of optional properties that are not present, + and should thus not be visible via + com.sun.star.beans.XPropertySet.getPropertySetInfo, + com.sun.star.beans.XPropertySet.addPropertyChangeListener, + com.sun.star.beans.XPropertySet.removePropertyChangeListener, + com.sun.star.beans.XPropertySet.addVetoableChangeListener, + and com.sun.star.beans.XPropertySet.removeVetoableChangeListener; null is treated the same as an + empty list; if non-null, the given array must not be modified after it is + passed to this constructor. For consistency reasons, the given + absentOptional should only contain the names of attributes + that represent optional properties that are not present (that is, the + attribute getters and setters always throw a + com.sun.star.beans.UnknownPropertyException), and should + contain each such name only once. If an optional property is not present + (that is, the corresponding attribute getter and setter always throw a + com.sun.star.beans.UnknownPropertyException) but is not + contained in the given absentOptional, then it will be + visible via + com.sun.star.beans.XPropertySet.getPropertySetInfo as a + com.sun.star.beans.Property with a set + com.sun.star.beans.PropertyAttribute.OPTIONAL. If the given + object does not implement + com.sun.star.beans.XPropertySet, then the given + absentOptional is effectively ignored and can be null or + empty. + */ + public PropertySetMixin( + XComponentContext context, XInterface object, Type type, + String[] absentOptional) + { + this.context = context; + this.object = object; + this.type = type; + this.absentOptional = absentOptional; + idlClass = getReflection(type.getTypeName()); + XTypeDescription ifc; + try { + XHierarchicalNameAccess xhna = UnoRuntime.queryInterface( + XHierarchicalNameAccess.class, + context.getValueByName( + "/singletons/com.sun.star.reflection." + + "theTypeDescriptionManager")); + ifc = UnoRuntime.queryInterface( + XTypeDescription.class, + xhna.getByHierarchicalName(type.getTypeName())); + } catch (NoSuchElementException e) { + throw new RuntimeException(e); + } + HashMap map = new HashMap(); + ArrayList handleNames = new ArrayList(); + initProperties(ifc, map, handleNames, new HashSet()); + properties = map; + handleMap = handleNames.toArray(new String[handleNames.size()]); + } + + /** + A method used by clients when implementing UNO interface type attribute + setter functions. + +

First, this method checks whether this instance has already been + disposed (see {@link #dispose}), and throws a + com.sun.star.beans.DisposedException if applicable. For a + constrained attribute (whose setter can explicitly raise + com.sun.star.beans.PropertyVetoException), this method + notifies any com.sun.star.beans.XVetoableChangeListeners. + For a bound attribute, this method modifies the passed-in + bound so that it can afterwards be used to notify any + com.sun.star.beans.XPropertyChangeListeners. This method + should be called before storing the new attribute value, and + bound.notifyListeners() should be called exactly once after + storing the new attribute value (in case the attribute is bound; + otherwise, calling bound.notifyListeners() is ignored). + Furthermore, bound.notifyListeners() and this method have to + be called from the same thread.

+ + @param propertyName the name of the property (which is the same as the + name of the attribute that is going to be set) + + @param oldValue the property value corresponding to the old attribute + value. This is only used as + com.sun.star.beans.PropertyChangeEvent.OldValue, which is + rather useless, anyway (see “Using the Observer Pattern” in + + OpenOffice.org Coding Guidelines). If the attribute + that is going to be set is neither bound nor constrained, or if + com.sun.star.beans.PropertyChangeEvent.OldValue should not + be set, {@link Any#VOID} can be used instead. + + @param newValue the property value corresponding to the new + attribute value. This is only used as + com.sun.star.beans.PropertyChangeEvent.NewValue, which is + rather useless, anyway (see “Using the Observer Pattern” in + + OpenOffice.org Coding Guidelines), unless the + attribute that is going to be set is constrained. If the attribute + that is going to be set is neither bound nor constrained, or if it is + only bound but + com.sun.star.beans.PropertyChangeEvent.NewValue should not + be set, {@link Any#VOID} can be used instead. + + @param bound a reference to a fresh {@link BoundListeners} instance + (which has not been passed to this method before, and on which + {@link BoundListeners#notifyListeners} has not yet been called); may only + be null if the attribute that is going to be set is not bound + + @throws PropertyVetoException if a vetoable listener throws it. + */ + public void prepareSet( + String propertyName, Object oldValue, Object newValue, + BoundListeners bound) + throws PropertyVetoException + { + // assert properties.get(propertyName) != null; + Property p = properties.get(propertyName).property; + ArrayList specificVeto = null; + ArrayList unspecificVeto = null; + synchronized (this) { + if (disposed) { + throw new DisposedException("disposed", object); + } + if ((p.Attributes & PropertyAttribute.CONSTRAINED) != 0) { + ArrayList o = vetoListeners.get(propertyName); + if (o != null) { + specificVeto = new ArrayList(o); + } + o = vetoListeners.get(""); + if (o != null) { + unspecificVeto = new ArrayList(o); + } + } + if ((p.Attributes & PropertyAttribute.BOUND) != 0) { + // assert bound != null; + ArrayList o = boundListeners.get(propertyName); + if (o != null) { + bound.specificListeners = new ArrayList(o); + } + o = boundListeners.get(""); + if (o != null) { + bound.unspecificListeners = new ArrayList(o); + } + } + } + if ((p.Attributes & PropertyAttribute.CONSTRAINED) != 0) { + PropertyChangeEvent event = new PropertyChangeEvent( + object, propertyName, false, p.Handle, oldValue, newValue); + if (specificVeto != null) { + for (Iterator i = specificVeto.iterator(); i.hasNext();) { + try { + i.next().vetoableChange(event); + } catch (DisposedException e) {} + } + } + if (unspecificVeto != null) { + for (Iterator i = unspecificVeto.iterator(); i.hasNext();) { + try { + i.next().vetoableChange(event); + } catch (DisposedException e) {} + } + } + } + if ((p.Attributes & PropertyAttribute.BOUND) != 0) { + // assert bound != null; + bound.event = new PropertyChangeEvent( + object, propertyName, false, p.Handle, oldValue, newValue); + } + } + + /** + A simplified version of {@link #prepareSet(String, Object, Object, + PropertySetMixin.BoundListeners)}. + +

This method is useful for attributes that are not constrained.

+ + @param propertyName the name of the property (which is the same as the + name of the attribute that is going to be set) + + @param bound a reference to a fresh {@link BoundListeners} instance + (which has not been passed to this method before, and on which + {@link BoundListeners#notifyListeners} has not yet been called); may only + be null if the attribute that is going to be set is not bound + */ + public void prepareSet(String propertyName, BoundListeners bound) { + try { + prepareSet(propertyName, Any.VOID, Any.VOID, bound); + } catch (PropertyVetoException e) { + throw new RuntimeException("unexpected " + e); + } + } + + /** + Marks this instance as being disposed. + +

See com.sun.star.lang.XComponent for the general concept + of disposing UNO objects. On the first call to this method, all + registered listeners + (com.sun.star.beans.XPropertyChangeListeners and + com.sun.star.beans.XVetoableChangeListeners) are notified of + the disposing source. Any subsequent calls to this method are + ignored.

+ */ + public void dispose() { + HashMap> bound; + HashMap> veto; + synchronized (this) { + bound = boundListeners; + boundListeners = null; + veto = vetoListeners; + vetoListeners = null; + disposed = true; + } + EventObject event = new EventObject(object); + if (bound != null) { + for (Iterator> i = bound.values().iterator(); i.hasNext();) { + for (Iterator j = i.next().iterator(); j.hasNext();) + { + j.next().disposing(event); + } + } + } + if (veto != null) { + for (Iterator> i = veto.values().iterator(); i.hasNext();) { + for (Iterator j = i.next().iterator(); j.hasNext();) + { + j.next().disposing(event); + } + } + } + } + + /** + Implements + com.sun.star.beans.XPropertySet.getPropertySetInfo. + @return See com.sun.star.beans.XPropertySet + */ + public XPropertySetInfo getPropertySetInfo() { + return new Info(properties); + } + + /** + Implements com.sun.star.beans.XPropertySet.setPropertyValue. + @param propertyName + See com.sun.star.beans.XPropertySet + @param value + See com.sun.star.beans.XPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XPropertySet + @throws PropertyVetoException + See com.sun.star.beans.XPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XPropertySet + */ + public void setPropertyValue(String propertyName, Object value) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + setProperty(propertyName, value, false, false, (short) 1); + } + + /** + Implements com.sun.star.beans.XPropertySet.getPropertyValue. + @param propertyName + See com.sun.star.beans.XPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XPropertySet + @return + See com.sun.star.beans.XPropertySet + */ + public Object getPropertyValue(String propertyName) + throws UnknownPropertyException, WrappedTargetException + { + return getProperty(propertyName, null); + } + + /** + Implements + com.sun.star.beans.XPropertySet.addPropertyChangeListener. + +

If a listener is added more than once, it will receive all relevant + notifications multiple times.

+ + @param propertyName + See com.sun.star.beans.XPropertySet + @param listener + See com.sun.star.beans.XPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XPropertySet + */ + public void addPropertyChangeListener( + String propertyName, XPropertyChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + // assert listener != null; + checkUnknown(propertyName); + boolean disp; + synchronized (this) { + disp = disposed; + if (!disp) { + ArrayList v = boundListeners.get(propertyName); + if (v == null) { + v = new ArrayList(); + boundListeners.put(propertyName, v); + } + v.add(listener); + } + } + if (disp) { + listener.disposing(new EventObject(object)); + } + } + + /** + Implements + com.sun.star.beans.XPropertySet.removePropertyChangeListener. + + @param propertyName + See com.sun.star.beans.XPropertySet + @param listener + See com.sun.star.beans.XPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XPropertySet + */ + public void removePropertyChangeListener( + String propertyName, XPropertyChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + // assert listener != null; + checkUnknown(propertyName); + synchronized (this) { + if (boundListeners != null) { + ArrayList v = boundListeners.get(propertyName); + if (v != null) { + v.remove(listener); + } + } + } + } + + /** + Implements + com.sun.star.beans.XPropertySet.addVetoableChangeListener. + +

If a listener is added more than once, it will receive all relevant + notifications multiple times.

+ + @param propertyName + See com.sun.star.beans.XPropertySet + @param listener + See com.sun.star.beans.XPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XPropertySet + */ + public void addVetoableChangeListener( + String propertyName, XVetoableChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + // assert listener != null; + checkUnknown(propertyName); + boolean disp; + synchronized (this) { + disp = disposed; + if (!disp) { + ArrayList v = vetoListeners.get(propertyName); + if (v == null) { + v = new ArrayList(); + vetoListeners.put(propertyName, v); + } + v.add(listener); + } + } + if (disp) { + listener.disposing(new EventObject(object)); + } + } + + /** + Implements + com.sun.star.beans.XPropertySet.removeVetoableChangeListener. + + @param propertyName + See com.sun.star.beans.XPropertySet + @param listener + See com.sun.star.beans.XPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XPropertySet + */ + public void removeVetoableChangeListener( + String propertyName, XVetoableChangeListener listener) + throws UnknownPropertyException, WrappedTargetException + { + // assert listener != null; + checkUnknown(propertyName); + synchronized (this) { + if (vetoListeners != null) { + ArrayList v = vetoListeners.get(propertyName); + if (v != null) { + v.remove(listener); + } + } + } + } + + /** + Implements + com.sun.star.beans.XFastPropertySet.setFastPropertyValue. + + @param handle + See com.sun.star.beans.XFastPropertySet + @param value + See com.sun.star.beans.XFastPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XFastPropertySet + @throws PropertyVetoException + See com.sun.star.beans.XFastPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XFastPropertySet + */ + public void setFastPropertyValue(int handle, Object value) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + setProperty(translateHandle(handle), value, false, false, (short) 1); + } + + /** + Implements + com.sun.star.beans.XFastPropertySet.getFastPropertyValue. + + @param handle + See com.sun.star.beans.XFastPropertySet + @throws UnknownPropertyException + See com.sun.star.beans.XFastPropertySet + @throws WrappedTargetException + See com.sun.star.beans.XFastPropertySet + @return + See com.sun.star.beans.XFastPropertySet + */ + public Object getFastPropertyValue(int handle) + throws UnknownPropertyException, WrappedTargetException + { + return getProperty(translateHandle(handle), null); + } + + /** + Implements + com.sun.star.beans.XPropertyAccess.getPropertyValues. + + @return + See com.sun.star.beans.XPropertyAccess + */ + public PropertyValue[] getPropertyValues() { + PropertyValue[] s = new PropertyValue[handleMap.length]; + int n = 0; + for (int i = 0; i < handleMap.length; ++i) { + PropertyState[] state = new PropertyState[1]; + Object value; + try { + value = getProperty(handleMap[i], state); + } catch (UnknownPropertyException e) { + continue; + } catch (WrappedTargetException e) { + throw new WrappedTargetRuntimeException(e.getCause(), + e.getMessage(), object, e.TargetException); + } + s[n++] = new PropertyValue(handleMap[i], i, value, state[0]); + } + if (n < handleMap.length) { + PropertyValue[] s2 = new PropertyValue[n]; + System.arraycopy(s, 0, s2, 0, n); + s = s2; + } + return s; + } + + /** + Implements + com.sun.star.beans.XPropertyAccess.setPropertyValues. + + @param props + See com.sun.star.beans.XPropertyAccess + @throws UnknownPropertyException + See com.sun.star.beans.XPropertyAccess + @throws PropertyVetoException + See com.sun.star.beans.XPropertyAccess + @throws WrappedTargetException + See com.sun.star.beans.XPropertyAccess + */ + public void setPropertyValues(PropertyValue[] props) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + for (int i = 0; i < props.length; ++i) { + if (props[i].Handle != -1 + && !props[i].Name.equals(translateHandle(props[i].Handle))) + { + throw new UnknownPropertyException( + ("name " + props[i].Name + " does not match handle " + + props[i].Handle), + object); + } + setProperty( + props[i].Name, props[i].Value, + props[i].State == PropertyState.AMBIGUOUS_VALUE, + props[i].State == PropertyState.DEFAULT_VALUE, (short) 0); + } + } + + /** + A class used by clients of {@link PropertySetMixin} when implementing UNO + interface type attribute setter functions. + + @see #prepareSet(String, Object, Object, PropertySetMixin.BoundListeners) + */ + public static final class BoundListeners { + + /** + Notifies any + com.sun.star.beans.XPropertyChangeListeners. + + @see #prepareSet(String, Object, Object, + PropertySetMixin.BoundListeners) + */ + public void notifyListeners() { + if (specificListeners != null) { + for (Iterator i = specificListeners.iterator(); i.hasNext();) { + try { + i.next().propertyChange(event); + } catch (DisposedException e) {} + } + } + if (unspecificListeners != null) { + for (Iterator i = unspecificListeners.iterator(); i.hasNext();) + { + try { + i.next().propertyChange(event); + } catch (DisposedException e) {} + } + } + } + + private ArrayList specificListeners = null; + private ArrayList unspecificListeners = null; + private PropertyChangeEvent event = null; + } + + private XIdlClass getReflection(String typeName) { + return theCoreReflection.get(context).forName(typeName); + } + + private void initProperties( + XTypeDescription type, HashMap map, ArrayList handleNames, HashSet seen) + { + XInterfaceTypeDescription2 ifc = UnoRuntime.queryInterface( + XInterfaceTypeDescription2.class, resolveTypedefs(type)); + if (!seen.add(ifc.getName())) { + return; + } + XTypeDescription[] bases = ifc.getBaseTypes(); + for (int i = 0; i < bases.length; ++i) { + initProperties(bases[i], map, handleNames, seen); + } + XInterfaceMemberTypeDescription[] members = ifc.getMembers(); + for (int i = 0; i < members.length; ++i) { + if (members[i].getTypeClass() == TypeClass.INTERFACE_ATTRIBUTE) + { + XInterfaceAttributeTypeDescription2 attr = + UnoRuntime.queryInterface( + XInterfaceAttributeTypeDescription2.class, + members[i]); + short attrAttribs = 0; + if (attr.isBound()) { + attrAttribs |= PropertyAttribute.BOUND; + } + boolean setUnknown = false; + if (attr.isReadOnly()) { + attrAttribs |= PropertyAttribute.READONLY; + setUnknown = true; + } + XCompoundTypeDescription[] excs = attr.getGetExceptions(); + boolean getUnknown = false; + //XXX Special interpretation of getter/setter exceptions + // only works if the specified exceptions are of the exact + // type, not of a supertype: + for (int j = 0; j < excs.length; ++j) { + if (excs[j].getName().equals( + "com.sun.star.beans.UnknownPropertyException")) + { + getUnknown = true; + break; + } + } + excs = attr.getSetExceptions(); + for (int j = 0; j < excs.length; ++j) { + if (excs[j].getName().equals( + "com.sun.star.beans.UnknownPropertyException")) + { + setUnknown = true; + } else if (excs[j].getName().equals( + "com.sun.star.beans." + + "PropertyVetoException")) + { + attrAttribs |= PropertyAttribute.CONSTRAINED; + } + } + if (getUnknown && setUnknown) { + attrAttribs |= PropertyAttribute.OPTIONAL; + } + XTypeDescription t = attr.getType(); + for (;;) { + t = resolveTypedefs(t); + short n; + if (t.getName().startsWith( + "com.sun.star.beans.Ambiguous<")) + { + n = PropertyAttribute.MAYBEAMBIGUOUS; + } else if (t.getName().startsWith( + "com.sun.star.beans.Defaulted<")) + { + n = PropertyAttribute.MAYBEDEFAULT; + } else if (t.getName().startsWith( + "com.sun.star.beans.Optional<")) + { + n = PropertyAttribute.MAYBEVOID; + } else { + break; + } + attrAttribs |= n; + t = UnoRuntime.queryInterface(XStructTypeDescription.class, t).getTypeArguments()[0]; + } + String name = members[i].getMemberName(); + boolean present = true; + if (absentOptional != null) { + for (int j = 0; j < absentOptional.length; ++j) { + if (name.equals(absentOptional[j])) { + present = false; + break; + } + } + } + if (map.put( + name, + new PropertyData( + new Property( + name, handleNames.size(), + new Type(t.getName(), t.getTypeClass()), + attrAttribs), + present)) + != null) + { + throw new RuntimeException( + "inconsistent UNO type registry"); + } + handleNames.add(name); + } + } + } + + private String translateHandle(int handle) throws UnknownPropertyException { + if (handle < 0 || handle >= handleMap.length) { + throw new UnknownPropertyException("bad handle " + handle, object); + } + return handleMap[handle]; + } + + private void setProperty( + String name, Object value, boolean isAmbiguous, boolean isDefaulted, + short illegalArgumentPosition) + throws UnknownPropertyException, PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, WrappedTargetException + { + PropertyData p = properties.get(name); + if (p == null) { + throw new UnknownPropertyException(name, object); + } + if ((isAmbiguous + && (p.property.Attributes & PropertyAttribute.MAYBEAMBIGUOUS) == 0) + || (isDefaulted + && ((p.property.Attributes & PropertyAttribute.MAYBEDEFAULT) + == 0))) + { + throw new com.sun.star.lang.IllegalArgumentException( + ("flagging as ambiguous/defaulted non-ambiguous/defaulted" + + " property " + name), + object, illegalArgumentPosition); + + } + XIdlField2 f = UnoRuntime.queryInterface( + XIdlField2.class, idlClass.getField(name)); + Object[] o = new Object[] { + new Any(type, UnoRuntime.queryInterface(type, object)) }; + Object v = wrapValue( + value, + UnoRuntime.queryInterface( + XIdlField2.class, idlClass.getField(name)).getType(), + (p.property.Attributes & PropertyAttribute.MAYBEAMBIGUOUS) != 0, + isAmbiguous, + (p.property.Attributes & PropertyAttribute.MAYBEDEFAULT) != 0, + isDefaulted, + (p.property.Attributes & PropertyAttribute.MAYBEVOID) != 0); + try { + f.set(o, v); + } catch (com.sun.star.lang.IllegalArgumentException e) { + if (e.ArgumentPosition == 1) { + throw new com.sun.star.lang.IllegalArgumentException(e, + e.getMessage(), object, illegalArgumentPosition); + } else { + throw new RuntimeException(e); + } + } catch (com.sun.star.lang.IllegalAccessException e) { + //TODO Clarify whether PropertyVetoException is the correct + // exception to throw when trying to set a read-only property: + throw new PropertyVetoException(e, + "cannot set read-only property " + name, object); + } catch (WrappedTargetRuntimeException e) { + //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not + // guaranteed to originate directly within XIdlField2.get (and thus + // have the expected semantics); it might also be passed through + // from lower layers. + if (new Type(UnknownPropertyException.class).isSupertypeOf( + AnyConverter.getType(e.TargetException)) + && (p.property.Attributes & PropertyAttribute.OPTIONAL) != 0) + { + throw new UnknownPropertyException(e, name, object); + } else if (new Type(PropertyVetoException.class).isSupertypeOf( + AnyConverter.getType(e.TargetException)) + && ((p.property.Attributes + & PropertyAttribute.CONSTRAINED) + != 0)) + { + throw new PropertyVetoException(e, name, object); + } else { + throw new WrappedTargetException(e.getCause(), + e.getMessage(), object, e.TargetException); + } + } + } + + Object getProperty(String name, PropertyState[] state) + throws UnknownPropertyException, WrappedTargetException + { + PropertyData p = properties.get(name); + if (p == null) { + throw new UnknownPropertyException(name, object); + } + XIdlField2 field = UnoRuntime.queryInterface( + XIdlField2.class, idlClass.getField(name)); + Object value; + try { + value = field.get( + new Any(type, UnoRuntime.queryInterface(type, object))); + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (WrappedTargetRuntimeException e) { + //FIXME A WrappedTargetRuntimeException from XIdlField2.get is not + // guaranteed to originate directly within XIdlField2.get (and thus + // have the expected semantics); it might also be passed through + // from lower layers. + if (new Type(UnknownPropertyException.class).isSupertypeOf( + AnyConverter.getType(e.TargetException)) + && (p.property.Attributes & PropertyAttribute.OPTIONAL) != 0) + { + throw new UnknownPropertyException(e, name, object); + } else { + throw new WrappedTargetException(e.getCause(), + e.getMessage(), object, e.TargetException); + } + } + boolean undoAmbiguous + = (p.property.Attributes & PropertyAttribute.MAYBEAMBIGUOUS) != 0; + boolean undoDefaulted + = (p.property.Attributes & PropertyAttribute.MAYBEDEFAULT) != 0; + boolean undoOptional + = (p.property.Attributes & PropertyAttribute.MAYBEVOID) != 0; + boolean isAmbiguous = false; + boolean isDefaulted = false; + while (undoAmbiguous || undoDefaulted || undoOptional) { + String typeName = AnyConverter.getType(value).getTypeName(); + if (undoAmbiguous + && typeName.startsWith("com.sun.star.beans.Ambiguous<")) + { + XIdlClass ambiguous = getReflection(typeName); + try { + isAmbiguous = AnyConverter.toBoolean( + UnoRuntime.queryInterface( + XIdlField2.class, + ambiguous.getField("IsAmbiguous")).get(value)); + value = UnoRuntime.queryInterface( + XIdlField2.class, + ambiguous.getField("Value")).get(value); + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } + undoAmbiguous = false; + } else if (undoDefaulted + && typeName.startsWith("com.sun.star.beans.Defaulted<")) + { + XIdlClass defaulted = getReflection(typeName); + try { + isDefaulted = AnyConverter.toBoolean( + UnoRuntime.queryInterface( + XIdlField2.class, + defaulted.getField("IsDefaulted")).get(value)); + value = UnoRuntime.queryInterface( + XIdlField2.class, + defaulted.getField("Value")).get(value); + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } + undoDefaulted = false; + } else if (undoOptional + && typeName.startsWith("com.sun.star.beans.Optional<")) + { + XIdlClass optional = getReflection(typeName); + try { + boolean present = AnyConverter.toBoolean( + UnoRuntime.queryInterface( + XIdlField2.class, + optional.getField("IsPresent")).get(value)); + if (!present) { + value = Any.VOID; + break; + } + value = UnoRuntime.queryInterface( + XIdlField2.class, + optional.getField("Value")).get(value); + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } + undoOptional = false; + } else { + throw new RuntimeException( + "unexpected type of attribute " + name); + } + } + if (state != null) { + //XXX If isAmbiguous && isDefaulted, arbitrarily choose + // AMBIGUOUS_VALUE over DEFAULT_VALUE: + state[0] = isAmbiguous + ? PropertyState.AMBIGUOUS_VALUE + : isDefaulted + ? PropertyState.DEFAULT_VALUE : PropertyState.DIRECT_VALUE; + } + return value; + } + + private Object wrapValue( + Object value, XIdlClass type, boolean wrapAmbiguous, + boolean isAmbiguous, boolean wrapDefaulted, boolean isDefaulted, + boolean wrapOptional) + { + if (wrapAmbiguous + && type.getName().startsWith("com.sun.star.beans.Ambiguous<")) + { + Object[] strct = new Object[1]; + type.createObject(strct); + try { + XIdlField2 field = UnoRuntime.queryInterface( + XIdlField2.class, type.getField("Value")); + field.set( + strct, + wrapValue( + value, field.getType(), false, false, wrapDefaulted, + isDefaulted, wrapOptional)); + UnoRuntime.queryInterface( + XIdlField2.class, type.getField("IsAmbiguous")).set( + strct, Boolean.valueOf(isAmbiguous)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (com.sun.star.lang.IllegalAccessException e) { + throw new RuntimeException(e); + } + return strct[0]; + } else if (wrapDefaulted + && type.getName().startsWith( + "com.sun.star.beans.Defaulted<")) + { + Object[] strct = new Object[1]; + type.createObject(strct); + try { + XIdlField2 field = UnoRuntime.queryInterface( + XIdlField2.class, type.getField("Value")); + field.set( + strct, + wrapValue( + value, field.getType(), wrapAmbiguous, isAmbiguous, + false, false, wrapOptional)); + UnoRuntime.queryInterface( + XIdlField2.class, type.getField("IsDefaulted")).set( + strct, Boolean.valueOf(isDefaulted)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (com.sun.star.lang.IllegalAccessException e) { + throw new RuntimeException(e); + } + return strct[0]; + } else if (wrapOptional + && type.getName().startsWith("com.sun.star.beans.Optional<")) + { + Object[] strct = new Object[1]; + type.createObject(strct); + boolean present = !AnyConverter.isVoid(value); + try { + UnoRuntime.queryInterface( + XIdlField2.class, type.getField("IsPresent")).set( + strct, Boolean.valueOf(present)); + if (present) { + XIdlField2 field = UnoRuntime.queryInterface( + XIdlField2.class, type.getField("Value")); + field.set( + strct, + wrapValue( + value, field.getType(), wrapAmbiguous, isAmbiguous, + wrapDefaulted, isDefaulted, false)); + } + } catch (com.sun.star.lang.IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (com.sun.star.lang.IllegalAccessException e) { + throw new RuntimeException(e); + } + return strct[0]; + } else { + if (wrapAmbiguous || wrapDefaulted || wrapOptional) { + throw new RuntimeException("unexpected type of attribute"); + } + return value; + } + } + + private static XTypeDescription resolveTypedefs(XTypeDescription type) { + while (type.getTypeClass() == TypeClass.TYPEDEF) { + type = UnoRuntime.queryInterface( + XIndirectTypeDescription.class, type).getReferencedType(); + } + return type; + } + + private PropertyData get(Object object, String propertyName) + throws UnknownPropertyException + { + PropertyData p = properties.get(propertyName); + if (p == null || !p.present) { + throw new UnknownPropertyException(propertyName, object); + } + return p; + } + + private void checkUnknown(String propertyName) + throws UnknownPropertyException + { + if (propertyName.length() != 0) { + get(this, propertyName); + } + } + + private static final class PropertyData { + public PropertyData(Property property, boolean present) { + this.property = property; + this.present = present; + } + + public final Property property; + public final boolean present; + } + + private final class Info extends WeakBase implements XPropertySetInfo + { + public Info(Map properties) { + this.properties = properties; + } + + public Property[] getProperties() { + ArrayList al = new ArrayList(properties.size()); + for (Iterator i = properties.values().iterator(); i.hasNext();) { + PropertyData p = i.next(); + if (p.present) { + al.add(p.property); + } + } + return al.toArray(new Property[al.size()]); + } + + public Property getPropertyByName(String name) + throws UnknownPropertyException + { + return get(this, name).property; + } + + public boolean hasPropertyByName(String name) { + PropertyData p = properties.get(name); + return p != null && p.present; + } + + private final Map properties; + } + + private final XComponentContext context; + private final XInterface object; + private final Type type; + private final String[] absentOptional; + private final XIdlClass idlClass; + private final Map properties; // from String to Property + private final String[] handleMap; + + private HashMap> boundListeners + = new HashMap>(); + // from String to Vector of XPropertyChangeListener + private HashMap> vetoListeners + = new HashMap>(); + // from String to Vector of XVetoableChangeListener + private boolean disposed = false; +} diff --git a/ridljar/com/sun/star/lib/uno/helper/UnoUrl.java b/ridljar/com/sun/star/lib/uno/helper/UnoUrl.java new file mode 100644 index 000000000000..8bb4d26432d9 --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/UnoUrl.java @@ -0,0 +1,401 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.helper; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.util.HashMap; + +/** + * Object representation and parsing of Uno Urls, + * which allow to locate a named Uno object in a + * different process. A Uno Url consists of the + * specification of a connection, protocol and + * rootOid delimited with a ';'. + * The syntax of a Uno Url is + * + * + * [uno:]connection-type,parameters;protocol-name,parameters;objectname"; + * + * + * An example Uno Url will look like this: + * + * + * socket,host=localhost,port=2002;urp;StarOffice.ServiceManager + * + * + * For more information about Uno Url please consult + * + * http://udk.openoffice.org/common/man/spec/uno-url.html + * + * Usage: + * + * + * UnoUrl url = UnoUrl.parseUnoUrl("socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"); + * + */ +public class UnoUrl { + + private static final String FORMAT_ERROR = + "syntax: [uno:]connection-type,parameters;protocol-name,parameters;objectname"; + + private static final String VALUE_CHAR_SET = "!$&'()*+-./:?@_~"; + private static final String OID_CHAR_SET = VALUE_CHAR_SET + ",="; + + private final UnoUrlPart connection; + private final UnoUrlPart protocol; + private final String rootOid; + + private static class UnoUrlPart { + + private final String partTypeName; + private final HashMap partParameters; + private final String uninterpretedParameterString; + + public UnoUrlPart( + String uninterpretedParameterString, + String partTypeName, + HashMap partParameters) { + this.uninterpretedParameterString = uninterpretedParameterString; + this.partTypeName = partTypeName; + this.partParameters = partParameters; + } + + public String getPartTypeName() { + return partTypeName; + } + + public HashMap getPartParameters() { + return partParameters; + } + + public String getUninterpretedParameterString() { + return uninterpretedParameterString; + } + + public String getUninterpretedString() { + StringBuffer buf = new StringBuffer(partTypeName); + if (uninterpretedParameterString.length() > 0) { + buf.append(','); + buf.append(uninterpretedParameterString); + } + return buf.toString(); + } + } + + private UnoUrl( + UnoUrlPart connectionPart, + UnoUrlPart protocolPart, + String rootOid) { + this.connection = connectionPart; + this.protocol = protocolPart; + this.rootOid = rootOid; + } + + /** + * Returns the name of the connection of this + * Uno Url. Encoded characters are not allowed. + * + * @return The connection name as string. + */ + public String getConnection() { + return connection.getPartTypeName(); + } + + /** + * Returns the name of the protocol of this + * Uno Url. Encoded characters are not allowed. + * + * @return The protocol name as string. + */ + public String getProtocol() { + return protocol.getPartTypeName(); + } + + /** + * Return the object name. Encoded character are + * not allowed. + * + * @return The object name as String. + */ + public String getRootOid() { + return rootOid; + } + + /** + * Returns the protocol parameters as + * a Hashmap with key/value pairs. Encoded + * characters like '%41' are decoded. + * + * @return a HashMap with key/value pairs for protocol parameters. + */ + public HashMap getProtocolParameters() { + return protocol.getPartParameters(); + } + + /** + * Returns the connection parameters as + * a Hashmap with key/value pairs. Encoded + * characters like '%41' are decoded. + * + * @return a HashMap with key/value pairs for connection parameters. + */ + public HashMap getConnectionParameters() { + return connection.getPartParameters(); + } + + /** + * Returns the raw specification of the protocol + * parameters. Encoded characters like '%41' are + * not decoded. + * + * @return The uninterpreted protocol parameters as string. + */ + public String getProtocolParametersAsString() { + return protocol.getUninterpretedParameterString(); + } + + /** + * Returns the raw specification of the connection + * parameters. Encoded characters like '%41' are + * not decoded. + * + * @return The uninterpreted connection parameters as string. + */ + public String getConnectionParametersAsString() { + return connection.getUninterpretedParameterString(); + } + + /** + * Returns the raw specification of the protocol + * name and parameters. Encoded characters like '%41' are + * not decoded. + * + * @return The uninterpreted protocol name and parameters as string. + */ + public String getProtocolAndParametersAsString() { + return protocol.getUninterpretedString(); + } + + /** + * Returns the raw specification of the connection + * name and parameters. Encoded characters like '%41' are + * not decoded. + * + * @return The uninterpreted connection name and parameters as string. + */ + public String getConnectionAndParametersAsString() { + return connection.getUninterpretedString(); + } + + private static String decodeUTF8(String s) + throws com.sun.star.lang.IllegalArgumentException { + + if (!s.contains("%")) { + return s; + } + try { + int length = s.length(); + ByteBuffer bb = ByteBuffer.allocate(length); + for (int i = 0; i < length; i++) { + int ch = s.charAt(i); + + if (ch == '%') { + if (i+3 > length) + throw new com.sun.star.lang.IllegalArgumentException( + "Incomplete trailing escape (%) pattern"); + try { + ch = Integer.parseInt(s.substring(i+1,i+3),16); + } catch (NumberFormatException e) { + throw new com.sun.star.lang.IllegalArgumentException(e); + } + if (ch < 0) + throw new com.sun.star.lang.IllegalArgumentException( + "Illegal hex characters in escape (%) pattern - negative value"); + i+=2; + } + + bb.put((byte) (ch & 0xFF)); + } + + byte[] bytes = new byte[bb.position()]; + System.arraycopy(bb.array(), 0, bytes, 0, bytes.length); + return new String(bytes, "UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new com.sun.star.lang.IllegalArgumentException(e, + "Couldn't convert parameter string to UTF-8 string"); + } + } + + private static HashMap buildParamHashMap(String paramString) + throws com.sun.star.lang.IllegalArgumentException { + HashMap params = new HashMap(); + + int pos = 0; + + while (true) { + char c = ','; + + StringBuffer sb = new StringBuffer(); + while ((pos < paramString.length()) + && ((c = paramString.charAt(pos++)) != '=')) { + sb.append(c); + } + String aKey = sb.toString(); + + sb = new StringBuffer(); + while ((pos < paramString.length()) + && ((c = paramString.charAt(pos++)) != ',') + && c != ';') { + sb.append(c); + } + String aValue = sb.toString(); + + if ((aKey.length() > 0) && (aValue.length() > 0)) { + + if (!isAlphaNumeric(aKey)) { + throw new com.sun.star.lang.IllegalArgumentException( + "The parameter key '" + + aKey + + "' may only consist of alpha numeric ASCII characters."); + } + + if (!isValidString(aValue, VALUE_CHAR_SET + "%")) { + throw new com.sun.star.lang.IllegalArgumentException( + "The parameter value for key '" + aKey + "' contains illegal characters."); + } + + params.put(aKey, decodeUTF8(aValue)); + } + + if ((pos >= paramString.length()) || (c != ',')) + break; + + } + + return params; + } + + private static UnoUrlPart parseUnoUrlPart(String thePart) + throws com.sun.star.lang.IllegalArgumentException { + String partName; + String theParamPart; + int index = thePart.indexOf(','); + if (index != -1) { + partName = thePart.substring(0, index).trim(); + theParamPart = thePart.substring(index + 1).trim(); + } else { + partName = thePart; + theParamPart = ""; + } + + if (!isAlphaNumeric(partName)) { + throw new com.sun.star.lang.IllegalArgumentException( + "The part name '" + + partName + + "' may only consist of alpha numeric ASCII characters."); + } + + HashMap params = buildParamHashMap(theParamPart); + + return new UnoUrlPart(theParamPart, partName, params); + } + + private static boolean isAlphaNumeric(String s) { + return isValidString(s, null); + } + + private static boolean isValidString(String identifier, String validCharSet) { + + int len = identifier.length(); + + for (int i = 0; i < len; i++) { + + int ch = identifier.charAt(i); + + boolean isValidChar = + ('A' <= ch && ch <= 'Z') + || ('a' <= ch && ch <= 'z') + || ('0' <= ch && ch <= '9'); + + if (!isValidChar && (validCharSet != null)) { + isValidChar = (validCharSet.indexOf(ch) != -1); + } + + if (!isValidChar) + return false; + } + + return true; + } + + /** + * Parses the given Uno Url and returns + * an in memory object representation. + * + * @param unoUrl The given uno URl as string. + * @return Object representation of class UnoUrl. + * @throws IllegalArgumentException if Url cannot be parsed. + */ + public static UnoUrl parseUnoUrl(String unoUrl) + throws com.sun.star.lang.IllegalArgumentException { + + String url = unoUrl; + + int index = url.indexOf(':'); + if (index != -1) { + String unoStr = url.substring(0, index).trim(); + if (!"uno".equals(unoStr)) { + throw new com.sun.star.lang.IllegalArgumentException( + "Uno Urls must start with 'uno:'. " + FORMAT_ERROR); + } + } + + url = url.substring(index + 1).trim(); + + index = url.indexOf(';'); + if (index == -1) { + throw new com.sun.star.lang.IllegalArgumentException("'"+unoUrl+"' is an invalid Uno Url. " + FORMAT_ERROR); + } + + String connection = url.substring(0, index).trim(); + url = url.substring(index + 1).trim(); + + UnoUrlPart connectionPart = parseUnoUrlPart(connection); + + index = url.indexOf(';'); + if (index == -1) { + throw new com.sun.star.lang.IllegalArgumentException("'"+unoUrl+"' is an invalid Uno Url. " + FORMAT_ERROR); + } + + String protocol = url.substring(0, index).trim(); + url = url.substring(index + 1).trim(); + + UnoUrlPart protocolPart = parseUnoUrlPart(protocol); + + String rootOid = url.trim(); + if (!isValidString(rootOid, OID_CHAR_SET)) { + throw new com.sun.star.lang.IllegalArgumentException( + "Root OID '"+ rootOid + "' contains illegal characters."); + } + + return new UnoUrl(connectionPart, protocolPart, rootOid); + + } + +} diff --git a/ridljar/com/sun/star/lib/uno/helper/WeakAdapter.java b/ridljar/com/sun/star/lib/uno/helper/WeakAdapter.java new file mode 100644 index 000000000000..67e01ac3276d --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/WeakAdapter.java @@ -0,0 +1,94 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.helper; +import java.lang.ref.WeakReference; +import com.sun.star.uno.XAdapter; +import com.sun.star.uno.XReference; +import java.util.List; +import java.util.Collections; +import java.util.LinkedList; + +/** An XAdapter implementation that holds a weak reference (java.lang.ref.WeakReference) + * to an object. Clients can register listener (com.sun.star.lang.XReference) which + * are notified when the object (the one which is kept weak) is being finalized. That + * is, that object is being destroyed because there are not any hard references + * to it. + */ +public class WeakAdapter implements XAdapter +{ + // references the XWeak implementation + private final WeakReference m_weakRef; + // contains XReference objects registered by addReference + private final List m_xreferenceList; + + /** + *@param component the object that is to be held weak + */ + public WeakAdapter(Object component) + { + m_weakRef= new WeakReference(component); + m_xreferenceList= Collections.synchronizedList( new LinkedList()); + } + + /** Called by the XWeak implementation (WeakBase) when it is being finalized. + * It is only being called once. + * The registered XReference listeners are notified. On notification they are + * to unregister themselves. The notification is thread-safe. However, it is possible + * to add a listener during the notification process, which will never receive a + * notification. To prevent this, one would have to synchronize this method with + * the addReference method. But this can result in deadlocks in a multi-threaded + * environment. + */ + void referentDying() + { + //synchronized call + XReference[] references= m_xreferenceList.toArray(new XReference[m_xreferenceList.size()]); + for (int i= references.length; i > 0; i--) + { + references[i-1].dispose(); + } + } + + /** Method of com.sun.star.uno.XAdapter. It is called to obtain a hard reference + * to the object which is kept weak by this instance. + * @return hard reference to the object + */ + public Object queryAdapted() + { + return m_weakRef.get(); + } + + /** Method of com.sun.star.uno.XAdapter. Called by clients to register listener which + * are notified when the weak object is dying. + *@param xReference a listener + */ + public void removeReference(XReference xReference) + { + m_xreferenceList.remove(xReference); + } + + /** Method of com.sun.star.uno.XAdapter. Called by clients to unregister listeners. + *@param xReference listener + */ + public void addReference(XReference xReference) + { + m_xreferenceList.add(xReference); + } +} + diff --git a/ridljar/com/sun/star/lib/uno/helper/WeakBase.java b/ridljar/com/sun/star/lib/uno/helper/WeakBase.java new file mode 100644 index 000000000000..ac175d3a6d5d --- /dev/null +++ b/ridljar/com/sun/star/lib/uno/helper/WeakBase.java @@ -0,0 +1,101 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.lib.uno.helper; +import com.sun.star.uno.XWeak; +import com.sun.star.uno.XAdapter; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.uno.Type; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; + + +/** This class can be used as the base class for UNO components. It implements the capability + * to be kept weak (com.sun.star.uno.XWeak) and it implements com.sun.star.lang.XTypeProvider + * which is necessary for using the component with StarBasic. + */ +public class WeakBase implements XWeak, XTypeProvider +{ + // Contains all WeakAdapter which have been created in this class + // They have to be notified when this object dies + private WeakAdapter m_adapter; + + protected static Map,Type[]> _mapTypes = new HashMap,Type[]>(); + + /** Method of XWeak. The returned XAdapter implementation can be used to keep + * a weak reference to this object. + * @return a com.sun.star.uno.XAdapter implementation. + */ + synchronized public XAdapter queryAdapter() + { + if (m_adapter == null) + m_adapter= new WeakAdapter(this); + return m_adapter; + } + + /** Override of Object.finalize. When there are no references to this object anymore + * then the garbage collector calls this method. Thereby causing the adapter object + * to be notified. The adapter, in turn, notifies all listeners (com.sun.star.uno.XReference) + */ + @Override + protected void finalize() throws java.lang.Throwable + { + if (m_adapter != null) + m_adapter.referentDying(); + super.finalize(); + } + + /** Method of XTypeProvider. It returns an array of Type objects which represent + * all implemented UNO interfaces of this object. + * @return Type objects of all implemented interfaces. + */ + public Type[] getTypes() + { + Type[] arTypes= _mapTypes.get( getClass()); + if (arTypes == null) + { + ArrayList vec= new ArrayList(); + Class currentClass= getClass(); + do + { + Class interfaces[]= currentClass.getInterfaces(); + for(int i = 0; i < interfaces.length; ++ i) + { + // Test if it is a UNO interface + if (com.sun.star.uno.XInterface.class.isAssignableFrom(interfaces[i])) + vec.add(new Type(interfaces[i])); + } + // get the superclass the currentClass inherits from + currentClass= currentClass.getSuperclass(); + } while (currentClass != null); + + Type types[]= vec.toArray(new Type[vec.size()]); + _mapTypes.put(getClass(), types); + arTypes= types; + } + return arTypes; + } + + /** Obsolete method of XTypeProvider. + */ + public byte[] getImplementationId() + { + return new byte[0]; + } +} diff --git a/ridljar/source/libreoffice/manifest b/ridljar/source/libreoffice/manifest new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoClassLoader.java b/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoClassLoader.java index c52165abfeb7..822d1609cd3b 100644 --- a/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoClassLoader.java +++ b/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoClassLoader.java @@ -49,8 +49,8 @@ public final class UnoClassLoader extends URLClassLoader { * Instantiates the root UNO class loader. * * @param base a base URL relative to which the URE JARs - * (java_uno.jar, juh.jar, - * ridl.jar) can be found; must not be null. + * (java_uno.jar and libreoffice.jar) + * can be found; must not be null. * * @param classPath an array of URLs that form the class path of this class * loader; may be null, which is the same as an empty array. @@ -191,11 +191,10 @@ public final class UnoClassLoader extends URLClassLoader { private static URL[] createUrls(URL base, URL[] classPath) throws MalformedURLException { - final int JARS = 3; + final int JARS = 2; URL[] urls = new URL[JARS + (classPath == null ? 0 : classPath.length)]; urls[0] = new URL(base, "java_uno.jar"); //TODO get rid of it here - urls[1] = new URL(base, "juh.jar"); - urls[2] = new URL(base, "ridl.jar"); + urls[1] = new URL(base, "libreoffice.jar"); if (classPath != null) { System.arraycopy(classPath, 0, urls, JARS, classPath.length); } diff --git a/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoLoader.java b/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoLoader.java index 1ed16fcca94c..23059b7b4cb5 100644 --- a/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoLoader.java +++ b/ridljar/source/unoloader/com/sun/star/lib/unoloader/UnoLoader.java @@ -38,7 +38,7 @@ public final class UnoLoader { * Executes a UNO JAR. * * @param base a base URL relative to which the URE JARs - * (ridl.jar, etc.) can be found; must + * (libreoffice.jar, etc.) can be found; must * not be null. * * @param jar the URL of a UNO JAR that specifies a Main-Class; must not be diff --git a/ridljar/util/manifest b/ridljar/util/manifest index ab777d6fe7ba..bb1209f90a22 100644 --- a/ridljar/util/manifest +++ b/ridljar/util/manifest @@ -6,6 +6,9 @@ Sealed: true Name: com/sun/star/comp/connections/ Sealed: true +Name: com/sun/star/comp/helper +Sealed: true + Name: com/sun/star/comp/loader/ Sealed: true @@ -24,6 +27,9 @@ Sealed: true Name: com/sun/star/lib/uno/ Sealed: true +Name: com/sun/star/lib/uno/adapter +Sealed: true + Name: com/sun/star/lib/uno/bridges/java_remote/ Sealed: true @@ -33,5 +39,8 @@ Sealed: true Name: com/sun/star/lib/uno/environments/remote/ Sealed: true +Name: com/sun/star/lib/uno/helper +Sealed: true + Name: com/sun/star/lib/uno/protocols/urp/ Sealed: true diff --git a/scripting/Jar_HelloWorld.mk b/scripting/Jar_HelloWorld.mk index c80f628eb765..1a44592e115c 100644 --- a/scripting/Jar_HelloWorld.mk +++ b/scripting/Jar_HelloWorld.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,HelloWorld)) $(eval $(call gb_Jar_use_jars,HelloWorld,\ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_add_sourcefiles,HelloWorld,\ diff --git a/scripting/Jar_Highlight.mk b/scripting/Jar_Highlight.mk index 18e3bf916a76..fb756cc8b1ff 100644 --- a/scripting/Jar_Highlight.mk +++ b/scripting/Jar_Highlight.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,Highlight)) $(eval $(call gb_Jar_use_jars,Highlight,\ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_add_sourcefiles,Highlight,\ diff --git a/scripting/Jar_MemoryUsage.mk b/scripting/Jar_MemoryUsage.mk index e1c0f9f8c11a..8f917d360c45 100644 --- a/scripting/Jar_MemoryUsage.mk +++ b/scripting/Jar_MemoryUsage.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,MemoryUsage)) $(eval $(call gb_Jar_use_jars,MemoryUsage,\ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_add_sourcefiles,MemoryUsage,\ diff --git a/scripting/Jar_ScriptFramework.mk b/scripting/Jar_ScriptFramework.mk index 8f0cd9a9062a..397de3ccbc72 100644 --- a/scripting/Jar_ScriptFramework.mk +++ b/scripting/Jar_ScriptFramework.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,ScriptFramework)) $(eval $(call gb_Jar_use_jars,ScriptFramework,\ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_set_componentfile,ScriptFramework,scripting/java/ScriptFramework,OOO)) diff --git a/scripting/Jar_ScriptProviderForBeanShell.mk b/scripting/Jar_ScriptProviderForBeanShell.mk index fdbbec8ab201..6f362818d7b3 100644 --- a/scripting/Jar_ScriptProviderForBeanShell.mk +++ b/scripting/Jar_ScriptProviderForBeanShell.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,ScriptProviderForBeanShell)) $(eval $(call gb_Jar_use_jars,ScriptProviderForBeanShell,\ - juh \ - ridl \ + libreoffice \ ScriptFramework \ )) diff --git a/scripting/Jar_ScriptProviderForJava.mk b/scripting/Jar_ScriptProviderForJava.mk index e0d4bee3756e..8e7d3e2d17a9 100644 --- a/scripting/Jar_ScriptProviderForJava.mk +++ b/scripting/Jar_ScriptProviderForJava.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,ScriptProviderForJava)) $(eval $(call gb_Jar_use_jars,ScriptProviderForJava,\ - juh \ - ridl \ + libreoffice \ ScriptFramework \ )) diff --git a/scripting/Jar_ScriptProviderForJavaScript.mk b/scripting/Jar_ScriptProviderForJavaScript.mk index 976c6ee7b809..c777cbcab302 100644 --- a/scripting/Jar_ScriptProviderForJavaScript.mk +++ b/scripting/Jar_ScriptProviderForJavaScript.mk @@ -10,8 +10,7 @@ $(eval $(call gb_Jar_Jar,ScriptProviderForJavaScript)) $(eval $(call gb_Jar_use_jars,ScriptProviderForJavaScript,\ - juh \ - ridl \ + libreoffice \ ScriptFramework \ )) diff --git a/smoketest/Jar_TestExtension.mk b/smoketest/Jar_TestExtension.mk index 22a3a5cdb5fd..c0621d94db5f 100644 --- a/smoketest/Jar_TestExtension.mk +++ b/smoketest/Jar_TestExtension.mk @@ -13,13 +13,11 @@ $(eval $(call gb_Jar_Jar,TestExtension)) $(eval $(call gb_Jar_set_manifest,TestExtension,$(SRCDIR)/smoketest/com/sun/star/comp/smoketest/MANIFEST.MF)) $(eval $(call gb_Jar_add_manifest_classpath,TestExtension,\ - juh.jar \ - ridl.jar \ + libreoffice.jar \ )) $(eval $(call gb_Jar_use_jars,TestExtension,\ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_set_packageroot,TestExtension,com)) diff --git a/smoketest/Jar_smoketest.mk b/smoketest/Jar_smoketest.mk index 86210c8eba70..19259910f03c 100644 --- a/smoketest/Jar_smoketest.mk +++ b/smoketest/Jar_smoketest.mk @@ -21,8 +21,7 @@ $(eval $(call gb_Jar_set_manifest,smoketest,$(SRCDIR)/smoketest/org/libreoffice/ $(eval $(call gb_Jar_set_packageroot,smoketest,org)) $(eval $(call gb_Jar_use_jars,smoketest, \ - juh \ - ridl \ + libreoffice \ )) # vim: set noet sw=4 ts=4: diff --git a/solenv/gbuild/CppunitTest.mk b/solenv/gbuild/CppunitTest.mk index d90a2c89311c..efe39ed45a8d 100644 --- a/solenv/gbuild/CppunitTest.mk +++ b/solenv/gbuild/CppunitTest.mk @@ -376,7 +376,7 @@ endef define gb_CppunitTest__use_java_ure $(call gb_CppunitTest_get_target,$(1)) : \ - $(foreach jar,java_uno juh ridl unoloader,$(call gb_Jar_get_target,$(jar))) \ + $(foreach jar,java_uno libreoffice unoloader,$(call gb_Jar_get_target,$(jar))) \ $(call gb_Library_get_target,affine_uno_uno) \ $(call gb_Library_get_target,java_uno) \ $(call gb_Library_get_target,jpipe) \ diff --git a/solenv/gbuild/JunitTest.mk b/solenv/gbuild/JunitTest.mk index 290fab3af4c8..401c8ff5cd97 100644 --- a/solenv/gbuild/JunitTest.mk +++ b/solenv/gbuild/JunitTest.mk @@ -163,7 +163,7 @@ endef define gb_JunitTest_use_unoapi_jars $(eval $(call gb_JunitTest_use_jars,$(1),\ OOoRunner \ - ridl \ + libreoffice \ test \ )) diff --git a/swext/Jar_mediawiki.mk b/swext/Jar_mediawiki.mk index 31d621561f7c..25a2ce91b453 100644 --- a/swext/Jar_mediawiki.mk +++ b/swext/Jar_mediawiki.mk @@ -15,8 +15,7 @@ $(eval $(call gb_Jar_set_packageroot,mediawiki,com)) $(eval $(call gb_Jar_set_manifest,mediawiki,$(SRCDIR)/swext/mediawiki/src/com/sun/star/wiki/MANIFEST.MF)) $(eval $(call gb_Jar_use_jars,mediawiki,\ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_add_sourcefiles,mediawiki,\ diff --git a/testtools/Jar_testComponent.mk b/testtools/Jar_testComponent.mk index d173a853627f..f3969a42277d 100644 --- a/testtools/Jar_testComponent.mk +++ b/testtools/Jar_testComponent.mk @@ -10,8 +10,11 @@ $(eval $(call gb_Jar_Jar,testComponent)) $(eval $(call gb_Jar_use_jars,testComponent,\ - ridl \ - juh \ + libreoffice \ +)) + +$(eval $(call gb_Jar_use_api,testComponent,\ + udkapi \ )) $(eval $(call gb_Jar_use_customtargets,testComponent,\ diff --git a/toolkit/JunitTest_toolkit_complex.mk b/toolkit/JunitTest_toolkit_complex.mk index 87c4e5e02994..4a06582a0083 100644 --- a/toolkit/JunitTest_toolkit_complex.mk +++ b/toolkit/JunitTest_toolkit_complex.mk @@ -20,7 +20,7 @@ $(eval $(call gb_JunitTest_JunitTest,toolkit_complex)) $(eval $(call gb_JunitTest_use_jars,toolkit_complex,\ OOoRunner \ - ridl \ + libreoffice \ test \ )) diff --git a/toolkit/test/accessibility/jawb.mf b/toolkit/test/accessibility/jawb.mf index 4ff1a259f892..88aa2cc765c6 100644 --- a/toolkit/test/accessibility/jawb.mf +++ b/toolkit/test/accessibility/jawb.mf @@ -1,3 +1,3 @@ Manifest-Version: 1.0 Main-Class: AccessibilityWorkBench -Class-Path: classes.jar ridl.jar juh.jar java_uno.jar xt.jar xml-apis.jar +Class-Path: classes.jar libreoffice.jar java_uno.jar xt.jar xml-apis.jar diff --git a/unoil/Jar_unoil.mk b/unoil/Jar_unoil.mk index a88615ddd9c2..b0265c93f364 100644 --- a/unoil/Jar_unoil.mk +++ b/unoil/Jar_unoil.mk @@ -10,7 +10,7 @@ $(eval $(call gb_Jar_Jar,unoil)) $(eval $(call gb_Jar_add_manifest_classpath,unoil, \ - ridl.jar \ + libreoffice.jar \ )) # vim:set noet sw=4 ts=4: diff --git a/unotest/Jar_test-tools.mk b/unotest/Jar_test-tools.mk index 939571a3947a..2f8034813712 100644 --- a/unotest/Jar_test-tools.mk +++ b/unotest/Jar_test-tools.mk @@ -11,13 +11,11 @@ $(eval $(call gb_Jar_Jar,test-tools)) $(eval $(call gb_Jar_add_manifest_classpath,test-tools,\ - juh.jar \ - ridl.jar \ + libreoffice.jar \ )) $(eval $(call gb_Jar_use_jars,test-tools,\ - juh \ - ridl \ + libreoffice \ )) $(eval $(call gb_Jar_set_packageroot,test-tools,org)) diff --git a/unotest/Jar_test.mk b/unotest/Jar_test.mk index 0619b91fbf11..45063ff1ccd9 100644 --- a/unotest/Jar_test.mk +++ b/unotest/Jar_test.mk @@ -11,13 +11,11 @@ $(eval $(call gb_Jar_Jar,test)) $(eval $(call gb_Jar_add_manifest_classpath,test,\ - $(call gb_Helper_make_url,$(call gb_Jar_get_target,juh)) \ - $(call gb_Helper_make_url,$(call gb_Jar_get_target,ridl)) \ + $(call gb_Helper_make_url,$(call gb_Jar_get_target,libreoffice)) \ )) $(eval $(call gb_Jar_use_jars,test,\ - juh \ - ridl \ + libreoffice \ OOoRunner \ )) diff --git a/ure/source/README b/ure/source/README index 27a2b6b994ce..aad11505e971 100644 --- a/ure/source/README +++ b/ure/source/README @@ -36,6 +36,7 @@ ELF platforms (Linux, Solaris, *BSD): /opt/libreoffice/ure/share/java/unoloader.jar /opt/libreoffice/ure/share/java/juh.jar /opt/libreoffice/ure/share/java/jurt.jar +/opt/libreoffice/ure/share/java/libreoffice.jar /opt/libreoffice/ure/share/java/ridl.jar /opt/libreoffice/ure/share/misc/types.rdb /opt/libreoffice/ure/share/misc/services.rdb @@ -93,6 +94,7 @@ Program Files\URE\bin\purpenvhelper3MSC.dll Program Files\URE\bin\sal3.dll Program Files\URE\bin\salhelper3MSC.dll Program Files\URE\java\unoloader.jar +Program Files\URE\java\libreoffice.jar Program Files\URE\java\juh.jar Program Files\URE\java\jurt.jar Program Files\URE\java\ridl.jar @@ -159,8 +161,8 @@ Files marked as [private] are private to the URE installation. To avoid stability issues, applications that use the URE should not access the functionality of these files. -Files marked as [GAC] are installed in the Global Assembly Cache on Windows. The -file path reflects the path as seen in the Explorer with the Assembly +Files marked as [GAC] are installed in the Global Assembly Cache on Windows. The +file path reflects the path as seen in the Explorer with the Assembly Cache Viewer Tool (Shfusion.dll) installed. The actual paths are different. @@ -186,12 +188,12 @@ functionality that these libraries offer, see the "C++ Reference" section of the SDK HTML documentation. The corresponding C++ header files are not in the URE, but rather in the SDK. -- unoloader.jar, juh.jar, and ridl.jar are the public Java UNO runtime -Java[tm] Archives (JARs) that client code can call (jurt.jar is still provided -for backwards compatibility, but is basically empty and has been merged into -ridl.jar). For details on the -functionality that these files offer, see the "Java UNO Runtime Reference" -section of the SDK HTML documentation. +- libreoffice.jar and unoloader.jar are the public Java UNO runtime +Java[tm] Archives (JARs) that client code can call. +juh.jar, jurt.jar, ridl.jar, unoil.jar are still provided for backwards compatibility, +but are basically empty and have been merged into libreoffice.jar. +For details on the functionality that these files offer, see the +"Java UNO Runtime Reference" section of the SDK HTML documentation. - types.rdb and services.rdb are preconfigured UNO type and service registries. For more details, see the "Deploying a URE" section of this README. diff --git a/ure/source/uretest/Makefile.pln b/ure/source/uretest/Makefile.pln index 3b44382675bc..3ea8c34827cc 100644 --- a/ure/source/uretest/Makefile.pln +++ b/ure/source/uretest/Makefile.pln @@ -143,7 +143,7 @@ out.pln/class/javamain/test/java/javamain/JavaMain.class: JavaMain.java \ rm -rf out.pln/class/javamain mkdir out.pln/class/javamain javac -classpath \ - $(URE_HOME)/program/classes/ridl.jar:out.pln/tester.jar \ + $(URE_HOME)/program/classes/libreoffice.jar:out.pln/tester.jar \ -sourcepath . -d out.pln/class/javamain $< @@ -176,7 +176,7 @@ out.pln/class/tester/test/java/tester/Tester.class: Tester.java \ rm -rf out.pln/class/tester mkdir out.pln/class/tester javac -classpath \ - $(URE_HOME)/program/classes/ridl.jar:out.pln/types.jar \ + $(URE_HOME)/program/classes/libreoffice.jar:out.pln/types.jar \ -sourcepath . -d out.pln/class/tester $< @@ -194,7 +194,7 @@ out.pln/class/javatest/test/java/javatest/JavaTest.class: JavaTest.java \ rm -rf out.pln/class/javatest mkdir out.pln/class/javatest javac -classpath \ - $(URE_HOME)/program/classes/ridl.jar:out.pln/types.jar \ + $(URE_HOME)/program/classes/libreoffice.jar:out.pln/types.jar \ -sourcepath . -d out.pln/class/javatest $< @@ -212,7 +212,7 @@ out.pln/class/javanative/test/java/javanative/JavaNative.class: \ rm -rf out.pln/class/javanative mkdir out.pln/class/javanative javac -classpath \ - $(URE_HOME)/program/classes/juh.jar:$(URE_HOME)/program/classes/ridl.jar:out.pln/tester.jar \ + $(URE_HOME)/program/classes/libreoffice.jar:out.pln/tester.jar \ -sourcepath . -d out.pln/class/javanative $< @@ -230,7 +230,7 @@ out.pln/class/javaclient/test/java/javaclient/JavaClient.class: \ rm -rf out.pln/class/javaclient mkdir out.pln/class/javaclient javac -classpath \ - $(URE_HOME)/program/classes/juh.jar:$(URE_HOME)/program/classes/ridl.jar:out.pln/types.jar \ + $(URE_HOME)/program/classes/libreoffice.jar:out.pln/types.jar \ -sourcepath . -d out.pln/class/javaclient $< diff --git a/wizards/Jar_commonwizards.mk b/wizards/Jar_commonwizards.mk index ca432ea37fb0..e2f92031d880 100644 --- a/wizards/Jar_commonwizards.mk +++ b/wizards/Jar_commonwizards.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_Jar,commonwizards)) $(eval $(call gb_Jar_use_jars,commonwizards,\ - ridl \ - juh \ + libreoffice \ java_uno \ )) diff --git a/wizards/Jar_form.mk b/wizards/Jar_form.mk index 626e5386b1e2..caad29b16702 100644 --- a/wizards/Jar_form.mk +++ b/wizards/Jar_form.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_Jar,form)) $(eval $(call gb_Jar_use_jars,form,\ - ridl \ - juh \ + libreoffice \ java_uno \ commonwizards \ )) diff --git a/wizards/Jar_query.mk b/wizards/Jar_query.mk index 5d58df01812b..16c27e991435 100644 --- a/wizards/Jar_query.mk +++ b/wizards/Jar_query.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_Jar,query)) $(eval $(call gb_Jar_use_jars,query,\ - ridl \ - juh \ + libreoffice \ java_uno \ commonwizards \ )) diff --git a/wizards/Jar_report.mk b/wizards/Jar_report.mk index 8f791383b70e..db16bc65716a 100644 --- a/wizards/Jar_report.mk +++ b/wizards/Jar_report.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_Jar,report)) $(eval $(call gb_Jar_use_jars,report,\ - ridl \ - juh \ + libreoffice \ java_uno \ commonwizards \ )) diff --git a/wizards/Jar_reportbuilder.mk b/wizards/Jar_reportbuilder.mk index f97ee8a40934..c6662faaf944 100644 --- a/wizards/Jar_reportbuilder.mk +++ b/wizards/Jar_reportbuilder.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_Jar,reportbuilderwizard)) $(eval $(call gb_Jar_use_jars,reportbuilderwizard,\ - ridl \ - juh \ + libreoffice \ java_uno \ commonwizards \ report \ diff --git a/wizards/Jar_table.mk b/wizards/Jar_table.mk index 6924c878c32d..cd1568ed6107 100644 --- a/wizards/Jar_table.mk +++ b/wizards/Jar_table.mk @@ -20,8 +20,7 @@ $(eval $(call gb_Jar_Jar,table)) $(eval $(call gb_Jar_use_jars,table,\ - ridl \ - juh \ + libreoffice \ java_uno \ commonwizards \ )) diff --git a/xmerge/Jar_XMergeBridge.mk b/xmerge/Jar_XMergeBridge.mk index 96ce1556edab..6cefaf433591 100644 --- a/xmerge/Jar_XMergeBridge.mk +++ b/xmerge/Jar_XMergeBridge.mk @@ -18,8 +18,7 @@ $(eval $(call gb_Jar_set_packageroot,XMergeBridge,*.class)) $(eval $(call gb_Jar_use_jars,XMergeBridge,\ xmerge \ - ridl \ - juh \ + libreoffice \ )) $(eval $(call gb_Jar_add_sourcefiles,XMergeBridge,\ diff --git a/xmerge/Jar_xmerge.mk b/xmerge/Jar_xmerge.mk index 022f8fefe8cd..f90139ca32be 100644 --- a/xmerge/Jar_xmerge.mk +++ b/xmerge/Jar_xmerge.mk @@ -13,8 +13,7 @@ $(eval $(call gb_Jar_Jar,xmerge)) $(eval $(call gb_Jar_set_manifest,xmerge,$(SRCDIR)/xmerge/source/xmerge/xmerge.mf)) $(eval $(call gb_Jar_use_jars,xmerge,\ - ridl \ - juh \ + libreoffice \ )) $(eval $(call gb_Jar_set_packageroot,xmerge,org)) -- cgit v1.2.3