Changeset 11529 for trunk/abcl/src/org/armedbear/lisp/java.lisp
- Timestamp:
- 01/03/09 13:17:22 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/java.lisp
r11528 r11529 76 76 (apply #'%jnew-proxy interface method-names-and-defs))) 77 77 78 (defun jmake-invocation-handler (function)79 (%jmake-invocation-handler function))80 81 (when (autoloadp 'jmake-proxy)82 (fmakunbound 'jmake-proxy))83 84 (defgeneric jmake-proxy (interface implementation &optional lisp-this)85 (:documentation "Returns a proxy Java object implementing the86 provided interface using methods implemented in Lisp - typically87 closures, but implementations are free to provide other88 mechanisms. You can pass an optional 'lisp-this' object that will89 be passed to the implementing methods as their first argument. If90 you don't provide this object, NIL will be used. The second91 argument of the Lisp methods is the name of the Java method being92 implemented. This has the implication that overloaded methods are93 merged, so you have to manually discriminate them if you want94 to. The remaining arguments are java-objects wrapping the method's95 parameters."))96 97 (defmethod jmake-proxy (interface invocation-handler &optional lisp-this)98 "Basic implementation that directly uses an invocation handler."99 (%jmake-proxy (jclass interface) invocation-handler lisp-this))100 101 (defmethod jmake-proxy (interface (implementation function) &optional lisp-this)102 "Implements a Java interface forwarding method calls to a Lisp function."103 (%jmake-proxy (jclass interface) (jmake-invocation-handler implementation) lisp-this))104 105 (defmethod jmake-proxy (interface (implementation package) &optional lisp-this)106 "Implements a Java interface mapping Java method names to symbols107 in a given package. javaMethodName is mapped to a JAVA-METHOD-NAME108 symbol. An error is signaled if no such symbol exists in the package,109 or if the symbol exists but does not name a function."110 111 (flet ((java->lisp (name)112 (with-output-to-string (str)113 (let ((last-lower-p nil))114 (map nil (lambda (char)115 (let ((upper-p (char= (char-upcase char) char)))116 (when (and last-lower-p upper-p)117 (princ "-" str))118 (setf last-lower-p (not upper-p))119 (princ (char-upcase char) str)))120 name)))))121 (%jmake-proxy (jclass interface)122 (jmake-invocation-handler123 (lambda (obj method &rest args)124 (let ((sym (find-symbol125 (java->lisp method)126 implementation)))127 (unless sym128 (error "Symbol ~A, implementation of method ~A, not found in ~A"129 (java->lisp method)130 method131 implementation))132 (if (fboundp sym)133 (apply (symbol-function sym) obj method args)134 (error "Function ~A, implementation of method ~A, not found in ~A"135 sym method implementation)))))136 lisp-this)))137 138 (defmethod jmake-proxy (interface (implementation hash-table) &optional lisp-this)139 "Implements a Java interface using closures in an hash-table keyed140 by Java method name."141 (%jmake-proxy (jclass interface)142 (jmake-invocation-handler143 (lambda (obj method &rest args)144 (let ((fn (gethash method implementation)))145 (if fn146 (apply fn obj args)147 (error "Implementation for method ~A not found in ~A"148 method implementation)))))149 lisp-this))150 151 78 (defun jobject-class (obj) 152 79 "Returns the Java class that OBJ belongs to" … … 307 234 308 235 (provide "JAVA-EXTENSIONS") 309 (defun jproperty-value (obj prop)310 (%jget-property-value obj prop))311 312 (defun (setf jproperty-value) (value obj prop)313 (%jset-property-value obj prop value))314
Note: See TracChangeset
for help on using the changeset viewer.