Class: RubyWrapperBeanAdapter
- Inherits:
-
Object
- Object
- RubyWrapperBeanAdapter
- Defined in:
- lib/fxmlloader/rrba.rb
Overview
/**
-
Exposes Java Bean properties of an object via the {@link Mapend interface.
-
A call to {@link Map#get(Object)end invokes the getter for the corresponding
-
property, and a call to {@link Map#put(Object, Object)end invokes the
-
property’s setter. Appending a “Property” suffix to the key returns the
-
corresponding property model.
*/
Constant Summary collapse
- GET_PREFIX =
"get"- IS_PREFIX =
"is"- SET_PREFIX =
"set"- PROPERTY_SUFFIX =
"Property"- VALUE_OF_METHOD_NAME =
"valueOf"- @@globalMethodCache =
{}
Class Method Summary collapse
-
.coerce(value, type) ⇒ Object
/** * Coerces a value to a given type.
- .for(names) ⇒ Object
-
.get3(target, sourceType, key) ⇒ Object
/** * Invokes the static getter method for the given property.
-
.getConstantValue(type, name) ⇒ Object
/** * Returns the value of a named constant.
-
.getGenericListItemType(listType) ⇒ Object
/** * Determines the type of a list item.
-
.getGenericMapValueType(mapType) ⇒ Object
/** * Determines the type of a map value.
-
.getGenericType(sourceType, key, targetType) ⇒ Object
/** * Returns the generic type of a static property.
-
.getListItemType(listType) ⇒ Object
/** * Determines the type of a list item.
-
.getMapValueType(mapType) ⇒ Object
/** * Determines the type of a map value.
- .getStaticGetterMethod(sourceType, key, targetType) ⇒ Object
- .getStaticSetterMethod(sourceType, key, valueType, targetType, rubify = false) ⇒ Object
-
.getType(sourceType, key, targetType) ⇒ Object
/** * Returns the type of a static property.
-
.isDefined(sourceType, key, targetType) ⇒ Object
/** * Tests the existence of a static property.
-
.put3(target, sourceType, key, value) ⇒ Object
/** * Invokes a static setter method for the given property.
- .toAllCaps(value) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#[]=(key, value) ⇒ Object
/** * Invokes a setter method for the given property.
- #coerce(value, type) ⇒ Object
- #entrySet ⇒ Object
-
#getBean ⇒ Object
/** * Returns the Bean object this adapter wraps.
- #getClassMethodCache(type) ⇒ Object
-
#getGenericType(key) ⇒ Object
/** * Returns the generic type of a property.
- #getGetterMethod(key) ⇒ Object
- #getMethod(name, *parameterTypes) ⇒ Object
- #getMethodName(prefix, key) ⇒ Object
-
#getPropertyModel(key) ⇒ Object
/** * Returns the property model for the given property.
- #getSetterMethod(key) ⇒ Object
-
#getType(key) ⇒ Object
/** * Returns the type of a property.
-
#has_key?(key) ⇒ Boolean
/** * Verifies the existence of a property.
-
#initialize(bean) ⇒ RubyWrapperBeanAdapter
constructor
Creates a Bean.new adapter.
-
#read_only?(key) ⇒ Boolean
/** * Tests the mutability of a property.
Constructor Details
#initialize(bean) ⇒ RubyWrapperBeanAdapter
Creates a Bean.new adapter.
The Bean object to wrap.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fxmlloader/rrba.rb', line 59 def initialize(bean) @bean = bean; type = @bean.java_class while (type != Java.java.lang.Object.java_class && !@@globalMethodCache.has_key?(type)) @@globalMethodCache[type] = getClassMethodCache(type) type = type.superclass(); end end |
Class Method Details
.coerce(value, type) ⇒ Object
/**
* Coerces a value to a given type.
*
* @param value
* @param type
*
* @return
* The coerced value.
*/
@SuppressWarnings("unchecked")
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/fxmlloader/rrba.rb', line 331 def self.coerce( value, type) dputs "coercing..." if (type == nil) dputs "WHAT!" raise "ArgumentError.new();" end if (value.class == Java::JavaObject) dputs "de-objectifying it!!!!" dp value.class dp value.java_class dp value.to_java value = value.to_java end coercedValue = nil; if (value == nil) # Null values can only be coerced to nil coercedValue = nil; elsif (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)) # Value doesn't require coercion coercedValue = value; elsif !value.respond_to?(:java_class) && !type.enum? # its a ruby value dir = ->(x){x} to_x = ->(x){->(o){o.send(x)}} to_dbl = ->(x){java.lang.Double.valueOf(x.to_s)} to_bool = ->(x){java.lang.Boolean.valueOf(x.to_s)} value_of = ->(x){type.ruby_class.valueOf(x.to_s)} # TODO: Java::double[].java_class.component_type mapper = { [String, java.lang.String.java_class] => dir, [Fixnum, java.lang.Integer.java_class] => dir, [Float, java.lang.Double.java_class] => dir, [Float, Java::double.java_class] => dir, [String, Java::double.java_class] => to_dbl, [String, java.lang.Double.java_class] => to_dbl, [String, Java::int.java_class] => to_x.call(:to_i), [String,java.lang.Integer.java_class] => to_x.call(:to_i), [String, Java::boolean.java_class] => to_bool, [String, Java::javafx.scene.paint.Paint.java_class] => value_of, [String, Java::java.lang.Object.java_class] => ->(x){x}, [String, Java::double[].java_class] => ->(x){x.split(/[, ]+/).map(&:to_f)} } if mapper[[value.class, type]] coercedValue = mapper[[value.class, type]].call(value) else dputs "!! Non-normal RUBY coerce (#{value}, #{type}) (#{value.inspect}, [#{value.class}, #{type.inspect}])" raise "Unknown Coercion map: (#{value}, #{type}) (#{value.inspect}, [#{value.class}, #{type.inspect}]; Please file a bug on this." end # Ruby String :D elsif value.class == String && type.enum? if value[0] == value[0].downcase puts "WHOA Value is not #{value}" #TODO: does this need proper snake casing when upcasting? value = value.upcase end coercedValue = type.ruby_class.valueOf(value) elsif value.respond_to?(:java_class) && value.java_class == Java::java.net.URL.java_class && type == Java::java.lang.String.java_class # TODO: HACK! dputs "COnverting url to string" coercedValue = value.to_s else dputs "!! Non-normal coerce (#{value}, #{type}) (#{value.inspect}, #{type.inspect})" if (type == java.lang.Boolean.java_class || type == Boolean.TYPE) coercedValue = Boolean.valueOf(value.toString()); elsif (type == Character.java_class || type == Character.TYPE) coercedValue = value.toString().charAt(0); elsif (type == Byte.java_class || type == Byte.TYPE) if (value.is_a? Number) coercedValue = (value).byteValue(); else coercedValue = Byte.valueOf(value.toString()); end elsif (type == Short.java_class || type == Short.TYPE) if (value.is_a? Number) coercedValue = (value).shortValue(); else coercedValue = Short.valueOf(value.toString()); end elsif (type == Integer.java_class || type == Integer.TYPE) if (value.is_a? Number) coercedValue = (value).intValue(); else coercedValue = Integer.valueOf(value.toString()); end elsif (type == Long.java_class || type == Long.TYPE) if (value.is_a? Number) coercedValue = (value).longValue(); else coercedValue = Long.valueOf(value.toString()); end elsif (type == BigInteger.java_class) if (value.is_a? Number) coercedValue = BigInteger.valueOf((value).longValue()); else coercedValue = BigInteger.new(value.toString()); end elsif (type == Float.java_class || type == Float.TYPE) if (value.is_a? Number) coercedValue = (value).floatValue(); else coercedValue = Float.valueOf(value.toString()); end elsif (type == Double.java_class || type == Double.TYPE) if (value.is_a? Number) coercedValue = (value).doubleValue(); else coercedValue = Double.valueOf(value.toString()); end elsif (type == Number.java_class) number = value.toString(); if (number.contains(".")) coercedValue = Double.valueOf(number); else coercedValue = Long.valueOf(number); end elsif (type == BigDecimal.java_class) if (value.is_a? Number) coercedValue = BigDecimal.valueOf((value).doubleValue()); else coercedValue = BigDecimal.new(value.toString()); end elsif (type == Class.java_class) begin ReflectUtil.checkPackageAccess(value.toString()); coercedValue = Class.forName( value.to_s, false, JRuby.runtime.get_class_loader); rescue ClassNotFoundException => exception raise Exception.new(exception); end else dputs "elsee" valueType = value.java_class(); valueOfMethod = nil; while (valueOfMethod == nil && valueType != nil) begin dputs "checking access" ReflectUtil.checkPackageAccess(type); valueOfMethod = type.declared_method(VALUE_OF_METHOD_NAME, valueType); rescue NoSuchMethodException => exception # No-op end if (valueOfMethod == nil) valueType = valueType.superclass(); end end if (valueOfMethod == nil) raise IllegalArgumentException.new("Unable to coerce " + value + " to " + type + "."); end if type.isEnum() && value.is_a?(String) && value[0] == value[0].downcase value = RubyWrapperBeansAdapter.toUpcase value; end begin coercedValue = MethodUtil.invoke(valueOfMethod, nil, [ value ]); rescue IllegalAccessException => exception dputs "EAI1" dp exception raise "RuntimeException.new(exception);" rescue InvocationTargetException => exception dputs "ETI1" dp exception raise "RuntimeException.new(exception);" rescue SecurityException => exception dputs "SE1" dp exception raise "RuntimeException.new(exception);" end end end dputs "Coerced #{value.class} into a #{coercedValue.class} for #{type}" dp value, coercedValue return coercedValue; end |
.for(names) ⇒ Object
1000 1001 1002 1003 1004 1005 1006 |
# File 'lib/fxmlloader/rrba.rb', line 1000 def self.for(names) if names.is_a? java.lang.Object RubyWrapperBeanAdapter.new(names) else RubyObjectWrapperBeanAdapter.new(names) end end |
.get3(target, sourceType, key) ⇒ Object
/**
* Invokes the static getter method for the given property.
*
* @param target
* The object to which the property is attached.
*
* @param sourceType
* The class that defines the property.
*
* @param key
* The property name.
*
* @return
* The value returned by the method, or <tt>nil</tt> if no such method
* exists.
*/
@SuppressWarnings("unchecked")
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'lib/fxmlloader/rrba.rb', line 529 def self.get3(target, sourceType, key) value = nil; targetType = target.java_class(); getterMethod = getStaticGetterMethod(sourceType, key, targetType); if (getterMethod != nil) begin value = MethodUtil.invoke(getterMethod, nil, [target ] ); rescue InvocationTargetException => exception raise RuntimeException.new(exception); rescue IllegalAccessException => exception raise RuntimeException.new(exception); end end return value; end |
.getConstantValue(type, name) ⇒ Object
/**
* Returns the value of a named constant.
*
* @param type
* The type that defines the constant.
*
* @param name
* The name of the constant.
*/
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
# File 'lib/fxmlloader/rrba.rb', line 829 def self.getConstantValue( type, name) if (type == nil) raise IllegalArgumentException.new(); end if (name == nil) raise IllegalArgumentException.new(); end field = nil begin field = FieldUtil.getField(type, name); rescue NoSuchFieldException => exception raise IllegalArgumentException.new(exception); end int fieldModifiers = field.modifiers(); if ((fieldModifiers & Modifier.STATIC) == 0 || (fieldModifiers & Modifier.FINAL) == 0) raise IllegalArgumentException.new("Field is not a constant."); end value = nil begin value = field.get(nil); rescue IllegalAccessException => exception raise IllegalArgumentException.new(exception); end return value; end |
.getGenericListItemType(listType) ⇒ Object
/**
* Determines the type of a list item.
*
* @param listType
*/
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'lib/fxmlloader/rrba.rb', line 709 def self.getGenericListItemType(listType) itemType = nil; parentType = listType; dputs "searching for generic #{listType}" while (parentType != nil) dputs "Still not nill" dp parentType if (parentType.is_a? ParameterizedType) dputs "Parametratized type!" parameterizedType = parentType; rawType = parameterizedType.getRawType(); dp rawType, parameterizedType if (List.java_class.assignable_from?(rawType)) itemType = parameterizedType.getActualTypeArguments()[0]; dputs "OOOOOHHH item type is #{itemType}" dp itemType end break; end classType = parentType; dputs "checinhg generic interfaces" genericInterfaces = classType.generic_interfaces(); genericInterfaces.each do |genericInterface| dputs "serarcing ingeraface" dp genericInterface if (genericInterface.is_a? ParameterizedType) parameterizedType = genericInterface; interfaceType = parameterizedType.getRawType(); dputs "checking" dp parameterizedType, interfaceType if (List.java_class.assignable_from?(interfaceType.java_class)) || (List.java_class.assignable_from?(interfaceType.java_object)) itemType = parameterizedType.getActualTypeArguments()[0]; dputs "found it at " dp parameterizedType, interfaceType, itemType dp itemType.bounds break; end end end if (itemType != nil) break; end parentType = classType.generic_superclass(); end if (itemType != nil && itemType.is_a?(java.lang.reflect.TypeVariable)) dputs 'aww shucks' dp itemType itemType = Java::java.lang.Object.java_class; end return itemType; end |
.getGenericMapValueType(mapType) ⇒ Object
/**
* Determines the type of a map value.
*
* @param mapType
*/
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 |
# File 'lib/fxmlloader/rrba.rb', line 774 def self.getGenericMapValueType( mapType) valueType = nil; parentType = mapType; while (parentType != nil) if (parentType.is_a? ParameterizedType) parameterizedType = parentType; rawType = parameterizedType.getRawType(); if (java.util.Map.java_class.assignable_from?(rawType)) valueType = parameterizedType.getActualTypeArguments()[1]; end break; end classType = parentType; genericInterfaces = classType.getGenericInterfaces(); genericInterfaces.each do |genericInterface| if (genericInterface.is_a? ParameterizedType) parameterizedType = genericInterface; interfaceType = parameterizedType.getRawType(); if (java.util.Map.java_class.assignable_from?(interfaceType)) valueType = parameterizedType.getActualTypeArguments()[1]; break; end end end if (valueType != nil) break; end parentType = classType.getGenericSuperclass(); end if valueType != nil && valueType.is_a?(TypeVariable) valueType = Java::java.lang.Object.java_class; end return valueType; end |
.getGenericType(sourceType, key, targetType) ⇒ Object
/**
* Returns the generic type of a static property.
*
* @param sourceType
* The class that defines the property.
*
* @param key
* The property name.
*
* @param targetType
* The type of the object to which the property applies.
*/
668 669 670 671 |
# File 'lib/fxmlloader/rrba.rb', line 668 def self.getGenericType( sourceType, key, targetType) Method getterMethod = getStaticGetterMethod(sourceType, key, targetType); return (getterMethod == nil) ? nil : getterMethod.getGenericReturnType(); end |
.getListItemType(listType) ⇒ Object
/**
* Determines the type of a list item.
*
* @param listType
*/
678 679 680 681 682 683 684 685 686 687 |
# File 'lib/fxmlloader/rrba.rb', line 678 def self.getListItemType(listType) itemType = getGenericListItemType(listType); if (itemType.is_a? ParameterizedType) itemType = (itemType).getRawType(); end dputs "Listem item type is for " dp listType, itemType return itemType; end |
.getMapValueType(mapType) ⇒ Object
/**
* Determines the type of a map value.
*
* @param listType
*/
694 695 696 697 698 699 700 701 702 |
# File 'lib/fxmlloader/rrba.rb', line 694 def self.getMapValueType( mapType) valueType = getGenericMapValueType(mapType); if (valueType.is_a? ParameterizedType) valueType = (valueType).getRawType(); end return valueType; end |
.getStaticGetterMethod(sourceType, key, targetType) ⇒ Object
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
# File 'lib/fxmlloader/rrba.rb', line 860 def self.getStaticGetterMethod( sourceType, key, targetType) if (sourceType == nil) raise ArgumentError.new(); end if (key == nil) raise ArgumentError.new(); end method = nil; if (targetType != nil) key = key[0].upcase + key[1..-1]; getMethodName = GET_PREFIX + key; isMethodName = IS_PREFIX + key; begin method = MethodUtil.getMethod(sourceType, getMethodName, [ targetType ]); rescue NoSuchMethodException => exception # No-op end if (method == nil) begin method = MethodUtil.getMethod(sourceType, isMethodName, [targetType ]); rescue NoSuchMethodException => exception # No-op end end # Check for interfaces if (method == nil) interfaces = targetType.interfaces(); interfaces.length.times do |i| begin method = MethodUtil.getMethod(sourceType, getMethodName, [ interfaces[i] ]); rescue NoSuchMethodException => exception # No-op end if (method == nil) begin method = MethodUtil.getMethod(sourceType, isMethodName, [interfaces[i]] ); rescue NoSuchMethodException => exception # No-op end end if (method != nil) break; end end end if (method == nil) method = getStaticGetterMethod(sourceType, key, targetType.superclass()); end end return method; end |
.getStaticSetterMethod(sourceType, key, valueType, targetType, rubify = false) ⇒ Object
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 |
# File 'lib/fxmlloader/rrba.rb', line 923 def self.getStaticSetterMethod( sourceType, key, valueType, targetType, rubify=false) if (sourceType == nil) raise "NULL PTR" end if (key == nil) raise "NULL PTR" end if (valueType == nil) dputs caller dp sourceType, key, valueType, targetType, rubify raise "NULL PTR" end method = nil; if (targetType != nil) key = key[0].upcase + key[1..-1]; setMethodName = SET_PREFIX + key; begin unless rubify method = MethodUtil.getMethod(sourceType, setMethodName,[ targetType, valueType ]); else method = sourceType.ruby_class.method(setMethodName) end rescue NoSuchMethodException => exception # No-op end # Check for interfaces if (method == nil) interfaces = targetType.interfaces(); interfaces.length.times do |i| begin method = MethodUtil.getMethod(sourceType, setMethodName, [ interfaces[i], valueType ]); rescue NoSuchMethodException => exception # No-op end if (method != nil) break; end end end if (method == nil) method = getStaticSetterMethod(sourceType, key, valueType, targetType.superclass()); end end return method; end |
.getType(sourceType, key, targetType) ⇒ Object
/**
* Returns the type of a static property.
*
* @param sourceType
* The class that defines the property.
*
* @param key
* The property name.
*
* @param targetType
* The type of the object to which the property applies.
*/
651 652 653 654 |
# File 'lib/fxmlloader/rrba.rb', line 651 def self.getType(sourceType, key, targetType) getterMethod = getStaticGetterMethod(sourceType, key, targetType); return (getterMethod == nil) ? nil : getterMethod.return_type(); end |
.isDefined(sourceType, key, targetType) ⇒ Object
/**
* Tests the existence of a static property.
*
* @param sourceType
* The class that defines the property.
*
* @param key
* The property name.
*
* @param targetType
* The type of the object to which the property applies.
*
* @return
* <tt>true</tt> if the property exists; <tt>false</tt>, otherwise.
*/
635 636 637 |
# File 'lib/fxmlloader/rrba.rb', line 635 def self.isDefined( sourceType, key, targetType) return (getStaticGetterMethod(sourceType, key, targetType) != nil); end |
.put3(target, sourceType, key, value) ⇒ Object
/**
* Invokes a static setter method for the given property. If the value is
* <tt>nil</tt> or there is no explicit setter for a given type, the
* {@link #coerce(Object, Class)end method is used to attempt to convert the
* value to the actual property type (defined by the return value of the
* getter method).
*
* @param target
* The object to which the property is or will be attached.
*
* @param sourceType
* The class that defines the property.
*
* @param key
* The property name.
*
* @param value
* The property.new value.
*
* @throws PropertyNotFoundException
* If the given static property does not exist or is read-only.
*/
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/fxmlloader/rrba.rb', line 570 def self.put3(target, sourceType, key, value) targetType = nil if target.respond_to? :java_class targetType = target.java_class(); elsif target.is_a? String targetType = java.lang.String.java_class else dp target, sourceType, key, value raise "Shoots!" end setterMethod = nil; if (value != nil) valueClass = nil if value.respond_to? :java_class valueClass = value.java_class(); elsif value.is_a? String valueClass = java.lang.String.java_class else dp target, sourceType, key, value raise "Shoots TWICE!" end setterMethod = getStaticSetterMethod(sourceType, key, valueClass, targetType); end if (setterMethod == nil) # Get the property type and attempt to coerce the value to it propertyType = getType(sourceType, key, targetType); if (propertyType != nil) setterMethod = getStaticSetterMethod(sourceType, key, propertyType, targetType); value = coerce(value, propertyType); end end if (setterMethod == nil) raise PropertyNotFoundException.new("Static property \"" + key + "\" does not exist" + " or is read-only."); end # Invoke the setter begin getStaticSetterMethod(sourceType, key, valueClass, targetType, true).call(target.java_object, value); rescue InvocationTargetException => exception raise "RuntimeException.new(exception);" rescue IllegalAccessException => exception raise " RuntimeException.new(exception);" end end |
.toAllCaps(value) ⇒ Object
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 |
# File 'lib/fxmlloader/rrba.rb', line 979 def self.toAllCaps(value) if (value == nil) raise "NULL PTR" end allCapsBuilder = Java.java.lang.StringBuilder.new(); value.length.times do |i| c = value[(i)]; if (c.upcase == c) allCapsBuilder.append('_'); end allCapsBuilder.append(c.upcase); end return allCapsBuilder.toString(); end |
Instance Method Details
#[](key) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/fxmlloader/rrba.rb', line 154 def [](key) key = key.to_s getterMethod = key.end_with?(PROPERTY_SUFFIX) ? getMethod(key) : getGetterMethod(key); value = nil if (getterMethod != nil) begin value = getterMethod.invoke @bean rescue IllegalAccessException => exception raise RuntimeException.new(exception); rescue InvocationTargetException => exception raise RuntimeException.new(exception); end else value = nil; end return value; end |
#[]=(key, value) ⇒ Object
/**
* Invokes a setter method for the given property. The
* {@link #coerce(Object, Class)end method is used as needed to attempt to
* convert a given value to the property type, as defined by the return
* value of the getter method.
*
* @param key
* The property name.
*
* @param value
* The property.new value.
*
* @return
* Returns <tt>nil</tt>, since returning the previous value would require
* an unnecessary call to the getter method.
*
* @throws PropertyNotFoundException
* If the given property does not exist or is read-only.
*/
@Override
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 |
# File 'lib/fxmlloader/rrba.rb', line 194 def []=(key, value) dputs "calling setter" if (key == nil) raise "NULL PTR" end setterMethod = getSetterMethod(key); if (setterMethod == nil) dputs caller dputs "error in []=!" dp key, value, @bean raise PropertyNotFoundException.new("Property \"" + key + "\" does not exist" + " or is read-only."); end begin ty = getType(key) co = coerce(value, ty) setterMethod.invoke(@bean, co ); rescue IllegalAccessException => exception dp "issues1" dp exception raise "RuntimeException.new(exception);" rescue InvocationTargetException => exception dp "issues2" dp exception raise R"untimeException.new(exception);" end dputs "eone" return nil; end |
#coerce(value, type) ⇒ Object
318 319 320 |
# File 'lib/fxmlloader/rrba.rb', line 318 def coerce(value, type) RubyWrapperBeanAdapter.coerce(value, type) end |
#entrySet ⇒ Object
243 244 245 |
# File 'lib/fxmlloader/rrba.rb', line 243 def entrySet() raise UnsupportedOperationException.new(); end |
#getBean ⇒ Object
/**
* Returns the Bean object this adapter wraps.
*
* @return
* The Bean object, or <tt>nil</tt> if no Bean has been set.
*/
100 101 102 |
# File 'lib/fxmlloader/rrba.rb', line 100 def getBean() return @bean; end |
#getClassMethodCache(type) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fxmlloader/rrba.rb', line 70 def getClassMethodCache(type) classMethodCache = {} ReflectUtil.checkPackageAccess(type); declaredMethods = type.declared_instance_methods(); declaredMethods.each do |method| modifiers = method.modifiers(); if (Modifier.public?(modifiers) && !Modifier.static?(modifiers)) name = method.name(); namedMethods = classMethodCache[name] if (namedMethods == nil) namedMethods = [] classMethodCache[name] = namedMethods end namedMethods << (method) end end return classMethodCache; end |
#getGenericType(key) ⇒ Object
/**
* Returns the generic type of a property.
*
* @param key
* The property name.
*/
305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/fxmlloader/rrba.rb', line 305 def getGenericType(key) if (key == nil) raise ArgumentError.new(); end getterMethod = getGetterMethod(key); dputs "GOt getter method for #{key}" dp getterMethod dputs getterMethod return (getterMethod == nil) ? nil : getterMethod.return_type end |
#getGetterMethod(key) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/fxmlloader/rrba.rb', line 130 def getGetterMethod( key) getterMethod = getMethod(getMethodName(GET_PREFIX, key)); if (getterMethod == nil) getterMethod = getMethod(getMethodName(IS_PREFIX, key)); end return getterMethod; end |
#getMethod(name, *parameterTypes) ⇒ Object
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 |
# File 'lib/fxmlloader/rrba.rb', line 104 def getMethod(name, *parameterTypes) type = @bean.java_class(); method = nil; while (type != Java::java.lang.Object.java_class) classMethodCache = @@globalMethodCache[(type)] || {} namedMethods = classMethodCache[name] if (namedMethods != nil) for namedMethod in namedMethods if (namedMethod.name() == (name) && namedMethod.parameter_types() == parameterTypes) method = namedMethod; break; end end end if (method != nil) break; end type = type.superclass(); end return method; end |
#getMethodName(prefix, key) ⇒ Object
150 151 152 |
# File 'lib/fxmlloader/rrba.rb', line 150 def getMethodName(prefix, key) return prefix + key[0].upcase + key[1..-1]; end |
#getPropertyModel(key) ⇒ Object
/**
* Returns the property model for the given property.
*
* @param key
* The property name.
*
* @return
* The named property model, or <tt>nil</tt> if no such property exists.
*/
@SuppressWarnings("unchecked")
275 276 277 278 279 280 281 |
# File 'lib/fxmlloader/rrba.rb', line 275 def getPropertyModel( key) if (key == nil) raise ArgumentError.new(); end return self[key + PROPERTY_SUFFIX] end |
#getSetterMethod(key) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/fxmlloader/rrba.rb', line 140 def getSetterMethod( key) type = getType(key); if (type == nil) raise UnsupportedOperationException.new("Cannot determine type for property."); end return getMethod(getMethodName(SET_PREFIX, key), type) end |
#getType(key) ⇒ Object
/**
* Returns the type of a property.
*
* @param key
* The property name.
*/
289 290 291 292 293 294 295 296 297 |
# File 'lib/fxmlloader/rrba.rb', line 289 def getType(key) if (key == nil) raise ArgumentError.new(); end getterMethod = getGetterMethod(key); return (getterMethod == nil) ? nil : getterMethod.return_type(); end |
#has_key?(key) ⇒ Boolean
/**
* Verifies the existence of a property.
*
* @param key
* The property name.
*
* @return
* <tt>true</tt> if the property exists; <tt>false</tt>, otherwise.
*/
@Override
235 236 237 238 239 240 241 |
# File 'lib/fxmlloader/rrba.rb', line 235 def has_key?( key) if (key == nil) raise "NULL PTR" end return getType(key.to_s) != nil; end |
#read_only?(key) ⇒ Boolean
/**
* Tests the mutability of a property.
*
* @param key
* The property name.
*
* @return
* <tt>true</tt> if the property is read-only; <tt>false</tt>, otherwise.
*/
256 257 258 259 260 261 262 263 |
# File 'lib/fxmlloader/rrba.rb', line 256 def read_only?(key) if (key == nil) raise "NULL PTR" end dputs "checking for readonly-ness of #{key}:" dp getSetterMethod(key) return getSetterMethod(key) == nil; end |