Changeset 11450
- Timestamp:
- 12/15/08 03:31:04 (12 years ago)
- Location:
- branches/scripting/j/src/org/armedbear/lisp
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/scripting/j/src/org/armedbear/lisp/JProxy.java
r11389 r11450 125 125 //NEW IMPLEMENTATION by Alessio Stalla 126 126 127 /** 128 * A weak map associating each proxy instance with a "Lisp-this" object. 129 */ 127 130 private static final Map<Object, LispObject> proxyMap = new WeakHashMap<Object, LispObject>(); 128 131 -
branches/scripting/j/src/org/armedbear/lisp/Java.java
r11297 r11450 22 22 package org.armedbear.lisp; 23 23 24 import java.beans.BeanInfo; 25 import java.beans.IntrospectionException; 26 import java.beans.Introspector; 27 import java.beans.PropertyDescriptor; 24 28 import java.lang.reflect.Array; 25 29 import java.lang.reflect.Constructor; … … 28 32 import java.lang.reflect.Method; 29 33 import java.lang.reflect.Modifier; 34 import java.util.HashMap; 30 35 import java.util.Map; 31 import java.util.HashMap;32 36 33 37 public final class Java extends Lisp … … 692 696 } 693 697 }; 694 698 699 private static final Primitive JGET_PROPERTY_VALUE = 700 new Primitive("%jget-property-value", PACKAGE_JAVA, true, 701 "java-object property-name") { 702 703 public LispObject execute(LispObject javaObject, LispObject propertyName) throws ConditionThrowable { 704 try { 705 Object obj = javaObject.javaInstance(); 706 PropertyDescriptor pd = getPropertyDescriptor(obj, propertyName); 707 return new JavaObject(pd.getReadMethod().invoke(obj)); 708 } catch (Exception e) { 709 ConditionThrowable t = new ConditionThrowable("Exception in accessing property"); 710 t.initCause(e); 711 throw t; 712 } 713 } 714 }; 715 716 private static final Primitive JSET_PROPERTY_VALUE = 717 new Primitive("%jset-property-value", PACKAGE_JAVA, true, 718 "java-object property-name value") { 719 720 public LispObject execute(LispObject javaObject, LispObject propertyName, LispObject value) throws ConditionThrowable { 721 try { 722 Object obj = javaObject.javaInstance(); 723 PropertyDescriptor pd = getPropertyDescriptor(obj, propertyName); 724 pd.getWriteMethod().invoke(obj, value.javaInstance()); 725 return value; 726 } catch (Exception e) { 727 ConditionThrowable t = new ConditionThrowable("Exception in accessing property"); 728 t.initCause(e); 729 throw t; 730 } 731 } 732 }; 733 734 private static PropertyDescriptor getPropertyDescriptor(Object obj, LispObject propertyName) throws ConditionThrowable, IntrospectionException { 735 String prop = ((AbstractString) propertyName).getStringValue(); 736 BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); 737 for(PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { 738 if(pd.getName().equals(prop)) { 739 return pd; 740 } 741 } 742 throw new ConditionThrowable("Property " + prop + " not found in " + obj); 743 } 744 695 745 private static Class classForName(String className) throws ConditionThrowable 696 746 { -
branches/scripting/j/src/org/armedbear/lisp/autoloads.lisp
r11379 r11450 192 192 (export 'jmake-proxy "JAVA") 193 193 (autoload 'jmake-proxy "java") 194 (export 'jproperty-value "JAVA") 195 (autoload 'jproperty-value "java") 194 196 (export 'jobject-class "JAVA") 195 197 (autoload 'jobject-class "java") -
branches/scripting/j/src/org/armedbear/lisp/java.lisp
r11389 r11450 279 279 (error "Unknown load-from for ~A" class-name))))) 280 280 281 (defun jproperty-value (obj prop) 282 (%jget-property-value obj prop)) 283 284 (defun (setf jproperty-value) (value obj prop) 285 (%jset-property-value obj prop value)) 286 281 287 (provide "JAVA-EXTENSIONS") -
branches/scripting/j/src/org/armedbear/lisp/scripting/AbclScriptEngine.java
r11393 r11450 327 327 public ScriptEngineFactory getFactory() { 328 328 return new AbclScriptEngineFactory(); 329 }330 331 public static String decoratedVariableName(String jvar) {332 return jvar.toUpperCase();333 329 } 334 330 -
branches/scripting/j/src/org/armedbear/lisp/scripting/AbclScriptEngineFactory.java
r11360 r11450 79 79 sb.append(method); 80 80 sb.append("\" "); 81 sb.append( AbclScriptEngine.decoratedVariableName(obj));81 sb.append(obj); 82 82 for(String arg : args) { 83 83 sb.append(" "); 84 sb.append( AbclScriptEngine.decoratedVariableName(arg));84 sb.append(arg); 85 85 } 86 86 sb.append(")"); -
branches/scripting/j/src/org/armedbear/lisp/scripting/lisp/abcl-script.lisp
r11393 r11450 88 88 (lambda () 89 89 ,@(read-from-string (concatenate 'string "(" code-string ")"))))))) 90 91 92 ;;Java interface implementation 93 94 (defvar *interface-implementation-map* (make-hash-table :test #'equal)) 95 96 (defun find-java-interface-implementation (interface) 97 (gethash interface *interface-implementation-map*)) 98 99 (defun register-java-interface-implementation (interface impl) 100 (setf (gethash interface *interface-implementation-map*) impl)) 101 102 (defun remove-java-interface-implementation (interface) 103 (remhash interface *interface-implementation-map*)) 104 105 (defun define-java-interface-implementation (interface implementation &optional lisp-this) 106 (register-java-interface-implementation 107 interface 108 (jmake-proxy interface implementation lisp-this))) -
branches/scripting/j/src/org/armedbear/lisp/scripting/lisp/packages.lisp
r11393 r11450 24 24 #:define-java-interface-implementation 25 25 #:find-java-interface-implementation 26 #:implement-java-interface)) 26 #:register-java-interface-implementation 27 #:remove-java-interface-implementation)) 27 28 28 29 (defpackage :abcl-script-user
Note: See TracChangeset
for help on using the changeset viewer.