Module java_proxy
September 11, 2015 ยท View on GitHub
This module implements a facility for creating Java object with an implementation in Erlang, using the Javassist byte code manipulation library. Copyright (c) 2014 Lars-Ake Fredlund
Authors: [Lars-Ake Fredlund (lfredlund@fi.upm.es)](mailto:Lars-Ake Fredlund (lfredlund@fi.upm.es)).
Data Types
reply()
reply() = {reply, java:value(), any()}
Function Index
| class/4 | |
| class/5 | Creates a new proxy class with the given name and superclass. |
| new/2 | |
| new/3 | Creates a new instance of a proxy class. |
Function Details
class/4
class(NodeId::java:node_id(), Name::atom(), SuperClassName::atom(), MethodFuns::[{[{atom(), java:type()}], fun((...) -> reply())}]) -> java:obj_ref()
class/5
class(NodeId::java:node_id(), Name::atom(), SuperClassName::atom(), MethodFuns::[{[{atom(), java:type()}], fun((...) -> reply())}], DefaultInit::any()) -> java:obj_ref()
Creates a new proxy class with the given name and superclass.
A method of that class is handled by including in the list in the last
argument a tuple {Methodname,Types,Fun}
where ''Methodname'' is the atom corresponding to a method in the class,
Types is a list corresponding to the types of the arguments to the method,
and Fun is a function of arity length(Types)+2 which provides the
implementation of the method. Any method not listed is handled by the superclass.
The function implementing the method receives a first argument a
binary tuple where the first element is the Java object on which the method was
invoked, and the second element is the Java representation of the method invoked.
The second argument is the state of the (Erlang) object, which is kept between
successive invocations of methods of the object.
The rest of the arguments correspond to the arguments of the method.
The function should return a tuple {reply,Result,NewState}
where Result is the result of the method call, and NewState
is the new (Erlang) object state.
An example:
_ActionListenerClass =
java_proxy:class
(N,
'myActionListener',
'javax.swing.AbstractAction',
[{{actionPerformed,['java.awt.event.ActionEvent']},fun actionPerformed/3}]).
actionPerformed(_Context,NumCalls,Event) ->
io:format("An action was performed!~n",[]),
..
{reply,void,NumCalls+1}.
creates a new Java class that handles invocations of actionPerformed
(typically in a Java Swing application).
new/2
new(NodeId::java:node_id(), Name::atom()) -> java:obj_ref()
new/3
new(NodeId::java:node_id(), Name::atom(), Init::any()) -> java:obj_ref()
Creates a new instance of a proxy class.
The third argument corresponds to the initial state of the (Erlang) object created.
An example:
java_proxy:new(N,'myActionListener',0).