Code example for TooManyListenersException

0
    } 
 
    public void addTestListener(TestListener listener) throws TooManyListenersException {
        if (listener != null) {
            if (this.listener != null) {
                throw new TooManyListenersException();
            } 
            this.listener = listener;
        } 
    } 
 
    public void removeTestListener(TestListener listener) {
        if (this.listener == listener) {
            this.listener = null;
        } 
    } 
 
    public TestListener[] getTestListeners() { 
        return (this.listener != null)
                ? new TestListener[] { this.listener }
                : new TestListener[0];