cz.cuni.amis.introspection.python
Class PyObjectAdapter

Package class diagram package PyObjectAdapter
java.lang.Object
  extended by cz.cuni.amis.introspection.python.PyObjectAdapter

public class PyObjectAdapter
extends Object

This class is wrapper for PyObject which probes the PyObject for it's type and accessibility and provides methods neccessary for introspection of the PyObject If you want to extend the number of classes the Python introspection accepts, than simply create class PyNewClassWrapper extends PyObjectWrapper and add it to a PyObjectAdapater.probeObject() body. The problem with Python introspection is, that we can't rely on the information about the wrapper of the object in stored place as it can change between two calls of PyObjectAdapter methods. That's why the method getWrapper() has as an parametr PyObject. It's advised to use the adapter like this: 1) retrieve PyObject object = adapter.getPyObject() 2) retrieve PyObjectWrapper wrapper = adapter.getWrapper(object) 3) get java representation of the object from the wrapper or set the value to the engine using adapter.set(wrapper, newValue)

Author:
Jimmy

Constructor Summary
PyObjectAdapter(String name, PyObjectPlace place)
          Initialize the read-write adapter for wrapped PyObject.
 
Method Summary
 ArrayList<PyObjectAdapter> getChildren()
          Returns array list of childrens.
 Object getJavaObject()
          Returns java representation of the object.
 String getName()
           
 Object getObject()
          Returns wrapped object.
 PyObjectWrapper getWrapper(Object object)
          The problem with Python introspection is, that we can't rely on the information about the wrapper of the object in stored place as it can change between two calls of PyObjectAdapter methods.
 boolean hasChildren()
          Whether the object has children ...
 void set(PyObjectWrapper wrapper, Object newValue)
          This accepts java class instance which is proper for the object it wrappes - it uses wrapper.getNewValue() for obtaining the PyObject representation of the java object and then it uses place.set() to insert the new value to it's correct place in another python object.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PyObjectAdapter

public PyObjectAdapter(String name,
                       PyObjectPlace place)
Initialize the read-write adapter for wrapped PyObject. Note that set() method will work iff it is supported by the wrapper.getNewValue() method.

Parameters:
name -
place -
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getChildren

public ArrayList<PyObjectAdapter> getChildren()
Returns array list of childrens.

Returns:
ArrayList childrens

getName

public String getName()

getWrapper

public PyObjectWrapper getWrapper(Object object)
The problem with Python introspection is, that we can't rely on the information about the wrapper of the object in stored place as it can change between two calls of PyObjectAdapter methods. That's why the method getWrapper() has as an parametr PyObject. Call getWrapper(getPyObject()) if you want the wrapper but bear in mind that the wrapper can change -> there for store it if you will want to call set().

Parameters:
object -
Returns:
wrapper for the object

getObject

public Object getObject()
Returns wrapped object.

Returns:
PyObject

getJavaObject

public Object getJavaObject()
Returns java representation of the object. The java representation is returned according to the wrapper of the object stored in the adapter (precisly according to the object stored in defined place).

Returns:
Object Java representation of the object

set

public void set(PyObjectWrapper wrapper,
                Object newValue)
This accepts java class instance which is proper for the object it wrappes - it uses wrapper.getNewValue() for obtaining the PyObject representation of the java object and then it uses place.set() to insert the new value to it's correct place in another python object.

Parameters:
newValue - java object

hasChildren

public boolean hasChildren()
Whether the object has children ... ... is list / dictionary / tuple / instance

Returns:
boolean


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.