One pattern of ensuring that a Jython base class implemented in Java can call an @ExposedMethod that has potentially been overridden in Python is to have a pair of methods on the base class:
a public method named for the method to be overridden by the derived class.
an @ExposedMethod declared as final that is available in python.
Then the derived class overrides the super class method in the standard fashion, i.e.
"it will check for the existence of a (Python) method redefining (the exposed name of) that method. If it fails to find one, it calls the version in the principal class (using the super keyword in Java). If it finds a Python re-definition, it invokes that using PyObject.__call__()"
This is done the use of the rest directive in the derived template - e.g. a typical implementation is:
1 base_class: PyDefaultDict
2 want_dict: true
3 ctr:
4 incl: dict
5 rest:
6 public PyObject __missing__(PyObject key) {
7 PyType self_type=getType();
8 PyObject impl=self_type.lookup("__missing__");
9 if (impl!=null) {
10 return impl.__get__(this,self_type).__call__(key);
11 }
12 return super.__missing__(key);
13 }
So the base class now defines an @ExposedMethod:
and the public method calls the @ExposedMethod directly like:
So if any method in the base class calls the public method it will result in standard Java dynamic method dispatch to a Py*Derived class if the instance in question has derived from the base class and that will call the overridden python method if it exists or default back to the base classes implementation via super.