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

org.objectquery.generic.ObjectQueryHandler Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.objectquery.generic;

import java.lang.reflect.Method;

import javassist.util.proxy.MethodHandler;

public class ObjectQueryHandler implements MethodHandler {

	private GenericObjectQuery abstractObjectQuery;
	private PathItem path;

	public ObjectQueryHandler(Class clazz, GenericObjectQuery abstractObjectQuery, PathItem parent, String name) {
		path = new PathItem(clazz, parent, name);
		this.abstractObjectQuery = abstractObjectQuery;
	}

	public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
		Object returnValue = null;
		String name = thisMethod.getName();
		if (name.startsWith("get") && Character.isUpperCase(name.charAt(3))) {
			returnValue = abstractObjectQuery.proxy(thisMethod.getReturnType(), path, Character.toLowerCase(name.charAt(3)) + name.substring(4));
		} else if (name.startsWith("is") && Character.isUpperCase(name.charAt(2))) {
			returnValue = abstractObjectQuery.proxy(thisMethod.getReturnType(), path, Character.toLowerCase(name.charAt(2)) + name.substring(3));
		} else {
			throw new ObjectQueryException("Unsupported opertation this is an Object for Query");
		}
		return returnValue;
	}

	public PathItem getPath() {
		return path;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy