jrubyfx-fxmlloader-master 0.4.master.2015.9.30-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,769 @@
1
+ =begin
2
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
+ *
5
+ * This code is free software; you can redistribute it and/or modify it
6
+ * under the terms of the GNU General Public License version 2 only, as
7
+ * published by the Free Software Foundation. Oracle designates this
8
+ * particular file as subject to the "Classpath" exception as provided
9
+ * by Oracle in the LICENSE file that accompanied this code.
10
+ *
11
+ * This code is distributed in the hope that it will be useful, but WITHOUT
12
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
+ * version 2 for more details (a copy is included in the LICENSE file that
15
+ * accompanied this code).
16
+ *
17
+ * You should have received a copy of the GNU General Public License version
18
+ * 2 along with this work; if not, write to the Free Software Foundation,
19
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
+ *
21
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
+ * or visit www.oracle.com if you need additional information or have any
23
+ * questions.
24
+ */
25
+ =end
26
+
27
+ #/**
28
+ # * Exposes Java Bean properties of an object via the {@link Mapend interface.
29
+ # * A call to {@link Map#get(Object)end invokes the getter for the corresponding
30
+ # * property, and a call to {@link Map#put(Object, Object)end invokes the
31
+ # * property's setter. Appending a "Property" suffix to the key returns the
32
+ # * corresponding property model.
33
+ # */
34
+ class RubyWrapperBeanAdapter
35
+
36
+ @@method_cache = {}
37
+
38
+ GET_PREFIX = "get"
39
+ IS_PREFIX = "is"
40
+ SET_PREFIX = "set"
41
+ PROPERTY_SUFFIX = "Property"
42
+
43
+ VALUE_OF_METHOD_NAME = "valueOf"
44
+
45
+ OBJECT_PUBLIC_METHODS = Object.new.public_methods
46
+
47
+ #@param @bean
48
+ #The Bean object to wrap.
49
+ def initialize(bean)
50
+ @bean = bean
51
+ type = @bean.java_class
52
+ javas = []
53
+ while type != java.lang.Object.java_class && !@@method_cache.has_key?(type)
54
+ javas += build_cache_for(type)
55
+ type = type.superclass
56
+ end
57
+ # class_methods = {}
58
+ # (@bean.public_methods - OBJECT_PUBLIC_METHODS - javas.map{|x|x.name.to_sym}).each do |method_name|
59
+ # puts "ruby method: #{method_name}"
60
+ # name = method_name.to_s
61
+ # unless class_methods.has_key? name
62
+ # class_methods[name] = []
63
+ # else
64
+ # class_methods[name]
65
+ # end << method_name.to_sym
66
+ # end
67
+ # @@method_cache[@bean.class] =
68
+ end
69
+
70
+ def build_cache_for(type)
71
+ class_methods = {}
72
+
73
+ ReflectUtil.checkPackageAccess(type) # TODO: do I want this ?
74
+
75
+ java_methods = type.declared_instance_methods.each do |method|
76
+ modifiers = method.modifiers
77
+ if Modifier.public?(modifiers) && !Modifier.static?(modifiers)
78
+ name = method.name
79
+ unless class_methods.has_key? name
80
+ class_methods[name] = []
81
+ else
82
+ class_methods[name]
83
+ end << method
84
+ end
85
+ end
86
+
87
+ @@method_cache[type] = class_methods
88
+ return java_methods
89
+ end
90
+
91
+ def getMethod(name, *parameter_types)
92
+ type = @bean.java_class
93
+ while type != java.lang.Object.java_class
94
+ if methods = (@@method_cache[type] || {})[name]
95
+ methods.each do |method|
96
+ return method if method.name == name && method.parameter_types == parameter_types
97
+ end
98
+ end
99
+ type = type.superclass
100
+ end
101
+ return nil
102
+ end
103
+
104
+ def getter(key)
105
+ capital = camelize(key)
106
+ return getMethod(GET_PREFIX + capital) if @bean.respond_to?(GET_PREFIX + capital)
107
+ return getMethod(IS_PREFIX + capital)
108
+ end
109
+
110
+ def setter(key)
111
+ raise java.lang.UnsupportedOperationException.new("Cannot determine type for property #{key}.") unless type = getType(key)
112
+ return getMethod(method_name(SET_PREFIX, key), type)
113
+ end
114
+
115
+ def method_name(prefix, key)
116
+ return prefix + camelize(key)
117
+ end
118
+
119
+ def camelize(key)
120
+ key[0].upcase + key[1..-1]
121
+ end
122
+
123
+ def [](key)
124
+ key = key.to_s
125
+ begin
126
+ unless key.end_with?(PROPERTY_SUFFIX)
127
+ camel = camelize(key)
128
+ unless !@bean.respond_to?(GET_PREFIX + camel) and @bean.respond_to?(IS_PREFIX + camel)
129
+ @bean.send(GET_PREFIX + camel)
130
+ else
131
+ @bean.send(IS_PREFIX + camel)
132
+ end
133
+ else
134
+ @bean.send key
135
+ end
136
+ rescue NoMethodError => nme
137
+ raise unless nme.name.to_s.end_with?(key)
138
+ puts "failing on #{key}"
139
+ # p @bean
140
+ # p @bean.class
141
+ # puts caller
142
+ nil
143
+ end
144
+ end
145
+
146
+ def []=(key, value)
147
+ raise "NULL PTR" unless key
148
+
149
+ setter = method_name(SET_PREFIX, key)
150
+
151
+ raise "Property \"#{key}\" does not exist or is read-only." unless @bean.respond_to? setter
152
+ ty = getType(key)
153
+ co = coerce(value, ty)
154
+ coi = RubyWrapperBeanAdapter.jit_export(co, value, ty, setter(key))
155
+ rputs @bean, "#{setter}(#{coi})"
156
+ if coi.start_with?("*[") # cheap way to not compute it twice :D
157
+ @bean.send(setter, *co)
158
+ else
159
+ @bean.send(setter, co)
160
+ end
161
+ co
162
+ end
163
+
164
+ def has_key?(key)
165
+ raise "NULL PTR" unless key
166
+ getType(key.to_s)
167
+ end
168
+
169
+ def read_only?(key)
170
+ setter(key) == nil
171
+ end
172
+
173
+ def getPropertyModel(key)
174
+ raise ArgumentError.new unless key
175
+ self[key + PROPERTY_SUFFIX]
176
+ end
177
+
178
+ def getType(key)
179
+ raise ArgumentError.new unless key
180
+ if @bean.respond_to? "#{key}GetType" # ruby type support ;-D
181
+ @bean.send("#{key}GetType")
182
+ else
183
+ getter = getter(key)
184
+ getter && getter.return_type
185
+ end
186
+ end
187
+
188
+ alias :getGenericType :getType
189
+
190
+ def coerce(value, type)
191
+ RubyWrapperBeanAdapter.coerce(value, type)
192
+ end
193
+
194
+ def self.jit_export(co, value, ty, setter, ignore=nil)
195
+ coi = co.inspect
196
+ if co.is_a? Java::JavaLang::Enum
197
+ coi = "Java::#{co.java_class.name.gsub(/[\$\.]/, "::")}::#{co.to_s}"
198
+ elsif co.is_a? EventHandlerWrapper
199
+ coi = "EventHandlerWrapper.new(__local_fxml_controller, #{co.funcName.inspect})"
200
+ elsif co.is_a? ScriptEventHandler
201
+ coi = "ScriptEventHandler.new(#{co.script.inspect}, __local_sem_lang_inst_#{rget_sem(co.scriptEngine)})"
202
+ elsif tmp = rget(value)
203
+ coi = tmp
204
+ elsif co.is_a? Java::javafx.scene.paint.Paint
205
+ coi = "RubyWrapperBeanAdapter.coerce(#{value.inspect}, #{ty.ruby_class}.java_class)"
206
+ elsif setter.respond_to? :varargs? and setter.varargs?
207
+ coi = "*#{coi}"
208
+ elsif coi.start_with? "#<"
209
+ # puts "ignoring #{setting}(#{coi})
210
+ # How about #{setting}(RubyWrapperBeanAdapter.coerce(#{value.inspect}, #{ty})) ?#
211
+
212
+ # "
213
+ coi = "RubyWrapperBeanAdapter.coerce(#{value.inspect}, #{ty.ruby_class}.java_class)"
214
+ end
215
+ return coi
216
+ end
217
+
218
+ @@mapper = nil
219
+ def self.mapper
220
+ unless @@mapper
221
+ dir = ->(x){x}
222
+ to_x = ->(x){->(o){o.send(x)}}
223
+ to_dbl = ->(x){java.lang.Double.valueOf(x.to_s)}
224
+ to_bool = ->(x){java.lang.Boolean.valueOf(x.to_s)}
225
+ value_of = ->(x, type){type.ruby_class.valueOf(x.to_s)}
226
+ # TODO: Java::double[].java_class.component_type
227
+ @@mapper = {
228
+ [String, java.lang.String.java_class] => dir,
229
+ [Fixnum, java.lang.Integer.java_class] => dir,
230
+ [Float, java.lang.Double.java_class] => dir,
231
+ [Float, Java::double.java_class] => dir,
232
+ [FalseClass, Java::boolean.java_class] => dir,
233
+ [TrueClass, Java::boolean.java_class] => dir,
234
+ [String, Java::double.java_class] => to_dbl,
235
+ [String, java.lang.Double.java_class] => to_dbl,
236
+ [String, Java::int.java_class] => to_x.call(:to_i),
237
+ [String,java.lang.Integer.java_class] => to_x.call(:to_i),
238
+ [String, Java::boolean.java_class] => to_bool,
239
+ [String, Java::javafx.scene.paint.Paint.java_class] => value_of,
240
+ [String, Java::javafx.scene.paint.Color.java_class] => value_of,
241
+ [String, Java::java.lang.Object.java_class] => dir,
242
+ [String, Java::double[].java_class] => ->(x){x.split(/[, ]+/).map(&:to_f)}
243
+ }
244
+ end
245
+ @@mapper
246
+ end
247
+
248
+ def self.coerce( value, type)
249
+ if (type == nil)
250
+ raise "ArgumentError.new();"
251
+ end
252
+ if (value.class == Java::JavaObject)
253
+ value = value.to_java
254
+ end
255
+
256
+ coercedValue = nil;
257
+ if (value == nil)
258
+ # Null values can only be coerced to nil
259
+ coercedValue = nil;
260
+ elsif type == java.lang.Object.java_class || (value.is_a?(EventHandlerWrapper) && type == Java.javafx.event.EventHandler.java_class) || (value.respond_to?(:java_class) && !value.is_a?(EventHandlerWrapper) && type.assignable_from?(value.java_class))
261
+ # Value doesn't require coercion
262
+ coercedValue = value;
263
+ elsif !value.respond_to?(:java_class) && !type.enum?
264
+ # its a ruby value
265
+
266
+ if mapper[[value.class, type]]
267
+ coercedValue = mapper[[value.class, type]]
268
+ if coercedValue.arity == 1
269
+ coercedValue = coercedValue.call(value)
270
+ else
271
+ coercedValue = coercedValue.call(value, type)
272
+ end
273
+ else
274
+ raise "Unknown Coercion map: (#{value}, #{type}) (#{value.inspect}, [#{value.class}, #{type.inspect}]; Please file a bug on this."
275
+ end
276
+ # Ruby String :D
277
+ elsif value.class == String && type.enum?
278
+ if value[0] == value[0].downcase
279
+ puts "WHOA Value is not #{value}"
280
+ #TODO: does this need proper snake casing when upcasting?
281
+ value = value.upcase
282
+ end
283
+ coercedValue = type.ruby_class.valueOf(value)
284
+ elsif value.respond_to?(:java_class) && value.java_class == Java::java.net.URL.java_class && type == Java::java.lang.String.java_class
285
+ # TODO: HACK!
286
+ dputs "COnverting url to string"
287
+ coercedValue = value.to_s
288
+ else
289
+ raise "!! Non-normal coerce (#{value}, #{type}) (#{value.inspect}, #{type.inspect})"
290
+ end
291
+ return coercedValue;
292
+ end
293
+
294
+ # /**
295
+ # * Invokes the static getter method for the given property.
296
+ # *
297
+ # * @param target
298
+ # * The object to which the property is attached.
299
+ # *
300
+ # * @param sourceType
301
+ # * The class that defines the property.
302
+ # *
303
+ # * @param key
304
+ # * The property name.
305
+ # *
306
+ # * @return
307
+ # * The value returned by the method, or <tt>nil</tt> if no such method
308
+ # * exists.
309
+ # */
310
+ # @SuppressWarnings("unchecked")
311
+ def self.get3(target, sourceType, key)
312
+ value = nil;
313
+
314
+ targetType = target.java_class();
315
+ getterMethod = getStaticGetterMethod(sourceType, key, targetType);
316
+
317
+ if (getterMethod != nil)
318
+ begin
319
+ value = MethodUtil.invoke(getterMethod, nil, [target ] );
320
+ rescue InvocationTargetException => exception
321
+ raise RuntimeException.new(exception);
322
+ rescue IllegalAccessException => exception
323
+ raise RuntimeException.new(exception);
324
+ end
325
+ end
326
+
327
+ return value;
328
+ end
329
+
330
+ # /**
331
+ # * Invokes a static setter method for the given property. If the value is
332
+ # * <tt>nil</tt> or there is no explicit setter for a given type, the
333
+ # * {@link #coerce(Object, Class)end method is used to attempt to convert the
334
+ # * value to the actual property type (defined by the return value of the
335
+ # * getter method).
336
+ # *
337
+ # * @param target
338
+ # * The object to which the property is or will be attached.
339
+ # *
340
+ # * @param sourceType
341
+ # * The class that defines the property.
342
+ # *
343
+ # * @param key
344
+ # * The property name.
345
+ # *
346
+ # * @param value
347
+ # * The property.new value.
348
+ # *
349
+ # * @throws PropertyNotFoundException
350
+ # * If the given static property does not exist or is read-only.
351
+ # */
352
+ def self.put3(target, sourceType, key, value)
353
+ targetType = nil
354
+ if target.respond_to? :java_class
355
+ targetType = target.java_class();
356
+ elsif target.is_a? String
357
+ targetType = java.lang.String.java_class
358
+ else
359
+ raise "Shoots!"
360
+ end
361
+
362
+ setterMethod = nil;
363
+ if (value != nil)
364
+ valueClass = nil
365
+
366
+ if value.respond_to? :java_class
367
+ valueClass = value.java_class();
368
+ elsif value.is_a? String
369
+ valueClass = java.lang.String.java_class
370
+ else
371
+ raise "Shoots TWICE!"
372
+ end
373
+ setterMethod = getStaticSetterMethod(sourceType, key, valueClass, targetType);
374
+ end
375
+
376
+ if (setterMethod == nil)
377
+ # Get the property type and attempt to coerce the value to it
378
+ propertyType = getType(sourceType, key, targetType);
379
+
380
+ if (propertyType != nil)
381
+ setterMethod = getStaticSetterMethod(sourceType, key, propertyType, targetType);
382
+ value = coerce(value, propertyType);
383
+ end
384
+ end
385
+
386
+ if (setterMethod == nil)
387
+ raise PropertyNotFoundException.new("Static property \"" + key + "\" does not exist" + " or is read-only.");
388
+ end
389
+
390
+ # Invoke the setter
391
+ begin
392
+ rputs target, "#{sourceType.ruby_class.inspect}.set#{key[0].upcase}#{key[1..-1]}(self, #{jit_export(value, value, targetType, key, "#{sourceType.ruby_class.inspect}.#{key}=")})"
393
+ getStaticSetterMethod(sourceType, key, valueClass, targetType, true).call(target.java_object, value);
394
+ rescue InvocationTargetException => exception
395
+ raise "RuntimeException.new(exception);"
396
+ rescue IllegalAccessException => exception
397
+ raise " RuntimeException.new(exception);"
398
+ end
399
+ end
400
+
401
+ # /**
402
+ # * Tests the existence of a static property.
403
+ # *
404
+ # * @param sourceType
405
+ # * The class that defines the property.
406
+ # *
407
+ # * @param key
408
+ # * The property name.
409
+ # *
410
+ # * @param targetType
411
+ # * The type of the object to which the property applies.
412
+ # *
413
+ # * @return
414
+ # * <tt>true</tt> if the property exists; <tt>false</tt>, otherwise.
415
+ # */
416
+ def self.isDefined( sourceType, key, targetType)
417
+ return (getStaticGetterMethod(sourceType, key, targetType) != nil);
418
+ end
419
+
420
+ # /**
421
+ # * Returns the type of a static property.
422
+ # *
423
+ # * @param sourceType
424
+ # * The class that defines the property.
425
+ # *
426
+ # * @param key
427
+ # * The property name.
428
+ # *
429
+ # * @param targetType
430
+ # * The type of the object to which the property applies.
431
+ # */
432
+ def self.getType(sourceType, key, targetType)
433
+ getterMethod = getStaticGetterMethod(sourceType, key, targetType);
434
+ return (getterMethod == nil) ? nil : getterMethod.return_type();
435
+ end
436
+
437
+ # /**
438
+ # * Returns the generic type of a static property.
439
+ # *
440
+ # * @param sourceType
441
+ # * The class that defines the property.
442
+ # *
443
+ # * @param key
444
+ # * The property name.
445
+ # *
446
+ # * @param targetType
447
+ # * The type of the object to which the property applies.
448
+ # */
449
+ def self.getGenericType( sourceType, key, targetType)
450
+ Method getterMethod = getStaticGetterMethod(sourceType, key, targetType);
451
+ return (getterMethod == nil) ? nil : getterMethod.getGenericReturnType();
452
+ end
453
+
454
+ # /**
455
+ # * Determines the type of a list item.
456
+ # *
457
+ # * @param listType
458
+ # */
459
+ def self.getListItemType(listType)
460
+ itemType = getGenericListItemType(listType);
461
+
462
+ if (itemType.is_a? ParameterizedType)
463
+ itemType = (itemType).getRawType();
464
+ end
465
+ return itemType;
466
+ end
467
+
468
+ # /**
469
+ # * Determines the type of a map value.
470
+ # *
471
+ # * @param listType
472
+ # */
473
+ def self.getMapValueType( mapType)
474
+ valueType = getGenericMapValueType(mapType);
475
+
476
+ if (valueType.is_a? ParameterizedType)
477
+ valueType = (valueType).getRawType();
478
+ end
479
+
480
+ return valueType;
481
+ end
482
+
483
+ # /**
484
+ # * Determines the type of a list item.
485
+ # *
486
+ # * @param listType
487
+ # */
488
+ def self.getGenericListItemType(listType)
489
+ itemType = nil;
490
+
491
+ parentType = listType;
492
+ while (parentType != nil)
493
+ if (parentType.is_a? ParameterizedType)
494
+ parameterizedType = parentType;
495
+ rawType = parameterizedType.getRawType();
496
+ if (List.java_class.assignable_from?(rawType))
497
+ itemType = parameterizedType.getActualTypeArguments()[0];
498
+ end
499
+
500
+ break;
501
+ end
502
+
503
+ classType = parentType;
504
+ genericInterfaces = classType.generic_interfaces();
505
+
506
+ genericInterfaces.each do |genericInterface|
507
+ if (genericInterface.is_a? ParameterizedType)
508
+ parameterizedType = genericInterface;
509
+ interfaceType = parameterizedType.getRawType();
510
+ if (List.java_class.assignable_from?(interfaceType.java_class)) || (List.java_class.assignable_from?(interfaceType.java_object))
511
+ itemType = parameterizedType.getActualTypeArguments()[0];
512
+ break;
513
+ end
514
+ end
515
+ end
516
+
517
+ if (itemType != nil)
518
+ break;
519
+ end
520
+
521
+ parentType = classType.generic_superclass();
522
+ end
523
+
524
+ if (itemType != nil && itemType.is_a?(java.lang.reflect.TypeVariable))
525
+ itemType = Java::java.lang.Object.java_class;
526
+ end
527
+
528
+ return itemType;
529
+ end
530
+
531
+ # /**
532
+ # * Determines the type of a map value.
533
+ # *
534
+ # * @param mapType
535
+ # */
536
+ def self.getGenericMapValueType( mapType)
537
+ valueType = nil;
538
+
539
+ parentType = mapType;
540
+ while (parentType != nil)
541
+ if (parentType.is_a? ParameterizedType)
542
+ parameterizedType = parentType;
543
+ rawType = parameterizedType.getRawType();
544
+
545
+ if (java.util.Map.java_class.assignable_from?(rawType))
546
+ valueType = parameterizedType.getActualTypeArguments()[1];
547
+ end
548
+
549
+ break;
550
+ end
551
+
552
+ classType = parentType;
553
+ genericInterfaces = classType.getGenericInterfaces();
554
+
555
+ genericInterfaces.each do |genericInterface|
556
+
557
+ if (genericInterface.is_a? ParameterizedType)
558
+ parameterizedType = genericInterface;
559
+ interfaceType = parameterizedType.getRawType();
560
+
561
+ if (java.util.Map.java_class.assignable_from?(interfaceType))
562
+ valueType = parameterizedType.getActualTypeArguments()[1];
563
+ break;
564
+ end
565
+ end
566
+ end
567
+
568
+ if (valueType != nil)
569
+ break;
570
+ end
571
+
572
+ parentType = classType.getGenericSuperclass();
573
+ end
574
+
575
+ if valueType != nil && valueType.is_a?(TypeVariable)
576
+ valueType = Java::java.lang.Object.java_class;
577
+ end
578
+
579
+ return valueType;
580
+ end
581
+
582
+ # /**
583
+ # * Returns the value of a named constant.
584
+ # *
585
+ # * @param type
586
+ # * The type that defines the constant.
587
+ # *
588
+ # * @param name
589
+ # * The name of the constant.
590
+ # */
591
+ def self.getConstantValue( type, name)
592
+ if (type == nil)
593
+ raise IllegalArgumentException.new();
594
+ end
595
+
596
+ if (name == nil)
597
+ raise IllegalArgumentException.new();
598
+ end
599
+
600
+ field = nil
601
+ begin
602
+ field = FieldUtil.getField(type, name);
603
+ rescue NoSuchFieldException => exception
604
+ raise IllegalArgumentException.new(exception);
605
+ end
606
+
607
+ int fieldModifiers = field.modifiers();
608
+ if ((fieldModifiers & Modifier.STATIC) == 0 || (fieldModifiers & Modifier.FINAL) == 0)
609
+ raise IllegalArgumentException.new("Field is not a constant.");
610
+ end
611
+
612
+ value = nil
613
+ begin
614
+ value = field.get(nil);
615
+ rescue IllegalAccessException => exception
616
+ raise IllegalArgumentException.new(exception);
617
+ end
618
+
619
+ return value;
620
+ end
621
+
622
+ def self.getStaticGetterMethod( sourceType, key, targetType)
623
+ if (sourceType == nil)
624
+ raise ArgumentError.new();
625
+ end
626
+
627
+ if (key == nil)
628
+ raise ArgumentError.new();
629
+ end
630
+
631
+ method = nil;
632
+
633
+ if (targetType != nil)
634
+ key = key[0].upcase + key[1..-1];
635
+
636
+ getMethodName = GET_PREFIX + key;
637
+ isMethodName = IS_PREFIX + key;
638
+
639
+ begin
640
+ method = MethodUtil.getMethod(sourceType, getMethodName, [ targetType ]);
641
+ rescue NoSuchMethodException => exception
642
+ # No-op
643
+ end
644
+
645
+ if (method == nil)
646
+ begin
647
+ method = MethodUtil.getMethod(sourceType, isMethodName, [targetType ]);
648
+ rescue NoSuchMethodException => exception
649
+ # No-op
650
+ end
651
+ end
652
+
653
+ # Check for interfaces
654
+ if (method == nil)
655
+ interfaces = targetType.interfaces();
656
+ interfaces.length.times do |i|
657
+ begin
658
+ method = MethodUtil.getMethod(sourceType, getMethodName, [ interfaces[i] ]);
659
+ rescue NoSuchMethodException => exception
660
+ # No-op
661
+ end
662
+
663
+ if (method == nil)
664
+ begin
665
+ method = MethodUtil.getMethod(sourceType, isMethodName, [interfaces[i]] );
666
+ rescue NoSuchMethodException => exception
667
+ # No-op
668
+ end
669
+ end
670
+
671
+ if (method != nil)
672
+ break;
673
+ end
674
+ end
675
+ end
676
+
677
+ if (method == nil)
678
+ method = getStaticGetterMethod(sourceType, key, targetType.superclass());
679
+ end
680
+ end
681
+
682
+ return method;
683
+ end
684
+
685
+ def self.getStaticSetterMethod( sourceType, key,
686
+ valueType, targetType, rubify=false)
687
+ if (sourceType == nil)
688
+ raise "NULL PTR"
689
+ end
690
+
691
+ if (key == nil)
692
+ raise "NULL PTR"
693
+ end
694
+
695
+ if (valueType == nil)
696
+ dputs caller
697
+ dp sourceType, key, valueType, targetType, rubify
698
+ raise "NULL PTR"
699
+ end
700
+
701
+ method = nil;
702
+
703
+ if (targetType != nil)
704
+ key = key[0].upcase + key[1..-1];
705
+
706
+ setMethodName = SET_PREFIX + key;
707
+ begin
708
+ unless rubify
709
+ method = MethodUtil.getMethod(sourceType, setMethodName,[ targetType, valueType ]);
710
+ else
711
+ method = sourceType.ruby_class.method(setMethodName)
712
+ end
713
+ rescue NoSuchMethodException => exception
714
+ # No-op
715
+ end
716
+
717
+ # Check for interfaces
718
+ if (method == nil)
719
+ interfaces = targetType.interfaces();
720
+ interfaces.length.times do |i|
721
+ begin
722
+ method = MethodUtil.getMethod(sourceType, setMethodName, [ interfaces[i], valueType ]);
723
+ rescue NoSuchMethodException => exception
724
+ # No-op
725
+ end
726
+
727
+ if (method != nil)
728
+ break;
729
+ end
730
+ end
731
+ end
732
+
733
+ if (method == nil)
734
+ method = getStaticSetterMethod(sourceType, key, valueType, targetType.superclass());
735
+ end
736
+ end
737
+
738
+ return method;
739
+ end
740
+
741
+ def self.toAllCaps(value)
742
+ if (value == nil)
743
+
744
+ raise "NULL PTR"
745
+ end
746
+
747
+ allCapsBuilder = Java.java.lang.StringBuilder.new();
748
+
749
+ value.length.times do |i|
750
+ c = value[(i)];
751
+
752
+ if (c.upcase == c)
753
+ allCapsBuilder.append('_');
754
+ end
755
+
756
+ allCapsBuilder.append(c.upcase);
757
+ end
758
+
759
+ return allCapsBuilder.toString();
760
+ end
761
+
762
+ def self.for(names)
763
+ if names.is_a? java.lang.Object or (names.is_a? Java::JavaObject and (names = names.to_java))
764
+ RubyWrapperBeanAdapter.new(names)
765
+ else
766
+ RubyObjectWrapperBeanAdapter.new(names)
767
+ end
768
+ end
769
+ end