cz.cuni.pogamut.introspection.python
Class PyObjectAdapter

java.lang.Object
  extended by cz.cuni.pogamut.introspection.python.PyObjectAdapter

public class PyObjectAdapter
extends java.lang.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)


Field Summary
private  java.lang.String name
          Visual name of the property.
private  PyObjectPlace place
          Place of the wrapped object ... if the set() is called this object determines where to write the new value.
 
Constructor Summary
private PyObjectAdapter(java.lang.String name)
          Basic initialization of the class.
  PyObjectAdapter(java.lang.String name, PyObjectPlace place)
          Initialize the read-write adapter for wrapped PyObject.
 
Method Summary
 java.util.ArrayList<PyObjectAdapter> getChildren()
          Returns array list of childrens.
 java.lang.Object getJavaObject()
          Returns java representation of the object.
 java.lang.String getName()
           
 java.lang.Object getObject()
          Returns wrapped object.
 PyObjectWrapper getWrapper(java.lang.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 ... ... is list / dictionary / tuple / instance
 void set(PyObjectWrapper wrapper, java.lang.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.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

private java.lang.String name
Visual name of the property.


place

private PyObjectPlace place
Place of the wrapped object ... if the set() is called this object determines where to write the new value.

Constructor Detail

PyObjectAdapter

private PyObjectAdapter(java.lang.String name)
Basic initialization of the class.

Parameters:
object -
place -

PyObjectAdapter

public PyObjectAdapter(java.lang.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

getChildren

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

Returns:
ArrayList childrens

getName

public java.lang.String getName()

getWrapper

public PyObjectWrapper getWrapper(java.lang.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 java.lang.Object getObject()
Returns wrapped object.

Returns:
PyObject

getJavaObject

public java.lang.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,
                java.lang.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