File: javavm_xml3.sql

package info (click to toggle)
virtuoso-opensource 6.1.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 245,116 kB
  • sloc: ansic: 639,631; sql: 439,225; xml: 287,085; java: 61,048; sh: 38,723; cpp: 36,889; cs: 25,240; php: 12,562; yacc: 9,036; lex: 7,149; makefile: 6,093; jsp: 4,447; awk: 1,643; perl: 1,017; ruby: 1,003; python: 329
file content (251 lines) | stat: -rw-r--r-- 8,216 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
--
--  $Id: javavm_xml3.sql,v 1.2.2.1 2009/04/20 21:14:00 source Exp $
--
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--
--  Copyright (C) 1998-2006 OpenLink Software
--
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
--

create procedure jvm_ref_print (in xx any, inout ses any)
{
  http (xx, ses);
};

create procedure jvm_ref_describe_constructor (inout jvm_method java_lang_reflect_Constructor, inout ses any)
{
  declare method_name varchar;

  method_name := jvm_method.getName ();

  jvm_ref_print (sprintf ('\n<%s>', 'constructor'), ses);


  declare is_primitive, is_array smallint;
  declare return_type any;

  return_type := 'void';

  declare param_types any;
  declare param_inx integer;
  param_types := jvm_method.getParameterTypes ();
  param_inx := 0;
  jvm_ref_print ('\n<parameters>', ses);
  while (param_inx < length (param_types))
    {
       declare param_type, ref_type varchar;
       declare param_type_obj java_lang_Class;

       param_type_obj := param_types[param_inx];
       param_type := param_type_obj.getName ();
       is_primitive := param_type_obj.isPrimitive ();
       is_array := param_type_obj.isArray ();
       if (is_primitive = 1 and is_array = 0)
	 ref_type := 'in';
       else
	 ref_type := 'inout';
       jvm_ref_print (
	   sprintf (
	     '\n<param name="p%d" type="%s" is_primitive="%d" is_array="%d" pltype="%s" signature="%s" soaptype="%s" reftype="%s" />',
	     param_inx + 1, param_type, is_primitive, is_array,
	     jvm_type_to_pl_type (param_type, is_primitive, is_array),
	     jvm_type_to_signature (param_type, is_primitive, is_array),
	     jvm_type_to_schema_type (param_type, is_primitive, is_array),
             ref_type
	     ), ses);
       param_inx := param_inx + 1;
       param_type_obj := null;
    }
  param_types := null;
  jvm_ref_print ('\n</parameters>', ses);
  jvm_ref_print (sprintf ('\n</%s>', 'constructor'), ses);
}
;


create procedure jvm_ref_describe_method2 (inout jvm_method java_lang_reflect_Method, inout ses any)
{
  declare method_name varchar;

  method_name := jvm_method.getName();

  declare modifiers, static_mask any;
  modifiers := cast (jvm_method.getModifiers() as integer);
  static_mask := cast (java_lang_reflect_Modifier::getSTATIC() as integer);

  jvm_ref_print (sprintf ('\n<%s name="%s" static="%d">',
	'method', method_name,
	bit_and (modifiers, static_mask) / static_mask
	), ses);

  declare is_primitive, is_array smallint;
  declare return_type varchar;
  declare return_type_cls java_lang_Class;
  return_type_cls := jvm_method.getReturnType ();
  return_type := return_type_cls.getName ();
  is_primitive := return_type_cls.isPrimitive ();
  is_array := return_type_cls.isArray ();
  return_type_cls := null;
  if (return_type <> 'void')
    jvm_ref_print (sprintf ('\n<returnType type="%s" is_primitive="%d" is_array="%d" pltype="%s" signature="%s" soaptype="%s"/>',
	 return_type, is_primitive, is_array,
	 jvm_type_to_pl_type (return_type, is_primitive, is_array),
	 jvm_type_to_signature (return_type, is_primitive, is_array),
	 jvm_type_to_schema_type (return_type, is_primitive, is_array)
	 ), ses);


  declare param_types any;
  declare param_inx integer;
  param_types := jvm_method.getParameterTypes ();
  param_inx := 0;
  jvm_ref_print ('\n<parameters>', ses);
  while (param_inx < length (param_types))
    {
       declare ref_type varchar;
       declare param_type varchar;
       declare param_type_obj java_lang_Class;

       param_type_obj := param_types[param_inx];
       param_type := param_type_obj.getName ();
       is_primitive := param_type_obj.isPrimitive ();
       is_array := param_type_obj.isArray ();
       if (is_primitive = 1 and is_array = 0)
	 ref_type := 'in';
       else
	 ref_type := 'inout';
       jvm_ref_print (
	   sprintf (
	     '\n<param name="p%d" type="%s" is_primitive="%d" is_array="%d" pltype="%s" signature="%s" soaptype="%s" reftype="%s" />',
	     param_inx + 1, param_type, is_primitive, is_array,
	     jvm_type_to_pl_type (param_type, is_primitive, is_array),
	     jvm_type_to_signature (param_type, is_primitive, is_array),
	     jvm_type_to_schema_type (param_type, is_primitive, is_array),
             ref_type
	     ), ses);
       param_inx := param_inx + 1;
       param_type_obj := null;
    }
  param_types := null;
  jvm_ref_print ('\n</parameters>', ses);
  jvm_ref_print (sprintf ('\n</%s>', 'method'), ses);
}
;

