2010-03-11 00:43:21 +01:00
|
|
|
package com.metaweb.gridworks.expr;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
2010-04-14 23:30:39 +02:00
|
|
|
import org.python.core.Py;
|
2010-03-11 00:43:21 +01:00
|
|
|
import org.python.core.PyObject;
|
|
|
|
|
|
|
|
public class JythonHasFieldsWrapper extends PyObject {
|
2010-03-11 20:56:43 +01:00
|
|
|
private static final long serialVersionUID = -1275353513262385099L;
|
2010-03-22 01:54:56 +01:00
|
|
|
|
|
|
|
public HasFields _obj;
|
|
|
|
|
|
|
|
private Properties _bindings;
|
|
|
|
|
|
|
|
public JythonHasFieldsWrapper(HasFields obj, Properties bindings) {
|
|
|
|
_obj = obj;
|
|
|
|
_bindings = bindings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PyObject __finditem__(PyObject key) {
|
|
|
|
String k = (String) key.__tojava__(String.class);
|
|
|
|
Object v = _obj.getField(k, _bindings);
|
|
|
|
if (v != null) {
|
2010-04-14 23:30:39 +02:00
|
|
|
if (v instanceof PyObject) {
|
2010-03-22 01:54:56 +01:00
|
|
|
return (PyObject) v;
|
2010-04-14 23:30:39 +02:00
|
|
|
} else if (v instanceof HasFields) {
|
|
|
|
return new JythonHasFieldsWrapper((HasFields) v, _bindings);
|
|
|
|
} else if (Py.getAdapter().canAdapt(v)) {
|
|
|
|
return Py.java2py(v);
|
2010-03-22 01:54:56 +01:00
|
|
|
} else {
|
|
|
|
return new JythonObjectWrapper(v);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 00:43:21 +01:00
|
|
|
}
|