View Javadoc
1   /*
2    * Copyright (C) 2012-2024 RRiBbit.org
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.rribbit;
17  
18  import java.lang.reflect.Method;
19  import java.util.List;
20  
21  /**
22   * This class represents an executable {@link Listener}. All the details of the {@link Listener} annotation, the method that it's declared on and the target object are stored, so that RRiBbit
23   * has a ready-made object to execute when it receives a request that matches a {@link Listener}. Mainly used for internal processing of requests and responses, not for users of the RRiBbit library.
24   *
25   * @author G.J. Schouten
26   *
27   */
28  public class ListenerObject {
29  
30  	private Object target;
31  	private Method method;
32  
33  	private Class<?> returnType;
34  	private List<String> hints;
35  
36  	//For lazy toString() implementation
37  	private String description;
38  
39  	public Object getTarget() {
40  		return target;
41  	}
42  
43  	public void setTarget(Object target) {
44  		this.target = target;
45  	}
46  
47  	public Method getMethod() {
48  		return method;
49  	}
50  
51  	public void setMethod(Method method) {
52  		this.method = method;
53  	}
54  
55  	public Class<?> getReturnType() {
56  		return returnType;
57  	}
58  
59  	public void setReturnType(Class<?> returnType) {
60  		this.returnType = returnType;
61  	}
62  
63  	public List<String> getHints() {
64  		return hints;
65  	}
66  
67  	public void setHints(List<String> hints) {
68  		this.hints = hints;
69  	}
70  
71  	@Override
72  	public String toString() {
73  
74  		if(description == null) {
75  			StringBuilder s = new StringBuilder("ListenerObject of method: '" + method + "', with hints: '" + hints.get(0) + "'");
76  			for(int i=1; i<hints.size(); i++) {
77  				s.append(", '" + hints.get(i) + "'");
78  			}
79  			description = s.toString();
80  		}
81  		return description;
82  	}
83  }