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

com.dooapp.gaedo.finders.collections.AbstractBasicEvaluator Maven / Gradle / Ivy

There is a newer version: 1.0.16
Show newest version
package com.dooapp.gaedo.finders.collections;

import java.lang.reflect.Field;

import com.dooapp.gaedo.CrudServiceException;
import com.dooapp.gaedo.properties.Property;

/**
 * Root class for simple evaluators
 * @author ndx
 *
 * @param 
 */
public abstract class AbstractBasicEvaluator implements Evaluator {
	static class NonExistentFieldException extends CrudServiceException {
		public NonExistentFieldException(Property field, Object element) {
			super("The field \"" +
					field.toGenericString()+
					"\"does not exists for class \""+element.getClass().getName()+"\"");
		}
	}

	/**
	 * Field to introspect
	 */
	private final Property source;

	public AbstractBasicEvaluator(Property source) {
		super();
		this.source = source;
	}

	/**
	 * Common implementation of reflection-backed value getter
	 * @param element
	 * @return
	 */
	protected Object getValue(DataType element) {
		try {
			if(source==null)
				return element;
			else
				return source.get(element);
		} catch (Exception e) {
			throw new NonExistentFieldException(source, element);
		}
	}

	/**
	 * Basic evaluators never support adding subevaluators; As a consequence, they always fire an {@link UnsupportedOperationException}
	 */
	public final void add(Evaluator subEvaluator) {
		throw new UnsupportedOperationException("don't thing about adding a child evaluator to a basic condition "+getClass().getSimpleName()+" man !");
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy