File: PyBeanEvent.java

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (43 lines) | stat: -rw-r--r-- 1,162 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) Corporation for National Research Initiatives
package org.python.core;

import java.lang.reflect.Method;

public class PyBeanEvent<T> extends PyObject {

    public Method addMethod;

    public Class<T> eventClass;

    public String __name__;

    public PyBeanEvent(String name, Class<T> eventClass, Method addMethod) {
        __name__ = name.intern();
        this.addMethod = addMethod;
        this.eventClass = eventClass;
    }

    public PyObject _doget(PyObject container) {
        throw Py.TypeError("write only attribute");
    }

    boolean jdontdel() {
        throw Py.TypeError("can't delete this attribute");
    }

    public boolean _doset(PyObject self, PyObject value) {
        Object jself = Py.tojava(self, addMethod.getDeclaringClass());
        T jvalue = Py.tojava(value, eventClass);
        try {
            addMethod.invoke(jself, jvalue);
        } catch (Exception e) {
            throw Py.JavaError(e);
        }
        return true;
    }

    public String toString() {
        return "<beanEvent " + __name__ + " for event " + eventClass.toString() + " "
                + Py.idstr(this) + ">";
    }
}