ListenerObject.java

/*
 * Copyright (C) 2012-2024 RRiBbit.org
 *
 * 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
 *
 * https://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 org.rribbit;

import java.lang.reflect.Method;
import java.util.List;

/**
 * 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
 * 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.
 *
 * @author G.J. Schouten
 *
 */
public class ListenerObject {

	private Object target;
	private Method method;

	private Class<?> returnType;
	private List<String> hints;

	//For lazy toString() implementation
	private String description;

	public Object getTarget() {
		return target;
	}

	public void setTarget(Object target) {
		this.target = target;
	}

	public Method getMethod() {
		return method;
	}

	public void setMethod(Method method) {
		this.method = method;
	}

	public Class<?> getReturnType() {
		return returnType;
	}

	public void setReturnType(Class<?> returnType) {
		this.returnType = returnType;
	}

	public List<String> getHints() {
		return hints;
	}

	public void setHints(List<String> hints) {
		this.hints = hints;
	}

	@Override
	public String toString() {

		if(description == null) {
			StringBuilder s = new StringBuilder("ListenerObject of method: '" + method + "', with hints: '" + hints.get(0) + "'");
			for(int i=1; i<hints.size(); i++) {
				s.append(", '" + hints.get(i) + "'");
			}
			description = s.toString();
		}
		return description;
	}
}