rubyuno 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,252 @@
1
+
2
+ #include "rubyuno.hxx"
3
+
4
+ #ifdef HAVE_RUBY_IO_H
5
+ #include <ruby/io.h>
6
+ #endif
7
+
8
+ #include <rtl/textenc.h>
9
+ #include <osl/thread.h>
10
+
11
+ using rtl::OString;
12
+ using rtl::OUString;
13
+ using rtl::OUStringToOString;
14
+
15
+ namespace rubyuno
16
+ {
17
+
18
+ OUString
19
+ asciiVALUE2OUString(VALUE str)
20
+ {
21
+ Check_Type(str, T_STRING);
22
+ return OUString(RSTRING_PTR(str), RSTRING_LEN(str), RTL_TEXTENCODING_ASCII_US);
23
+ }
24
+
25
+ VALUE
26
+ asciiOUString2VALUE(const OUString &str)
27
+ {
28
+ OString o = OUStringToOString(str, RTL_TEXTENCODING_ASCII_US);
29
+ #ifdef HAVE_RUBY_ENCODING_H
30
+ return rb_enc_str_new(o.getStr(), o.getLength(), rb_usascii_encoding());
31
+ #else
32
+ return rb_str_new(o.getStr(), o.getLength());
33
+ #endif
34
+ }
35
+
36
+ #ifdef HAVE_RUBY_ENCODING_H
37
+ rtl_TextEncoding
38
+ Encoding2TextEncoding(VALUE encoding)
39
+ {
40
+ rtl_TextEncoding ret;
41
+ int index = rb_to_encoding_index(encoding);
42
+
43
+ if (index == rb_enc_find_index("US-ASCII"))
44
+ ret = RTL_TEXTENCODING_ASCII_US;
45
+ else if (index == rb_enc_find_index("UTF-8"))
46
+ ret = RTL_TEXTENCODING_UTF8;
47
+ else if (index == rb_enc_find_index("EUC-JP"))
48
+ ret = RTL_TEXTENCODING_EUC_JP;
49
+ else if (index == rb_enc_find_index("Shift_JIS"))
50
+ ret = RTL_TEXTENCODING_SHIFT_JIS;
51
+ else if (index == rb_enc_find_index("Big5"))
52
+ ret = RTL_TEXTENCODING_BIG5;
53
+ else if (index == rb_enc_find_index("EUC-KR"))
54
+ ret = RTL_TEXTENCODING_EUC_KR;
55
+ else if (index == rb_enc_find_index("EUC-TW"))
56
+ ret = RTL_TEXTENCODING_EUC_TW;
57
+ else if (index == rb_enc_find_index("GB18030"))
58
+ ret = RTL_TEXTENCODING_GB_18030;
59
+ else if (index == rb_enc_find_index("GBK"))
60
+ ret = RTL_TEXTENCODING_GBK;
61
+ else if (index == rb_enc_find_index("ISO-8859-1"))
62
+ ret = RTL_TEXTENCODING_ISO_8859_1;
63
+ else if (index == rb_enc_find_index("ISO-8859-2"))
64
+ ret = RTL_TEXTENCODING_ISO_8859_2;
65
+ else if (index == rb_enc_find_index("ISO-8859-3"))
66
+ ret = RTL_TEXTENCODING_ISO_8859_3;
67
+ else if (index == rb_enc_find_index("ISO-8859-4"))
68
+ ret = RTL_TEXTENCODING_ISO_8859_4;
69
+ else if (index == rb_enc_find_index("ISO-8859-5"))
70
+ ret = RTL_TEXTENCODING_ISO_8859_5;
71
+ else if (index == rb_enc_find_index("ISO-8859-6"))
72
+ ret = RTL_TEXTENCODING_ISO_8859_6;
73
+ else if (index == rb_enc_find_index("ISO-8859-7"))
74
+ ret = RTL_TEXTENCODING_ISO_8859_7;
75
+ else if (index == rb_enc_find_index("ISO-8859-8"))
76
+ ret = RTL_TEXTENCODING_ISO_8859_8;
77
+ else if (index == rb_enc_find_index("ISO-8859-9"))
78
+ ret = RTL_TEXTENCODING_ISO_8859_9;
79
+ else if (index == rb_enc_find_index("ISO-8859-10"))
80
+ ret = RTL_TEXTENCODING_ISO_8859_10;
81
+ else if (index == rb_enc_find_index("ISO-8859-13"))
82
+ ret = RTL_TEXTENCODING_ISO_8859_13;
83
+ else if (index == rb_enc_find_index("ISO-8859-14"))
84
+ ret = RTL_TEXTENCODING_ISO_8859_14;
85
+ else if (index == rb_enc_find_index("ISO-8859-15"))
86
+ ret = RTL_TEXTENCODING_ISO_8859_15;
87
+ else if (index == rb_enc_find_index("KOI8-R"))
88
+ ret = RTL_TEXTENCODING_KOI8_R;
89
+ else if (index == rb_enc_find_index("KOI8-U"))
90
+ ret = RTL_TEXTENCODING_KOI8_U;
91
+ else if (index == rb_enc_find_index("Windows-1251"))
92
+ ret = RTL_TEXTENCODING_MS_1251;
93
+ else if (index == rb_enc_find_index("IBM437"))
94
+ ret = RTL_TEXTENCODING_IBM_437 ;
95
+ else if (index == rb_enc_find_index("IBM737"))
96
+ ret = RTL_TEXTENCODING_IBM_737;
97
+ else if (index == rb_enc_find_index("IBM775"))
98
+ ret = RTL_TEXTENCODING_IBM_775;
99
+ else if (index == rb_enc_find_index("IBM852"))
100
+ ret = RTL_TEXTENCODING_IBM_852;
101
+ else if (index == rb_enc_find_index("IBM852"))
102
+ ret = RTL_TEXTENCODING_IBM_855;
103
+ else if (index == rb_enc_find_index("IBM855"))
104
+ ret = RTL_TEXTENCODING_IBM_857;
105
+ else if (index == rb_enc_find_index("IBM857"))
106
+ ret = RTL_TEXTENCODING_IBM_860;
107
+ else if (index == rb_enc_find_index("IBM860"))
108
+ ret = RTL_TEXTENCODING_IBM_861;
109
+ else if (index == rb_enc_find_index("IBM861"))
110
+ ret = RTL_TEXTENCODING_IBM_862;
111
+ else if (index == rb_enc_find_index("IBM862"))
112
+ ret = RTL_TEXTENCODING_IBM_863;
113
+ else if (index == rb_enc_find_index("IBM863"))
114
+ ret = RTL_TEXTENCODING_IBM_864;
115
+ else if (index == rb_enc_find_index("IBM864"))
116
+ ret = RTL_TEXTENCODING_IBM_865;
117
+ else if (index == rb_enc_find_index("IBM865"))
118
+ ret = RTL_TEXTENCODING_IBM_866;
119
+ else if (index == rb_enc_find_index("IBM866"))
120
+ ret = RTL_TEXTENCODING_IBM_869 ;
121
+ else if (index == rb_enc_find_index("Windows-1258"))
122
+ ret = RTL_TEXTENCODING_MS_1258;
123
+ else if (index == rb_enc_find_index("macCentEuro"))
124
+ ret = RTL_TEXTENCODING_APPLE_CENTEURO;
125
+ else if (index == rb_enc_find_index("macCroatian"))
126
+ ret = RTL_TEXTENCODING_APPLE_CROATIAN;
127
+ else if (index == rb_enc_find_index("macCyrillic"))
128
+ ret = RTL_TEXTENCODING_APPLE_CYRILLIC;
129
+ else if (index == rb_enc_find_index("macGreek"))
130
+ ret = RTL_TEXTENCODING_APPLE_GREEK;
131
+ else if (index == rb_enc_find_index("macIceland"))
132
+ ret = RTL_TEXTENCODING_APPLE_ICELAND;
133
+ else if (index == rb_enc_find_index("macRoman"))
134
+ ret = RTL_TEXTENCODING_APPLE_ROMAN;
135
+ else if (index == rb_enc_find_index("macRomania"))
136
+ ret = RTL_TEXTENCODING_APPLE_ROMANIAN;
137
+ else if (index == rb_enc_find_index("macThai"))
138
+ ret = RTL_TEXTENCODING_APPLE_THAI;
139
+ else if (index == rb_enc_find_index("macTurkish"))
140
+ ret = RTL_TEXTENCODING_APPLE_TURKISH;
141
+ else if (index == rb_enc_find_index("stateless-ISO-2022-JP"))
142
+ ret = RTL_TEXTENCODING_ISO_2022_JP;
143
+ else if (index == rb_enc_find_index("GB2312"))
144
+ ret = RTL_TEXTENCODING_GB_2312;
145
+ else if (index == rb_enc_find_index("GB12345"))
146
+ ret = RTL_TEXTENCODING_GBT_12345;
147
+ else if (index == rb_enc_find_index("Windows-1252"))
148
+ ret = RTL_TEXTENCODING_MS_1252;
149
+ else if (index == rb_enc_find_index("Windows-1250"))
150
+ ret = RTL_TEXTENCODING_MS_1250;
151
+ else if (index == rb_enc_find_index("Windows-1253"))
152
+ ret = RTL_TEXTENCODING_MS_1253;
153
+ else if (index == rb_enc_find_index("Windows-1254"))
154
+ ret = RTL_TEXTENCODING_MS_1254;
155
+ else if (index == rb_enc_find_index("Windows-1255"))
156
+ ret = RTL_TEXTENCODING_MS_1255;
157
+ else if (index == rb_enc_find_index("Windows-1256"))
158
+ ret = RTL_TEXTENCODING_MS_1256;
159
+ else if (index == rb_enc_find_index("Windows-1257"))
160
+ ret = RTL_TEXTENCODING_MS_1257;
161
+ else if (index == rb_enc_find_index("MacJapanese"))
162
+ ret = RTL_TEXTENCODING_APPLE_JAPANESE;
163
+ else
164
+ ret = RTL_TEXTENCODING_UTF8;
165
+
166
+ return ret;
167
+ }
168
+ #else
169
+ rtl_TextEncoding
170
+ Encoding2TextEncoding(const char *enc)
171
+ {
172
+ rtl_TextEncoding ret;
173
+ if (strcmp(enc, "UTF8") == 0)
174
+ {
175
+ ret = RTL_TEXTENCODING_UTF8;
176
+ }
177
+ else if (strcmp(enc, "SJIS") == 0)
178
+ {
179
+ ret = RTL_TEXTENCODING_SHIFT_JIS;
180
+ }
181
+ else if (strcmp(enc, "EUC") == 0)
182
+ {
183
+ ret = RTL_TEXTENCODING_EUC_JP;
184
+ }
185
+ else
186
+ {
187
+ ret = RTL_TEXTENCODING_UTF8;
188
+ }
189
+ return ret;
190
+ }
191
+ #endif
192
+
193
+ static rtl_TextEncoding external_encoding;
194
+
195
+ VALUE
196
+ ustring2RString(const ::rtl::OUString &str)
197
+ {
198
+ #ifdef HAVE_RUBY_ENCODING_H
199
+ //OString o = OUStringToOString(str, RTL_TEXTENCODING_UTF8);
200
+ //return rb_enc_str_new(o.getStr(), o.getLength(), rb_utf8_encoding());
201
+ OString o = OUStringToOString(str, external_encoding);
202
+ return rb_enc_str_new(o.getStr(), o.getLength(), rb_default_external_encoding());
203
+ #else
204
+ OString o = OUStringToOString(str, external_encoding);
205
+ return rb_str_new(o.getStr(), o.getLength());
206
+ #endif
207
+ }
208
+
209
+ OUString
210
+ rbString2OUString(VALUE rbstr)
211
+ {
212
+ Check_Type(rbstr, T_STRING);
213
+ #ifdef HAVE_RUBY_ENCODING_H
214
+ //VALUE str = rb_funcall(rbstr, rb_intern("encode"), 1, rb_str_new2("UTF-8"));
215
+ //return OUString(RSTRING_PTR(str), RSTRING_LEN(str), RTL_TEXTENCODING_UTF8);
216
+
217
+ return OUString(RSTRING_PTR(rbstr), RSTRING_LEN(rbstr), Encoding2TextEncoding(rb_obj_encoding(rbstr)));
218
+ #else
219
+ return OUString(RSTRING_PTR(rbstr), RSTRING_LEN(rbstr), external_encoding);
220
+ #endif
221
+ }
222
+
223
+ /*
224
+ void
225
+ set_external_encoding(VALUE encoding)
226
+ {
227
+ external_encoding = Encoding2TextEncoding(encoding);
228
+ }
229
+ */
230
+
231
+ void
232
+ init_external_encoding()
233
+ {
234
+ #ifdef HAVE_RUBY_ENCODING_H
235
+ external_encoding = Encoding2TextEncoding(rb_enc_default_external());
236
+ #else
237
+ external_encoding = Encoding2TextEncoding(rb_get_kcode());
238
+ #endif
239
+ }
240
+
241
+ VALUE
242
+ bytes2VALUE(const com::sun::star::uno::Sequence< sal_Int8 > &bytes)
243
+ {
244
+ #ifdef HAVE_RUBY_ENCODING_H
245
+ return rb_enc_str_new((char*)bytes.getConstArray(), bytes.getLength(), rb_ascii8bit_encoding());
246
+ #else
247
+ return rb_str_new((char*)bytes.getConstArray(), bytes.getLength());
248
+ #endif
249
+ }
250
+
251
+ }
252
+
@@ -0,0 +1,358 @@
1
+
2
+ #include "rubyuno.hxx"
3
+
4
+ #include <osl/thread.h>
5
+ #include <rtl/ustrbuf.hxx>
6
+ #include <typelib/typedescription.hxx>
7
+
8
+ #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
9
+
10
+ using com::sun::star::lang::XSingleServiceFactory;
11
+ using com::sun::star::reflection::XInterfaceTypeDescription2;
12
+ using com::sun::star::reflection::XTypeDescription;
13
+ using com::sun::star::script::XInvocation2;
14
+ using com::sun::star::uno::Any;
15
+ using com::sun::star::uno::Reference;
16
+ using com::sun::star::uno::RuntimeException;
17
+ using com::sun::star::uno::Sequence;
18
+ using com::sun::star::uno::TypeDescription;
19
+ using com::sun::star::uno::UNO_QUERY;
20
+ using com::sun::star::uno::XInterface;
21
+
22
+ using rtl::OUString;
23
+ using rtl::OUStringToOString;
24
+ using rtl::OUStringBuffer;
25
+
26
+ namespace rubyuno
27
+ {
28
+
29
+ VALUE
30
+ get_module_class()
31
+ {
32
+ return rb_const_get(rb_cObject, rb_intern("Rubyuno"));
33
+ ID id;
34
+ id = rb_intern("Rubyuno");
35
+ if (rb_const_defined(rb_cObject, id))
36
+ return rb_const_get(rb_cObject, id);
37
+ rb_raise(rb_eRuntimeError, "module undefined (Rubyuno)");
38
+ }
39
+
40
+ VALUE
41
+ get_class(const char *name)
42
+ {
43
+ VALUE module;
44
+ ID id;
45
+ id = rb_intern(name);
46
+
47
+ module = get_module_class();
48
+ if (rb_const_defined(module, id))
49
+ return rb_const_get(module, id);
50
+ rb_raise(rb_eRuntimeError, "class undefined (%s)", RSTRING_PTR(&name));
51
+ }
52
+
53
+
54
+ VALUE
55
+ get_proxy_class()
56
+ {
57
+ return get_class("RubyunoProxy");
58
+ }
59
+
60
+ VALUE
61
+ get_enum_class()
62
+ {
63
+ return get_class("Enum");
64
+ }
65
+
66
+ VALUE
67
+ get_type_class()
68
+ {
69
+ return get_class("Type");
70
+ }
71
+
72
+ VALUE
73
+ get_char_class()
74
+ {
75
+ return get_class("Char");
76
+ }
77
+
78
+ VALUE
79
+ get_any_class()
80
+ {
81
+ return get_class("Any");
82
+ }
83
+
84
+ VALUE
85
+ get_bytes_class()
86
+ {
87
+ return get_class("ByteSequence");
88
+ }
89
+
90
+ VALUE
91
+ get_interface_class()
92
+ {
93
+ ID id;
94
+ VALUE module = get_module_class();
95
+ id = rb_intern("Com");
96
+ if (!rb_const_defined(module, id))
97
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com)");
98
+ VALUE com_module = rb_const_get(module, id);
99
+ id = rb_intern("Sun");
100
+ if (!rb_const_defined(com_module, id))
101
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun)");
102
+ VALUE sun_module = rb_const_get(com_module, id);
103
+ id = rb_intern("Star");
104
+ if (!rb_const_defined(sun_module, id))
105
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun::Star)");
106
+ VALUE star_module = rb_const_get(sun_module, id);
107
+ id = rb_intern("Uno");
108
+ if (!rb_const_defined(star_module, id))
109
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun::Star::Uno)");
110
+ VALUE uno_module = rb_const_get(star_module, id);
111
+ id = rb_intern("XInterface");
112
+ if (!rb_const_defined(uno_module, id))
113
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun::Star::Uno::XInterface)");
114
+ return rb_const_get(uno_module, id);
115
+ }
116
+
117
+ VALUE
118
+ get_struct_class()
119
+ {
120
+ return get_class("RubyunoStruct");
121
+ }
122
+
123
+ VALUE
124
+ get_exception_class()
125
+ {
126
+ ID id;
127
+ VALUE module = get_module_class();
128
+ id = rb_intern("Com");
129
+ if (!rb_const_defined(module, id))
130
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com)");
131
+ VALUE com_module = rb_const_get(module, id);
132
+ id = rb_intern("Sun");
133
+ if (!rb_const_defined(com_module, id))
134
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun)");
135
+ VALUE sun_module = rb_const_get(com_module, id);
136
+ id = rb_intern("Star");
137
+ if (!rb_const_defined(sun_module, id))
138
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun::Star)");
139
+ VALUE star_module = rb_const_get(sun_module, id);
140
+ id = rb_intern("Uno");
141
+ if (!rb_const_defined(star_module, id))
142
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun::Star::Uno)");
143
+ VALUE uno_module = rb_const_get(star_module, id);
144
+ id = rb_intern("Exception");
145
+ if (!rb_const_defined(uno_module, id))
146
+ rb_raise(rb_eRuntimeError, "unknown error (Rubyuno::Com::Sun::Star::Uno::Exception)");
147
+ return rb_const_get(uno_module, id);
148
+ }
149
+
150
+ VALUE
151
+ new_Type(VALUE type_name, VALUE type_class)
152
+ {
153
+ return rb_funcall(get_enum_class(), rb_intern("new"), type_name, type_class);
154
+ }
155
+
156
+ VALUE
157
+ new_Char(VALUE character)
158
+ {
159
+ VALUE char_class = get_char_class();
160
+ return rb_funcall(char_class, rb_intern("new"), character);
161
+ }
162
+
163
+
164
+ VALUE
165
+ new_rubyuno_object(const Any &a, const Reference< XSingleServiceFactory > &xFactory)
166
+ {
167
+ Reference< XInterface > tmp_interface;
168
+ a >>= tmp_interface;
169
+ if (!tmp_interface.is())
170
+ return Qnil;
171
+ return new_rubyuno_proxy(a, xFactory, get_proxy_class());
172
+ }
173
+
174
+ VALUE
175
+ new_rubyuno_proxy(const Any &object, const Reference< XSingleServiceFactory > &xFactory, VALUE klass)
176
+ {
177
+ Sequence< Any > arguments(1);
178
+ arguments[0] <<= object;
179
+ Reference< XInvocation2 > xinvocation(xFactory->createInstanceWithArguments(arguments), UNO_QUERY);
180
+
181
+ VALUE obj;
182
+ RubyunoInternal *rubyuno;
183
+ rubyuno = new RubyunoInternal();
184
+ obj = rb_obj_alloc(klass);
185
+ DATA_PTR(obj) = rubyuno;
186
+
187
+ rubyuno->wrapped = object;
188
+ rubyuno->invocation = xinvocation;
189
+ return obj;
190
+ }
191
+
192
+ void
193
+ set_rubyuno_struct(const Any &object, const Reference< XSingleServiceFactory > &xFactory, VALUE &self)
194
+ {
195
+ Sequence< Any > arguments(1);
196
+ arguments[0] <<= object;
197
+
198
+ Reference< XInvocation2 > xinvocation(xFactory->createInstanceWithArguments(arguments), UNO_QUERY);
199
+
200
+ RubyunoInternal *rubyuno;
201
+ Data_Get_Struct(self, RubyunoInternal, rubyuno);
202
+
203
+ rubyuno->wrapped = object;
204
+ rubyuno->invocation = xinvocation;
205
+ }
206
+
207
+
208
+ /*
209
+ * Create or get modules according to name.
210
+ */
211
+ VALUE
212
+ create_module(const OUString &name)
213
+ {
214
+ VALUE parent;
215
+ parent = get_module_class();
216
+
217
+ ID id;
218
+ sal_Int32 ends, pos, tmp;
219
+ char *s;
220
+ OUStringBuffer buf;
221
+ ends = name.lastIndexOfAsciiL(".", 1);
222
+ if (!(ends > 1))
223
+ rb_raise(rb_eArgError, "invalid name(%s)",
224
+ OUStringToOString(name, osl_getThreadTextEncoding()).getStr());
225
+ tmp = 0;
226
+ pos = name.indexOfAsciiL(".", 1, 0);
227
+ OUString tmpName = name.copy(ends + 1);
228
+ if (tmpName.getLength() < 1)
229
+ rb_raise(rb_eRuntimeError, "invalid name (%s)",
230
+ OUStringToOString(tmpName, osl_getThreadTextEncoding()).getStr());
231
+
232
+ while (pos < ends)
233
+ {
234
+ pos = name.indexOfAsciiL(".", 1, tmp);
235
+
236
+ buf.append(name.copy(tmp, 1).toAsciiUpperCase()).append(name.copy(tmp +1, pos - tmp -1));
237
+ s = (char*)(OUStringToOString(buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US).getStr());
238
+
239
+ id = rb_intern(s);
240
+ if (rb_const_defined(parent, id))
241
+ parent = rb_const_get(parent, id);
242
+ else
243
+ parent = rb_define_module_under(parent, s);
244
+
245
+ tmp = pos + 1;
246
+ }
247
+ return parent;
248
+ }
249
+
250
+
251
+ /*
252
+ * Find and define class (for structs and exceptions) or module (for interfaces).
253
+ */
254
+ VALUE
255
+ find_class(const OUString &name, typelib_TypeClass typeClass)
256
+ {
257
+ ID id;
258
+ VALUE module;
259
+ sal_Int32 ends;
260
+ char *className;
261
+
262
+ module = create_module(name);
263
+ ends = name.lastIndexOfAsciiL(".", 1);
264
+ className = (char*) OUStringToOString(
265
+ name.copy(ends + 1), RTL_TEXTENCODING_ASCII_US).getStr();
266
+ id = rb_intern(className);
267
+ if (rb_const_defined(module, id))
268
+ {
269
+ return rb_const_get(module, id);
270
+ }
271
+ VALUE klass;
272
+
273
+ if (typeClass == typelib_TypeClass_STRUCT)
274
+ {
275
+ klass = rb_define_class_under(module, className, get_struct_class());
276
+ }
277
+ else if (typeClass == typelib_TypeClass_EXCEPTION)
278
+ {
279
+ klass = rb_define_class_under(module, className, get_exception_class());
280
+ }
281
+ else if (typeClass == typelib_TypeClass_INTERFACE)
282
+ {
283
+ klass = rb_define_module_under(module, className);
284
+ }
285
+ else
286
+ {
287
+ rb_raise(rb_eArgError, "unsupported type (%s)", className);
288
+ }
289
+ rb_define_const(klass, "TYPENAME", asciiOUString2VALUE(name));
290
+ return klass;
291
+ }
292
+
293
+
294
+ /*
295
+ * Define interface module.
296
+ */
297
+ VALUE
298
+ find_interface(Reference< XTypeDescription > &xTd)
299
+ {
300
+ OUString name = xTd->getName();
301
+
302
+ VALUE module = find_class(name, (typelib_TypeClass)xTd->getTypeClass());
303
+
304
+ Reference< XInterfaceTypeDescription2 > xInterfaceTd(xTd, UNO_QUERY);
305
+ Sequence< Reference< XTypeDescription > > xBaseTypes = xInterfaceTd->getBaseTypes();
306
+ Sequence< Reference< XTypeDescription> > xOptionalTypes = xInterfaceTd->getOptionalBaseTypes();
307
+
308
+ VALUE parent;
309
+ for (int i = 0; i < xBaseTypes.getLength(); i++)
310
+ {
311
+ parent = find_interface(xBaseTypes[i]);
312
+ if (! NIL_P(parent))
313
+ rb_include_module(module, parent);
314
+ }
315
+ for (int i = 0; i < xOptionalTypes.getLength(); i++)
316
+ {
317
+ parent = find_interface(xBaseTypes[i]);
318
+ if (! NIL_P(parent))
319
+ rb_include_module(module, parent);
320
+ }
321
+ return module;
322
+ }
323
+
324
+ void
325
+ raise_rb_exception(const Any &a)
326
+ {
327
+ try
328
+ {
329
+ com::sun::star::uno::Exception e;
330
+ a >>= e;
331
+
332
+ VALUE module, klass;
333
+ Runtime runtime;
334
+
335
+ OUString typeName = a.getValueTypeName();
336
+ module = create_module(typeName);
337
+
338
+ klass = find_class(typeName, (typelib_TypeClass)a.getValueTypeClass());
339
+
340
+ rb_raise(klass, OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
341
+ }
342
+ catch (com::sun::star::lang::IllegalArgumentException &e)
343
+ {
344
+ rb_raise(rb_eRuntimeError, "illegal argument exception at exception conversion.");
345
+ }
346
+ catch (com::sun::star::script::CannotConvertException &e)
347
+ {
348
+ rb_raise(rb_eRuntimeError, "error at exception conversion.");
349
+ }
350
+ catch (RuntimeException &e)
351
+ {
352
+ rb_raise(rb_eRuntimeError, "runtime exception at exception conversion.");
353
+ }
354
+ }
355
+
356
+
357
+ }
358
+