aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/event/MethodEventSource.java
blob: e1b4d76ddc0092b44b5bcb3c02dc8e46b6489caa (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 * Copyright 2000-2022 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.vaadin.event;

import java.io.Serializable;
import java.lang.reflect.Method;

import com.vaadin.shared.Registration;

/**
 * <p>
 * Interface for classes supporting registration of methods as event receivers.
 * </p>
 *
 * <p>
 * For more information on the inheritable event mechanism see the
 * {@link com.vaadin.event com.vaadin.event package documentation}.
 * </p>
 *
 * @author Vaadin Ltd.
 * @since 3.0
 */
public interface MethodEventSource extends Serializable {

    /**
     * Registers a new event listener with the specified activation method to
     * listen events generated by this component. If the activation method does
     * not have any arguments the event object will not be passed to it when
     * it's called.
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the type of the listened event. Events of this type or its
     *            subclasses activate the listener.
     * @param object
     *            the object instance who owns the activation method.
     * @param method
     *            the activation method.
     * @return a registration object for removing the listener
     * @throws IllegalArgumentException
     *             unless <code>method</code> has exactly one match in
     *             <code>object</code>
     * @throws NullPointerException
     *             if {@code object} is {@code null}
     * @since 8.0
     */
    @Deprecated
    public Registration addListener(Class<?> eventType, Object object,
            Method method);

    /**
     * Registers a new event listener with the specified activation method to
     * listen events generated by this component. If the activation method does
     * not have any arguments the event object will not be passed to it when
     * it's called.
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the type of the listened event. Events of this type or its
     *            subclasses activate the listener.
     * @param listener
     *            the listener instance who owns the activation method.
     * @param method
     *            the activation method.
     * @return a registration object for removing the listener
     * @throws IllegalArgumentException
     *             unless <code>method</code> has exactly one match in
     *             <code>object</code>
     * @throws NullPointerException
     *             if {@code object} is {@code null}
     * @since 8.12
     */
    public Registration addListener(Class<?> eventType,
            SerializableEventListener listener, Method method);

    /**
     * Registers a new listener with the specified activation method to listen
     * events generated by this component. If the activation method does not
     * have any arguments the event object will not be passed to it when it's
     * called.
     *
     * <p>
     * This version of <code>addListener</code> gets the name of the activation
     * method as a parameter. The actual method is reflected from
     * <code>object</code>, and unless exactly one match is found,
     * <code>java.lang.IllegalArgumentException</code> is thrown.
     * </p>
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the type of the listened event. Events of this type or its
     *            subclasses activate the listener.
     * @param object
     *            the object instance who owns the activation method.
     * @param methodName
     *            the name of the activation method.
     * @return a registration object for removing the listener
     * @throws IllegalArgumentException
     *             unless <code>method</code> has exactly one match in
     *             <code>object</code>
     * @throws NullPointerException
     *             if {@code object} is {@code null}
     * @since 8.0
     */
    @Deprecated
    public Registration addListener(Class<?> eventType, Object object,
            String methodName);

    /**
     * Registers a new listener with the specified activation method to listen
     * events generated by this component. If the activation method does not
     * have any arguments the event object will not be passed to it when it's
     * called.
     *
     * <p>
     * This version of <code>addListener</code> gets the name of the activation
     * method as a parameter. The actual method is reflected from
     * <code>listener</code>, and unless exactly one match is found,
     * <code>java.lang.IllegalArgumentException</code> is thrown.
     * </p>
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the type of the listened event. Events of this type or its
     *            subclasses activate the listener.
     * @param listener
     *            the listener instance who owns the activation method.
     * @param methodName
     *            the name of the activation method.
     * @return a registration object for removing the listener
     * @throws IllegalArgumentException
     *             unless <code>method</code> has exactly one match in
     *             <code>object</code>
     * @throws NullPointerException
     *             if {@code object} is {@code null}
     * @since 8.12
     */
    public Registration addListener(Class<?> eventType,
            SerializableEventListener object, String methodName);

    /**
     * Removes all registered listeners matching the given parameters. Since
     * this method receives the event type and the listener object as
     * parameters, it will unregister all <code>object</code>'s methods that are
     * registered to listen to events of type <code>eventType</code> generated
     * by this component.
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the exact event type the <code>object</code> listens to.
     * @param target
     *            the target object that has registered to listen to events of
     *            type <code>eventType</code> with one or more methods.
     */
    @Deprecated
    public void removeListener(Class<?> eventType, Object target);

    /**
     * Removes all registered listeners matching the given parameters. Since
     * this method receives the event type and the listener object as
     * parameters, it will unregister all <code>object</code>'s methods that are
     * registered to listen to events of type <code>eventType</code> generated
     * by this component.
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the exact event type the <code>object</code> listens to.
     * @param listener
     *            the listener that has registered to listen to events of type
     *            <code>eventType</code> with one or more methods.
     * @since 8.12
     */
    public void removeListener(Class<?> eventType,
            SerializableEventListener listener);

    /**
     * Removes one registered listener method. The given method owned by the
     * given object will no longer be called when the specified events are
     * generated by this component.
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the exact event type the <code>object</code> listens to.
     * @param target
     *            the target object that has registered to listen to events of
     *            type eventType with one or more methods.
     * @param method
     *            the method owned by the target that's registered to listen to
     *            events of type eventType.
     * @deprecated use a {@link Registration} returned by
     *             {@link #addListener(Class, Object, Method)}
     */
    @Deprecated
    public void removeListener(Class<?> eventType, Object target,
            Method method);

    /**
     * Removes one registered listener method. The given method owned by the
     * given object will no longer be called when the specified events are
     * generated by this component.
     *
     * <p>
     * This version of <code>removeListener</code> gets the name of the
     * activation method as a parameter. The actual method is reflected from the
     * target, and unless exactly one match is found,
     * <code>java.lang.IllegalArgumentException</code> is thrown.
     * </p>
     *
     * <p>
     * For more information on the inheritable event mechanism see the
     * {@link com.vaadin.event com.vaadin.event package documentation}.
     * </p>
     *
     * @param eventType
     *            the exact event type the <code>object</code> listens to.
     * @param target
     *            the target object that has registered to listen to events of
     *            type <code>eventType</code> with one or more methods.
     * @param methodName
     *            the name of the method owned by <code>target</code> that's
     *            registered to listen to events of type <code>eventType</code>.
     * @deprecated use a {@link Registration} returned by
     *             {@link #addListener(Class, Object, String)}
     */
    @Deprecated
    public void removeListener(Class<?> eventType, Object target,
            String methodName);
}