All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.gkutiel.flip.web.MethodInvoker Maven / Gradle / Ivy

package com.github.gkutiel.flip.web;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.gkutiel.flip.web.annotation.MimeType;
import com.github.gkutiel.flip.web.annotation.Xsl;

abstract class MethodInvoker {

	protected final Method method;
	protected final Class clazz;

	MethodInvoker(final Class clazz, final Method method) {
		this.clazz = clazz;
		this.method = method;
		this.method.setAccessible(true);
	}

	protected Object getInstance(final HttpServletRequest req, final HttpServletResponse res) {
		try {
			final Object instance = this.clazz.newInstance();
			if (instance instanceof Flipper) {
				final Flipper flipper = (Flipper) instance;
				flipper.req = req;
				flipper.res = res;
			}
			return instance;
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
	}

	String getMimeType() {
		return this.method.getAnnotation(MimeType.class).value();
	}

	Xsl getXsl() {
		return this.method.getAnnotation(Xsl.class);
	}

	// TODO (gilad) this is bad !!! make this method not abstract and another abstract method that returns the actualParams
	abstract Object invoke(final HttpServletRequest req, final HttpServletResponse res);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy