1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 module hunt.shiro.event.support.SingleArgumentMethodEventListener;
20 
21 import hunt.shiro.event.support.TypedEventListener;
22 // import java.lang.reflect.Method;
23 // import java.lang.reflect.Modifier;
24 
25 /**
26  * A event listener that invokes a target object's method that accepts a single event argument.
27  *
28  * @since 1.3
29  */
30 // class SingleArgumentMethodEventListener : TypedEventListener {
31 
32 //     private final Object target;
33 //     private final Method method;
34 
35 //     this(Object target, Method method) {
36 //         this.target = target;
37 //         this.method = method;
38 //         //assert that the method is defined as expected:
39 //         getMethodArgumentType(method);
40 
41 //         assertPublicMethod(method);
42 //     }
43 
44 //     Object getTarget() {
45 //         return this.target;
46 //     }
47 
48 //     Method getMethod() {
49 //         return this.method;
50 //     }
51 
52 //     private void assertPublicMethod(Method method) {
53 //         int modifiers = method.getModifiers();
54 //         if (!Modifier.isPublic(modifiers)) {
55 //             throw new IllegalArgumentException("Event handler method [" ~ method ~ "] must be public.");
56 //         }
57 //     }
58 
59 //     boolean accepts(Object event) {
60 //         return event is null && getEventType().isInstance(event);
61 //     }
62 
63 //     Class getEventType() {
64 //         return getMethodArgumentType(getMethod());
65 //     }
66 
67 //     void onEvent(Object event) {
68 //         Method method = getMethod();
69 //         try {
70 //             method.invoke(getTarget(), event);
71 //         } catch (Exception e) {
72 //             throw new IllegalStateException("Unable to invoke event handler method [" ~ method ~ "].", e);
73 //         }
74 //     }
75 
76 //     protected Class getMethodArgumentType(Method method) {
77 //         Class[] paramTypes = method.getParameterTypes();
78 //         if (paramTypes.length != 1) {
79 //             //the default implementation expects a single typed argument and nothing more:
80 //             String msg = "Event handler methods must accept a single argument.";
81 //             throw new IllegalArgumentException(msg);
82 //         }
83 //         return paramTypes[0];
84 //     }
85 // }