create procedure jvm_ref_describe_class2 (in jvm varchar, in inherited integer := 0)
{
  declare inx integer;

  declare ses any;
  ses := string_output ();

  jvm_ref_print (sprintf ('\n<class type="%s">', jvm), ses);

  declare jvm_class java_lang_Class;
  jvm_class := java_lang_Class::forName(jvm);

-- fields
  declare jvm_fields any;
  if (inherited <> 0)
      jvm_fields := jvm_class.getFields();
  else
      jvm_fields := jvm_class.getDeclaredFields ();
  inx := 0;
  while (inx < length (jvm_fields))
    {
      declare fld_name, fld_type varchar;
      declare is_primitive, is_array smallint;
      declare modifiers, static_mask, final_mask integer;
      declare jvm_field java_lang_reflect_Field;
      declare fld_type_obj java_lang_Class;

      jvm_field := jvm_fields[inx];
      fld_name := jvm_field.getName();
      fld_type_obj := jvm_field.getType();
      fld_type := fld_type_obj.getName();
      is_primitive := fld_type_obj.isPrimitive();
      is_array := fld_type_obj.isArray();
      modifiers := cast (jvm_field.getModifiers() as integer);
      static_mask := cast (java_lang_reflect_Modifier::getSTATIC() as integer);
      final_mask := cast (java_lang_reflect_Modifier::getFINAL() as integer);
      jvm_ref_print (
	  sprintf (
	    '\n<field name="%s" type="%s" static="%d" final="%d" is_primitive="%d" is_array="%d" pltype="%s" signature="%s" soaptype="%s" />',
	    fld_name, fld_type,
	    bit_and (modifiers, static_mask) / static_mask,
	    bit_and (modifiers, final_mask) / final_mask,
	    is_primitive,
	    is_array,
	    jvm_type_to_pl_type (fld_type, is_primitive, is_array),
	    jvm_type_to_signature (fld_type, is_primitive, is_array),
	    jvm_type_to_schema_type (fld_type, is_primitive, is_array)
	    ), ses);
      inx := inx + 1;
      fld_type_obj := null;
      jvm_field := null;
    }
  jvm_fields := null;

-- constructors
  declare jvm_constructors any;
  if (inherited <> 0)
      jvm_constructors := jvm_class.getConstructors();
  else
      jvm_constructors := jvm_class.getDeclaredConstructors ();
  inx := 0;
  while (inx < length (jvm_constructors))
    {
      declare jvm_constructor java_lang_reflect_Constructor;
      jvm_constructor := jvm_constructors[inx];
      jvm_ref_describe_constructor (jvm_constructor, ses);
      inx := inx + 1;
      jvm_constructor := null;
    }
  jvm_constructors := null;

-- methods
  declare jvm_methods any;
  if (inherited <> 0)
      jvm_methods := jvm_class.getMethods ();
  else
      jvm_methods := jvm_class.getDeclaredMethods ();
  inx := 0;
  while (inx < length (jvm_methods))
    {
      declare jvm_method java_lang_reflect_Method;
      jvm_method := jvm_methods[inx];
      jvm_ref_describe_method2 (jvm_method, ses);
      inx := inx + 1;
      jvm_method := null;
    }
  jvm_methods := null;
  jvm_class := null;

  jvm_ref_print ('\n</class>', ses);
  java_vm_detach();

  return string_output_string (ses);
}
;


create procedure jvm_java_map2 (in class_name varchar, in bytecode any)
{
  java_load_class (class_name, bytecode);
  return jvm_ref_describe_class2 (class_name);
}
;