26#include <com/sun/star/uno/RuntimeException.hpp>
29#include <rtl/string.hxx>
30#include <rtl/strbuf.hxx>
31#include <rtl/ustrbuf.hxx>
33#include <uno/lbnames.h>
46 if (!
m_td.get()->bComplete)
49 "cannot make type complete: "
50 + OUString::unacquired( &
m_td.get()->pTypeName )
60 jni_env->DeleteGlobalRef(
m_type );
70 assert(
m_td.get()->eTypeClass == typelib_TypeClass_INTERFACE );
72 OUString
const & uno_name = OUString::unacquired( &
m_td.get()->pTypeName );
85 arg.l = jo_class.
get();
87 jni, jni->CallStaticObjectMethodA(
100 typelib_InterfaceTypeDescription * td =
101 reinterpret_cast< typelib_InterfaceTypeDescription *
>(
104 m_methods.reset(
new jmethodID[ td->nMapFunctionIndexToMemberIndex ]);
105 sal_Int32 nMethodIndex = 0;
106 typelib_TypeDescriptionReference ** ppMembers = td->ppMembers;
107 sal_Int32 nMembers = td->nMembers;
113 OStringBuffer sig_buf( 64 );
115 if (member_td.
get()->eTypeClass ==
116 typelib_TypeClass_INTERFACE_METHOD)
118 typelib_InterfaceMethodTypeDescription * method_td =
120 typelib_InterfaceMethodTypeDescription *
>(
123 sig_buf.append(
'(' );
124 for ( sal_Int32
i = 0;
i < method_td->nParams; ++
i )
126 typelib_MethodParameter
const & param =
127 method_td->pParams[
i ];
129 sig_buf.append(
'[' );
132 sig_buf.append(
')' );
135 OString method_signature( sig_buf.makeStringAndClear() );
138 &method_td->aBase.pMemberName ),
139 RTL_TEXTENCODING_JAVA_UTF8 ) );
141 m_methods[ nMethodIndex ] = jni->GetMethodID(
142 static_cast<jclass
>(jo_class.
get()), method_name.getStr(),
143 method_signature.getStr() );
145 assert(
m_methods[ nMethodIndex ] !=
nullptr );
151 member_td.
get()->eTypeClass ==
152 typelib_TypeClass_INTERFACE_ATTRIBUTE );
153 typelib_InterfaceAttributeTypeDescription * attribute_td =
155 typelib_InterfaceAttributeTypeDescription *
>(
160 &sig_buf, attribute_td->pAttributeTypeRef );
161 OString type_sig( sig_buf.makeStringAndClear() );
162 sig_buf.ensureCapacity( 64 );
164 OUString
const & member_name =
165 OUString::unacquired(
166 &attribute_td->aBase.pMemberName );
169 sig_buf.append(
"()" + type_sig );
170 OString method_signature( sig_buf.makeStringAndClear() );
173 rtl::Concat2View(
"get" + member_name),
174 RTL_TEXTENCODING_JAVA_UTF8 ) );
175 m_methods[ nMethodIndex ] = jni->GetMethodID(
176 static_cast<jclass
>(jo_class.
get()), method_name.getStr(),
177 method_signature.getStr() );
179 assert(
m_methods[ nMethodIndex ] !=
nullptr );
181 if (! attribute_td->bReadOnly)
184 method_signature =
"(" + type_sig +
")V";
186 rtl::Concat2View(
"set" + member_name),
187 RTL_TEXTENCODING_JAVA_UTF8 );
188 m_methods[ nMethodIndex ] = jni->GetMethodID(
189 static_cast<jclass
>(jo_class.
get()), method_name.getStr(),
190 method_signature.getStr() );
192 assert(
m_methods[ nMethodIndex ] !=
nullptr );
204 m_class =
static_cast<jclass
>(jni->NewGlobalRef( jo_class.
get() ));
205 m_type = jni->NewGlobalRef( jo_type.
get() );
221 m_exc_ctor( nullptr )
223 assert(
m_td.get()->eTypeClass == typelib_TypeClass_STRUCT ||
224 m_td.get()->eTypeClass == typelib_TypeClass_EXCEPTION );
225 typelib_CompoundTypeDescription * td =
226 reinterpret_cast< typelib_CompoundTypeDescription *
>(
m_td.get() );
228 OUString
const & uno_name =
229 OUString::unacquired( &td->aBase.pTypeName );
232 std::u16string_view nucleus;
233 sal_Int32
i = uno_name.indexOf(
'<' );
237 nucleus = uno_name.subView( 0,
i );
244 nucleus, RTL_TEXTENCODING_JAVA_UTF8 ).getStr() ) );
248 if (
m_td.get()->eTypeClass == typelib_TypeClass_EXCEPTION)
252 static_cast<jclass
>(jo_class.
get()),
"<init>",
"(Ljava/lang/String;)V" );
264 td->pBaseTypeDescription );
281 static_cast<jclass
>(jo_class.
get()),
"Context",
"Ljava/lang/Object;" );
288 sal_Int32 nMembers = td->nMembers;
289 m_fields.reset(
new jfieldID[ nMembers ]);
294 if (td->aBase.eTypeClass == typelib_TypeClass_STRUCT
295 &&
reinterpret_cast< typelib_StructTypeDescription *
>(
296 td)->pParameterizedTypes !=
nullptr
297 &&
reinterpret_cast< typelib_StructTypeDescription *
>(
298 td)->pParameterizedTypes[
nPos])
300 sig = OString(
"Ljava/lang/Object;" );
302 OStringBuffer sig_buf( 32 );
304 sig = sig_buf.makeStringAndClear();
309 OUString::unacquired( &td->ppMemberNames[
nPos ] ),
310 RTL_TEXTENCODING_JAVA_UTF8 ) );
313 static_cast<jclass
>(jo_class.
get()), member_name.getStr(),
326 m_class =
static_cast<jclass
>(jni->NewGlobalRef( jo_class.
get() ));
333 OUString
const & uno_name = OUString::unacquired( &td->pTypeName );
336 switch (td->eTypeClass)
338 case typelib_TypeClass_STRUCT:
339 case typelib_TypeClass_EXCEPTION:
344 case typelib_TypeClass_INTERFACE:
358 std::unique_lock guard(
m_mutex );
360 if (holder.
m_info ==
nullptr)
384 OUString
const & uno_name = OUString::unacquired( &td->pTypeName );
386 std::unique_lock guard(
m_mutex );
388 t_str2type::const_iterator iFind(
m_type_map.find( uno_name ) );
396 info = iFind->second.m_info;
404 JNI_context const & jni, typelib_TypeDescriptionReference * type )
const
411 OUString
const & uno_name = OUString::unacquired( &
type->pTypeName );
413 std::unique_lock guard(
m_mutex );
414 t_str2type::const_iterator iFind(
m_type_map.find( uno_name ) );
423 info = iFind->second.m_info;
431 JNI_context const & jni, OUString
const & uno_name )
const
433 if ( uno_name ==
"com.sun.star.uno.XInterface" )
439 std::unique_lock guard(
m_mutex );
440 t_str2type::const_iterator iFind(
m_type_map.find( uno_name ) );
444 css::uno::TypeDescription td( uno_name );
454 info = iFind->second.m_info;
462 JNIEnv * jni_env, jobject class_loader, jclass classClass,
463 jmethodID methodForName )
464 : m_class_Class( classClass ),
465 m_method_Class_forName( methodForName ),
466 m_class_JNI_proxy( nullptr ),
467 m_XInterface_queryInterface_td(
468 (reinterpret_cast< typelib_InterfaceTypeDescription * >(
469 css::
uno::TypeDescription(
471 .
get())->ppMembers[ 0 ] ) ),
474 m_void_type(
cppu::UnoType<void>::
get()),
475 m_XInterface_type_info( nullptr )
485 jni,
find_class( jni,
"java.lang.Throwable" ) );
487 jni,
find_class( jni,
"java.lang.Character" ) );
489 jni,
find_class( jni,
"java.lang.Boolean" ) );
495 jni,
find_class( jni,
"java.lang.Integer" ) );
505 jni,
find_class( jni,
"com.sun.star.uno.RuntimeException" ) );
507 jni,
find_class( jni,
"com.sun.star.uno.UnoRuntime" ) );
509 jni,
find_class( jni,
"com.sun.star.uno.Any" ) );
511 jni,
find_class( jni,
"com.sun.star.uno.Enum" ) );
513 jni,
find_class( jni,
"com.sun.star.uno.Type" ) );
515 jni,
find_class( jni,
"com.sun.star.uno.TypeClass" ) );
517 jni,
find_class( jni,
"com.sun.star.uno.IEnvironment" ) );
519 jni,
find_class( jni,
"com.sun.star.bridges.jni_uno.JNI_proxy" ) );
521 jni,
find_class( jni,
"com.sun.star.lib.util.AsynchronousFinalizer" ) );
525 static_cast<jclass
>(jo_Object.
get()),
"toString",
"()Ljava/lang/String;" );
530 static_cast<jclass
>(jo_Class.
get()),
"getName",
"()Ljava/lang/String;" );
536 static_cast<jclass
>(jo_Throwable.
get()),
"getMessage",
"()Ljava/lang/String;" );
542 static_cast<jclass
>(jo_Character.
get()),
"charValue",
"()C" );
547 static_cast<jclass
>(jo_Boolean.
get()),
"booleanValue",
"()Z" );
552 static_cast<jclass
>(jo_Byte.
get()),
"byteValue",
"()B" );
557 static_cast<jclass
>(jo_Short.
get()),
"shortValue",
"()S" );
562 static_cast<jclass
>(jo_Integer.
get()),
"intValue",
"()I" );
567 static_cast<jclass
>(jo_Long.
get()),
"longValue",
"()J" );
572 static_cast<jclass
>(jo_Float.
get()),
"floatValue",
"()F" );
577 static_cast<jclass
>(jo_Double.
get()),
"doubleValue",
"()D" );
583 static_cast<jclass
>(jo_Character.
get()),
"<init>",
"(C)V" );
588 static_cast<jclass
>(jo_Boolean.
get()),
"<init>",
"(Z)V" );
593 static_cast<jclass
>(jo_Byte.
get()),
"<init>",
"(B)V" );
598 static_cast<jclass
>(jo_Short.
get()),
"<init>",
"(S)V" );
603 static_cast<jclass
>(jo_Integer.
get()),
"<init>",
"(I)V" );
608 static_cast<jclass
>(jo_Long.
get()),
"<init>",
"(J)V" );
613 static_cast<jclass
>(jo_Float.
get()),
"<init>",
"(F)V" );
618 static_cast<jclass
>(jo_Double.
get()),
"<init>",
"(D)V" );
624 static_cast<jclass
>(jo_UnoRuntime.
get()),
625 "generateOid",
"(Ljava/lang/Object;)Ljava/lang/String;" );
630 static_cast<jclass
>(jo_UnoRuntime.
get()),
632 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)Ljava/lang/Object;" );
638 static_cast<jclass
>(jo_Enum.
get()),
"m_value",
"I" );
644 static_cast<jclass
>(jo_TypeClass.
get()),
645 "fromInt",
"(I)Lcom/sun/star/uno/TypeClass;" );
651 static_cast<jclass
>(jo_Type.
get()),
"<init>",
"(Ljava/lang/Class;)V" );
656 static_cast<jclass
>(jo_Type.
get()),
657 "<init>",
"(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V" );
662 static_cast<jclass
>(jo_Type.
get()),
"_typeName",
"Ljava/lang/String;" );
668 static_cast<jclass
>(jo_Any.
get()),
669 "<init>",
"(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V" );
675 static_cast<jclass
>(jo_Any.
get()),
"_type",
"Lcom/sun/star/uno/Type;" );
680 static_cast<jclass
>(jo_Any.
get()),
"_object",
"Ljava/lang/Object;" );
686 static_cast<jclass
>(jo_IEnvironment.
get()),
687 "getRegisteredInterface",
688 "(Ljava/lang/String;Lcom/sun/star/uno/Type;)Ljava/lang/Object;" );
693 static_cast<jclass
>(jo_IEnvironment.
get()),
"registerInterface",
694 "(Ljava/lang/Object;[Ljava/lang/String;Lcom/sun/star/uno/Type;)"
695 "Ljava/lang/Object;" );
701 static_cast<jclass
>(jo_JNI_proxy.
get()),
"get_proxy_ctor",
702 "(Ljava/lang/Class;)Ljava/lang/reflect/Constructor;" );
707 static_cast<jclass
>(jo_JNI_proxy.
get()),
"create",
708 "(JLcom/sun/star/uno/IEnvironment;JJLcom/sun/star/uno/Type;Ljava/lang"
709 "/String;Ljava/lang/reflect/Constructor;"
710 "Lcom/sun/star/lib/util/AsynchronousFinalizer;)Ljava/lang/Object;" );
715 static_cast<jclass
>(jo_JNI_proxy.
get()),
"m_receiver_handle",
"J" );
720 static_cast<jclass
>(jo_JNI_proxy.
get()),
"m_td_handle",
"J" );
725 static_cast<jclass
>(jo_JNI_proxy.
get()),
"m_type",
"Lcom/sun/star/uno/Type;" );
730 static_cast<jclass
>(jo_JNI_proxy.
get()),
"m_oid",
"Ljava/lang/String;" );
736 static_cast<jclass
>(jo_AsynchronousFinalizer.
get()),
"<init>",
"()V" );
741 static_cast<jclass
>(jo_AsynchronousFinalizer.
get()),
"drain",
"()V" );
746 OUString java_env_type_name( UNO_LB_JAVA );
751 args[ 1 ].l =
nullptr;
752 jmethodID method_getEnvironment = jni->GetStaticMethodID(
753 static_cast<jclass
>(jo_UnoRuntime.
get()),
"getEnvironment",
754 "(Ljava/lang/String;Ljava/lang/Object;)"
755 "Lcom/sun/star/uno/IEnvironment;" );
757 assert( method_getEnvironment !=
nullptr );
759 jni, jni->CallStaticObjectMethodA(
760 static_cast<jclass
>(jo_UnoRuntime.
get()), method_getEnvironment,
args ) );
763 jfieldID field_Any_VOID = jni->GetStaticFieldID(
764 static_cast<jclass
>(jo_Any.
get()),
"VOID",
"Lcom/sun/star/uno/Any;" );
766 assert( field_Any_VOID !=
nullptr );
768 jni, jni->GetStaticObjectField(
769 static_cast<jclass
>(jo_Any.
get()), field_Any_VOID ) );
771 jfieldID field_Type_UNSIGNED_SHORT = jni->GetStaticFieldID(
772 static_cast<jclass
>(jo_Type.
get()),
"UNSIGNED_SHORT",
"Lcom/sun/star/uno/Type;" );
774 assert( field_Type_UNSIGNED_SHORT !=
nullptr );
776 jni, jni->GetStaticObjectField(
777 static_cast<jclass
>(jo_Type.
get()), field_Type_UNSIGNED_SHORT ) );
779 jfieldID field_Type_UNSIGNED_LONG = jni->GetStaticFieldID(
780 static_cast<jclass
>(jo_Type.
get()),
"UNSIGNED_LONG",
"Lcom/sun/star/uno/Type;" );
782 assert( field_Type_UNSIGNED_LONG !=
nullptr );
784 jni, jni->GetStaticObjectField(
785 static_cast<jclass
>(jo_Type.
get()), field_Type_UNSIGNED_LONG ) );
787 jfieldID field_Type_UNSIGNED_HYPER = jni->GetStaticFieldID(
788 static_cast<jclass
>(jo_Type.
get()),
"UNSIGNED_HYPER",
"Lcom/sun/star/uno/Type;" );
790 assert( field_Type_UNSIGNED_HYPER !=
nullptr );
792 jni, jni->GetStaticObjectField(
793 static_cast<jclass
>(jo_Type.
get()), field_Type_UNSIGNED_HYPER ) );
797 static_cast<jclass
>(jni->NewGlobalRef( jo_UnoRuntime.
get() ));
799 static_cast<jclass
>(jni->NewGlobalRef( jo_RuntimeException.
get() ));
801 static_cast<jclass
>(jni->NewGlobalRef( jo_Any.
get() ));
803 static_cast<jclass
>(jni->NewGlobalRef( jo_Type.
get() ));
805 static_cast<jclass
>(jni->NewGlobalRef( jo_TypeClass.
get() ));
807 static_cast<jclass
>(jni->NewGlobalRef( jo_JNI_proxy.
get() ));
809 static_cast<jclass
>(jni->NewGlobalRef( jo_AsynchronousFinalizer.
get() ));
812 static_cast<jclass
>(jni->NewGlobalRef( jo_Character.
get() ));
814 static_cast<jclass
>(jni->NewGlobalRef( jo_Boolean.
get() ));
816 static_cast<jclass
>(jni->NewGlobalRef( jo_Byte.
get() ));
818 static_cast<jclass
>(jni->NewGlobalRef( jo_Short.
get() ));
820 static_cast<jclass
>(jni->NewGlobalRef( jo_Integer.
get() ));
822 static_cast<jclass
>(jni->NewGlobalRef( jo_Long.
get() ));
824 static_cast<jclass
>(jni->NewGlobalRef( jo_Float.
get() ));
826 static_cast<jclass
>(jni->NewGlobalRef( jo_Double.
get() ));
828 static_cast<jclass
>(jni->NewGlobalRef( jo_String.
get() ));
830 static_cast<jclass
>(jni->NewGlobalRef( jo_Object.
get() ));
835 jni->NewGlobalRef( jo_Any_VOID.
get() );
837 jni->NewGlobalRef( jo_Type_UNSIGNED_SHORT.
get() );
839 jni->NewGlobalRef( jo_Type_UNSIGNED_LONG.
get() );
841 jni->NewGlobalRef( jo_Type_UNSIGNED_HYPER.
get() );
846 css::uno::TypeDescription XInterface_td(
864 i.second.m_info->destroy( jni_env );
906 uno_vm->getVirtualMachine() );
909 nullptr, jni_env,
static_cast< jobject
>(uno_vm->getClassLoader()) );
912 jmethodID jo_forName;
918 "com.sun.star.bridges.jni_uno.JNI_info_holder", jo_class,
919 jo_forName,
false ) );
921 jfieldID field_s_jni_info_handle =
922 jni->GetStaticFieldID(
923 static_cast<jclass
>(jo_JNI_info_holder.
get()),
"s_jni_info_handle",
"J" );
925 assert( field_s_jni_info_handle !=
nullptr );
928 reinterpret_cast< JNI_info const *
>(
929 jni->GetStaticLongField(
930 static_cast<jclass
>(jo_JNI_info_holder.
get()), field_s_jni_info_handle ) );
931 if (jni_info ==
nullptr)
934 jni_env,
static_cast< jobject
>(uno_vm->getClassLoader()), jo_class,
937 osl::ClearableMutexGuard g( osl::Mutex::getGlobalMutex() );
939 reinterpret_cast< JNI_info const *
>(
940 jni->GetStaticLongField(
941 static_cast<jclass
>(jo_JNI_info_holder.
get()),
942 field_s_jni_info_handle ) );
943 if (jni_info ==
nullptr)
945 jni->SetStaticLongField(
946 static_cast<jclass
>(jo_JNI_info_holder.
get()), field_s_jni_info_handle,
947 reinterpret_cast< jlong
>( new_info ) );
968 JNIEnv * jni_env, SAL_UNUSED_PARAMETER jobject, jlong jni_info_handle )
jclass findClass(char const *name, jclass classClass, jmethodID methodForName, bool inException) const
OUString get_stack_trace(jobject jo_exc=nullptr) const
JNI_info const * get_info() const
void ensure_no_exception() const
JNIEnv * get_jni_env() const
void getClassForName(jclass *classClass, jmethodID *methodForName) const
jmethodID m_method_IEnvironment_getRegisteredInterface
jfieldID m_field_JNI_proxy_m_td_handle
jmethodID m_ctor_Short_with_short
jmethodID m_method_Integer_intValue
jmethodID m_method_Boolean_booleanValue
jmethodID m_ctor_Character_with_char
jmethodID m_method_Short_shortValue
jmethodID m_ctor_Double_with_double
void destruct(JNIEnv *jni_env)
jmethodID m_method_Long_longValue
jclass m_class_UnoRuntime
jmethodID m_method_Class_getName
::com::sun::star::uno::Type const & m_RuntimeException_type
static JNI_info const * get_jni_info(rtl::Reference< jvmaccess::UnoVirtualMachine > const &uno_vm)
jfieldID m_field_JNI_proxy_m_oid
jmethodID m_ctor_Float_with_float
jfieldID m_field_Type_typeName
jmethodID m_ctor_Any_with_Type_Object
jclass m_class_RuntimeException
jmethodID m_method_JNI_proxy_get_proxy_ctor
jmethodID m_method_Double_doubleValue
jfieldID m_field_JNI_proxy_m_type
jobject m_object_Type_UNSIGNED_LONG
jmethodID m_method_IEnvironment_registerInterface
jfieldID m_field_Enum_m_value
::com::sun::star::uno::Type const & m_Exception_type
jmethodID m_method_TypeClass_fromInt
jobject m_object_Type_UNSIGNED_HYPER
jmethodID m_method_Float_floatValue
JNI_info(const JNI_info &)=delete
jmethodID m_ctor_Byte_with_byte
jmethodID m_ctor_Type_with_Name_TypeClass
jmethodID m_ctor_Boolean_with_boolean
jfieldID m_field_Any_object
jobject m_object_java_env
jmethodID m_ctor_Long_with_long
JNI_type_info const * get_type_info(JNI_context const &jni, typelib_TypeDescription *type) const
JNI_interface_type_info const * m_XInterface_type_info
jfieldID m_field_Any_type
jmethodID m_method_Byte_byteValue
jmethodID m_method_JNI_proxy_create
void destroy(JNIEnv *jni_env)
static void append_sig(OStringBuffer *buf, typelib_TypeDescriptionReference *type, bool use_Object_for_type_XInterface=true, bool use_slashes=true)
jmethodID m_ctor_AsynchronousFinalizer
jmethodID m_ctor_Integer_with_int
jmethodID m_method_UnoRuntime_generateOid
jmethodID m_ctor_Type_with_Class
jfieldID m_field_JNI_proxy_m_receiver_handle
jmethodID m_method_AsynchronousFinalizer_drain
jobject m_object_Type_UNSIGNED_SHORT
jmethodID m_method_UnoRuntime_queryInterface
jobject m_object_Any_VOID
JNI_type_info const * create_type_info(JNI_context const &jni, typelib_TypeDescription *td) const
jmethodID m_method_Character_charValue
jclass m_class_AsynchronousFinalizer
jmethodID m_method_Object_toString
jmethodID m_method_Throwable_getMessage
typelib_TypeDescription * get() const
JNIEnv * getEnvironment() const
SAL_JNI_EXPORT void JNICALL Java_com_sun_star_bridges_jni_1uno_JNI_1info_1holder_finalize__J(JNIEnv *jni_env, SAL_UNUSED_PARAMETER jobject, jlong jni_info_handle) SAL_THROW_EXTERN_C()
struct _typelib_TypeDescription typelib_TypeDescription
bool type_equals(typelib_TypeDescriptionReference *type1, typelib_TypeDescriptionReference *type2)
jstring ustring_to_jstring(JNI_context const &jni, rtl_uString const *ustr)
jclass find_class(JNI_context const &jni, char const *class_name, bool inException=false)
jobject create_type(JNI_context const &jni, jclass clazz)
bool is_XInterface(typelib_TypeDescriptionReference *type)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
std::unique_ptr< jfieldID[]> m_fields
virtual void destroy(JNIEnv *jni_env) override
JNI_compound_type_info(JNI_context const &jni, typelib_TypeDescription *td)
JNI_type_info const * m_base
JNI_interface_type_info(JNI_context const &jni, typelib_TypeDescription *td)
virtual void destroy(JNIEnv *jni_env) override
std::unique_ptr< jmethodID[]> m_methods
void destruct(JNIEnv *jni_env)
::com::sun::star::uno::TypeDescription m_td
JNI_type_info(const JNI_type_info &)=delete
virtual void destroy(JNIEnv *jni_env)=0
#define SAL_THROW_EXTERN_C()