* defined in the script.
*/
private PyObject _createObject() throws IllegalActionException {
// create an instance by using the __call__ method
// of the Main class object
PyObject object = _class.__call__();
if (object == null) {
throw new IllegalActionException(this,
"Error in creating an instance of the Main class "
+ "defined in the script.");
}
// set up access to this actor
// first create an attribute "actor" on the object
// the PyObject class does not allow adding a new attribute to the
// object
object.__setattr__("actor", new PyJavaInstance(this));
// give the object access to attributes and ports of this actor
Iterator attributes = attributeList().iterator();
while (attributes.hasNext()) {
Attribute attribute = (Attribute) attributes.next();
String mangledName = _mangleName(attribute.getName());
if (_debugging) {
_debug("set up reference to attribute \"" + attribute.getName()
+ "\" as \"" + mangledName + "\"");
}
object.__setattr__(new PyString(mangledName), new PyJavaInstance(
attribute));
}
Iterator ports = portList().iterator();
while (ports.hasNext()) {
Port port = (Port) ports.next();
String mangledName = _mangleName(port.getName());
if (_debugging) {
_debug("set up reference to port \"" + port.getName()
+ "\" as \"" + mangledName + "\"");
}
object.__setattr__(new PyString(mangledName), new PyJavaInstance(
port));
}
// populate the method map
for (int i = 0; i < _METHOD_NAMES.length; ++i) {
String methodName = _METHOD_NAMES[i];
PyMethod method = null;
try {
method = (PyMethod) object.__findattr__(methodName);
} catch (ClassCastException ex) {
// the object has an attribute with the methodName but
// is not a method, ignore
}